Search in sources :

Example 56 with TempVars

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);
//        }
}
Also used : Quaternion(com.jme3.math.Quaternion) Vector3f(com.jme3.math.Vector3f) BitSet(java.util.BitSet)

Example 57 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 58 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 59 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 60 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)

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