2016-12-15 14:53:39 +01:00
|
|
|
/**
|
|
|
|
* Looks from currentPosition to targetPosition (default up is 0,1,0)
|
|
|
|
* @param id
|
|
|
|
* @param name
|
2016-12-19 17:44:15 +01:00
|
|
|
* @param currentComponent GameLib.Component
|
|
|
|
* @param targetComponent GameLib.Component
|
2016-12-15 14:53:39 +01:00
|
|
|
* @param targetPositionOffset GameLib.API.Vector3
|
|
|
|
* @param rotationSpeed Number
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
GameLib.D3.API.LookAt = function (
|
|
|
|
id,
|
|
|
|
name,
|
2016-12-19 17:44:15 +01:00
|
|
|
currentComponent,
|
|
|
|
targetComponent,
|
2016-12-15 14:53:39 +01:00
|
|
|
targetPositionOffset,
|
2016-12-19 17:44:15 +01:00
|
|
|
rotationSpeed
|
2016-12-15 14:53:39 +01:00
|
|
|
) {
|
|
|
|
|
2016-12-19 17:44:15 +01:00
|
|
|
GameLib.Component.call(
|
|
|
|
this,
|
|
|
|
GameLib.Component.COMPONENT_LOOK_AT,
|
|
|
|
[
|
|
|
|
'currentComponent',
|
|
|
|
'targetComponent'
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
2016-12-15 14:53:39 +01:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
|
|
|
id = GameLib.Utils.RandomId();
|
|
|
|
}
|
|
|
|
this.id = id;
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(name)) {
|
|
|
|
name = this.constructor.name;
|
|
|
|
}
|
|
|
|
this.name = name;
|
|
|
|
|
2016-12-19 17:44:15 +01:00
|
|
|
if(GameLib.Utils.UndefinedOrNull(currentComponent)) {
|
|
|
|
currentComponent = null;
|
2016-12-15 14:53:39 +01:00
|
|
|
}
|
2016-12-19 17:44:15 +01:00
|
|
|
this.currentComponent = currentComponent;
|
2016-12-15 14:53:39 +01:00
|
|
|
|
2016-12-19 17:44:15 +01:00
|
|
|
if(GameLib.Utils.UndefinedOrNull(targetComponent)) {
|
|
|
|
targetComponent = null;
|
2016-12-15 14:53:39 +01:00
|
|
|
}
|
2016-12-19 17:44:15 +01:00
|
|
|
this.targetComponent = targetComponent;
|
2016-12-15 14:53:39 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2016-12-19 17:44:15 +01:00
|
|
|
this.lookAtMatrix = new GameLib.API.Matrix4();
|
2016-12-15 14:53:39 +01:00
|
|
|
|
2016-12-19 17:44:15 +01:00
|
|
|
this.up = new GameLib.API.Vector3(0, 1, 0);
|
2016-12-15 14:53:39 +01:00
|
|
|
|
2016-12-19 17:44:15 +01:00
|
|
|
this.currentRotation = new GameLib.API.Quaternion();
|
2016-12-15 14:53:39 +01:00
|
|
|
};
|
2016-12-19 17:44:15 +01:00
|
|
|
|
|
|
|
GameLib.D3.API.LookAt.prototype = Object.create(GameLib.Component.prototype);
|
|
|
|
GameLib.D3.API.LookAt.prototype.constructor = GameLib.D3.API.LookAt;
|