2016-12-12 17:24:05 +01:00
|
|
|
/**
|
|
|
|
* Runtime apiVector4 for updating instance objects
|
|
|
|
* @param graphics GameLib.D3.Graphics
|
2016-12-15 14:53:39 +01:00
|
|
|
* @param apiVector4 GameLib.API.Vector4
|
2017-01-17 13:24:45 +01:00
|
|
|
* @param parentObject GameLib.*
|
2016-12-12 17:24:05 +01:00
|
|
|
* @param grain Number
|
|
|
|
* @constructor
|
|
|
|
*/
|
2017-01-17 13:24:45 +01:00
|
|
|
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
|
|
|
|
2017-05-11 04:48:02 +02:00
|
|
|
if (apiVector4 instanceof GameLib.Vector4) {
|
|
|
|
return apiVector4;
|
|
|
|
}
|
|
|
|
|
|
|
|
GameLib.API.Vector4.call(
|
2016-12-12 17:24:05 +01:00
|
|
|
this,
|
|
|
|
apiVector4.x,
|
|
|
|
apiVector4.y,
|
|
|
|
apiVector4.z,
|
|
|
|
apiVector4.w
|
|
|
|
);
|
|
|
|
|
2017-01-17 13:24:45 +01:00
|
|
|
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
|
|
|
};
|
|
|
|
|
2016-12-15 14:53:39 +01:00
|
|
|
GameLib.Vector4.prototype = Object.create(GameLib.API.Vector4.prototype);
|
|
|
|
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
|
|
|
|
*/
|
2016-12-15 14:53:39 +01:00
|
|
|
GameLib.Vector4.prototype.updateInstance = function() {
|
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
|
|
|
|
2017-01-17 13:24:45 +01:00
|
|
|
if (this.parentObject &&
|
|
|
|
this.parentObject.updateInstance) {
|
2016-12-12 17:24:05 +01:00
|
|
|
this.parentObject.updateInstance();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
};
|