Time for action – rotate it again, Sam

Think of a quaternion as a Java object capable of storing rotations, which you can then apply to a geometry. Don't worry, the 3D engine does the tough calculation work for you!

As an exercise, let's create a Quaternion object that accepts a 45-degree rotation around the x axis:

  1. Create a Quaternion object:
    Quaternion roll045 = new Quaternion();
    
  2. Supply the angle and the axis as arguments. The angle is 45*FastMath.DEG_TO_RAD. The constant for the x axis is Vector3f.UNIT_X. This gives us:
    roll045.fromAngleAxis( 45*FastMath.DEG_TO_RAD , Vector3f.UNIT_X );
    
  3. Replace the relative rotate() method from the previous exercises and apply this absolute rotation instead:
    geom2.setLocalRotation( roll045 );
    
  4. Clean and build the ...

Get jMonkeyEngine 3.0 Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.