normalize camera quat, entity parent uses a static tmpvector for it's calculations.

todo: we have a huge memory issue. 700mb on the heap.
beta.r3js.org
polygonboutique 2016-11-29 16:55:50 +01:00
parent 563f18fc99
commit bc27db190d
5 changed files with 30 additions and 27 deletions

View File

@ -1 +1,2 @@
//#define EDITOR__
//#define DEBUG__

View File

@ -1 +1,2 @@
//#define RUNTIME__
//#define RUNTIME__
//#define DEBUG__

View File

@ -37,6 +37,11 @@ GameLib.D3.ComponentCamera.prototype.onLateUpdate = function(
deltaTime,
parentEntity
) {
this.camera.quaternion.copy(parentEntity.quaternion);
this.camera.quaternion.copy(parentEntity.quaternion).normalize();
this.camera.position.copy(parentEntity.position);
parentEntity.quaternion.x = this.camera.quaternion.x;
parentEntity.quaternion.y = this.camera.quaternion.y;
parentEntity.quaternion.z = this.camera.quaternion.z;
parentEntity.quaternion.w = this.camera.quaternion.w;
};

View File

@ -27,6 +27,12 @@ GameLib.D3.ComponentEntityParent = function ComponentEntityParent(
};
//#ifdef RUNTIME__
if(typeof THREE != "undefined") {
ComponentEntityParent_TmpVector = new THREE.Vector3();
ComponentEntityParent_TmpQuaternion = new THREE.Vector3();
}
///////////////////////// Methods to override //////////////////////////
GameLib.D3.ComponentEntityParent.prototype.onLateUpdate = function(
deltaTime,
@ -43,22 +49,25 @@ GameLib.D3.ComponentEntityParent.prototype.onLateUpdate = function(
// apply quaternion
//
var tmpVector = new THREE.Vector3(
ComponentEntityParent_TmpQuaternion.set(
this.parent.quaternion.x,
this.parent.quaternion.y,
this.parent.quaternion.z,
this.parent.quaternion.w
);
ComponentEntityParent_TmpVector =
ComponentEntityParent_TmpVector.set(
this.parentEntity.position.x,
this.parentEntity.position.y,
this.parentEntity.position.z
).applyQuaternion(
new THREE.Quaternion(
this.parent.quaternion.x,
this.parent.quaternion.y,
this.parent.quaternion.z,
this.parent.quaternion.w
)
ComponentEntityParent_TmpQuaternion
);
this.parentEntity.position.x = tmpVector.x + this.parent.position.x;
this.parentEntity.position.y = tmpVector.y + this.parent.position.y;
this.parentEntity.position.z = tmpVector.z + this.parent.position.z;
this.parentEntity.position.x = ComponentEntityParent_TmpVector.x + this.parent.position.x;
this.parentEntity.position.y = ComponentEntityParent_TmpVector.y + this.parent.position.y;
this.parentEntity.position.z = ComponentEntityParent_TmpVector.z + this.parent.position.z;
} else {
this.parentEntity.position.x = this.parent.position.x;
@ -76,21 +85,6 @@ GameLib.D3.ComponentEntityParent.prototype.onLateUpdate = function(
this.parentEntity.scale.z = this.parent.scale.z;
this.parentEntity.mesh.updateMatrix();
/*//
this.parentEntity.mesh.position.x = this.parentEntity.position.x;
this.parentEntity.mesh.position.y = this.parentEntity.position.y;
this.parentEntity.mesh.position.z = this.parentEntity.position.z;
this.parentEntity.mesh.quaternion.x = this.parentEntity.quaternion.x;
this.parentEntity.mesh.quaternion.y = this.parentEntity.quaternion.y;
this.parentEntity.mesh.quaternion.z = this.parentEntity.quaternion.z;
this.parentEntity.mesh.quaternion.w = this.parentEntity.quaternion.w;
this.parentEntity.mesh.scale.x = this.parentEntity.scale.x;
this.parentEntity.mesh.scale.y = this.parentEntity.scale.y;
this.parentEntity.mesh.scale.z = this.parentEntity.scale.z;*/
}
};

View File

@ -68,6 +68,7 @@ GameLib.D3.ComponentPathAI.prototype.onUpdate = function(
// - - -- - - - - -- - - - - - - - - - - - - - -
// D E B U G G I N G
// - - - - - - - - - - - - - - - - - -
//#ifdef DEBUG__
if(this.sensorVisualizer) {
for(var i = 0, l = this.sensors.length; i < l; ++i) {
@ -141,6 +142,7 @@ GameLib.D3.ComponentPathAI.prototype.onUpdate = function(
}
}
//#endif
};