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

The following examples show how to use com.jme3.math.Quaternion#set() . 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: VehicleWheel.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Apply this wheel's physics location and orientation to its associated
 * spatial, if any.
 */
public void applyWheelTransform() {
    if (wheelSpatial == null) {
        return;
    }
    Quaternion localRotationQuat = wheelSpatial.getLocalRotation();
    Vector3f localLocation = wheelSpatial.getLocalTranslation();
    if (!applyLocal && wheelSpatial.getParent() != null) {
        localLocation.set(wheelWorldLocation).subtractLocal(wheelSpatial.getParent().getWorldTranslation());
        localLocation.divideLocal(wheelSpatial.getParent().getWorldScale());
        tmp_inverseWorldRotation.set(wheelSpatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation);

        localRotationQuat.set(wheelWorldRotation);
        tmp_inverseWorldRotation.set(wheelSpatial.getParent().getWorldRotation()).inverseLocal().mult(localRotationQuat, localRotationQuat);

        wheelSpatial.setLocalTranslation(localLocation);
        wheelSpatial.setLocalRotation(localRotationQuat);
    } else {
        wheelSpatial.setLocalTranslation(wheelWorldLocation);
        wheelSpatial.setLocalRotation(wheelWorldRotation);
    }
}
 
Example 2
Source File: AbstractPhysicsDebugControl.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Apply the specified location and orientation to the specified spatial.
 *
 * @param worldLocation location vector (in physics-space coordinates, not
 * null, unaffected)
 * @param worldRotation orientation (in physics-space coordinates, not null,
 * unaffected)
 * @param spatial where to apply (may be null)
 */
protected void applyPhysicsTransform(Vector3f worldLocation, Quaternion worldRotation, Spatial spatial) {
    if (spatial != null) {
        Vector3f localLocation = spatial.getLocalTranslation();
        Quaternion localRotationQuat = spatial.getLocalRotation();
        if (spatial.getParent() != null) {
            localLocation.set(worldLocation).subtractLocal(spatial.getParent().getWorldTranslation());
            localLocation.divideLocal(spatial.getParent().getWorldScale());
            tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation);
            localRotationQuat.set(worldRotation);
            tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().mult(localRotationQuat, localRotationQuat);
            spatial.setLocalTranslation(localLocation);
            spatial.setLocalRotation(localRotationQuat);
        } else {
            spatial.setLocalTranslation(worldLocation);
            spatial.setLocalRotation(worldRotation);
        }
    }

}
 
Example 3
Source File: AbstractPhysicsControl.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Apply a physics transform to the spatial.
 *
 * @param worldLocation location vector (in physics-space coordinates, not
 * null, unaffected)
 * @param worldRotation orientation (in physics-space coordinates, not null,
 * unaffected)
 */
protected void applyPhysicsTransform(Vector3f worldLocation, Quaternion worldRotation) {
    if (enabled && spatial != null) {
        Vector3f localLocation = spatial.getLocalTranslation();
        Quaternion localRotationQuat = spatial.getLocalRotation();
        if (!applyLocal && spatial.getParent() != null) {
            localLocation.set(worldLocation).subtractLocal(spatial.getParent().getWorldTranslation());
            localLocation.divideLocal(spatial.getParent().getWorldScale());
            tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation);
            localRotationQuat.set(worldRotation);
            tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().mult(localRotationQuat, localRotationQuat);

            spatial.setLocalTranslation(localLocation);
            spatial.setLocalRotation(localRotationQuat);
        } else {
            spatial.setLocalTranslation(worldLocation);
            spatial.setLocalRotation(worldRotation);
        }
    }

}
 
Example 4
Source File: VRUtil.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static Quaternion FastFullAngles(Quaternion use, float yaw, float pitch, float roll) {
    float angle;
    float sinRoll, sinPitch, sinYaw, cosRoll, cosPitch, cosYaw;
    angle = roll * 0.5f;
    sinPitch = (float)Math.sin(angle);
    cosPitch = (float)Math.cos(angle);
    angle = yaw * 0.5f;
    sinRoll = (float)Math.sin(angle);
    cosRoll = (float)Math.cos(angle);
    angle = pitch * 0.5f;
    sinYaw = (float)Math.sin(angle);
    cosYaw = (float)Math.cos(angle);

    // variables used to reduce multiplication calls.
    float cosRollXcosPitch = cosRoll * cosPitch;
    float sinRollXsinPitch = sinRoll * sinPitch;
    float cosRollXsinPitch = cosRoll * sinPitch;
    float sinRollXcosPitch = sinRoll * cosPitch;

    use.set((cosRollXcosPitch * sinYaw + sinRollXsinPitch * cosYaw),
            (sinRollXcosPitch * cosYaw + cosRollXsinPitch * sinYaw),
            (cosRollXsinPitch * cosYaw - sinRollXcosPitch * sinYaw),
            (cosRollXcosPitch * cosYaw - sinRollXsinPitch * sinYaw));

    return use;     
}
 
Example 5
Source File: VehicleWheel.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void applyWheelTransform() {
    if (wheelSpatial == null) {
        return;
    }
    Quaternion localRotationQuat = wheelSpatial.getLocalRotation();
    Vector3f localLocation = wheelSpatial.getLocalTranslation();
    if (!applyLocal && wheelSpatial.getParent() != null) {
        localLocation.set(wheelWorldLocation).subtractLocal(wheelSpatial.getParent().getWorldTranslation());
        localLocation.divideLocal(wheelSpatial.getParent().getWorldScale());
        tmp_inverseWorldRotation.set(wheelSpatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation);

        localRotationQuat.set(wheelWorldRotation);
        tmp_inverseWorldRotation.set(wheelSpatial.getParent().getWorldRotation()).inverseLocal().mult(localRotationQuat, localRotationQuat);

        wheelSpatial.setLocalTranslation(localLocation);
        wheelSpatial.setLocalRotation(localRotationQuat);
    } else {
        wheelSpatial.setLocalTranslation(wheelWorldLocation);
        wheelSpatial.setLocalRotation(wheelWorldRotation);
    }
}
 
Example 6
Source File: VehicleWheel.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public synchronized void applyWheelTransform() {
    if (wheelSpatial == null) {
        return;
    }
    Quaternion localRotationQuat = wheelSpatial.getLocalRotation();
    Vector3f localLocation = wheelSpatial.getLocalTranslation();
    if (!applyLocal && wheelSpatial.getParent() != null) {
        localLocation.set(wheelWorldLocation).subtractLocal(wheelSpatial.getParent().getWorldTranslation());
        localLocation.divideLocal(wheelSpatial.getParent().getWorldScale());
        tmp_inverseWorldRotation.set(wheelSpatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation);

        localRotationQuat.set(wheelWorldRotation);
        tmp_inverseWorldRotation.set(wheelSpatial.getParent().getWorldRotation()).inverseLocal().mult(localRotationQuat, localRotationQuat);

        wheelSpatial.setLocalTranslation(localLocation);
        wheelSpatial.setLocalRotation(localRotationQuat);
    } else {
        wheelSpatial.setLocalTranslation(wheelWorldLocation);
        wheelSpatial.setLocalRotation(wheelWorldRotation);
    }
}
 
Example 7
Source File: VehicleWheel.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public synchronized void applyWheelTransform() {
    if (wheelSpatial == null) {
        return;
    }
    Quaternion localRotationQuat = wheelSpatial.getLocalRotation();
    Vector3f localLocation = wheelSpatial.getLocalTranslation();
    if (!applyLocal && wheelSpatial.getParent() != null) {
        localLocation.set(wheelWorldLocation).subtractLocal(wheelSpatial.getParent().getWorldTranslation());
        localLocation.divideLocal(wheelSpatial.getParent().getWorldScale());
        tmp_inverseWorldRotation.set(wheelSpatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation);

        localRotationQuat.set(wheelWorldRotation);
        tmp_inverseWorldRotation.set(wheelSpatial.getParent().getWorldRotation()).inverseLocal().mult(localRotationQuat, localRotationQuat);

        wheelSpatial.setLocalTranslation(localLocation);
        wheelSpatial.setLocalRotation(localRotationQuat);
    } else {
        wheelSpatial.setLocalTranslation(wheelWorldLocation);
        wheelSpatial.setLocalRotation(wheelWorldRotation);
    }
}
 
Example 8
Source File: QuaternionPropertyEditor.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void setAsText(String text) throws IllegalArgumentException {
    text = text.replace('[', ' ');
    text = text.replace(']', ' ');
    String[] values = text.split(",");
    if (values.length != 3) {
        throw (new IllegalArgumentException("String not correct"));
    }
    float[] floats = new float[3];
    for (int i = 0; i < values.length; i++) {
        String string = values[i];
        floats[i] = (float)Math.toRadians(Float.parseFloat(string));
    }
    Quaternion old=new Quaternion();
    old.set(quaternion);
    quaternion.fromAngles(floats);
    notifyListeners(old,quaternion);
}
 
Example 9
Source File: LWJGLOpenVR.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void getPositionAndOrientation(Vector3f storePos, Quaternion storeRot) {
    hmdPose.toTranslationVector(storePos);
    storePos.x = -storePos.x;
    storePos.z = -storePos.z;
    storeRot.set(getOrientation());
}
 
Example 10
Source File: OpenVR.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void getPositionAndOrientation(Vector3f storePos, Quaternion storeRot) {
    hmdPose.toTranslationVector(storePos);
    storePos.x = -storePos.x;
    storePos.z = -storePos.z;
    storeRot.set(getOrientation());
}
 
Example 11
Source File: OSVR.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void getPositionAndOrientation(Vector3f storePos, Quaternion storeRot) {
    storePos.x = (float)-hmdPose.translation.data[0];
    storePos.y = (float)hmdPose.translation.data[1];
    storePos.z = (float)-hmdPose.translation.data[2];
    storeRot.set((float)-hmdPose.rotation.data[1],
                 (float)hmdPose.rotation.data[2],
                 (float)-hmdPose.rotation.data[3],
                 (float)hmdPose.rotation.data[0]);
    if( storeRot.equals(Quaternion.ZERO) ) storeRot.set(Quaternion.DIRECTION_Z);
}
 
Example 12
Source File: VRUtil.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static void convertMatrix4toQuat(Matrix4f in, Quaternion out) {
    // convert rotation matrix to quat
    out.fromRotationMatrix(in.m00, in.m01, in.m02, in.m10, in.m11, in.m12, in.m20, in.m21, in.m22);
    // flip the pitch
    out.set(-out.getX(), out.getY(), -out.getZ(), out.getW());
}
 
Example 13
Source File: CompactQuaternionArray.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
protected Quaternion deserialize(int i, Quaternion store) {
    int j = i * getTupleSize();
    store.set(array[j], array[j + 1], array[j + 2], array[j + 3]);
    return store;
}
 
Example 14
Source File: CompactQuaternionArray.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
protected Quaternion deserialize(int i, Quaternion store) {
    int j = i * getTupleSize();
    store.set(array[j], array[j + 1], array[j + 2], array[j + 3]);
    return store;
}
 
Example 15
Source File: VehicleWheel.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Copy this wheel's physics-space orientation to the specified quaternion.
 *
 * @param store storage for the result (not null, modified)
 */
public void getWheelWorldRotation(final Quaternion store) {
    store.set(this.wheelWorldRotation);
}
 
Example 16
Source File: VehicleWheel.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
* write the content of the wheelWorldRotation into the store
* 
* @param store
*/
public void getWheelWorldRotation(final Quaternion store) {
    store.set(this.wheelWorldRotation);
}