/** * compute the index of the waypoint and the interpolation value according to a distance * returns a vector 2 containing the index in the x field and the interpolation value in the y field * @param distance the distance traveled on this path * @return the waypoint index and the interpolation value in a vector2 */ 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()) { if (sum + len >= distance) { return new Vector2f((float) i, (distance - sum) / len); } sum += len; i++; } store.set((float) spline.getControlPoints().size() - 1, 1.0f); return store; }
/** * compute the index of the waypoint and the interpolation value according to a distance * returns a vector 2 containing the index in the x field and the interpolation value in the y field * @param distance the distance traveled on this path * @return the waypoint index and the interpolation value in a vector2 */ 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()) { if (sum + len >= distance) { return new Vector2f((float) i, (distance - sum) / len); } sum += len; i++; } store.set((float) spline.getControlPoints().size() - 1, 1.0f); return store; }