/** * Runtime apiVector4 for updating instance objects * @param graphics GameLib.GraphicsRuntime * @param apiVector4 GameLib.API.Vector4 * @param parentObject GameLib.* * @param grain Number * @constructor */ GameLib.Vector4 = function ( graphics, apiVector4, parentObject, grain ) { this.graphics = graphics; this.graphics.isNotThreeThrow(); if (GameLib.Utils.UndefinedOrNull(apiVector4)) { apiVector4 = {}; } GameLib.API.Vector4.call( this, apiVector4.x, apiVector4.y, apiVector4.z, apiVector4.w ); if (GameLib.Utils.UndefinedOrNull(parentObject)) { parentObject = null; } this.parentObject = parentObject; if (GameLib.Utils.UndefinedOrNull(grain)) { grain = 0.001; } this.grain = grain; this.createInstance(); }; GameLib.Vector4.prototype = Object.create(GameLib.API.Vector4.prototype); GameLib.Vector4.prototype.constructor = GameLib.Vector4; /** * Creates an instance vector4 * @returns {*} */ GameLib.Vector4.prototype.createInstance = function() { this.instance = new THREE.Quaternion( this.x, this.y, this.z, this.w ); }; /** * Updates the instance vector, calls updateInstance on the parent object */ GameLib.Vector4.prototype.updateInstance = function(property) { this.instance.x = this.x; this.instance.y = this.y; this.instance.z = this.z; this.instance.w = this.w; if (this.parentObject && this.parentObject.updateInstance) { this.parentObject.updateInstance(property); } }; /** * Converts runtime vector to API Vector */ GameLib.Vector4.prototype.toApiObject = function() { return new GameLib.API.Vector4( this.x, this.y, this.z, this.w ); };