beta.r3js.org
polygonboutique 2016-11-25 09:57:09 +01:00
parent 87d327cb4a
commit 9c90cb81ac
3 changed files with 187 additions and 6 deletions

View File

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

View File

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

View File

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