/** * * @param id * @param name * @param axis {GameLib.D3.Vector3} * @param getOffsetFunc {function} * @param userData {Object} * @constructor */ GameLib.D3.ComponentOffsettor = function ComponentOffsettor( id, name, axis, getOffsetFunc, userData ) { 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.offset = 1; var component = this; this.getOffsetFunc = getOffsetFunc || function(entity, component, userData){ return component.offset; }; this.userData = userData; 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 )); parentEntity.position.x += pos.x; parentEntity.position.y += pos.y; parentEntity.position.z += pos.z; parentEntity.mesh.updateMatrix(); } }; //#endif