start update path following
parent
c8c0d45e18
commit
24a17da5d4
|
@ -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.
|
||||
|
@ -174,7 +174,7 @@ GameLib.D3.ComponentPathFollowing.prototype.onSetParentEntity = function(
|
|||
parentScene,
|
||||
parentEntity
|
||||
) {
|
||||
if(!this.splineCurve3) {
|
||||
if (!this.spline) {
|
||||
console.error("NO PATH GIVEN");
|
||||
}
|
||||
};
|
|
@ -330,3 +330,19 @@ 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);
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue