/** * This component makes the parentEntity (ex. car) follow the path provided by the spline * @param graphics GameLib.D3.Graphics * @param parentObject * @param apiPathFollowing GameLib.D3.API.PathFollowing * @constructor */ GameLib.D3.PathFollowing = function RuntimePathFollowing( graphics, parentObject, apiPathFollowing ) { this.graphics = graphics; this.graphics.isNotThreeThrow(); if (GameLib.Utils.UndefinedOrNull(parentObject)) { parentObject = null; } this.parentObject = parentObject; GameLib.D3.API.PathFollowing.call( this, apiPathFollowing.id, apiPathFollowing.name, apiPathFollowing.spline, apiPathFollowing.raytraceMesh, apiPathFollowing.accelleration, apiPathFollowing.maxSpeed, apiPathFollowing.baseOffset, apiPathFollowing.maxOffset, apiPathFollowing.steeringSpeed, apiPathFollowing.targetOffset, apiPathFollowing.currentOffset, apiPathFollowing.currentPathValue, apiPathFollowing.currentSpeed, apiPathFollowing.direction, apiPathFollowing.raycaster, apiPathFollowing.currentPosition, apiPathFollowing.futurePosition, apiPathFollowing.up, apiPathFollowing.rotationMatrix, apiPathFollowing.rotationVector ); this.baseOffset = new GameLib.Vector3( this.graphics, this, this.baseOffset ); this.maxOffset = new GameLib.Vector3( this.graphics, this, this.maxOffset ); this.targetOffset = new GameLib.Vector3( this.graphics, this, this.targetOffset ); this.currentOffset = new GameLib.Vector3( this.graphics, this, this.currentOffset ); this.raycaster = new GameLib.D3.Raycaster( this.graphics, this, this.raycaster ); this.currentPosition = new GameLib.Vector3( this.graphics, this, this.currentPosition ); this.futurePosition = new GameLib.Vector3( this.graphics, this, this.futurePosition ); this.up = new GameLib.Vector3( this.graphics, this, this.up ); this.rotationMatrix = new GameLib.Matrix4( this.graphics, this, this.rotationMatrix ); this.rotationVector = new GameLib.Quaternion( this.graphics, this, this.rotationVector ); }; GameLib.D3.PathFollowing.prototype = Object.create(GameLib.D3.API.PathFollowing.prototype); GameLib.D3.PathFollowing.prototype.constructor = GameLib.D3.PathFollowing; GameLib.D3.PathFollowing.prototype.toApiComponent = function() { var apiPathFollowing = new GameLib.D3.API.PathFollowing( this.id, this.name, this.spline, this.raytraceMesh, this.accelleration, this.maxSpeed, this.baseOffset.toApiVector(), this.maxOffset.toApiVector(), this.steeringSpeed, this.targetOffset.toApiVector(), this.currentOffset.toApiVector(), this.currentPathValue, this.currentSpeed, this.direction, this.raycaster.toApiRaycaster(), this.currentPosition.toApiVector(), this.futurePosition.toApiVector(), this.up.toApiVector(), this.rotationMatrix.toApiMatrix(), this.rotationVector.toApiQuaternion() ); return apiPathFollowing; }; GameLib.D3.PathFollowing.FromObjectComponent = function(graphics, objectComponent) { var apiPathFollowing = new GameLib.D3.API.PathFollowing( objectComponent.id, objectComponent.name, objectComponent.spline, objectComponent.raytraceMesh, objectComponent.accelleration, objectComponent.maxSpeed, new GameLib.API.Vector3( objectComponent.baseOffset.x, objectComponent.baseOffset.y, objectComponent.baseOffset.z ), new GameLib.API.Vector3( objectComponent.maxOffset.x, objectComponent.maxOffset.y, objectComponent.maxOffset.z ), objectComponent.steeringSpeed, new GameLib.API.Vector3( objectComponent.targetOffset.x, objectComponent.targetOffset.y, objectComponent.targetOffset.z ), new GameLib.API.Vector3( objectComponent.currentOffset.x, objectComponent.currentOffset.y, objectComponent.currentOffset.z ), this.currentPathValue, this.currentSpeed, this.direction, new GameLib.D3.API.Raycaster( new GameLib.API.Vector3( objectComponent.raycaster.position.x, objectComponent.raycaster.position.y, objectComponent.raycaster.position.z ), new GameLib.API.Vector3( objectComponent.raycaster.direction.x, objectComponent.raycaster.direction.y, objectComponent.raycaster.direction.z ) ), new GameLib.API.Vector3( objectComponent.currentPosition.x, objectComponent.currentPosition.y, objectComponent.currentPosition.z ), new GameLib.API.Vector3( objectComponent.futurePosition.x, objectComponent.futurePosition.y, objectComponent.futurePosition.z ), new GameLib.API.Vector3( objectComponent.up.x, objectComponent.up.y, objectComponent.up.z ), //TODO : objectComponent rotationVector matrix4 new GameLib.API.Matrix4( new GameLib.API.Quaternion(), new GameLib.API.Quaternion(), new GameLib.API.Quaternion(), new GameLib.API.Quaternion() ), new GameLib.API.Quaternion( objectComponent.rotationVector.x, objectComponent.rotationVector.y, objectComponent.rotationVector.z, objectComponent.rotationVector.w ) ); return new GameLib.D3.PathFollowing( graphics, this, apiPathFollowing ); };