Search in sources :

Example 11 with TempVars

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;
}
Also used : Vector2f(com.jme3.math.Vector2f) Vector3f(com.jme3.math.Vector3f) TempVars(com.jme3.util.TempVars)

Example 12 with TempVars

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;
}
Also used : TempVars(com.jme3.util.TempVars)

Example 13 with TempVars

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();
    }
}
Also used : TempVars(com.jme3.util.TempVars)

Example 14 with TempVars

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);
}
Also used : TempVars(com.jme3.util.TempVars)

Example 15 with TempVars

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();
}
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