2016-12-15 14:53:39 +01:00
|
|
|
/**
|
|
|
|
* Entities with LookAt component looks to targetPosition (default up is 0,1,0)
|
|
|
|
* @param graphics GameLib.D3.Graphics
|
|
|
|
* @param parentObject
|
|
|
|
* @param apiLookAt GameLib.D3.API.LookAt
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
GameLib.D3.LookAt = function RuntimeLookAt(
|
|
|
|
graphics,
|
|
|
|
parentObject,
|
|
|
|
apiLookAt
|
|
|
|
) {
|
|
|
|
this.graphics = graphics;
|
|
|
|
this.graphics.isNotThreeThrow();
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(parentObject)) {
|
|
|
|
parentObject = null;
|
|
|
|
}
|
|
|
|
this.parentObject = parentObject;
|
|
|
|
|
|
|
|
GameLib.D3.API.LookAt.call(
|
|
|
|
this,
|
2016-12-19 17:44:15 +01:00
|
|
|
apiLookAt.id,
|
|
|
|
apiLookAt.name,
|
|
|
|
apiLookAt.currentComponent,
|
|
|
|
apiLookAt.targetComponent,
|
|
|
|
apiLookAt.targetPositionOffset,
|
|
|
|
apiLookAt.rotationSpeed
|
2016-12-15 14:53:39 +01:00
|
|
|
);
|
|
|
|
|
2016-12-19 17:44:15 +01:00
|
|
|
this.targetPositionOffset = new GameLib.Vector3(
|
2016-12-15 14:53:39 +01:00
|
|
|
this.graphics,
|
|
|
|
this,
|
2016-12-19 17:44:15 +01:00
|
|
|
this.targetPositionOffset
|
2016-12-15 14:53:39 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
this.lookAtMatrix = new GameLib.Matrix4(
|
|
|
|
this.graphics,
|
|
|
|
this,
|
|
|
|
this.lookAtMatrix
|
|
|
|
);
|
|
|
|
|
|
|
|
this.up = new GameLib.Vector3(
|
|
|
|
this.graphics,
|
|
|
|
this,
|
|
|
|
this.up
|
|
|
|
);
|
|
|
|
|
|
|
|
this.currentRotation = new GameLib.Quaternion(
|
|
|
|
this.graphics,
|
|
|
|
this,
|
|
|
|
this.currentRotation
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
GameLib.D3.LookAt.prototype = Object.create(GameLib.D3.API.LookAt.prototype);
|
|
|
|
GameLib.D3.LookAt.prototype.constructor = GameLib.D3.LookAt;
|
2016-12-19 17:44:15 +01:00
|
|
|
|
|
|
|
GameLib.D3.LookAt.prototype.toApiComponent = function() {
|
|
|
|
|
|
|
|
var apiLookAt = new GameLib.D3.API.LookAt(
|
|
|
|
this.id,
|
|
|
|
this.name,
|
|
|
|
GameLib.Utils.IdOrNull(this.currentComponent),
|
|
|
|
GameLib.Utils.IdOrNull(this.targetComponent),
|
|
|
|
this.targetPositionOffset.toApiVector(),
|
|
|
|
this.rotationSpeed
|
|
|
|
);
|
|
|
|
|
|
|
|
return apiLookAt;
|
|
|
|
};
|
|
|
|
|
|
|
|
GameLib.D3.LookAt.FromObjectComponent = function(graphics, objectComponent) {
|
|
|
|
|
|
|
|
var apiLookAt = new GameLib.D3.API.LookAt(
|
|
|
|
objectComponent.id,
|
|
|
|
objectComponent.name,
|
|
|
|
objectComponent.currentComponent,
|
|
|
|
objectComponent.targetComponent,
|
|
|
|
objectComponent.targetPositionOffset,
|
|
|
|
objectComponent.rotationSpeed
|
|
|
|
);
|
|
|
|
|
|
|
|
return new GameLib.D3.LookAt(
|
|
|
|
graphics,
|
|
|
|
this,
|
|
|
|
apiLookAt
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the component
|
|
|
|
* @param deltaTime
|
|
|
|
*/
|
|
|
|
GameLib.D3.LookAt.prototype.update = function(deltaTime) {
|
|
|
|
|
|
|
|
};
|