Fixed issue in MotionPath where having a path with only 2 waypoints with the same coordinates was causing an IndexArrayOutOfBound exception.
Also used a temp var for a Vec2 that was instanciated on each frame
This commit is contained in:
parent
d7b3d580ed
commit
dbae186426
@ -80,11 +80,12 @@ public class MotionPath implements Savable {
|
||||
TempVars vars = TempVars.get();
|
||||
Vector3f temp = vars.vect1;
|
||||
Vector3f tmpVector = vars.vect2;
|
||||
Vector2f v = vars.vect2d;
|
||||
//computing traveled distance according to new time
|
||||
traveledDistance = time * (getLength() / control.getInitialDuration());
|
||||
|
||||
//getting waypoint index and current value from new traveled distance
|
||||
Vector2f v = getWayPointIndexForDistance(traveledDistance);
|
||||
v = getWayPointIndexForDistance(traveledDistance,v);
|
||||
|
||||
//setting values
|
||||
control.setCurrentWayPoint((int) v.x);
|
||||
@ -180,8 +181,12 @@ public class MotionPath implements Savable {
|
||||
* @param distance the distance traveled on this path
|
||||
* @return the waypoint index and the interpolation value in a vector2
|
||||
*/
|
||||
public Vector2f getWayPointIndexForDistance(float distance) {
|
||||
public Vector2f getWayPointIndexForDistance(float distance, Vector2f store) {
|
||||
float sum = 0;
|
||||
if(spline.getTotalLength() == 0){
|
||||
store.set(0, 0);
|
||||
return store;
|
||||
}
|
||||
distance = distance % spline.getTotalLength();
|
||||
int i = 0;
|
||||
for (Float len : spline.getSegmentsLength()) {
|
||||
@ -191,7 +196,8 @@ public class MotionPath implements Savable {
|
||||
sum += len;
|
||||
i++;
|
||||
}
|
||||
return new Vector2f((float) spline.getControlPoints().size() - 1, 1.0f);
|
||||
store.set((float) spline.getControlPoints().size() - 1, 1.0f);
|
||||
return store;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user