use of com.jme3.util.TempVars in project jmonkeyengine by jMonkeyEngine.
the class MotionPath method interpolatePath.
/**
* interpolate the path giving the time since the beginning and the motionControl
* this methods sets the new localTranslation to the spatial of the MotionEvent control.
* @param time the time since the animation started
* @param control the control over the moving spatial
*/
public float interpolatePath(float time, MotionEvent control, float tpf) {
float traveledDistance = 0;
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
v = getWayPointIndexForDistance(traveledDistance, v);
//setting values
control.setCurrentWayPoint((int) v.x);
control.setCurrentValue(v.y);
//interpolating new position
getSpline().interpolate(control.getCurrentValue(), control.getCurrentWayPoint(), temp);
if (control.needsDirection()) {
tmpVector.set(temp);
control.setDirection(tmpVector.subtractLocal(control.getSpatial().getLocalTranslation()).normalizeLocal());
}
checkWayPoint(control, tpf);
control.getSpatial().setLocalTranslation(temp);
vars.release();
return traveledDistance;
}
use of com.jme3.util.TempVars in project jmonkeyengine by jMonkeyEngine.
the class AnimChannel method reset.
public void reset(boolean rewind) {
if (rewind) {
setTime(0);
if (control.getSkeleton() != null) {
control.getSkeleton().resetAndUpdate();
} else {
TempVars vars = TempVars.get();
update(0, vars);
vars.release();
}
}
animation = null;
notified = false;
}
use of com.jme3.util.TempVars in project jmonkeyengine by jMonkeyEngine.
the class AnimControl method controlUpdate.
/**
* Internal use only.
*/
@Override
protected void controlUpdate(float tpf) {
if (skeleton != null) {
// reset skeleton to bind pose
skeleton.reset();
}
TempVars vars = TempVars.get();
for (int i = 0; i < channels.size(); i++) {
channels.get(i).update(tpf, vars);
}
vars.release();
if (skeleton != null) {
skeleton.updateWorldVectors();
}
}
use of com.jme3.util.TempVars in project jmonkeyengine by jMonkeyEngine.
the class BoundingBox method distanceToEdge.
public float distanceToEdge(Vector3f point) {
// compute coordinates of point in box coordinate system
TempVars vars = TempVars.get();
Vector3f closest = vars.vect1;
point.subtract(center, closest);
// project test point onto box
float sqrDistance = 0.0f;
float delta;
if (closest.x < -xExtent) {
delta = closest.x + xExtent;
sqrDistance += delta * delta;
closest.x = -xExtent;
} else if (closest.x > xExtent) {
delta = closest.x - xExtent;
sqrDistance += delta * delta;
closest.x = xExtent;
}
if (closest.y < -yExtent) {
delta = closest.y + yExtent;
sqrDistance += delta * delta;
closest.y = -yExtent;
} else if (closest.y > yExtent) {
delta = closest.y - yExtent;
sqrDistance += delta * delta;
closest.y = yExtent;
}
if (closest.z < -zExtent) {
delta = closest.z + zExtent;
sqrDistance += delta * delta;
closest.z = -zExtent;
} else if (closest.z > zExtent) {
delta = closest.z - zExtent;
sqrDistance += delta * delta;
closest.z = zExtent;
}
vars.release();
return FastMath.sqrt(sqrDistance);
}
use of com.jme3.util.TempVars in project jmonkeyengine by jMonkeyEngine.
the class BoundingBox method computeFromTris.
public void computeFromTris(int[] indices, Mesh mesh, int start, int end) {
if (end - start <= 0) {
return;
}
TempVars vars = TempVars.get();
Vector3f vect1 = vars.vect1;
Vector3f vect2 = vars.vect2;
Triangle triangle = vars.triangle;
Vector3f min = vect1.set(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY);
Vector3f max = vect2.set(Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY);
Vector3f point;
for (int i = start; i < end; i++) {
mesh.getTriangle(indices[i], triangle);
point = triangle.get(0);
checkMinMax(min, max, point);
point = triangle.get(1);
checkMinMax(min, max, point);
point = triangle.get(2);
checkMinMax(min, max, point);
}
center.set(min.addLocal(max));
center.multLocal(0.5f);
xExtent = max.x - center.x;
yExtent = max.y - center.y;
zExtent = max.z - center.z;
vars.release();
}
Aggregations