Java Code Examples for com.jme3.math.Quaternion#getW()

The following examples show how to use com.jme3.math.Quaternion#getW() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VRUtil.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static Quaternion stripToYaw(Quaternion q) {
    float yaw;
    float w = q.getW();
    float x = q.getX();
    float y = q.getY();
    float z = q.getZ();
    float sqx = x*x;
    float sqy = y*y;
    float sqz = z*z;
    float sqw = w*w;
    float unit = sqx + sqy + sqz + sqw; // if normalized is one, otherwise
    // is correction factor
    float test = x * y + z * w;
    if (test > 0.499 * unit) { // singularity at north pole
        yaw = 2 * FastMath.atan2(x, w);
    } else if (test < -0.499 * unit) { // singularity at south pole
        yaw = -2 * FastMath.atan2(x, w);
    } else {
        yaw = FastMath.atan2(2 * y * w - 2 * x * z, sqx - sqy - sqz + sqw); // roll or heading 
    }
    FastFullAngles(q, yaw, 0f, 0f);
    return q;
}
 
Example 2
Source File: CompactQuaternionArray.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected void serialize(int i, Quaternion store) {
    int j = i * getTupleSize();
    array[j] = store.getX();
    array[j + 1] = store.getY();
    array[j + 2] = store.getZ();
    array[j + 3] = store.getW();
}
 
Example 3
Source File: InstancedGeometry.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void updateInstance(Matrix4f worldMatrix, float[] store,
                            int offset, Matrix3f tempMat3,
                            Quaternion tempQuat) {
    worldMatrix.toRotationMatrix(tempMat3);
    tempMat3.invertLocal();

    // NOTE: No need to take the transpose in order to encode
    // into quaternion, the multiplication in the shader is vec * quat
    // apparently...
    tempQuat.fromRotationMatrix(tempMat3);

    // Column-major encoding. The "W" field in each of the encoded
    // vectors represents the quaternion.
    store[offset + 0] = worldMatrix.m00;
    store[offset + 1] = worldMatrix.m10;
    store[offset + 2] = worldMatrix.m20;
    store[offset + 3] = tempQuat.getX();
    store[offset + 4] = worldMatrix.m01;
    store[offset + 5] = worldMatrix.m11;
    store[offset + 6] = worldMatrix.m21;
    store[offset + 7] = tempQuat.getY();
    store[offset + 8] = worldMatrix.m02;
    store[offset + 9] = worldMatrix.m12;
    store[offset + 10] = worldMatrix.m22;
    store[offset + 11] = tempQuat.getZ();
    store[offset + 12] = worldMatrix.m03;
    store[offset + 13] = worldMatrix.m13;
    store[offset + 14] = worldMatrix.m23;
    store[offset + 15] = tempQuat.getW();
}
 
Example 4
Source File: CompactQuaternionArray.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected void serialize(int i, Quaternion store) {
    int j = i * getTupleSize();
    array[j] = store.getX();
    array[j + 1] = store.getY();
    array[j + 2] = store.getZ();
    array[j + 3] = store.getW();
}