86 lines
2.1 KiB
JavaScript
86 lines
2.1 KiB
JavaScript
|
/**
|
||
|
* Looks from currentPosition to targetPosition (default up is 0,1,0)
|
||
|
* @param id
|
||
|
* @param name
|
||
|
* @param currentComponent R3.Component
|
||
|
* @param targetComponent R3.Component
|
||
|
* @param targetPositionOffset R3.API.Vector3
|
||
|
* @param rotationSpeed Number
|
||
|
* @param parentEntity
|
||
|
* @constructor
|
||
|
*/
|
||
|
R3.D3.API.LookAt = function (
|
||
|
id,
|
||
|
name,
|
||
|
currentComponent,
|
||
|
targetComponent,
|
||
|
targetPositionOffset,
|
||
|
rotationSpeed,
|
||
|
parentEntity
|
||
|
) {
|
||
|
|
||
|
if (R3.Utils.UndefinedOrNull(id)) {
|
||
|
id = R3.Utils.RandomId();
|
||
|
}
|
||
|
this.id = id;
|
||
|
|
||
|
if (R3.Utils.UndefinedOrNull(name)) {
|
||
|
name = this.constructor.name;
|
||
|
}
|
||
|
this.name = name;
|
||
|
|
||
|
if(R3.Utils.UndefinedOrNull(currentComponent)) {
|
||
|
currentComponent = null;
|
||
|
}
|
||
|
this.currentComponent = currentComponent;
|
||
|
|
||
|
if(R3.Utils.UndefinedOrNull(targetComponent)) {
|
||
|
targetComponent = null;
|
||
|
}
|
||
|
this.targetComponent = targetComponent;
|
||
|
|
||
|
if(R3.Utils.UndefinedOrNull(targetPositionOffset)) {
|
||
|
targetPositionOffset = new R3.API.Vector3(0, 0, 0);
|
||
|
}
|
||
|
this.targetPositionOffset = targetPositionOffset;
|
||
|
|
||
|
if (R3.Utils.UndefinedOrNull(rotationSpeed)) {
|
||
|
rotationSpeed = 22.0;
|
||
|
}
|
||
|
this.rotationSpeed = rotationSpeed;
|
||
|
|
||
|
this.lookAtMatrix = new R3.API.Matrix4();
|
||
|
|
||
|
this.up = new R3.API.Vector3(0, 1, 0);
|
||
|
|
||
|
this.currentRotation = new R3.API.Quaternion();
|
||
|
|
||
|
this.targetPosition = new R3.API.Vector3();
|
||
|
|
||
|
if(R3.Utils.UndefinedOrNull(parentEntity)) {
|
||
|
parentEntity = null;
|
||
|
}
|
||
|
this.parentEntity = parentEntity;
|
||
|
};
|
||
|
|
||
|
R3.D3.API.LookAt.prototype = Object.create(R3.Component.prototype);
|
||
|
R3.D3.API.LookAt.prototype.constructor = R3.D3.API.LookAt;
|
||
|
|
||
|
/**
|
||
|
* Object to R3.D3.API.LookAt
|
||
|
* @param objectComponent
|
||
|
* @returns {R3.D3.API.LookAt}
|
||
|
* @constructor
|
||
|
*/
|
||
|
R3.D3.API.LookAt.FromObject = function(objectComponent) {
|
||
|
return new R3.D3.API.LookAt(
|
||
|
objectComponent.id,
|
||
|
objectComponent.name,
|
||
|
objectComponent.currentComponent,
|
||
|
objectComponent.targetComponent,
|
||
|
R3.API.Vector3.FromObject(objectComponent.targetPositionOffset),
|
||
|
objectComponent.rotationSpeed,
|
||
|
objectComponent.parentEntity
|
||
|
);
|
||
|
};
|