/** * Runtime apiVector3 for updating instance objects * @param graphics GameLib.D3.Graphics * @param parentObject GameLib.D3.* * @param apiVector3 GameLib.API.Vector3 * @param grain Number * @constructor */ GameLib.Vector3 = function RuntimeVector3(graphics, parentObject, apiVector3, grain) { for (var property in apiVector3) { if (apiVector3.hasOwnProperty(property)) { this[property] = apiVector3[property]; } } GameLib.Utils.Extend(GameLib.Vector3, GameLib.API.Vector3); this.graphics = graphics; this.graphics.isNotThreeThrow(); this.parentObject = parentObject; if (GameLib.Utils.UndefinedOrNull(grain)) { grain = 0.001; } this.grain = grain; this.instance = this.createInstance(); }; /** * Creates an instance vector3 * @param update * @returns {*} */ GameLib.Vector3.prototype.createInstance = function(update) { var instance = null; if (update) { instance = this.instance; instance.x = this.x; instance.y = this.y; instance.z = this.z; } else { instance = new THREE.Vector3(this.x, this.y, this.z); } return instance; }; /** * Updates the instance vector, calls updateInstance on the parent object */ GameLib.Vector3.prototype.updateInstance = function() { this.createInstance(true); if (this.parentObject.updateInstance) { this.parentObject.updateInstance(); } }; /** * Converts runtime vector to API Vector */ GameLib.Vector3.prototype.toApiVector = function() { return new GameLib.API.Vector3( this.x, this.y, this.z ); }; /** * Converts runtime vector to API Vector */ GameLib.Vector3.prototype.copy = function() { return new GameLib.Vector3( this.graphics, this.parentObject, new GameLib.API.Vector3( this.x, this.y, this.z ), this.grain ) };