use of com.jme3.util.TempVars in project jmonkeyengine by jMonkeyEngine.
the class BoneTrack method setTime.
/**
*
* Modify the bone which this track modifies in the skeleton to contain
* the correct animation transforms for a given time.
* The transforms can be interpolated in some method from the keyframes.
*
* @param time the current time of the animation
* @param weight the weight of the animation
* @param control
* @param channel
* @param vars
*/
public void setTime(float time, float weight, AnimControl control, AnimChannel channel, TempVars vars) {
BitSet affectedBones = channel.getAffectedBones();
if (affectedBones != null && !affectedBones.get(targetBoneIndex)) {
return;
}
Bone target = control.getSkeleton().getBone(targetBoneIndex);
Vector3f tempV = vars.vect1;
Vector3f tempS = vars.vect2;
Quaternion tempQ = vars.quat1;
Vector3f tempV2 = vars.vect3;
Vector3f tempS2 = vars.vect4;
Quaternion tempQ2 = vars.quat2;
int lastFrame = times.length - 1;
if (time < 0 || lastFrame == 0) {
rotations.get(0, tempQ);
translations.get(0, tempV);
if (scales != null) {
scales.get(0, tempS);
}
} else if (time >= times[lastFrame]) {
rotations.get(lastFrame, tempQ);
translations.get(lastFrame, tempV);
if (scales != null) {
scales.get(lastFrame, tempS);
}
} else {
int startFrame = 0;
int endFrame = 1;
// use lastFrame so we never overflow the array
int i;
for (i = 0; i < lastFrame && times[i] < time; i++) {
startFrame = i;
endFrame = i + 1;
}
float blend = (time - times[startFrame]) / (times[endFrame] - times[startFrame]);
rotations.get(startFrame, tempQ);
translations.get(startFrame, tempV);
if (scales != null) {
scales.get(startFrame, tempS);
}
rotations.get(endFrame, tempQ2);
translations.get(endFrame, tempV2);
if (scales != null) {
scales.get(endFrame, tempS2);
}
tempQ.nlerp(tempQ2, blend);
tempV.interpolateLocal(tempV2, blend);
tempS.interpolateLocal(tempS2, blend);
}
// if (weight != 1f) {
target.blendAnimTransforms(tempV, tempQ, scales != null ? tempS : null, weight);
// } else {
// target.setAnimTransforms(tempV, tempQ, scales != null ? tempS : null);
// }
}
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);
}
Aggregations