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