Search in sources :

Example 71 with TempVars

use of com.jme3.util.TempVars in project jmonkeyengine by jMonkeyEngine.

the class KinematicRagdollControl method applyUserControl.

public void applyUserControl() {
    for (Bone bone : skeleton.getRoots()) {
        RagdollUtils.setUserControl(bone, false);
    }
    if (ikTargets.isEmpty()) {
        setKinematicMode();
    } else {
        Iterator iterator = ikTargets.keySet().iterator();
        TempVars vars = TempVars.get();
        while (iterator.hasNext()) {
            Bone bone = (Bone) iterator.next();
            while (bone.getParent() != null) {
                Quaternion tmpRot1 = vars.quat1;
                Vector3f position = vars.vect1;
                matchPhysicObjectToBone(boneLinks.get(bone.getName()), position, tmpRot1);
                bone.setUserControl(true);
                bone = bone.getParent();
            }
        }
        vars.release();
    }
}
Also used : Quaternion(com.jme3.math.Quaternion) Vector3f(com.jme3.math.Vector3f) Bone(com.jme3.animation.Bone) TempVars(com.jme3.util.TempVars)

Example 72 with TempVars

use of com.jme3.util.TempVars in project jmonkeyengine by jMonkeyEngine.

the class BoundingBox method intersects.

/**
     * determines if this bounding box intersects with a given oriented bounding
     * box.
     * 
     * @see com.jme.bounding.BoundingVolume#intersectsOrientedBoundingBox(com.jme.bounding.OrientedBoundingBox)
     */
//    public boolean intersectsOrientedBoundingBox(OrientedBoundingBox obb) {
//        return obb.intersectsBoundingBox(this);
//    }
/**
     * determines if this bounding box intersects with a given ray object. If an
     * intersection has occurred, true is returned, otherwise false is returned.
     * 
     * @see BoundingVolume#intersects(com.jme3.math.Ray) 
     */
public boolean intersects(Ray ray) {
    assert Vector3f.isValidVector(center);
    float rhs;
    TempVars vars = TempVars.get();
    Vector3f diff = ray.origin.subtract(getCenter(vars.vect2), vars.vect1);
    final float[] fWdU = vars.fWdU;
    final float[] fAWdU = vars.fAWdU;
    final float[] fDdU = vars.fDdU;
    final float[] fADdU = vars.fADdU;
    final float[] fAWxDdU = vars.fAWxDdU;
    fWdU[0] = ray.getDirection().dot(Vector3f.UNIT_X);
    fAWdU[0] = FastMath.abs(fWdU[0]);
    fDdU[0] = diff.dot(Vector3f.UNIT_X);
    fADdU[0] = FastMath.abs(fDdU[0]);
    if (fADdU[0] > xExtent && fDdU[0] * fWdU[0] >= 0.0) {
        vars.release();
        return false;
    }
    fWdU[1] = ray.getDirection().dot(Vector3f.UNIT_Y);
    fAWdU[1] = FastMath.abs(fWdU[1]);
    fDdU[1] = diff.dot(Vector3f.UNIT_Y);
    fADdU[1] = FastMath.abs(fDdU[1]);
    if (fADdU[1] > yExtent && fDdU[1] * fWdU[1] >= 0.0) {
        vars.release();
        return false;
    }
    fWdU[2] = ray.getDirection().dot(Vector3f.UNIT_Z);
    fAWdU[2] = FastMath.abs(fWdU[2]);
    fDdU[2] = diff.dot(Vector3f.UNIT_Z);
    fADdU[2] = FastMath.abs(fDdU[2]);
    if (fADdU[2] > zExtent && fDdU[2] * fWdU[2] >= 0.0) {
        vars.release();
        return false;
    }
    Vector3f wCrossD = ray.getDirection().cross(diff, vars.vect2);
    fAWxDdU[0] = FastMath.abs(wCrossD.dot(Vector3f.UNIT_X));
    rhs = yExtent * fAWdU[2] + zExtent * fAWdU[1];
    if (fAWxDdU[0] > rhs) {
        vars.release();
        return false;
    }
    fAWxDdU[1] = FastMath.abs(wCrossD.dot(Vector3f.UNIT_Y));
    rhs = xExtent * fAWdU[2] + zExtent * fAWdU[0];
    if (fAWxDdU[1] > rhs) {
        vars.release();
        return false;
    }
    fAWxDdU[2] = FastMath.abs(wCrossD.dot(Vector3f.UNIT_Z));
    rhs = xExtent * fAWdU[1] + yExtent * fAWdU[0];
    if (fAWxDdU[2] > rhs) {
        vars.release();
        return false;
    }
    vars.release();
    return true;
}
Also used : TempVars(com.jme3.util.TempVars)

Example 73 with TempVars

use of com.jme3.util.TempVars in project jmonkeyengine by jMonkeyEngine.

the class BoundingBox method computeFromTris.

/**
     * <code>computeFromTris</code> creates a new Bounding Box from a given
     * set of triangles. It is used in OBBTree calculations.
     * 
     * @param tris
     * @param start
     * @param end
     */
public void computeFromTris(Triangle[] tris, int start, int end) {
    if (end - start <= 0) {
        return;
    }
    TempVars vars = TempVars.get();
    Vector3f min = vars.vect1.set(new Vector3f(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY));
    Vector3f max = vars.vect2.set(new Vector3f(Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY));
    Vector3f point;
    for (int i = start; i < end; i++) {
        point = tris[i].get(0);
        checkMinMax(min, max, point);
        point = tris[i].get(1);
        checkMinMax(min, max, point);
        point = tris[i].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();
}
Also used : TempVars(com.jme3.util.TempVars)

Example 74 with TempVars

use of com.jme3.util.TempVars in project jmonkeyengine by jMonkeyEngine.

the class BoundingBox method transform.

public BoundingVolume transform(Matrix4f trans, BoundingVolume store) {
    BoundingBox box;
    if (store == null || store.getType() != Type.AABB) {
        box = new BoundingBox();
    } else {
        box = (BoundingBox) store;
    }
    TempVars vars = TempVars.get();
    float w = trans.multProj(center, box.center);
    box.center.divideLocal(w);
    Matrix3f transMatrix = vars.tempMat3;
    trans.toRotationMatrix(transMatrix);
    // Make the rotation matrix all positive to get the maximum x/y/z extent
    transMatrix.absoluteLocal();
    vars.vect1.set(xExtent, yExtent, zExtent);
    transMatrix.mult(vars.vect1, vars.vect1);
    // Assign the biggest rotations after scales.
    box.xExtent = FastMath.abs(vars.vect1.getX());
    box.yExtent = FastMath.abs(vars.vect1.getY());
    box.zExtent = FastMath.abs(vars.vect1.getZ());
    vars.release();
    return box;
}
Also used : TempVars(com.jme3.util.TempVars)

Example 75 with TempVars

use of com.jme3.util.TempVars in project jmonkeyengine by jMonkeyEngine.

the class BoundingBox method collideWithRay.

private int collideWithRay(Ray ray) {
    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])
                return 2;
            else
                return 1;
        }
        return 0;
    } finally {
        vars.release();
    }
}
Also used : TempVars(com.jme3.util.TempVars)

Aggregations

TempVars (com.jme3.util.TempVars)103 Vector3f (com.jme3.math.Vector3f)50 Quaternion (com.jme3.math.Quaternion)13 Matrix4f (com.jme3.math.Matrix4f)12 BoundingBox (com.jme3.bounding.BoundingBox)10 Bone (com.jme3.animation.Bone)8 Spatial (com.jme3.scene.Spatial)7 CollisionResult (com.jme3.collision.CollisionResult)6 Vector2f (com.jme3.math.Vector2f)6 FloatBuffer (java.nio.FloatBuffer)6 BoundingSphere (com.jme3.bounding.BoundingSphere)5 BoundingVolume (com.jme3.bounding.BoundingVolume)5 Transform (com.jme3.math.Transform)5 DirectionalLight (com.jme3.light.DirectionalLight)4 PointLight (com.jme3.light.PointLight)4 Geometry (com.jme3.scene.Geometry)4 SpotLight (com.jme3.light.SpotLight)3 ColorRGBA (com.jme3.math.ColorRGBA)3 Matrix3f (com.jme3.math.Matrix3f)3 Vector4f (com.jme3.math.Vector4f)3