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

View File

@ -330,3 +330,19 @@ GameLib.D3.Utils.FixPolyZPlane = function(verticesFlat, grain) {
return vertices; 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);
}
};