offset component

beta.r3js.org
polygonboutique 2016-11-30 12:32:58 +01:00
parent 9f96389ae5
commit 3aca24eb87
1 changed files with 57 additions and 0 deletions

View File

@ -0,0 +1,57 @@
/**
*
* @param id
* @param name
* @param axis {GameLib.D3.Vector3}
* @param getOffsetFunc
* @constructor
*/
GameLib.D3.ComponentOffsettor = function ComponentOffsettor(
id,
name,
axis,
getOffsetFunc
) {
this.id = id || GameLib.D3.Tools.RandomId();
if (typeof name == 'undefined') {
name = this.constructor.name;
}
this.name = name;
this.parentEntity = null;
this.axis = axis || new GameLib.D3.Vector3();
this.getOffsetFunc = getOffsetFunc || function(){ return 1; };
GameLib.D3.Utils.Extend(GameLib.D3.ComponentOffsettor, GameLib.D3.ComponentInterface);
};
//#ifdef RUNTIME__
///////////////////////// Methods to override //////////////////////////
GameLib.D3.ComponentOffsettor.prototype.onLateUpdate = function(
deltaTime,
parentEntity
) {
if(parentEntity) {
var pos = new THREE.Vector3(
this.axis.x,
this.axis.y,
this.axis.z
).normalize().applyQuaternion(
new THREE.Quaternion(
parentEntity.quaternion.x,
parentEntity.quaternion.y,
parentEntity.quaternion.z,
parentEntity.quaternion.w
)
).multiplyScalar(this.getOffsetFunc());
parentEntity.position.x += pos.x;
parentEntity.position.y += pos.y;
parentEntity.position.z += pos.z;
parentEntity.mesh.updateMatrix();
}
};
//#endif