From 9c90cb81ac518d4c0586519f20f98c3e9ec0094a Mon Sep 17 00:00:00 2001 From: polygonboutique Date: Fri, 25 Nov 2016 09:57:09 +0100 Subject: [PATCH] backup --- src/game-lib-component-path-ai.js | 183 ++++++++++++++++++++++- src/game-lib-component-path-controls.js | 4 + src/game-lib-component-path-following.js | 6 + 3 files changed, 187 insertions(+), 6 deletions(-) diff --git a/src/game-lib-component-path-ai.js b/src/game-lib-component-path-ai.js index 97f7472..6a85d37 100644 --- a/src/game-lib-component-path-ai.js +++ b/src/game-lib-component-path-ai.js @@ -61,11 +61,20 @@ GameLib.D3.ComponentPathAI.prototype.onUpdate = function( this.pathFollowingComponent.offset.z = -1; }*/ + // tell path following component to move forward + this.pathFollowingComponent.direction = 1; + + + + + // - - -- - - - - -- - - - - - - - - - - - - - - + // D E B U G G I N G + // - - - - - - - - - - - - - - - - - - if(this.sensorVisualizer) { - for(var i = 0, i = this.sensors.length; i < l; ++i) { + for(var i = 0, l = this.sensors.length; i < l; ++i) { var sensor = this.sensors[i]; @@ -94,11 +103,44 @@ GameLib.D3.ComponentPathAI.prototype.onUpdate = function( if(this.sensorVisualizer.sensors[i].arrow) { - this.sensorVisualizer.sensors[s].sensorMesh.remove(this.sensorVisualizer.sensors[i].arrow); + this.sensorVisualizer.sensors[i].sensorMesh.remove(this.sensorVisualizer.sensors[i].arrow); } // create new + this.sensorVisualizer.sensors[i].arrow = new THREE.ArrowHelper( + new THREE.Vector3( + sensor.sensorDirection.x, + sensor.sensorDirection.y, + sensor.sensorDirection.z + ).applyQuaternion(new THREE.Quaternion( + this.parentEntity.quaternion.x, + this.parentEntity.quaternion.y, + this.parentEntity.quaternion.z, + this.parentEntity.quaternion.w + )).normalize(), + + new THREE.Vector3( + this.parentEntity.position.x, + this.parentEntity.position.y, + this.parentEntity.position.z + ).add(new THREE.Vector3( + sensor.sensorPositionOffset.x, + sensor.sensorPositionOffset.y, + sensor.sensorPositionOffset.z + ).applyQuaternion(new THREE.Quaternion( + this.parentEntity.quaternion.x, + this.parentEntity.quaternion.y, + this.parentEntity.quaternion.z, + this.parentEntity.quaternion.w + ))), + + sensor.sensorLength, + + sensor.sensorColor + ); + + this.sensorVisualizer.sensors[i].sensorMesh.add(this.sensorVisualizer.sensors[i].arrow); } @@ -124,30 +166,159 @@ GameLib.D3.ComponentPathAI.prototype.onSetParentEntity = function( var boundingBox = this.parentEntity.mesh.geometry.boundingBox; var sensorLength = this.sensorLength; - var sensorColor = new THREE.Color(1, 0, 0); + var sensorColor = new THREE.Color(0, 1, 0); // Create sensors + // Front this.sensors.push ( { sensorLength : sensorLength, sensorColor : sensorColor, sensorDirection : new THREE.Vector3( - 1, + -1, 0, 0 ).normalize(), sensorPositionOffset : new THREE.Vector3( - boundingBox.max.x * this.parentEntity.mesh.scale.x, - boundingBox.max.z * this.parentEntity.mesh.scale.z, + -boundingBox.max.x * this.parentEntity.mesh.scale.x, + boundingBox.max.y * this.parentEntity.mesh.scale.y, 0 ) } ); + var sideSensorLengthMultiplier = 0.5; + + // Absolute left + this.sensors.push + ( + { + sensorLength : sensorLength * sideSensorLengthMultiplier, + sensorColor : sensorColor, + sensorDirection : new THREE.Vector3( + 0, + 0, + 1 + ).normalize(), + + sensorPositionOffset : new THREE.Vector3( + -boundingBox.max.x * this.parentEntity.mesh.scale.x, + boundingBox.max.y * this.parentEntity.mesh.scale.y, + boundingBox.max.z * this.parentEntity.mesh.scale.z + ) + + } + ); + + // Tilted left + this.sensors.push + ( + { + sensorLength : sensorLength * sideSensorLengthMultiplier, + sensorColor : sensorColor, + sensorDirection : new THREE.Vector3( + -0.5, + 0, + 0.5 + ).normalize(), + + sensorPositionOffset : new THREE.Vector3( + -boundingBox.max.x * this.parentEntity.mesh.scale.x, + boundingBox.max.y * this.parentEntity.mesh.scale.y, + boundingBox.max.z * this.parentEntity.mesh.scale.z + ) + + } + ); + + // left forward + this.sensors.push + ( + { + sensorLength : sensorLength * sideSensorLengthMultiplier, + sensorColor : sensorColor, + sensorDirection : new THREE.Vector3( + -1, + 0, + 0 + ).normalize(), + + sensorPositionOffset : new THREE.Vector3( + -boundingBox.max.x * this.parentEntity.mesh.scale.x, + boundingBox.max.y * this.parentEntity.mesh.scale.y, + boundingBox.max.z * this.parentEntity.mesh.scale.z + ) + + } + ); + + // Absolute Right + this.sensors.push + ( + { + sensorLength : sensorLength * sideSensorLengthMultiplier, + sensorColor : sensorColor, + sensorDirection : new THREE.Vector3( + 0, + 0, + -1 + ).normalize(), + + sensorPositionOffset : new THREE.Vector3( + -boundingBox.max.x * this.parentEntity.mesh.scale.x, + boundingBox.max.y * this.parentEntity.mesh.scale.y, + -boundingBox.max.z * this.parentEntity.mesh.scale.z + ) + + } + ); + + // right forward + this.sensors.push + ( + { + sensorLength : sensorLength * sideSensorLengthMultiplier, + sensorColor : sensorColor, + sensorDirection : new THREE.Vector3( + -1, + 0, + 0 + ).normalize(), + + sensorPositionOffset : new THREE.Vector3( + -boundingBox.max.x * this.parentEntity.mesh.scale.x, + boundingBox.max.y * this.parentEntity.mesh.scale.y, + -boundingBox.max.z * this.parentEntity.mesh.scale.z + ) + + } + ); + + // Tilted right + this.sensors.push + ( + { + sensorLength : sensorLength * sideSensorLengthMultiplier, + sensorColor : sensorColor, + sensorDirection : new THREE.Vector3( + -0.5, + 0, + -0.5 + ).normalize(), + + sensorPositionOffset : new THREE.Vector3( + -boundingBox.max.x * this.parentEntity.mesh.scale.x, + boundingBox.max.y * this.parentEntity.mesh.scale.y, + -boundingBox.max.z * this.parentEntity.mesh.scale.z + ) + + } + ); + // debug code this.sensorVisualizer = { diff --git a/src/game-lib-component-path-controls.js b/src/game-lib-component-path-controls.js index 8bc4ed0..23c5391 100644 --- a/src/game-lib-component-path-controls.js +++ b/src/game-lib-component-path-controls.js @@ -53,6 +53,10 @@ GameLib.D3.ComponentPathControls.prototype.onUpdate = function( this.pathFollowingComponent.offset.x = 0; this.pathFollowingComponent.offset.y = 0; this.pathFollowingComponent.offset.z = -1; + } else if(!this.keyRightPressed && !this.keyLeftPressed){ + this.pathFollowingComponent.offset.x = 0; + this.pathFollowingComponent.offset.y = 0; + this.pathFollowingComponent.offset.z = 0; } }; diff --git a/src/game-lib-component-path-following.js b/src/game-lib-component-path-following.js index 085c014..6833059 100644 --- a/src/game-lib-component-path-following.js +++ b/src/game-lib-component-path-following.js @@ -66,7 +66,13 @@ GameLib.D3.ComponentPathFollowing.prototype.onUpdate = function( //To maintain a constant speed, you use .getPointAt( t ) instead of .getPoint( t ). //http://stackoverflow.com/questions/18400667/three-js-object-following-a-spline-path-rotation-tanget-issues-constant-sp var position = this.splineCurve3.getPointAt(this.currentPathValue); + + +// var nextPosition = this.splineCurve3.getPointAt(this.currentPathValue + 0.01); + var rotation = this.splineCurve3.getTangentAt(this.currentPathValue).normalize(); + //var tangent = this.splineCurve3.getTangentAt(this.currentPathValue).normalize(); + //var rotation = position.clone().normalize().cross( tangent ); // extract rotation var forward = new THREE.Vector3(-1, 0, 0);