rotator component

beta.r3js.org
polygonboutique 2016-11-30 11:40:33 +01:00
parent 2895b74b6c
commit 9f96389ae5
2 changed files with 73 additions and 1 deletions

View File

@ -44,7 +44,7 @@ GameLib.D3.ComponentPathAI.prototype.onUpdate = function(
deltaTime,
parentEntity
) {
var forward = false;
var forward = true;
var backward = false;
var left = false;
var right = false;

View File

@ -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