r3-legacy/bak/game-lib-d3-api-path-follow...

204 lines
5.8 KiB
JavaScript

/**
* This component makes the parentEntity (ex. car) follow the path provided by the spline
* @param id String
* @param name String
* @param spline GameLib.D3.API.Spline
* @param mesh GameLib.D3.API.Mesh
* @param raytraceMesh GameLib.D3.API.Mesh
* @param accelleration Number
* @param maxSpeed Number
* @param baseOffset GameLib.API.Vector
* @param maxOffset GameLib.API.Vector
* @param steeringSpeed Number
* @param targetOffset GameLib.API.Vector3
* @param currentOffset GameLib.API.Vector3
* @param currentPathValue Number
* @param currentSpeed Number
* @param direction Number
* @param raycaster GameLib.D3.Raycaster
* @param currentPosition GameLib.API.Vector3
* @param futurePosition GameLib.API.Vector3
* @param up GameLib.API.Vector3
* @param rotationMatrix GameLib.API.Matrix4
* @param rotationVector GameLib.API.Quaternion
* @param parentEntity
* @constructor
*/
GameLib.D3.API.PathFollowing = function (
id,
name,
spline,
mesh,
raytraceMesh,
accelleration,
maxSpeed,
baseOffset,
maxOffset,
steeringSpeed,
targetOffset,
currentOffset,
currentPathValue,
currentSpeed,
direction,
raycaster,
currentPosition,
futurePosition,
up,
rotationMatrix,
rotationVector,
parentEntity
) {
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
this.id = id;
if (GameLib.Utils.UndefinedOrNull(name)) {
name = this.constructor.name;
}
this.name = name;
if (GameLib.Utils.UndefinedOrNull(spline)) {
spline = null;
}
this.spline = spline;
if (GameLib.Utils.UndefinedOrNull(mesh)) {
mesh = null;
}
this.mesh = mesh;
if (GameLib.Utils.UndefinedOrNull(raytraceMesh)) {
raytraceMesh = null;
}
this.raytraceMesh = raytraceMesh;
if (GameLib.Utils.UndefinedOrNull(maxSpeed)) {
maxSpeed = 0.03;
}
this.maxSpeed = maxSpeed;
if (GameLib.Utils.UndefinedOrNull(accelleration)) {
accelleration = 0.1;
}
this.accelleration = accelleration;
if (GameLib.Utils.UndefinedOrNull(baseOffset)) {
baseOffset = new GameLib.API.Vector3();
}
this.baseOffset = baseOffset;
if (GameLib.Utils.UndefinedOrNull(maxOffset)) {
maxOffset = new GameLib.API.Vector3();
}
this.maxOffset = maxOffset;
if (GameLib.Utils.UndefinedOrNull(steeringSpeed)) {
steeringSpeed = 1.0;
}
this.steeringSpeed = steeringSpeed;
if (GameLib.Utils.UndefinedOrNull(targetOffset)) {
targetOffset = new GameLib.API.Vector3();
}
this.targetOffset = targetOffset;
if (GameLib.Utils.UndefinedOrNull(currentOffset)) {
currentOffset = new GameLib.API.Vector3();
}
this.currentOffset = currentOffset;
if (GameLib.Utils.UndefinedOrNull(currentPathValue)) {
currentPathValue = 0;
}
this.currentPathValue = currentPathValue;
if (GameLib.Utils.UndefinedOrNull(currentSpeed)) {
currentSpeed = 0;
}
this.currentSpeed = currentSpeed;
if (GameLib.Utils.UndefinedOrNull(direction)) {
direction = 1;
}
this.direction = direction;
if (GameLib.Utils.UndefinedOrNull(raycaster)) {
raycaster = new GameLib.D3.API.Raycaster();
}
this.raycaster = raycaster;
if (GameLib.Utils.UndefinedOrNull(currentPosition)) {
currentPosition = new GameLib.API.Vector3();
}
this.currentPosition = currentPosition;
if (GameLib.Utils.UndefinedOrNull(futurePosition)) {
futurePosition = new GameLib.API.Vector3();
}
this.futurePosition = futurePosition;
if(GameLib.Utils.UndefinedOrNull(up)) {
up = new GameLib.API.Vector3(0, 1, 0);
}
this.up = up;
if (GameLib.Utils.UndefinedOrNull(rotationMatrix)) {
rotationMatrix = new GameLib.API.Matrix4();
}
this.rotationMatrix = rotationMatrix;
if (GameLib.Utils.UndefinedOrNull(rotationVector)) {
rotationVector = new GameLib.API.Quaternion();
}
this.rotationVector = rotationVector;
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
parentEntity = null;
}
this.parentEntity = parentEntity;
};
GameLib.D3.API.PathFollowing.prototype = Object.create(GameLib.Component.prototype);
GameLib.D3.API.PathFollowing.prototype.constructor = GameLib.D3.API.PathFollowing;
/**
* Returns an API path following component from an Object path following component
* @param objectComponent
* @constructor
*/
GameLib.D3.API.PathFollowing.FromObject = function(objectComponent) {
var apiRaycaster = null;
if (objectComponent.raycaster) {
apiRaycaster = GameLib.D3.API.Raycaster.FromObject(objectComponent.raycaster);
}
return new GameLib.D3.API.PathFollowing(
objectComponent.id,
objectComponent.name,
objectComponent.spline,
objectComponent.mesh,
objectComponent.raytraceMesh,
objectComponent.accelleration,
objectComponent.maxSpeed,
GameLib.API.Vector3.FromObject(objectComponent.baseOffset),
GameLib.API.Vector3.FromObject(objectComponent.maxOffset),
objectComponent.steeringSpeed,
GameLib.API.Vector3.FromObject(objectComponent.targetOffset),
GameLib.API.Vector3.FromObject(objectComponent.currentOffset),
objectComponent.currentPathValue,
objectComponent.currentSpeed,
objectComponent.direction,
apiRaycaster,
GameLib.API.Vector3.FromObject(objectComponent.currentPosition),
GameLib.API.Vector3.FromObject(objectComponent.futurePosition),
GameLib.API.Vector3.FromObject(objectComponent.up),
GameLib.API.Matrix4.FromObject(objectComponent.rotationMatrix),
GameLib.API.Quaternion.FromObject(objectComponent.rotationVector),
objectComponent.parentEntity
);
};