rotator component
parent
2895b74b6c
commit
9f96389ae5
|
@ -44,7 +44,7 @@ GameLib.D3.ComponentPathAI.prototype.onUpdate = function(
|
||||||
deltaTime,
|
deltaTime,
|
||||||
parentEntity
|
parentEntity
|
||||||
) {
|
) {
|
||||||
var forward = false;
|
var forward = true;
|
||||||
var backward = false;
|
var backward = false;
|
||||||
var left = false;
|
var left = false;
|
||||||
var right = false;
|
var right = false;
|
||||||
|
|
|
@ -0,0 +1,72 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* @param name
|
||||||
|
* @param axis {GameLib.D3.Vector3}
|
||||||
|
* @param getRotationFunc {Number}
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.ComponentRotator = function ComponentRotator(
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
axis,
|
||||||
|
getRotationFunc
|
||||||
|
) {
|
||||||
|
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.getRotationFunc = getRotationFunc || function(){} ;
|
||||||
|
|
||||||
|
GameLib.D3.Utils.Extend(GameLib.D3.ComponentRotator, GameLib.D3.ComponentInterface);
|
||||||
|
};
|
||||||
|
|
||||||
|
//#ifdef RUNTIME__
|
||||||
|
|
||||||
|
///////////////////////// Methods to override //////////////////////////
|
||||||
|
GameLib.D3.ComponentRotator.prototype.onLateUpdate = function(
|
||||||
|
deltaTime,
|
||||||
|
parentEntity
|
||||||
|
) {
|
||||||
|
if(parentEntity) {
|
||||||
|
|
||||||
|
var quat = new THREE.Quaternion(
|
||||||
|
parentEntity.quaternion.x,
|
||||||
|
parentEntity.quaternion.y,
|
||||||
|
parentEntity.quaternion.z,
|
||||||
|
parentEntity.quaternion.w
|
||||||
|
).multiply(
|
||||||
|
new THREE.Quaternion().setFromAxisAngle(
|
||||||
|
new THREE.Vector3(
|
||||||
|
this.axis.x,
|
||||||
|
this.axis.y,
|
||||||
|
this.axis.z
|
||||||
|
),
|
||||||
|
this.getRotationFunc()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
/* var quat = new THREE.Quaternion().setFromAxisAngle(
|
||||||
|
new THREE.Vector3(
|
||||||
|
this.axis.x,
|
||||||
|
this.axis.y,
|
||||||
|
this.axis.z
|
||||||
|
),
|
||||||
|
this.getRotationFunc()
|
||||||
|
);*/
|
||||||
|
|
||||||
|
parentEntity.quaternion.x = quat.x;
|
||||||
|
parentEntity.quaternion.y = quat.y;
|
||||||
|
parentEntity.quaternion.z = quat.z;
|
||||||
|
parentEntity.quaternion.w = quat.w;
|
||||||
|
|
||||||
|
parentEntity.mesh.updateMatrix();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
//#endif
|
Loading…
Reference in New Issue