start update path following

beta.r3js.org
Theunis J. Botha 2016-12-07 09:52:23 +01:00
parent c8c0d45e18
commit 24a17da5d4
2 changed files with 28 additions and 12 deletions

View File

@ -2,8 +2,8 @@
*
* @param id
* @param name
* @param splineCurve3
* @param trackThreeMeshArray
* @param spline GameLib.D3.Spline
* @param meshes[] GameLib.D3.Mesh
* @param accel
* @param maxSpeed
* @param baseOffset
@ -14,8 +14,8 @@
GameLib.D3.ComponentPathFollowing = function ComponentPathFollowing(
id,
name,
splineCurve3,
trackThreeMeshArray,
spline,
meshes,
accel,
maxSpeed,
baseOffset,
@ -31,8 +31,8 @@ GameLib.D3.ComponentPathFollowing = function ComponentPathFollowing(
this.name = name;
this.parentEntity = null;
this.splineCurve3 = splineCurve3;
this.trackThreeMeshArray = trackThreeMeshArray;
this.spline = spline;
this.trackThreeMeshArray = mesh;
this.maxSpeed = maxSpeed || 10.0;
this.accel = accel || 2.0;
@ -66,7 +66,7 @@ GameLib.D3.ComponentPathFollowing.prototype.onUpdate = function(
parentEntity
) {
if(this.splineCurve3 && this.trackThreeMeshArray) {
if(this.spline && this.trackThreeMeshArray) {
if(this.currentPathValue >= 1 || this.currentPathValue < 0) {
this.currentPathValue = 0;
@ -74,7 +74,7 @@ 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 position = this.spline.instance.getPointAt(this.currentPathValue);
// Update the current thing
@ -96,7 +96,7 @@ GameLib.D3.ComponentPathFollowing.prototype.onUpdate = function(
nextIndex = 0;
}
var nextPoint = this.splineCurve3.getPointAt(nextIndex);
var nextPoint = this.spline.instance.getPointAt(nextIndex);
// - - - - - - - - - - - - -
// Ray trace from the current position.
@ -117,7 +117,7 @@ GameLib.D3.ComponentPathFollowing.prototype.onUpdate = function(
this.trackThreeMeshArray[m]
);
if(intersect) {
if (intersect) {
normal = intersect[0].face.normal;
break;
}
@ -174,7 +174,7 @@ GameLib.D3.ComponentPathFollowing.prototype.onSetParentEntity = function(
parentScene,
parentEntity
) {
if(!this.splineCurve3) {
if (!this.spline) {
console.error("NO PATH GIVEN");
}
};

View File

@ -329,4 +329,20 @@ GameLib.D3.Utils.FixPolyZPlane = function(verticesFlat, grain) {
}
return vertices;
};
};
GameLib.D3.Utils.MovingAverage = function(period) {
var nums = [];
return function(num) {
nums.push(num);
if (nums.length > period)
nums.splice(0,1); // remove the first element of the array
var sum = 0;
for (var i in nums)
sum += nums[i];
var n = period;
if (nums.length < period)
n = nums.length;
return(sum/n);
}
};