offset component
parent
9f96389ae5
commit
3aca24eb87
|
@ -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
|
Loading…
Reference in New Issue