backup
parent
87d327cb4a
commit
9c90cb81ac
|
@ -61,11 +61,20 @@ GameLib.D3.ComponentPathAI.prototype.onUpdate = function(
|
||||||
this.pathFollowingComponent.offset.z = -1;
|
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) {
|
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];
|
var sensor = this.sensors[i];
|
||||||
|
|
||||||
|
@ -94,11 +103,44 @@ GameLib.D3.ComponentPathAI.prototype.onUpdate = function(
|
||||||
|
|
||||||
if(this.sensorVisualizer.sensors[i].arrow) {
|
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
|
// 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 boundingBox = this.parentEntity.mesh.geometry.boundingBox;
|
||||||
var sensorLength = this.sensorLength;
|
var sensorLength = this.sensorLength;
|
||||||
var sensorColor = new THREE.Color(1, 0, 0);
|
var sensorColor = new THREE.Color(0, 1, 0);
|
||||||
|
|
||||||
// Create sensors
|
// Create sensors
|
||||||
|
|
||||||
|
// Front
|
||||||
this.sensors.push
|
this.sensors.push
|
||||||
(
|
(
|
||||||
{
|
{
|
||||||
sensorLength : sensorLength,
|
sensorLength : sensorLength,
|
||||||
sensorColor : sensorColor,
|
sensorColor : sensorColor,
|
||||||
sensorDirection : new THREE.Vector3(
|
sensorDirection : new THREE.Vector3(
|
||||||
1,
|
-1,
|
||||||
0,
|
0,
|
||||||
0
|
0
|
||||||
).normalize(),
|
).normalize(),
|
||||||
|
|
||||||
sensorPositionOffset : new THREE.Vector3(
|
sensorPositionOffset : new THREE.Vector3(
|
||||||
boundingBox.max.x * this.parentEntity.mesh.scale.x,
|
-boundingBox.max.x * this.parentEntity.mesh.scale.x,
|
||||||
boundingBox.max.z * this.parentEntity.mesh.scale.z,
|
boundingBox.max.y * this.parentEntity.mesh.scale.y,
|
||||||
0
|
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
|
// debug code
|
||||||
this.sensorVisualizer = {
|
this.sensorVisualizer = {
|
||||||
|
|
|
@ -53,6 +53,10 @@ GameLib.D3.ComponentPathControls.prototype.onUpdate = function(
|
||||||
this.pathFollowingComponent.offset.x = 0;
|
this.pathFollowingComponent.offset.x = 0;
|
||||||
this.pathFollowingComponent.offset.y = 0;
|
this.pathFollowingComponent.offset.y = 0;
|
||||||
this.pathFollowingComponent.offset.z = -1;
|
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;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,13 @@ GameLib.D3.ComponentPathFollowing.prototype.onUpdate = function(
|
||||||
//To maintain a constant speed, you use .getPointAt( t ) instead of .getPoint( t ).
|
//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
|
//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 position = this.splineCurve3.getPointAt(this.currentPathValue);
|
||||||
|
|
||||||
|
|
||||||
|
// var nextPosition = this.splineCurve3.getPointAt(this.currentPathValue + 0.01);
|
||||||
|
|
||||||
var rotation = this.splineCurve3.getTangentAt(this.currentPathValue).normalize();
|
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
|
// extract rotation
|
||||||
var forward = new THREE.Vector3(-1, 0, 0);
|
var forward = new THREE.Vector3(-1, 0, 0);
|
||||||
|
|
Loading…
Reference in New Issue