69 lines
1.8 KiB
JavaScript
69 lines
1.8 KiB
JavaScript
/**
|
|
* Looks from currentPosition to targetPosition (default up is 0,1,0)
|
|
* @param id
|
|
* @param name
|
|
* @param currentComponent GameLib.Component
|
|
* @param targetComponent GameLib.Component
|
|
* @param targetPositionOffset GameLib.API.Vector3
|
|
* @param rotationSpeed Number
|
|
* @constructor
|
|
*/
|
|
GameLib.D3.API.LookAt = function (
|
|
id,
|
|
name,
|
|
currentComponent,
|
|
targetComponent,
|
|
targetPositionOffset,
|
|
rotationSpeed
|
|
) {
|
|
|
|
GameLib.Component.call(
|
|
this,
|
|
GameLib.Component.COMPONENT_LOOK_AT,
|
|
{
|
|
'currentComponent' : GameLib.Component,
|
|
'targetComponent' : GameLib.Component
|
|
}
|
|
);
|
|
|
|
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(currentComponent)) {
|
|
currentComponent = null;
|
|
}
|
|
this.currentComponent = currentComponent;
|
|
|
|
if(GameLib.Utils.UndefinedOrNull(targetComponent)) {
|
|
targetComponent = null;
|
|
}
|
|
this.targetComponent = targetComponent;
|
|
|
|
if(GameLib.Utils.UndefinedOrNull(targetPositionOffset)) {
|
|
targetPositionOffset = new GameLib.API.Vector3(0, 0, 0);
|
|
}
|
|
this.targetPositionOffset = targetPositionOffset;
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(rotationSpeed)) {
|
|
rotationSpeed = 22.0;
|
|
}
|
|
this.rotationSpeed = rotationSpeed;
|
|
|
|
this.lookAtMatrix = new GameLib.API.Matrix4();
|
|
|
|
this.up = new GameLib.API.Vector3(0, 1, 0);
|
|
|
|
this.currentRotation = new GameLib.API.Quaternion();
|
|
|
|
this.targetPosition = new GameLib.API.Vector3();
|
|
};
|
|
|
|
GameLib.D3.API.LookAt.prototype = Object.create(GameLib.Component.prototype);
|
|
GameLib.D3.API.LookAt.prototype.constructor = GameLib.D3.API.LookAt; |