Search in sources :

Example 91 with TempVars

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

the class LineSegment method distanceSquared.

public float distanceSquared(Vector3f point) {
    TempVars vars = TempVars.get();
    Vector3f compVec1 = vars.vect1;
    point.subtract(origin, compVec1);
    float segmentParameter = direction.dot(compVec1);
    if (-extent < segmentParameter) {
        if (segmentParameter < extent) {
            origin.add(direction.mult(segmentParameter, compVec1), compVec1);
        } else {
            origin.add(direction.mult(extent, compVec1), compVec1);
        }
    } else {
        origin.subtract(direction.mult(extent, compVec1), compVec1);
    }
    compVec1.subtractLocal(point);
    float len = compVec1.lengthSquared();
    vars.release();
    return len;
}
Also used : TempVars(com.jme3.util.TempVars)

Example 92 with TempVars

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

the class Spatial method checkDoTransformUpdate.

/**
     * Computes the world transform of this Spatial in the most
     * efficient manner possible.
     */
void checkDoTransformUpdate() {
    if ((refreshFlagGetAnd(RF_TRANSFORM)) == 0) {
        return;
    }
    if (parent == null) {
        worldTransform.set(localTransform);
        refreshFlagAnd(~RF_TRANSFORM);
    } else {
        TempVars vars = TempVars.get();
        Spatial[] stack = vars.spatialStack;
        Spatial rootNode = this;
        int i = 0;
        while (true) {
            Spatial hisParent = rootNode.parent;
            if (hisParent == null) {
                rootNode.worldTransform.set(rootNode.localTransform);
                rootNode.refreshFlagAnd(~RF_TRANSFORM);
                i--;
                break;
            }
            stack[i] = rootNode;
            if ((hisParent.refreshFlagGetAnd(RF_TRANSFORM)) == 0) {
                break;
            }
            rootNode = hisParent;
            i++;
        }
        vars.release();
        for (int j = i; j >= 0; j--) {
            rootNode = stack[j];
            //rootNode.worldTransform.set(rootNode.localTransform);
            //rootNode.worldTransform.combineWithParent(rootNode.parent.worldTransform);
            //rootNode.refreshFlags &= ~RF_TRANSFORM;
            rootNode.updateWorldTransforms();
        }
    }
}
Also used : TempVars(com.jme3.util.TempVars)

Example 93 with TempVars

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

the class Camera method setClipPlane.

/**
     * Sets a clipPlane for this camera.
     * The clipPlane is used to recompute the
     * projectionMatrix using the plane as the near plane     
     * This technique is known as the oblique near-plane clipping method introduced by Eric Lengyel
     * more info here
     * <ul>
     * <li><a href="http://www.terathon.com/code/oblique.html">http://www.terathon.com/code/oblique.html</a>
     * <li><a href="http://aras-p.info/texts/obliqueortho.html">http://aras-p.info/texts/obliqueortho.html</a>
     * <li><a href="http://hacksoflife.blogspot.com/2008/12/every-now-and-then-i-come-across.html">http://hacksoflife.blogspot.com/2008/12/every-now-and-then-i-come-across.html</a>
     * </ul>
     *
     * Note that this will work properly only if it's called on each update, and be aware that it won't work properly with the sky bucket.
     * if you want to handle the sky bucket, look at how it's done in SimpleWaterProcessor.java
     * @param clipPlane the plane
     * @param side the side the camera stands from the plane
     */
public void setClipPlane(Plane clipPlane, Plane.Side side) {
    float sideFactor = 1;
    if (side == Plane.Side.Negative) {
        sideFactor = -1;
    }
    //we are on the other side of the plane no need to clip anymore.
    if (clipPlane.whichSide(location) == side) {
        return;
    }
    TempVars vars = TempVars.get();
    try {
        Matrix4f p = projectionMatrixOverride.set(projectionMatrix);
        Matrix4f ivm = viewMatrix;
        Vector3f point = clipPlane.getNormal().mult(clipPlane.getConstant(), vars.vect1);
        Vector3f pp = ivm.mult(point, vars.vect2);
        Vector3f pn = ivm.multNormal(clipPlane.getNormal(), vars.vect3);
        Vector4f clipPlaneV = vars.vect4f1.set(pn.x * sideFactor, pn.y * sideFactor, pn.z * sideFactor, -(pp.dot(pn)) * sideFactor);
        Vector4f v = vars.vect4f2.set(0, 0, 0, 0);
        v.x = (Math.signum(clipPlaneV.x) + p.m02) / p.m00;
        v.y = (Math.signum(clipPlaneV.y) + p.m12) / p.m11;
        v.z = -1.0f;
        v.w = (1.0f + p.m22) / p.m23;
        //clipPlaneV.x * v.x + clipPlaneV.y * v.y + clipPlaneV.z * v.z + clipPlaneV.w * v.w;
        float dot = clipPlaneV.dot(v);
        Vector4f c = clipPlaneV.multLocal(2.0f / dot);
        p.m20 = c.x - p.m30;
        p.m21 = c.y - p.m31;
        p.m22 = c.z - p.m32;
        p.m23 = c.w - p.m33;
        setProjectionMatrix(p);
    } finally {
        vars.release();
    }
}
Also used : TempVars(com.jme3.util.TempVars)

Example 94 with TempVars

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

the class BatchNode method doCopyBuffer.

private void doCopyBuffer(FloatBuffer inBuf, int offset, FloatBuffer outBuf, int componentSize) {
    TempVars vars = TempVars.get();
    Vector3f pos = vars.vect1;
    // offset is given in element units
    // convert to be in component units
    offset *= componentSize;
    for (int i = 0; i < inBuf.limit() / componentSize; i++) {
        pos.x = inBuf.get(i * componentSize + 0);
        pos.y = inBuf.get(i * componentSize + 1);
        pos.z = inBuf.get(i * componentSize + 2);
        outBuf.put(offset + i * componentSize + 0, pos.x);
        outBuf.put(offset + i * componentSize + 1, pos.y);
        outBuf.put(offset + i * componentSize + 2, pos.z);
    }
    vars.release();
}
Also used : Vector3f(com.jme3.math.Vector3f) TempVars(com.jme3.util.TempVars)

Example 95 with TempVars

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

the class Matrix3f method fillFloatBuffer.

/**
     * <code>fillFloatBuffer</code> fills a FloatBuffer object with the matrix
     * data.
     * 
     * @param fb
     *            the buffer to fill, starting at current position. Must have
     *            room for 9 more floats.
     * @return matrix data as a FloatBuffer. (position is advanced by 9 and any
     *         limit set is not changed).
     */
public FloatBuffer fillFloatBuffer(FloatBuffer fb, boolean columnMajor) {
    //        if (columnMajor){
    //            fb.put(m00).put(m10).put(m20);
    //            fb.put(m01).put(m11).put(m21);
    //            fb.put(m02).put(m12).put(m22);
    //        }else{
    //            fb.put(m00).put(m01).put(m02);
    //            fb.put(m10).put(m11).put(m12);
    //            fb.put(m20).put(m21).put(m22);
    //        }
    TempVars vars = TempVars.get();
    fillFloatArray(vars.matrixWrite, columnMajor);
    fb.put(vars.matrixWrite, 0, 9);
    vars.release();
    return fb;
}
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