use of com.jme3.util.TempVars in project jmonkeyengine by jMonkeyEngine.
the class KinematicRagdollControl method ikUpdate.
private void ikUpdate(float tpf) {
TempVars vars = TempVars.get();
Quaternion tmpRot1 = vars.quat1;
Quaternion[] tmpRot2 = new Quaternion[] { vars.quat2, new Quaternion() };
Iterator<String> it = ikTargets.keySet().iterator();
float distance;
Bone bone;
String boneName;
while (it.hasNext()) {
boneName = it.next();
bone = (Bone) boneLinks.get(boneName).bone;
if (!bone.hasUserControl()) {
Logger.getLogger(KinematicRagdollControl.class.getSimpleName()).log(Level.FINE, "{0} doesn't have user control", boneName);
continue;
}
distance = bone.getModelSpacePosition().distance(ikTargets.get(boneName));
if (distance < IKThreshold) {
Logger.getLogger(KinematicRagdollControl.class.getSimpleName()).log(Level.FINE, "Distance is close enough");
continue;
}
int depth = 0;
int maxDepth = ikChainDepth.get(bone.getName());
updateBone(boneLinks.get(bone.getName()), tpf * (float) FastMath.sqrt(distance), vars, tmpRot1, tmpRot2, bone, ikTargets.get(boneName), depth, maxDepth);
Vector3f position = vars.vect1;
for (PhysicsBoneLink link : boneLinks.values()) {
matchPhysicObjectToBone(link, position, tmpRot1);
}
}
vars.release();
}
use of com.jme3.util.TempVars in project jmonkeyengine by jMonkeyEngine.
the class BoundingBox method transform.
/**
* <code>transform</code> modifies the center of the box to reflect the
* change made via a rotation, translation and scale.
*
* @param trans
* the transform to apply
* @param store
* box to store result in
*/
public BoundingVolume transform(Transform trans, BoundingVolume store) {
BoundingBox box;
if (store == null || store.getType() != Type.AABB) {
box = new BoundingBox();
} else {
box = (BoundingBox) store;
}
center.mult(trans.getScale(), box.center);
trans.getRotation().mult(box.center, box.center);
box.center.addLocal(trans.getTranslation());
TempVars vars = TempVars.get();
Matrix3f transMatrix = vars.tempMat3;
transMatrix.set(trans.getRotation());
// Make the rotation matrix all positive to get the maximum x/y/z extent
transMatrix.absoluteLocal();
Vector3f scale = trans.getScale();
vars.vect1.set(xExtent * FastMath.abs(scale.x), yExtent * FastMath.abs(scale.y), zExtent * FastMath.abs(scale.z));
transMatrix.mult(vars.vect1, vars.vect2);
// Assign the biggest rotations after scales.
box.xExtent = FastMath.abs(vars.vect2.getX());
box.yExtent = FastMath.abs(vars.vect2.getY());
box.zExtent = FastMath.abs(vars.vect2.getZ());
vars.release();
return box;
}
use of com.jme3.util.TempVars in project jmonkeyengine by jMonkeyEngine.
the class BoundingBox method collideWithRay.
/**
* @see com.jme.bounding.BoundingVolume#intersectsWhere(com.jme.math.Ray)
*/
private int collideWithRay(Ray ray, CollisionResults results) {
TempVars vars = TempVars.get();
try {
Vector3f diff = vars.vect1.set(ray.origin).subtractLocal(center);
Vector3f direction = vars.vect2.set(ray.direction);
//float[] t = {0f, Float.POSITIVE_INFINITY};
// use one of the tempvars arrays
float[] t = vars.fWdU;
t[0] = 0;
t[1] = Float.POSITIVE_INFINITY;
float saveT0 = t[0], saveT1 = t[1];
boolean notEntirelyClipped = clip(+direction.x, -diff.x - xExtent, t) && clip(-direction.x, +diff.x - xExtent, t) && clip(+direction.y, -diff.y - yExtent, t) && clip(-direction.y, +diff.y - yExtent, t) && clip(+direction.z, -diff.z - zExtent, t) && clip(-direction.z, +diff.z - zExtent, t);
if (notEntirelyClipped && (t[0] != saveT0 || t[1] != saveT1)) {
if (t[1] > t[0]) {
float[] distances = t;
Vector3f point0 = new Vector3f(ray.direction).multLocal(distances[0]).addLocal(ray.origin);
Vector3f point1 = new Vector3f(ray.direction).multLocal(distances[1]).addLocal(ray.origin);
CollisionResult result = new CollisionResult(point0, distances[0]);
results.addCollision(result);
result = new CollisionResult(point1, distances[1]);
results.addCollision(result);
return 2;
}
Vector3f point = new Vector3f(ray.direction).multLocal(t[0]).addLocal(ray.origin);
CollisionResult result = new CollisionResult(point, t[0]);
results.addCollision(result);
return 1;
}
return 0;
} finally {
vars.release();
}
}
use of com.jme3.util.TempVars in project jmonkeyengine by jMonkeyEngine.
the class BoundingSphere method collideWithRay.
private int collideWithRay(Ray ray) {
TempVars vars = TempVars.get();
Vector3f diff = vars.vect1.set(ray.getOrigin()).subtractLocal(center);
float a = diff.dot(diff) - (getRadius() * getRadius());
float a1, discr;
if (a <= 0.0) {
// inside sphere
vars.release();
return 1;
}
a1 = ray.direction.dot(diff);
vars.release();
if (a1 >= 0.0) {
return 0;
}
discr = a1 * a1 - a;
if (discr < 0.0) {
return 0;
} else if (discr >= FastMath.ZERO_TOLERANCE) {
return 2;
}
return 1;
}
use of com.jme3.util.TempVars in project jmonkeyengine by jMonkeyEngine.
the class BoundingSphere method collideWithRay.
/*
* (non-Javadoc)
*
* @see com.jme.bounding.BoundingVolume#intersectsWhere(com.jme.math.Ray)
*/
private int collideWithRay(Ray ray, CollisionResults results) {
TempVars vars = TempVars.get();
Vector3f diff = vars.vect1.set(ray.getOrigin()).subtractLocal(center);
float a = diff.dot(diff) - (getRadius() * getRadius());
float a1, discr, root;
if (a <= 0.0) {
// inside sphere
a1 = ray.direction.dot(diff);
discr = (a1 * a1) - a;
root = FastMath.sqrt(discr);
float distance = root - a1;
Vector3f point = new Vector3f(ray.direction).multLocal(distance).addLocal(ray.origin);
CollisionResult result = new CollisionResult(point, distance);
results.addCollision(result);
vars.release();
return 1;
}
a1 = ray.direction.dot(diff);
vars.release();
if (a1 >= 0.0) {
return 0;
}
discr = a1 * a1 - a;
if (discr < 0.0) {
return 0;
} else if (discr >= FastMath.ZERO_TOLERANCE) {
root = FastMath.sqrt(discr);
float dist = -a1 - root;
Vector3f point = new Vector3f(ray.direction).multLocal(dist).addLocal(ray.origin);
results.addCollision(new CollisionResult(point, dist));
dist = -a1 + root;
point = new Vector3f(ray.direction).multLocal(dist).addLocal(ray.origin);
results.addCollision(new CollisionResult(point, dist));
return 2;
} else {
float dist = -a1;
Vector3f point = new Vector3f(ray.direction).multLocal(dist).addLocal(ray.origin);
results.addCollision(new CollisionResult(point, dist));
return 1;
}
}
Aggregations