r3-legacy/src/game-lib-vector4.js

80 lines
1.8 KiB
JavaScript
Raw Normal View History

2016-12-12 17:24:05 +01:00
/**
* Runtime apiVector4 for updating instance objects
* @param graphics GameLib.D3.Graphics
* @param parentObject GameLib.D3.*
* @param apiVector4 GameLib.D3.API.Vector4
* @param grain Number
* @constructor
*/
GameLib.D3.Vector4 = function RuntimeVector4(graphics, parentObject, apiVector4, grain) {
GameLib.D3.API.Vector4.call(
this,
apiVector4.x,
apiVector4.y,
apiVector4.z,
apiVector4.w
);
this.graphics = graphics;
this.graphics.isNotThreeThrow();
this.parentObject = parentObject;
if (GameLib.D3.Utils.UndefinedOrNull(grain)) {
grain = 0.001;
}
this.grain = grain;
this.instance = this.createInstance();
};
GameLib.D3.Vector4.prototype = Object.create(GameLib.D3.API.Vector4.prototype);
GameLib.D3.Vector4.prototype.constructor = GameLib.D3.Vector4;
/**
* Creates an instance vector3
* @param update
* @returns {*}
*/
GameLib.D3.Vector4.prototype.createInstance = function(update) {
var instance = null;
if (update) {
instance = this.instance;
instance.x = this.x;
instance.y = this.y;
instance.z = this.z;
instance.w = this.w;
} else {
instance = new THREE.Quaternion(this.x, this.y, this.z, this.w);
}
return instance;
};
/**
* Updates the instance vector, calls updateInstance on the parent object
*/
GameLib.D3.Vector4.prototype.updateInstance = function() {
this.createInstance(true);
if (this.parentObject.updateInstance) {
this.parentObject.updateInstance();
}
};
/**
* Converts runtime vector to API Vector
*/
GameLib.D3.Vector4.prototype.toApiVector = function() {
return new GameLib.D3.API.Vector4(
this.x,
this.y,
this.z,
this.w
);
};