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

The following examples show how to use com.jme3.math.Quaternion#fromAngleNormalAxis() . 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: CubeField.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Forcefully takes over Camera adding functionality and placing it behind the character
 * @param tpf Tickes Per Frame
 */
private void camTakeOver(float tpf) {
    cam.setLocation(player.getLocalTranslation().add(-8, 2, 0));
    cam.lookAt(player.getLocalTranslation(), Vector3f.UNIT_Y);
    
    Quaternion rot = new Quaternion();
    rot.fromAngleNormalAxis(camAngle, Vector3f.UNIT_Z);
    cam.setRotation(cam.getRotation().mult(rot));
    camAngle *= FastMath.pow(.99f, fpsRate * tpf);
}
 
Example 2
Source File: TestSkyRotation.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Handle an input action from the user.
 *
 * @param name the name of the action
 * @param ongoing true→depress key, false→release key
 * @param ignored
 */
@Override
public void onAction(String name, boolean ongoing, float ignored) {
    if (!ongoing) {
        return;
    }
    /*
     * Update the Y-axis rotation angle based on which key was pressed.
     */
    if (name.equals("left")) {
        angle += 0.1f; // radians
        System.out.print("rotate floor and sky leftward ...");
    } else if (name.equals("right")) {
        angle -= 0.1f; // radians
        System.out.printf("rotate floor and sky spatials rightward ...");
    } else {
        return;
    }
    /*
     * Update the local rotations of both objects based on the angle.
     */
    System.out.printf(" to %.1f radians left of start%n", angle);
    Quaternion rotation = new Quaternion();
    rotation.fromAngleNormalAxis(angle, Vector3f.UNIT_Y);
    floor.setLocalRotation(rotation);
    sky.setLocalRotation(rotation);
}
 
Example 3
Source File: ChaseCameraAppState.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * rotate the camera around the target
 */
protected void rotateCamera() {
    verticalRotation = FastMath.clamp(verticalRotation, minVerticalRotation, maxVerticalRotation);
    TempVars vars = TempVars.get();
    Quaternion rot = vars.quat1;
    Quaternion rot2 = vars.quat2;
    rot.fromAngleNormalAxis(verticalRotation, leftVector);
    rot2.fromAngleNormalAxis(horizontalRotation, upVector);
    rot2.multLocal(rot);
    target.setLocalRotation(rot2);
    vars.release();
}
 
Example 4
Source File: CubeField.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Forcefully takes over Camera adding functionality and placing it behind the character
 * @param tpf Tickes Per Frame
 */
private void camTakeOver(float tpf) {
    cam.setLocation(player.getLocalTranslation().add(-8, 2, 0));
    cam.lookAt(player.getLocalTranslation(), Vector3f.UNIT_Y);
    
    Quaternion rot = new Quaternion();
    rot.fromAngleNormalAxis(camAngle, Vector3f.UNIT_Z);
    cam.setRotation(cam.getRotation().mult(rot));
    camAngle *= FastMath.pow(.99f, fpsRate * tpf);
}