From 3283eb40ce4d002a8f68ef520456d2295a226fe6 Mon Sep 17 00:00:00 2001 From: polygonboutique Date: Tue, 29 Nov 2016 13:53:12 +0100 Subject: [PATCH 01/12] parent entity link component --- src/game-lib-component-entity-parent.js | 41 +++++++---- src/game-lib-component-entity-permutation.js | 17 +++-- src/game-lib-component-path-ai.js | 4 -- src/game-lib-component-path-following.js | 75 ++++++++++---------- 4 files changed, 76 insertions(+), 61 deletions(-) diff --git a/src/game-lib-component-entity-parent.js b/src/game-lib-component-entity-parent.js index 4b7684f..1c40c5f 100644 --- a/src/game-lib-component-entity-parent.js +++ b/src/game-lib-component-entity-parent.js @@ -8,7 +8,8 @@ GameLib.D3.ComponentEntityParent = function ComponentEntityParent( id, name, - parent + parent, + centerToOrigin ) { this.id = id || GameLib.D3.Tools.RandomId(); @@ -19,9 +20,9 @@ GameLib.D3.ComponentEntityParent = function ComponentEntityParent( this.parent = parent; this.parentEntity = null; + this.centerToOrigin = centerToOrigin; this.originPosition = new GameLib.D3.Vector3(0, 0, 0); - // Todo: this should be executed somewhere in game-lib-z, so that we don't execute it on every construction of an object. GameLib.D3.Utils.Extend(GameLib.D3.ComponentEntityParent, GameLib.D3.ComponentInterface); }; @@ -34,16 +35,24 @@ GameLib.D3.ComponentEntityParent.prototype.onLateUpdate = function( if(parentEntity && this.parent) { - // parentEntity = this component's parent - parentEntity.position.x = this.parent.position.x /*+ this.parentOrigin.x + this.originPosition.x*/; - parentEntity.position.y = this.parent.position.y /*+ this.parentOrigin.y + this.originPosition.y*/; - parentEntity.position.z = this.parent.position.z /*+ this.parentOrigin.z + this.originPosition.z*/; + if(this.centerToOrigin) { + parentEntity.position.x = this.parent.position.x + this.parent.origin.x - this.originPosition.x; + parentEntity.position.y = this.parent.position.y + this.parent.origin.y - this.originPosition.y; + parentEntity.position.z = this.parent.position.z + this.parent.origin.z - this.originPosition.z; + } else { + parentEntity.position.x = this.parent.position.x; + parentEntity.position.y = this.parent.position.y; + parentEntity.position.z = this.parent.position.z; + } parentEntity.quaternion.x = this.parent.quaternion.x; parentEntity.quaternion.y = this.parent.quaternion.y; parentEntity.quaternion.z = this.parent.quaternion.z; parentEntity.quaternion.w = this.parent.quaternion.w; + parentEntity.scale.x = this.parent.scale.x; + parentEntity.scale.y = this.parent.scale.y; + parentEntity.scale.z = this.parent.scale.z; } }; @@ -53,17 +62,21 @@ GameLib.D3.ComponentEntityParent.prototype.onSetParentEntity = function( ) { if(parentEntity && parentEntity.mesh) { - /* var scale = parentEntity.mesh.scale.clone(); - /!* parentEntity.mesh.updateMatrix(); - parentEntity.mesh.geometry.applyMatrix( parentEntity.mesh.matrix ); - parentEntity.mesh.updateMatrix();*!/ - */ + // The entities should already be scaled down and stuff + // The matrix transform should already be applied to the geometry. - /*this.parentOrigin = this.parent.mesh.geometry.center(); - this.originPosition = parentEntity.mesh.geometry.center();*/ + if(this.centerToOrigin) { + if(GameLib.D3.Utils.UndefinedOrNull(this.parent.origin)) { + this.parent.origin = this.parent.mesh.geometry.center(); + parentEntity.position.x = this.parent.position.x - this.parent.origin.x; + parentEntity.position.y = this.parent.position.y - this.parent.origin.y; + parentEntity.position.z = this.parent.position.z - this.parent.origin.z; + } + + this.originPosition = parentEntity.mesh.geometry.center(); + } - // don't forget to set the scale on the entity itself!!! } }; diff --git a/src/game-lib-component-entity-permutation.js b/src/game-lib-component-entity-permutation.js index 7e3149e..4484411 100644 --- a/src/game-lib-component-entity-permutation.js +++ b/src/game-lib-component-entity-permutation.js @@ -23,11 +23,20 @@ GameLib.D3.ComponentEntityPermutation = function ComponentEntityPermutation( this.parentEntity = null; - this.positionOffset = positionOffset || new GameLib.D3.Vector3(0, 0, 0); - this.quaternionOffset = quaternionOffset || new GameLib.D3.Vector4(0, 0, 0, 1); - this.scaleOffset = scaleOffset || new GameLib.D3.Vector3(0, 0, 0); + if(GameLib.D3.Utils.UndefinedOrNull(positionOffset)) { + positionOffset = new GameLib.D3.Vector3(0, 0, 0); + } this.positionOffset = positionOffset; + + + if(GameLib.D3.Utils.UndefinedOrNull(quaternionOffset)) { + quaternionOffset = new GameLib.D3.Vector4(0, 0, 0, 1); + } this.quaternionOffset = quaternionOffset; + + + if(GameLib.D3.Utils.UndefinedOrNull(scaleOffset)) { + scaleOffset = new GameLib.D3.Vector3(0, 0, 0); + } this.scaleOffset = scaleOffset; - // Todo: this should be executed somewhere in game-lib-z, so that we don't execute it on every construction of an object. GameLib.D3.Utils.Extend(GameLib.D3.ComponentEntityPermutation, GameLib.D3.ComponentInterface); }; diff --git a/src/game-lib-component-path-ai.js b/src/game-lib-component-path-ai.js index 6a85d37..db12295 100644 --- a/src/game-lib-component-path-ai.js +++ b/src/game-lib-component-path-ai.js @@ -65,10 +65,6 @@ GameLib.D3.ComponentPathAI.prototype.onUpdate = function( this.pathFollowingComponent.direction = 1; - - - - // - - -- - - - - -- - - - - - - - - - - - - - - // D E B U G G I N G // - - - - - - - - - - - - - - - - - - diff --git a/src/game-lib-component-path-following.js b/src/game-lib-component-path-following.js index de3852a..eeb8b72 100644 --- a/src/game-lib-component-path-following.js +++ b/src/game-lib-component-path-following.js @@ -42,14 +42,17 @@ GameLib.D3.ComponentPathFollowing = function ComponentPathFollowing( this.steeringSpeed = steeringSpeed || 1.0; - //#ifdef RUNTIME__ // runtime code + + //#ifdef RUNTIME__ this.offset = new GameLib.D3.Vector3(); // this one is our destination offset this.currentOffset = new GameLib.D3.Vector3(); this.currentPathValue = 0.0; this.currentSpeed = 0.0; this.direction = 0; //#endif + + // extend GameLib.D3.Utils.Extend(GameLib.D3.ComponentPathFollowing, GameLib.D3.ComponentInterface); }; @@ -95,9 +98,9 @@ GameLib.D3.ComponentPathFollowing.prototype.onUpdate = function( var nextPoint = this.splineCurve3.getPointAt(nextIndex); - // - - - - - - - - - - - - - - // Raytrace from thhe current position. + // Ray trace from the current position. + // - - - - - - - - -- - - - - ComponentPathFollowing_Three_Raycaster.set( position, new THREE.Vector3( @@ -107,7 +110,6 @@ GameLib.D3.ComponentPathFollowing.prototype.onUpdate = function( ) ); - var normal = new THREE.Vector3(0, 1, 0); for(var m = 0, ml = this.trackThreeMeshArray.length; m < ml; ++m) { @@ -116,9 +118,7 @@ GameLib.D3.ComponentPathFollowing.prototype.onUpdate = function( ); if(intersect) { - normal = intersect[0].face.normal; - break; } } @@ -127,47 +127,44 @@ GameLib.D3.ComponentPathFollowing.prototype.onUpdate = function( var matrix = new THREE.Matrix4().lookAt(position, nextPoint, normal); var quaternion = new THREE.Quaternion().setFromRotationMatrix(matrix); - { // update position + // update position - t = deltaTime * ((this.currentSpeed / this.maxSpeed) * this.steeringSpeed); // put this into another variable - t = t * t * t * (t * (6.0 * t - 15.0) + 10.0); + t = deltaTime * ((this.currentSpeed / this.maxSpeed) * this.steeringSpeed); // put this into another variable + t = t * t * t * (t * (6.0 * t - 15.0) + 10.0); - var targetVector = new THREE.Vector3( - this.maxOffset.x * this.offset.x, - this.maxOffset.y * this.offset.y, - this.maxOffset.z * this.offset.z - ); + var targetVector = new THREE.Vector3( + this.maxOffset.x * this.offset.x, + this.maxOffset.y * this.offset.y, + this.maxOffset.z * this.offset.z + ); - var lerpedOffset = new THREE.Vector3( - this.currentOffset.x, - this.currentOffset.y, - this.currentOffset.z - ).lerp(targetVector, t); + var lerpedOffset = new THREE.Vector3( + this.currentOffset.x, + this.currentOffset.y, + this.currentOffset.z + ).lerp(targetVector, t); - this.currentOffset.x = lerpedOffset.x; - this.currentOffset.y = lerpedOffset.y; - this.currentOffset.z = lerpedOffset.z; + this.currentOffset.x = lerpedOffset.x; + this.currentOffset.y = lerpedOffset.y; + this.currentOffset.z = lerpedOffset.z; - var transformedOffset = new THREE.Vector3( - this.baseOffset.x + lerpedOffset.x, - this.baseOffset.y + lerpedOffset.y, - this.baseOffset.z + lerpedOffset.z - ).applyQuaternion(quaternion); + var transformedOffset = new THREE.Vector3( + this.baseOffset.x + lerpedOffset.x, + this.baseOffset.y + lerpedOffset.y, + this.baseOffset.z + lerpedOffset.z + ).applyQuaternion(quaternion); - // apply to parent rigidbody instead of direclty to the mesh. - parentEntity.position.x = position.x + transformedOffset.x; - parentEntity.position.y = position.y + transformedOffset.y; - parentEntity.position.z = position.z + transformedOffset.z; - } + // apply to parent rigidbody instead of direclty to the mesh. + parentEntity.position.x = position.x + transformedOffset.x; + parentEntity.position.y = position.y + transformedOffset.y; + parentEntity.position.z = position.z + transformedOffset.z; - { - // update rotation - parentEntity.quaternion.x = quaternion.x; - parentEntity.quaternion.y = quaternion.y; - parentEntity.quaternion.z = quaternion.z; - parentEntity.quaternion.w = quaternion.w; - } + // update rotation + parentEntity.quaternion.x = quaternion.x; + parentEntity.quaternion.y = quaternion.y; + parentEntity.quaternion.z = quaternion.z; + parentEntity.quaternion.w = quaternion.w; } }; From fafc068fad1acbb745f1263340d0105f4c56254c Mon Sep 17 00:00:00 2001 From: polygonboutique Date: Tue, 29 Nov 2016 15:26:54 +0100 Subject: [PATCH 02/12] parent entity link component: center to origin fixed --- src/game-lib-component-entity-parent.js | 49 ++++++++++++++++++------- src/game-lib-entity.js | 9 ++++- 2 files changed, 44 insertions(+), 14 deletions(-) diff --git a/src/game-lib-component-entity-parent.js b/src/game-lib-component-entity-parent.js index 1c40c5f..b5a66b6 100644 --- a/src/game-lib-component-entity-parent.js +++ b/src/game-lib-component-entity-parent.js @@ -36,23 +36,46 @@ GameLib.D3.ComponentEntityParent.prototype.onLateUpdate = function( if(parentEntity && this.parent) { if(this.centerToOrigin) { - parentEntity.position.x = this.parent.position.x + this.parent.origin.x - this.originPosition.x; - parentEntity.position.y = this.parent.position.y + this.parent.origin.y - this.originPosition.y; - parentEntity.position.z = this.parent.position.z + this.parent.origin.z - this.originPosition.z; + this.parentEntity.position.x = this.parent.position.x + ((this.parent.origin.x - this.originPosition.x) * this.parent.scale.x); + this.parentEntity.position.y = this.parent.position.y + ((this.parent.origin.y - this.originPosition.y) * this.parent.scale.y); + this.parentEntity.position.z = this.parent.position.z + ((this.parent.origin.z - this.originPosition.z) * this.parent.scale.z); + + // apply quaternion + // + + var tmpVector = new THREE.Vector3( + parentEntity.position.x, + parentEntity.position.y, + parentEntity.position.z + ).applyQuaternion( + new THREE.Quaternion( + this.parent.quaternion.x, + this.parent.quaternion.y, + this.parent.quaternion.z, + this.parent.quaternion.w + ) + ); + + this.parentEntity.position.x = tmpVector.x; + this.parentEntity.position.y = tmpVector.y; + this.parentEntity.position.z = tmpVector.z; + } else { - parentEntity.position.x = this.parent.position.x; - parentEntity.position.y = this.parent.position.y; - parentEntity.position.z = this.parent.position.z; + this.parentEntity.position.x = this.parent.position.x; + this.parentEntity.position.y = this.parent.position.y; + this.parentEntity.position.z = this.parent.position.z; } - parentEntity.quaternion.x = this.parent.quaternion.x; - parentEntity.quaternion.y = this.parent.quaternion.y; - parentEntity.quaternion.z = this.parent.quaternion.z; - parentEntity.quaternion.w = this.parent.quaternion.w; + this.parentEntity.quaternion.x = this.parent.quaternion.x; + this.parentEntity.quaternion.y = this.parent.quaternion.y; + this.parentEntity.quaternion.z = this.parent.quaternion.z; + this.parentEntity.quaternion.w = this.parent.quaternion.w; - parentEntity.scale.x = this.parent.scale.x; - parentEntity.scale.y = this.parent.scale.y; - parentEntity.scale.z = this.parent.scale.z; + this.parentEntity.scale.x = this.parent.scale.x; + this.parentEntity.scale.y = this.parent.scale.y; + this.parentEntity.scale.z = this.parent.scale.z; + + this.parentEntity.mesh.updateMatrix(); } }; diff --git a/src/game-lib-entity.js b/src/game-lib-entity.js index 0a5c524..ebda39a 100644 --- a/src/game-lib-entity.js +++ b/src/game-lib-entity.js @@ -55,8 +55,15 @@ GameLib.D3.Entity.prototype.update = function( if(this.mesh) { this.mesh.position.set(this.position.x, this.position.y, this.position.z); - this.mesh.quaternion.set(this.quaternion.x, this.quaternion.y, this.quaternion.z, this.quaternion.w); this.mesh.scale.set(this.scale.x, this.scale.y, this.scale.z); + this.mesh.quaternion.set(this.quaternion.x, this.quaternion.y, this.quaternion.z, this.quaternion.w).normalize(); + + // normalize the quaternion, if we have a mesh. + // if we don't do this, then the mesh will get stretched + this.quaternion.x = this.mesh.quaternion.x; + this.quaternion.y = this.mesh.quaternion.y; + this.quaternion.z = this.mesh.quaternion.z; + this.quaternion.w = this.mesh.quaternion.w; } this.onUpdate(deltaTime); From b2bacd2d7e88491ea53d8ce9038617e5ada376f3 Mon Sep 17 00:00:00 2001 From: polygonboutique Date: Tue, 29 Nov 2016 15:40:27 +0100 Subject: [PATCH 03/12] fixed. --- src/game-lib-component-entity-parent.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/game-lib-component-entity-parent.js b/src/game-lib-component-entity-parent.js index b5a66b6..74c52d7 100644 --- a/src/game-lib-component-entity-parent.js +++ b/src/game-lib-component-entity-parent.js @@ -36,9 +36,9 @@ GameLib.D3.ComponentEntityParent.prototype.onLateUpdate = function( if(parentEntity && this.parent) { if(this.centerToOrigin) { - this.parentEntity.position.x = this.parent.position.x + ((this.parent.origin.x - this.originPosition.x) * this.parent.scale.x); - this.parentEntity.position.y = this.parent.position.y + ((this.parent.origin.y - this.originPosition.y) * this.parent.scale.y); - this.parentEntity.position.z = this.parent.position.z + ((this.parent.origin.z - this.originPosition.z) * this.parent.scale.z); + this.parentEntity.position.x = ((this.parent.origin.x - this.originPosition.x) * this.parent.scale.x); + this.parentEntity.position.y = ((this.parent.origin.y - this.originPosition.y) * this.parent.scale.y); + this.parentEntity.position.z = ((this.parent.origin.z - this.originPosition.z) * this.parent.scale.z); // apply quaternion // @@ -56,9 +56,9 @@ GameLib.D3.ComponentEntityParent.prototype.onLateUpdate = function( ) ); - this.parentEntity.position.x = tmpVector.x; - this.parentEntity.position.y = tmpVector.y; - this.parentEntity.position.z = tmpVector.z; + 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; } else { this.parentEntity.position.x = this.parent.position.x; From 563f18fc9932503a28b886e55ea5ab5ecfb3902d Mon Sep 17 00:00:00 2001 From: polygonboutique Date: Tue, 29 Nov 2016 16:11:56 +0100 Subject: [PATCH 04/12] fixed mesh delay error --- src/game-lib-component-entity-parent.js | 21 ++++++++++++++--- src/game-lib-entity.js | 31 +++++++++++++++---------- 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/src/game-lib-component-entity-parent.js b/src/game-lib-component-entity-parent.js index 74c52d7..da04308 100644 --- a/src/game-lib-component-entity-parent.js +++ b/src/game-lib-component-entity-parent.js @@ -44,9 +44,9 @@ GameLib.D3.ComponentEntityParent.prototype.onLateUpdate = function( // var tmpVector = new THREE.Vector3( - parentEntity.position.x, - parentEntity.position.y, - parentEntity.position.z + this.parentEntity.position.x, + this.parentEntity.position.y, + this.parentEntity.position.z ).applyQuaternion( new THREE.Quaternion( this.parent.quaternion.x, @@ -76,6 +76,21 @@ 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-entity.js b/src/game-lib-entity.js index ebda39a..a4219d7 100644 --- a/src/game-lib-entity.js +++ b/src/game-lib-entity.js @@ -38,6 +38,21 @@ GameLib.D3.Entity = function Entity( this.scale = scale; }; +GameLib.D3.Entity.prototype.updateMesh = function() { + if(this.mesh) { + this.mesh.position.set(this.position.x, this.position.y, this.position.z); + this.mesh.scale.set(this.scale.x, this.scale.y, this.scale.z); + this.mesh.quaternion.set(this.quaternion.x, this.quaternion.y, this.quaternion.z, this.quaternion.w).normalize(); + + // normalize the quaternion, if we have a mesh. + // if we don't do this, then the mesh will get stretched + this.quaternion.x = this.mesh.quaternion.x; + this.quaternion.y = this.mesh.quaternion.y; + this.quaternion.z = this.mesh.quaternion.z; + this.quaternion.w = this.mesh.quaternion.w; + } +}; + /** * Updates the Entity and it's components * @param deltaTime Number @@ -53,18 +68,8 @@ GameLib.D3.Entity.prototype.update = function( } } - if(this.mesh) { - this.mesh.position.set(this.position.x, this.position.y, this.position.z); - this.mesh.scale.set(this.scale.x, this.scale.y, this.scale.z); - this.mesh.quaternion.set(this.quaternion.x, this.quaternion.y, this.quaternion.z, this.quaternion.w).normalize(); - - // normalize the quaternion, if we have a mesh. - // if we don't do this, then the mesh will get stretched - this.quaternion.x = this.mesh.quaternion.x; - this.quaternion.y = this.mesh.quaternion.y; - this.quaternion.z = this.mesh.quaternion.z; - this.quaternion.w = this.mesh.quaternion.w; - } + // todo: maybe we only need to call this AFTER late update + this.updateMesh(); this.onUpdate(deltaTime); }; @@ -84,6 +89,8 @@ GameLib.D3.Entity.prototype.lateUpdate = function( } } + this.updateMesh(); + this.onLateUpdate(deltaTime); }; From bc27db190de9633c5cad16014e7d0733c4325096 Mon Sep 17 00:00:00 2001 From: polygonboutique Date: Tue, 29 Nov 2016 16:55:50 +0100 Subject: [PATCH 05/12] normalize camera quat, entity parent uses a static tmpvector for it's calculations. todo: we have a huge memory issue. 700mb on the heap. --- defines/editor.js | 1 + defines/runtime.js | 3 +- src/game-lib-component-camera.js | 7 +++- src/game-lib-component-entity-parent.js | 44 +++++++++++-------------- src/game-lib-component-path-ai.js | 2 ++ 5 files changed, 30 insertions(+), 27 deletions(-) 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 }; From eaea4255dff0def5e2c837db07af072be8aa2d21 Mon Sep 17 00:00:00 2001 From: polygonboutique Date: Wed, 30 Nov 2016 09:19:35 +0100 Subject: [PATCH 06/12] fixed tmpQuat --- src/game-lib-component-entity-parent.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/game-lib-component-entity-parent.js b/src/game-lib-component-entity-parent.js index 6ecfd92..0706dbc 100644 --- a/src/game-lib-component-entity-parent.js +++ b/src/game-lib-component-entity-parent.js @@ -28,9 +28,9 @@ GameLib.D3.ComponentEntityParent = function ComponentEntityParent( //#ifdef RUNTIME__ -if(typeof THREE != "undefined") { +if(typeof THREE !== "undefined") { ComponentEntityParent_TmpVector = new THREE.Vector3(); - ComponentEntityParent_TmpQuaternion = new THREE.Vector3(); + ComponentEntityParent_TmpQuaternion = new THREE.Quaternion(); } ///////////////////////// Methods to override ////////////////////////// From 61ed31e517fde4f5d2b89d9fa5ff6926ffb37368 Mon Sep 17 00:00:00 2001 From: polygonboutique Date: Wed, 30 Nov 2016 10:31:44 +0100 Subject: [PATCH 07/12] added kinematic setting to rigid-body. next up: spinning wheels, ai collision avoidance, onCollide-event --- src/game-lib-component-path-ai.js | 43 ++++++++++++++++++++++------ src/game-lib-rigid-body.js | 47 +++++++++++++++++++++++-------- 2 files changed, 69 insertions(+), 21 deletions(-) diff --git a/src/game-lib-component-path-ai.js b/src/game-lib-component-path-ai.js index 77db5a8..1a15165 100644 --- a/src/game-lib-component-path-ai.js +++ b/src/game-lib-component-path-ai.js @@ -31,6 +31,14 @@ GameLib.D3.ComponentPathAI = function ComponentPathAI( //#ifdef RUNTIME__ + +var componentPathAI_Raycast = function(from, to, settings, world) { + /* var raycastResult = new sys.physicsEngine.instance.RaycastResult(); + world.raycastClosest(from, to, settings, raycastResult); + return raycastResult;*/ +}; + + ///////////////////////// Methods to override ////////////////////////// GameLib.D3.ComponentPathAI.prototype.onUpdate = function( deltaTime, @@ -42,27 +50,44 @@ GameLib.D3.ComponentPathAI.prototype.onUpdate = function( var right = false; - /*if (this.keyForwardPressed) { // Forward [i] + // Ray tracing part. + + var scaledSensorLengthOffset = this.pathFollowingComponent.currentSpeed; + + /*world.raycastClosest( + fromC, + + toC, + + {}, + + result + );*/ + + + + + if(forward && !backward) { this.pathFollowingComponent.direction = 1; - } else if (this.keyBackPressed){ + } else if (backward && !forward) { this.pathFollowingComponent.direction = -1; } else { this.pathFollowingComponent.direction = 0; } - // left right - if (this.keyLeftPressed) { // Left [j] + if(left && !right) { this.pathFollowingComponent.offset.x = 0; this.pathFollowingComponent.offset.y = 0; this.pathFollowingComponent.offset.z = 1; - } else if (this.keyRightPressed) { // Right [l] + } else if (right && !left) { this.pathFollowingComponent.offset.x = 0; this.pathFollowingComponent.offset.y = 0; this.pathFollowingComponent.offset.z = -1; - }*/ - - // tell path following component to move forward - this.pathFollowingComponent.direction = 1; + } else { + this.pathFollowingComponent.offset.x = 0; + this.pathFollowingComponent.offset.y = 0; + this.pathFollowingComponent.offset.z = 0; + } // - - -- - - - - -- - - - - - - - - - - - - - - diff --git a/src/game-lib-rigid-body.js b/src/game-lib-rigid-body.js index cc6dcef..a5510ac 100644 --- a/src/game-lib-rigid-body.js +++ b/src/game-lib-rigid-body.js @@ -16,6 +16,7 @@ * @param collisionFilterMask * @param fixedRotation * @param shape GameLib.D3.Shape + * @param kinematic Boolean * @returns {GameLib.D3.Physics.RigidBody} * @constructor */ @@ -35,7 +36,8 @@ GameLib.D3.RigidBody = function( collisionFilterGroup, collisionFilterMask, fixedRotation, - shape + shape, + kinematic ) { this.id = GameLib.D3.Tools.RandomId(); this.position = position || new GameLib.D3.Vector3(); @@ -53,6 +55,7 @@ GameLib.D3.RigidBody = function( this.collisionFilterMask = typeof collisionFilterMask == "undefined" ? 1 : collisionFilterMask; this.fixedRotation = typeof fixedRotation == "undefined" ? false : fixedRotation; this.shape = typeof shape == "undefined" ? null : shape; + this.kinematic = kinematic || false; this.engine = engine; this.engine.isNotCannonThrow(); @@ -150,19 +153,39 @@ GameLib.D3.RigidBody.prototype.onUpdate = function( parentEntity ) { if(parentEntity) { - var quaternion = new THREE.Quaternion(); - quaternion.copy(this.instance.quaternion); + if (this.kinematic) { + // reapply the entity's transform back to the rigid body, since it is kinematic + this.instance.position.x = parentEntity.position.x; + this.instance.position.y = parentEntity.position.y; + this.instance.position.z = parentEntity.position.z; - var position = new THREE.Vector3(); - position.copy(this.instance.position); + this.instance.quaternion.x = parentEntity.quaternion.x; + this.instance.quaternion.y = parentEntity.quaternion.y; + this.instance.quaternion.z = parentEntity.quaternion.z; + this.instance.quaternion.w = parentEntity.quaternion.w; - parentEntity.position.x = position.x; - parentEntity.position.y = position.y; - parentEntity.position.z = position.z; + this.instance.inertia.x = 0; + this.instance.inertia.y = 0; + this.instance.inertia.z = 0; - parentEntity.quaternion.x = quaternion.x; - parentEntity.quaternion.y = quaternion.y; - parentEntity.quaternion.z = quaternion.z; - parentEntity.quaternion.w = quaternion.w; + this.instance.velocity.x = 0; + this.instance.velocity.y = 0; + this.instance.velocity.z = 0; + } else { + var quaternion = new THREE.Quaternion(); + quaternion.copy(this.instance.quaternion); + + var position = new THREE.Vector3(); + position.copy(this.instance.position); + + parentEntity.position.x = position.x; + parentEntity.position.y = position.y; + parentEntity.position.z = position.z; + + parentEntity.quaternion.x = quaternion.x; + parentEntity.quaternion.y = quaternion.y; + parentEntity.quaternion.z = quaternion.z; + parentEntity.quaternion.w = quaternion.w; + } } }; \ No newline at end of file From 2895b74b6c6ecc9f8e3f3e67ffc2365b4dfd3e11 Mon Sep 17 00:00:00 2001 From: polygonboutique Date: Wed, 30 Nov 2016 10:46:25 +0100 Subject: [PATCH 08/12] addde remove component method to entity --- src/game-lib-entity.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/game-lib-entity.js b/src/game-lib-entity.js index a4219d7..ad08754 100644 --- a/src/game-lib-entity.js +++ b/src/game-lib-entity.js @@ -138,6 +138,13 @@ GameLib.D3.Entity.prototype.addComponent = function( }; +GameLib.D3.Entity.prototype.removeComponent = function(component) { + if(component && component.id && this.parentScene.idToComponent[component.id]) { + this.ids = this.ids.splice(this.ids.indexOf(component), 1); + delete this.parentScene.idToComponent[component.id]; + } +}; + GameLib.D3.Entity.prototype.getComponent = function( componentType ) { From 9f96389ae551ca45b20be67a2930c8283630b506 Mon Sep 17 00:00:00 2001 From: polygonboutique Date: Wed, 30 Nov 2016 11:40:33 +0100 Subject: [PATCH 09/12] rotator component --- src/game-lib-component-path-ai.js | 2 +- src/game-lib-component-rotator.js | 72 +++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 src/game-lib-component-rotator.js diff --git a/src/game-lib-component-path-ai.js b/src/game-lib-component-path-ai.js index 1a15165..3700ea5 100644 --- a/src/game-lib-component-path-ai.js +++ b/src/game-lib-component-path-ai.js @@ -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; diff --git a/src/game-lib-component-rotator.js b/src/game-lib-component-rotator.js new file mode 100644 index 0000000..65e1e7a --- /dev/null +++ b/src/game-lib-component-rotator.js @@ -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 \ No newline at end of file From 3aca24eb8753f8fe8ea578a3b2695da24cc73340 Mon Sep 17 00:00:00 2001 From: polygonboutique Date: Wed, 30 Nov 2016 12:32:58 +0100 Subject: [PATCH 10/12] offset component --- src/game-lib-component-offsettor.js | 57 +++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/game-lib-component-offsettor.js diff --git a/src/game-lib-component-offsettor.js b/src/game-lib-component-offsettor.js new file mode 100644 index 0000000..24f0663 --- /dev/null +++ b/src/game-lib-component-offsettor.js @@ -0,0 +1,57 @@ +/** + * + * @param id + * @param name + * @param axis {GameLib.D3.Vector3} + * @param getOffsetFunc + * @constructor + */ +GameLib.D3.ComponentOffsettor = function ComponentOffsettor( + id, + name, + axis, + getOffsetFunc +) { + 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.getOffsetFunc = getOffsetFunc || function(){ return 1; }; + + 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.position.x += pos.x; + parentEntity.position.y += pos.y; + parentEntity.position.z += pos.z; + parentEntity.mesh.updateMatrix(); + } +}; +//#endif \ No newline at end of file From 52af3c1f3deb74e6ee4dfc2bb7b32f8b8accd881 Mon Sep 17 00:00:00 2001 From: polygonboutique Date: Wed, 30 Nov 2016 13:12:54 +0100 Subject: [PATCH 11/12] changed component signature of offsettor, rotator --- src/game-lib-component-offsettor.js | 13 ++++++++++--- src/game-lib-component-rotator.js | 22 +++++++++------------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/game-lib-component-offsettor.js b/src/game-lib-component-offsettor.js index 24f0663..c449854 100644 --- a/src/game-lib-component-offsettor.js +++ b/src/game-lib-component-offsettor.js @@ -4,13 +4,15 @@ * @param name * @param axis {GameLib.D3.Vector3} * @param getOffsetFunc + * @param userData * @constructor */ GameLib.D3.ComponentOffsettor = function ComponentOffsettor( id, name, axis, - getOffsetFunc + getOffsetFunc, + userData ) { this.id = id || GameLib.D3.Tools.RandomId(); @@ -21,7 +23,8 @@ GameLib.D3.ComponentOffsettor = function ComponentOffsettor( this.parentEntity = null; this.axis = axis || new GameLib.D3.Vector3(); - this.getOffsetFunc = getOffsetFunc || function(){ return 1; }; + this.getOffsetFunc = getOffsetFunc || function(entity, component, userData){ return 1; }; + this.userData = userData; GameLib.D3.Utils.Extend(GameLib.D3.ComponentOffsettor, GameLib.D3.ComponentInterface); }; @@ -46,7 +49,11 @@ GameLib.D3.ComponentOffsettor.prototype.onLateUpdate = function( parentEntity.quaternion.z, parentEntity.quaternion.w ) - ).multiplyScalar(this.getOffsetFunc()); + ).multiplyScalar(this.getOffsetFunc( + parentEntity, + this, + this.userData + )); parentEntity.position.x += pos.x; parentEntity.position.y += pos.y; diff --git a/src/game-lib-component-rotator.js b/src/game-lib-component-rotator.js index 65e1e7a..288a65f 100644 --- a/src/game-lib-component-rotator.js +++ b/src/game-lib-component-rotator.js @@ -10,7 +10,8 @@ GameLib.D3.ComponentRotator = function ComponentRotator( id, name, axis, - getRotationFunc + getRotationFunc, + userData ) { this.id = id || GameLib.D3.Tools.RandomId(); @@ -21,7 +22,8 @@ GameLib.D3.ComponentRotator = function ComponentRotator( this.parentEntity = null; this.axis = axis || new GameLib.D3.Vector3(); - this.getRotationFunc = getRotationFunc || function(){} ; + this.getRotationFunc = getRotationFunc || function(entity, component, userData){ return 1; }; + this.userData = userData; GameLib.D3.Utils.Extend(GameLib.D3.ComponentRotator, GameLib.D3.ComponentInterface); }; @@ -47,20 +49,14 @@ GameLib.D3.ComponentRotator.prototype.onLateUpdate = function( this.axis.y, this.axis.z ), - this.getRotationFunc() + this.getRotationFunc( + parentEntity, + this, + this.userData + ) ) ); - - /* 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; From 490001d3163930add6cae7bc499dc46d765d693c Mon Sep 17 00:00:00 2001 From: polygonboutique Date: Wed, 30 Nov 2016 15:45:19 +0100 Subject: [PATCH 12/12] added some stuff to rotator & offsettor components. also added some docs + lapcounter to the main.js --- src/game-lib-component-entity-parent.js | 7 ++++--- src/game-lib-component-entity-permutation.js | 4 ++-- src/game-lib-component-mesh-permutation.js | 4 ++-- src/game-lib-component-offsettor.js | 8 +++++--- src/game-lib-component-path-controls.js | 3 ++- src/game-lib-component-rotator.js | 7 +++++-- 6 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/game-lib-component-entity-parent.js b/src/game-lib-component-entity-parent.js index 0706dbc..67a2a80 100644 --- a/src/game-lib-component-entity-parent.js +++ b/src/game-lib-component-entity-parent.js @@ -1,8 +1,9 @@ /** * - * @param id - * @param name - * @param parent + * @param id {String} + * @param name {String} + * @param parent {GameLib.D3.Entity} + * @param centerToOrigin {Boolean} * @constructor */ GameLib.D3.ComponentEntityParent = function ComponentEntityParent( diff --git a/src/game-lib-component-entity-permutation.js b/src/game-lib-component-entity-permutation.js index 4484411..49a751a 100644 --- a/src/game-lib-component-entity-permutation.js +++ b/src/game-lib-component-entity-permutation.js @@ -34,7 +34,7 @@ GameLib.D3.ComponentEntityPermutation = function ComponentEntityPermutation( if(GameLib.D3.Utils.UndefinedOrNull(scaleOffset)) { - scaleOffset = new GameLib.D3.Vector3(0, 0, 0); + scaleOffset = new GameLib.D3.Vector3(1, 1, 1); } this.scaleOffset = scaleOffset; GameLib.D3.Utils.Extend(GameLib.D3.ComponentEntityPermutation, GameLib.D3.ComponentInterface); @@ -71,7 +71,7 @@ GameLib.D3.ComponentEntityPermutation.prototype.onUpdate = function( ComponentEntityPermutation_scale.copy(parentEntity.scale); ComponentEntityPermutation_offsetScale.copy(this.scaleOffset); - ComponentEntityPermutation_scale = ComponentEntityPermutation_scale.add(ComponentEntityPermutation_offsetScale); + ComponentEntityPermutation_scale = ComponentEntityPermutation_scale.multiply(ComponentEntityPermutation_offsetScale); parentEntity.position.x = ComponentEntityPermutation_position.x; parentEntity.position.y = ComponentEntityPermutation_position.y; diff --git a/src/game-lib-component-mesh-permutation.js b/src/game-lib-component-mesh-permutation.js index bc1740d..fb5502b 100644 --- a/src/game-lib-component-mesh-permutation.js +++ b/src/game-lib-component-mesh-permutation.js @@ -25,7 +25,7 @@ GameLib.D3.ComponentMeshPermutation = function ComponentMeshPermutation( this.positionOffset = positionOffset || new GameLib.D3.Vector3(0, 0, 0); this.quaternionOffset = quaternionOffset || new GameLib.D3.Vector4(0, 0, 0, 1); - this.scaleOffset = scaleOffset || new GameLib.D3.Vector3(0, 0, 0); + this.scaleOffset = scaleOffset || new GameLib.D3.Vector3(1, 1, 1); // Todo: this should be executed somewhere in game-lib-z, so that we don't execute it on every construction of an object. GameLib.D3.Utils.Extend(GameLib.D3.ComponentMeshPermutation, GameLib.D3.ComponentInterface); @@ -62,7 +62,7 @@ GameLib.D3.ComponentMeshPermutation.prototype.onLateUpdate = function( ComponentMeshPermutation_scale.copy(parentEntity.mesh.scale); ComponentMeshPermutation_offsetScale.copy(this.scaleOffset); - ComponentMeshPermutation_scale = ComponentMeshPermutation_scale.add(ComponentMeshPermutation_offsetScale); + ComponentMeshPermutation_scale = ComponentMeshPermutation_scale.multiply(ComponentMeshPermutation_offsetScale); parentEntity.mesh.position.copy(ComponentMeshPermutation_position); parentEntity.mesh.quaternion.copy(ComponentMeshPermutation_quaternion); diff --git a/src/game-lib-component-offsettor.js b/src/game-lib-component-offsettor.js index c449854..c7e0a87 100644 --- a/src/game-lib-component-offsettor.js +++ b/src/game-lib-component-offsettor.js @@ -3,8 +3,8 @@ * @param id * @param name * @param axis {GameLib.D3.Vector3} - * @param getOffsetFunc - * @param userData + * @param getOffsetFunc {function} + * @param userData {Object} * @constructor */ GameLib.D3.ComponentOffsettor = function ComponentOffsettor( @@ -23,7 +23,9 @@ GameLib.D3.ComponentOffsettor = function ComponentOffsettor( this.parentEntity = null; this.axis = axis || new GameLib.D3.Vector3(); - this.getOffsetFunc = getOffsetFunc || function(entity, component, userData){ return 1; }; + 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); diff --git a/src/game-lib-component-path-controls.js b/src/game-lib-component-path-controls.js index 54ce11c..80aa98c 100644 --- a/src/game-lib-component-path-controls.js +++ b/src/game-lib-component-path-controls.js @@ -39,7 +39,8 @@ GameLib.D3.ComponentPathControls.prototype.onUpdate = function( if (this.keyForwardPressed) { // Forward [i] this.pathFollowingComponent.direction = 1; } else if (this.keyBackPressed){ - this.pathFollowingComponent.direction = -1; + this.pathFollowingComponent.direction = 0; + // this.pathFollowingComponent.direction = -1; } else { this.pathFollowingComponent.direction = 0; } diff --git a/src/game-lib-component-rotator.js b/src/game-lib-component-rotator.js index 288a65f..69f6d3b 100644 --- a/src/game-lib-component-rotator.js +++ b/src/game-lib-component-rotator.js @@ -3,7 +3,8 @@ * @param id * @param name * @param axis {GameLib.D3.Vector3} - * @param getRotationFunc {Number} + * @param getRotationFunc {Function} + * @param userData {Object} * @constructor */ GameLib.D3.ComponentRotator = function ComponentRotator( @@ -21,8 +22,10 @@ GameLib.D3.ComponentRotator = function ComponentRotator( this.name = name; this.parentEntity = null; + this.rotation = 0; + var component = this; this.axis = axis || new GameLib.D3.Vector3(); - this.getRotationFunc = getRotationFunc || function(entity, component, userData){ return 1; }; + this.getRotationFunc = getRotationFunc || function(entity, component, userData){ return component.rotation; }; this.userData = userData; GameLib.D3.Utils.Extend(GameLib.D3.ComponentRotator, GameLib.D3.ComponentInterface);