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:
Create a
Quaternion
object:Quaternion roll045 = new Quaternion();
Supply the angle and the axis as arguments. The angle is
45*FastMath.DEG_TO_RAD
. The constant for the x axis isVector3f.UNIT_X
. This gives us:roll045.fromAngleAxis( 45*FastMath.DEG_TO_RAD , Vector3f.UNIT_X );
Replace the relative
rotate()
method from the previous exercises and apply this absolute rotation instead:geom2.setLocalRotation( roll045 );
Clean and build the
BasicGame
template, then right-click on it and run the file.The yellow cube should be rotated by 45° as before.