Search in sources :

Example 16 with Matrix4f

use of com.jme3.math.Matrix4f in project jmonkeyengine by jMonkeyEngine.

the class Quaternion method toRotationMatrix.

/**
     * <code>toRotationMatrix</code> converts this quaternion to a rotational
     * matrix. The result is stored in result. 4th row and 4th column values are
     * untouched. Note: the result is created from a normalized version of this quat.
     * 
     * @param result
     *            The Matrix4f to store the result in.
     * @return the rotation matrix representation of this quaternion.
     */
public Matrix4f toRotationMatrix(Matrix4f result) {
    TempVars tempv = TempVars.get();
    Vector3f originalScale = tempv.vect1;
    result.toScaleVector(originalScale);
    result.setScale(1, 1, 1);
    float norm = norm();
    // we explicitly test norm against one here, saving a division
    // at the cost of a test and branch.  Is it worth it?
    float s = (norm == 1f) ? 2f : (norm > 0f) ? 2f / norm : 0;
    // compute xs/ys/zs first to save 6 multiplications, since xs/ys/zs
    // will be used 2-4 times each.
    float xs = x * s;
    float ys = y * s;
    float zs = z * s;
    float xx = x * xs;
    float xy = x * ys;
    float xz = x * zs;
    float xw = w * xs;
    float yy = y * ys;
    float yz = y * zs;
    float yw = w * ys;
    float zz = z * zs;
    float zw = w * zs;
    // using s=2/norm (instead of 1/norm) saves 9 multiplications by 2 here
    result.m00 = 1 - (yy + zz);
    result.m01 = (xy - zw);
    result.m02 = (xz + yw);
    result.m10 = (xy + zw);
    result.m11 = 1 - (xx + zz);
    result.m12 = (yz - xw);
    result.m20 = (xz - yw);
    result.m21 = (yz + xw);
    result.m22 = 1 - (xx + yy);
    result.setScale(originalScale);
    tempv.release();
    return result;
}
Also used : TempVars(com.jme3.util.TempVars)

Example 17 with Matrix4f

use of com.jme3.math.Matrix4f in project jmonkeyengine by jMonkeyEngine.

the class FbxBindPose method buildTransform.

private static Matrix4f buildTransform(double[] transform) {
    float[] m = new float[transform.length];
    for (int i = 0; i < transform.length; ++i) m[i] = (float) transform[i];
    Matrix4f matrix = new Matrix4f();
    matrix.set(m, false);
    return matrix;
}
Also used : Matrix4f(com.jme3.math.Matrix4f)

Example 18 with Matrix4f

use of com.jme3.math.Matrix4f in project jmonkeyengine by jMonkeyEngine.

the class FbxNode method buildBindPoseBoneTransform.

public void buildBindPoseBoneTransform() {
    if (bone != null) {
        Matrix4f t = bindTransform;
        if (t != null) {
            Matrix4f parentMatrix = parentFbxNode != null ? parentFbxNode.bindTransform : Matrix4f.IDENTITY;
            if (parentMatrix == null)
                parentMatrix = node.getLocalToWorldMatrix(null);
            t = parentMatrix.invert().multLocal(t);
            bone.setBindTransforms(t.toTranslationVector(), t.toRotationQuat(), t.toScaleVector());
        } else {
            bone.setBindTransforms(node.getLocalTranslation(), node.getLocalRotation(), node.getLocalScale());
        }
    }
}
Also used : Matrix4f(com.jme3.math.Matrix4f)

Example 19 with Matrix4f

use of com.jme3.math.Matrix4f in project jmonkeyengine by jMonkeyEngine.

the class FbxNode method setWorldBindPose.

public void setWorldBindPose(Matrix4f worldBindPose) {
    if (cachedWorldBindPose != null) {
        if (!cachedWorldBindPose.equals(worldBindPose)) {
            throw new UnsupportedOperationException("Bind poses don't match");
        }
    }
    cachedWorldBindPose = worldBindPose;
    this.jmeWorldBindPose = new Transform();
    this.jmeWorldBindPose.setTranslation(worldBindPose.toTranslationVector());
    this.jmeWorldBindPose.setRotation(worldBindPose.toRotationQuat());
    this.jmeWorldBindPose.setScale(worldBindPose.toScaleVector());
    System.out.println("\tBind Pose for " + getName());
    System.out.println(jmeWorldBindPose);
    float[] angles = new float[3];
    jmeWorldBindPose.getRotation().toAngles(angles);
    System.out.println("Angles: " + angles[0] * FastMath.RAD_TO_DEG + ", " + angles[1] * FastMath.RAD_TO_DEG + ", " + angles[2] * FastMath.RAD_TO_DEG);
}
Also used : Transform(com.jme3.math.Transform)

Example 20 with Matrix4f

use of com.jme3.math.Matrix4f in project jmonkeyengine by jMonkeyEngine.

the class FbxNode method computeFbxLocalTransform.

public Transform computeFbxLocalTransform() {
    // TODO: implement the actual algorithm, which is this:
    // Render Local Translation =
    //      Inv Scale Pivot * Lcl Scale * Scale Pivot * Scale Offset * Inv Rota Pivot * Post Rotation * Rotation * Pre Rotation * Rotation Pivot * Rotation Offset * Translation
    // LclTranslation, 
    // LclRotation, 
    // PreRotation, 
    // PostRotation, 
    // RotationPivot, 
    // RotationOffset, 
    // LclScaling, 
    // ScalingPivot, 
    // ScalingOffset
    Matrix4f scaleMat = new Matrix4f();
    scaleMat.setScale(jmeLocalNodeTransform.getScale());
    Matrix4f rotationMat = new Matrix4f();
    rotationMat.setRotationQuaternion(jmeLocalNodeTransform.getRotation());
    Matrix4f translationMat = new Matrix4f();
    translationMat.setTranslation(jmeLocalNodeTransform.getTranslation());
    Matrix4f result = new Matrix4f();
    result.multLocal(scaleMat).multLocal(rotationMat).multLocal(translationMat);
    Transform t = new Transform();
    t.fromTransformMatrix(result);
    return t;
}
Also used : Matrix4f(com.jme3.math.Matrix4f) Transform(com.jme3.math.Transform)

Aggregations

Matrix4f (com.jme3.math.Matrix4f)36 TempVars (com.jme3.util.TempVars)24 Vector3f (com.jme3.math.Vector3f)15 FloatBuffer (java.nio.FloatBuffer)7 BoundingBox (com.jme3.bounding.BoundingBox)6 Transform (com.jme3.math.Transform)6 Bone (com.jme3.animation.Bone)4 CollisionResult (com.jme3.collision.CollisionResult)3 Spatial (com.jme3.scene.Spatial)3 BoundingVolume (com.jme3.bounding.BoundingVolume)2 Material (com.jme3.material.Material)2 Quaternion (com.jme3.math.Quaternion)2 Geometry (com.jme3.scene.Geometry)2 BoneContext (com.jme3.scene.plugins.blender.animations.BoneContext)2 Structure (com.jme3.scene.plugins.blender.file.Structure)2 FbxId (com.jme3.scene.plugins.fbx.file.FbxId)2 FrameBuffer (com.jme3.texture.FrameBuffer)2 Texture2D (com.jme3.texture.Texture2D)2 Picture (com.jme3.ui.Picture)2 ByteBuffer (java.nio.ByteBuffer)2