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

86 lines
2.3 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
) {
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();
2017-06-16 15:49:53 +02:00
if(GameLib.Utils.UndefinedOrNull(parentEntity)) {
parentEntity = null;
}
this.parentEntity = parentEntity;
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);
2017-01-06 16:53:53 +01:00
GameLib.D3.API.LookAt.prototype.constructor = GameLib.D3.API.LookAt;
/**
* Object to GameLib.D3.API.LookAt
* @param objectComponent
* @returns {GameLib.D3.API.LookAt}
* @constructor
*/
2017-06-14 14:21:57 +02:00
GameLib.D3.API.LookAt.FromObject = function(objectComponent) {
2017-01-06 16:53:53 +01:00
return new GameLib.D3.API.LookAt(
objectComponent.id,
objectComponent.name,
objectComponent.currentComponent,
objectComponent.targetComponent,
2017-06-14 14:21:57 +02:00
GameLib.API.Vector3.FromObject(objectComponent.targetPositionOffset),
2017-01-06 16:53:53 +01:00
objectComponent.rotationSpeed,
objectComponent.parentEntity
);
};