diff --git a/defines/editor.js b/defines/editor.js index a3d2723..076a55e 100644 --- a/defines/editor.js +++ b/defines/editor.js @@ -1 +1,2 @@ //#define EDITOR__ +//#define DEBUG__ \ No newline at end of file diff --git a/defines/runtime.js b/defines/runtime.js index a3097b4..5ebd2fa 100644 --- a/defines/runtime.js +++ b/defines/runtime.js @@ -1 +1,2 @@ -//#define RUNTIME__ \ No newline at end of file +//#define RUNTIME__ +//#define DEBUG__ \ No newline at end of file diff --git a/src/game-lib-component-camera.js b/src/game-lib-component-camera.js index 2db6a13..24c3a82 100644 --- a/src/game-lib-component-camera.js +++ b/src/game-lib-component-camera.js @@ -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; }; \ No newline at end of file diff --git a/src/game-lib-component-entity-parent.js b/src/game-lib-component-entity-parent.js index da04308..6ecfd92 100644 --- a/src/game-lib-component-entity-parent.js +++ b/src/game-lib-component-entity-parent.js @@ -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;*/ - } }; diff --git a/src/game-lib-component-path-ai.js b/src/game-lib-component-path-ai.js index db12295..77db5a8 100644 --- a/src/game-lib-component-path-ai.js +++ b/src/game-lib-component-path-ai.js @@ -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 };