r3-legacy/src/game-lib-d3-api-look-at.js

73 lines
1.9 KiB
JavaScript
Raw Normal View History

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
2017-01-02 17:05:40 +01:00
* @param parentEntity
2016-12-15 14:53:39 +01:00
* @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,
2017-01-02 17:05:40 +01:00
rotationSpeed,
parentEntity
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' : GameLib.Component,
'targetComponent' : GameLib.Component
2017-01-02 17:05:40 +01:00
},
null,
parentEntity
2016-12-19 17:44:15 +01:00
);
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();
this.targetPosition = new GameLib.API.Vector3();
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;