/** * R3.Quaternion * @param apiComponent * @constructor */ R3.Quaternion = function( apiComponent ) { __RUNTIME_COMPONENT__; Object.defineProperty( this, 'angle', R3.Utils.LimitToPI('angle', this.angle) ); __UPGRADE_TO_RUNTIME__; }; R3.Quaternion.prototype = Object.create(R3.Component.prototype); R3.Quaternion.prototype.constructor = R3.Quaternion; /** * Creates an instance quaternion * @returns {*} */ R3.Quaternion.prototype.createInstance = function() { var runtime = R3.Component.GetComponentRuntime(this.parent); switch (runtime) { case R3.Runtime.GRAPHICS : this.instance = new this.graphics.Quaternion( this.x, this.y, this.z, this.w ); break; case R3.Runtime.PHYSICS : this.instance = new this.physics.Quaternion( this.x, this.y, this.z, this.w ); break; default: throw new Error('unhandled component runtime: ' + runtime); } __CREATE_INSTANCE__; }; /** * Updates the instance vector, calls updateInstance on the parent object */ R3.Quaternion.prototype.updateInstance = function(property) { if (property === 'x') { this.instance.x = this.x; return; } if (property === 'y') { this.instance.y = this.y; return; } if (property === 'z') { this.instance.z = this.z; return; } if (property === 'w') { this.instance.w = this.w; return; } if (property === 'axis') { console.warn('todo: axis update'); return; } if (property === 'angle') { console.warn('todo: angle update'); return; } __UPDATE_INSTANCE__; }; /** * Checks if quaternion is equal to another quaternion * @param quaternion * @returns {boolean} */ R3.Quaternion.prototype.equals = function(quaternion) { return ( this.x === quaternion.x && this.y === quaternion.y && this.z === quaternion.z && this.w === quaternion.w && this.axis.equals(quaternion.axis) && this.angle === quaternion.angle ); }; R3.Quaternion.prototype.setFrom = function(quaternion) { this.x = quaternion.x; this.y = quaternion.y; this.z = quaternion.z; this.w = quaternion.w; this.axis.setFrom(quaternion.axis); this.angle = quaternion.angle; }; R3.Quaternion.prototype.copy = function() { R3.API.Quaternion.prototype.copy.call(this); };