drive input component - spline updates
parent
9c2af5de8f
commit
12c5ac1450
|
@ -73,12 +73,12 @@ GameLib.D3.API.Mesh = function(
|
|||
this.name = name;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(vertices)) {
|
||||
throw new Error('Cannot create a mesh with no vertices');
|
||||
vertices = [];
|
||||
}
|
||||
this.vertices = vertices;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(faces)) {
|
||||
throw new Error('Cannot create a mesh with no faces');
|
||||
faces = [];
|
||||
}
|
||||
this.faces = faces;
|
||||
|
||||
|
|
|
@ -165,12 +165,6 @@ GameLib.D3.API.PathFollowing = function (
|
|||
rotationVector = new GameLib.API.Quaternion();
|
||||
}
|
||||
this.rotationVector = rotationVector;
|
||||
|
||||
this.mx = new GameLib.Utils.MovingAverage(10);
|
||||
|
||||
this.my = new GameLib.Utils.MovingAverage(10);
|
||||
|
||||
this.mz = new GameLib.Utils.MovingAverage(10);
|
||||
};
|
||||
|
||||
GameLib.D3.API.PathFollowing.prototype = Object.create(GameLib.Component.prototype);
|
||||
|
|
|
@ -32,6 +32,8 @@ GameLib.D3.Input.Drive = function RuntimeInputDrive(
|
|||
|
||||
this.keyRight = false;
|
||||
|
||||
this.distance = 0;
|
||||
|
||||
this.instance = this.createInstance();
|
||||
};
|
||||
|
||||
|
@ -114,15 +116,21 @@ GameLib.D3.Input.Drive.FromObjectComponent = function(graphics, objectComponent)
|
|||
|
||||
GameLib.D3.Input.Drive.prototype.update = function(deltaTime) {
|
||||
if (this.pathFollowingComponent) {
|
||||
|
||||
this.pathFollowingComponent.mesh.localPosition.x = this.pathFollowingComponent.rotationMatrix.up.x;
|
||||
this.pathFollowingComponent.mesh.localPosition.y = this.pathFollowingComponent.rotationMatrix.up.y;
|
||||
this.pathFollowingComponent.mesh.localPosition.z = this.pathFollowingComponent.rotationMatrix.up.z;
|
||||
|
||||
if (this.keyLeft) {
|
||||
|
||||
|
||||
|
||||
this.pathFollowingComponent.mesh.localPosition
|
||||
this.distance -= 0.05;
|
||||
}
|
||||
|
||||
if (this.keyRight) {
|
||||
console.log('keyRight');
|
||||
this.distance += 0.05;
|
||||
}
|
||||
|
||||
this.pathFollowingComponent.mesh.localPosition.x += (this.distance * this.pathFollowingComponent.rotationMatrix.left.x);
|
||||
this.pathFollowingComponent.mesh.localPosition.y += (this.distance * this.pathFollowingComponent.rotationMatrix.left.y);
|
||||
this.pathFollowingComponent.mesh.localPosition.z += (this.distance * this.pathFollowingComponent.rotationMatrix.left.z);
|
||||
}
|
||||
};
|
|
@ -92,6 +92,13 @@ GameLib.D3.Mesh = function RuntimeMesh(
|
|||
this.computeNormals = computeNormals;
|
||||
|
||||
this.instance = this.createInstance(false);
|
||||
|
||||
this.instance.geometry.computeBoundingBox();
|
||||
|
||||
this.width = this.instance.geometry.boundingBox.max.x - this.instance.geometry.boundingBox.min.x;
|
||||
this.height = this.instance.geometry.boundingBox.max.y - this.instance.geometry.boundingBox.min.y;
|
||||
this.depth = this.instance.geometry.boundingBox.max.z - this.instance.geometry.boundingBox.min.z;
|
||||
|
||||
};
|
||||
|
||||
GameLib.D3.Mesh.prototype = Object.create(GameLib.D3.API.Mesh.prototype);
|
||||
|
|
|
@ -105,6 +105,13 @@ GameLib.D3.PathFollowing = function RuntimePathFollowing(
|
|||
this.rotationVector
|
||||
);
|
||||
|
||||
|
||||
this.mx = new GameLib.Utils.MovingAverage(10);
|
||||
|
||||
this.my = new GameLib.Utils.MovingAverage(10);
|
||||
|
||||
this.mz = new GameLib.Utils.MovingAverage(10);
|
||||
|
||||
};
|
||||
|
||||
GameLib.D3.PathFollowing.prototype = Object.create(GameLib.D3.API.PathFollowing.prototype);
|
||||
|
@ -238,7 +245,11 @@ GameLib.D3.PathFollowing.prototype.update = function(deltaTime) {
|
|||
}
|
||||
this.grain = (this.currentSpeed / 100.0);
|
||||
|
||||
this.currentPosition = this.spline.getPointAt(this.currentPathValue);
|
||||
var currentPosition = this.spline.getPointAt(this.currentPathValue);
|
||||
|
||||
this.currentPosition.x = currentPosition.x;
|
||||
this.currentPosition.y = currentPosition.y;
|
||||
this.currentPosition.z = currentPosition.z;
|
||||
|
||||
this.currentPathValue += this.grain;
|
||||
|
||||
|
@ -250,12 +261,30 @@ GameLib.D3.PathFollowing.prototype.update = function(deltaTime) {
|
|||
this.currentPathValue = 0.0;
|
||||
}
|
||||
|
||||
this.futurePosition = this.spline.getPointAt(this.currentPathValue);
|
||||
var futurePosition = this.spline.getPointAt(this.currentPathValue);
|
||||
|
||||
this.futurePosition.x = futurePosition.x;
|
||||
this.futurePosition.y = futurePosition.y;
|
||||
this.futurePosition.z = futurePosition.z;
|
||||
|
||||
this.raycaster.setPosition(
|
||||
this.futurePosition
|
||||
);
|
||||
|
||||
var direction = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
new GameLib.API.Vector3(
|
||||
this.up.x * -1,
|
||||
this.up.y * -1,
|
||||
this.up.z * -1
|
||||
)
|
||||
);
|
||||
|
||||
this.raycaster.setDirection(
|
||||
direction
|
||||
);
|
||||
|
||||
var normal = this.raycaster.getFaceNormal(this.raytraceMesh);
|
||||
|
||||
if (normal) {
|
||||
|
@ -277,8 +306,12 @@ GameLib.D3.PathFollowing.prototype.update = function(deltaTime) {
|
|||
/**
|
||||
* Update Position
|
||||
*/
|
||||
// this.mesh.position.x = this.futurePosition.x + (this.rotationMatrix.up.x * (this.mesh.height - (2 * this.rotationMatrix.up.x)) / 2);// + transformedOffset.x;
|
||||
// this.mesh.position.y = this.futurePosition.y + (this.rotationMatrix.up.y * (this.mesh.height - (2 * this.rotationMatrix.up.y)) / 2);
|
||||
// this.mesh.position.z = this.futurePosition.z + (this.rotationMatrix.up.z * (this.mesh.height - (2 * this.rotationMatrix.up.z)) / 2);// + transformedOffset.z;
|
||||
|
||||
this.mesh.position.x = this.futurePosition.x;// + transformedOffset.x;
|
||||
this.mesh.position.y = this.futurePosition.y;// + transformedOffset.y;
|
||||
this.mesh.position.y = this.futurePosition.y;
|
||||
this.mesh.position.z = this.futurePosition.z;// + transformedOffset.z;
|
||||
|
||||
/**
|
||||
|
|
|
@ -111,7 +111,9 @@ GameLib.D3.Raycaster.prototype.setDirection = function(
|
|||
GameLib.D3.Raycaster.prototype.setPosition = function(
|
||||
position
|
||||
) {
|
||||
this.position = position;
|
||||
this.position.x = position.x;
|
||||
this.position.y = position.y;
|
||||
this.position.z = position.z;
|
||||
|
||||
this.position.updateInstance();
|
||||
|
||||
|
@ -144,4 +146,32 @@ GameLib.D3.Raycaster.prototype.getFaceNormal = function(mesh) {
|
|||
}
|
||||
|
||||
return normal;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the face normal (if any) of an intersection between current ray position, direction and a provided mesh
|
||||
* @param mesh GameLib.D3.Mesh
|
||||
* @returns {null | GameLib.Vector3}
|
||||
*/
|
||||
GameLib.D3.Raycaster.prototype.getIntersectPoint = function(mesh) {
|
||||
|
||||
var point = null;
|
||||
|
||||
var intersect = this.instance.intersectObject(
|
||||
mesh.instance
|
||||
);
|
||||
|
||||
if (intersect && intersect.length > 0) {
|
||||
point = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
new GameLib.API.Vector3(
|
||||
intersect[0].point.x,
|
||||
intersect[0].point.y,
|
||||
intersect[0].point.z
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return point;
|
||||
};
|
Loading…
Reference in New Issue