/** * Looks from currentPosition to targetPosition (default up is 0,1,0) * @param id * @param name * @param currentComponent GameLib.Component * @param targetComponent GameLib.Component * @param targetPositionOffset GameLib.API.Vector3 * @param rotationSpeed Number * @param parentEntity * @constructor */ GameLib.D3.API.LookAt = function ( id, name, currentComponent, targetComponent, targetPositionOffset, rotationSpeed, parentEntity ) { if (GameLib.Utils.UndefinedOrNull(id)) { id = GameLib.Utils.RandomId(); } this.id = id; if (GameLib.Utils.UndefinedOrNull(name)) { name = this.constructor.name; } this.name = name; if(GameLib.Utils.UndefinedOrNull(currentComponent)) { currentComponent = null; } this.currentComponent = currentComponent; if(GameLib.Utils.UndefinedOrNull(targetComponent)) { targetComponent = null; } this.targetComponent = targetComponent; 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; this.lookAtMatrix = new GameLib.API.Matrix4(); this.up = new GameLib.API.Vector3(0, 1, 0); this.currentRotation = new GameLib.API.Quaternion(); this.targetPosition = new GameLib.API.Vector3(); if(GameLib.Utils.UndefinedOrNull(parentEntity)) { parentEntity = null; } this.parentEntity = parentEntity; }; GameLib.D3.API.LookAt.prototype = Object.create(GameLib.Component.prototype); GameLib.D3.API.LookAt.prototype.constructor = GameLib.D3.API.LookAt; /** * Object to GameLib.D3.API.LookAt * @param objectComponent * @returns {GameLib.D3.API.LookAt} * @constructor */ GameLib.D3.API.LookAt.FromObject = function(objectComponent) { return new GameLib.D3.API.LookAt( objectComponent.id, objectComponent.name, objectComponent.currentComponent, objectComponent.targetComponent, GameLib.API.Vector3.FromObject(objectComponent.targetPositionOffset), objectComponent.rotationSpeed, objectComponent.parentEntity ); };