r3-legacy/src/game-lib-component-offsetto...

64 lines
1.5 KiB
JavaScript
Raw Normal View History

2016-11-30 12:32:58 +01:00
/**
*
* @param id
* @param name
* @param axis {GameLib.D3.Vector3}
* @param getOffsetFunc
* @param userData
2016-11-30 12:32:58 +01:00
* @constructor
*/
GameLib.D3.ComponentOffsettor = function ComponentOffsettor(
id,
name,
axis,
getOffsetFunc,
userData
2016-11-30 12:32:58 +01:00
) {
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(entity, component, userData){ return 1; };
this.userData = userData;
2016-11-30 12:32:58 +01:00
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,
this,
this.userData
));
2016-11-30 12:32:58 +01:00
parentEntity.position.x += pos.x;
parentEntity.position.y += pos.y;
parentEntity.position.z += pos.z;
parentEntity.mesh.updateMatrix();
}
};
//#endif