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

87 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.GraphicsRuntime
2016-12-15 14:53:39 +01:00
* @param apiVector4 GameLib.API.Vector4
* @param parentObject GameLib.*
2016-12-12 17:24:05 +01:00
* @param grain Number
* @constructor
*/
GameLib.Vector4 = function (
graphics,
apiVector4,
parentObject,
grain
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(apiVector4)) {
apiVector4 = {};
}
2016-12-12 17:24:05 +01:00
GameLib.API.Vector4.call(
2016-12-12 17:24:05 +01:00
this,
apiVector4.x,
apiVector4.y,
apiVector4.z,
apiVector4.w
);
if (GameLib.Utils.UndefinedOrNull(parentObject)) {
parentObject = null;
}
2016-12-12 17:24:05 +01:00
this.parentObject = parentObject;
2016-12-15 14:53:39 +01:00
if (GameLib.Utils.UndefinedOrNull(grain)) {
2016-12-12 17:24:05 +01:00
grain = 0.001;
}
this.grain = grain;
2017-10-23 14:52:35 +02:00
this.createInstance();
2016-12-12 17:24:05 +01:00
};
2018-01-11 14:33:32 +01:00
GameLib.Vector4.prototype = Object.create(GameLib.API.Vector4.prototype);
2016-12-15 14:53:39 +01:00
GameLib.Vector4.prototype.constructor = GameLib.Vector4;
2016-12-12 17:24:05 +01:00
/**
2017-10-23 14:52:35 +02:00
* Creates an instance vector4
2016-12-12 17:24:05 +01:00
* @returns {*}
*/
2017-10-23 14:52:35 +02:00
GameLib.Vector4.prototype.createInstance = function() {
this.instance = new THREE.Quaternion(
this.x,
this.y,
this.z,
this.w
);
2016-12-12 17:24:05 +01:00
};
/**
* Updates the instance vector, calls updateInstance on the parent object
*/
2017-11-05 15:53:23 +01:00
GameLib.Vector4.prototype.updateInstance = function(property) {
2016-12-12 17:24:05 +01:00
2017-10-23 14:52:35 +02:00
this.instance.x = this.x;
this.instance.y = this.y;
this.instance.z = this.z;
this.instance.w = this.w;
2016-12-12 17:24:05 +01:00
if (this.parentObject &&
this.parentObject.updateInstance) {
2017-11-05 15:53:23 +01:00
this.parentObject.updateInstance(property);
2016-12-12 17:24:05 +01:00
}
};
/**
* Converts runtime vector to API Vector
*/
2017-05-16 14:51:57 +02:00
GameLib.Vector4.prototype.toApiObject = function() {
2016-12-15 14:53:39 +01:00
return new GameLib.API.Vector4(
2016-12-12 17:24:05 +01:00
this.x,
this.y,
this.z,
this.w
);
2017-01-02 17:05:40 +01:00
};