= 3-D Rotation :revnumber: 2.0 :revdate: 2020/07/13 _Bad news: 3D rotation is done using matrix calculus. + Good news: If you do not understand calculus, there are two simple rules how you get it right._ *3D rotation* is a crazy mathematical operation where you need to multiply all vertices in your object by four floating point numbers; the multiplication is referred to as concatenation, the array of four numbers {x,y,z,w} is referred to as xref:core:math/quaternion.adoc[quaternions]. Don't worry, the 3D engine does the tough work for you. All you need to know is: *The Quaternion* is an object capable of deep-freezing and storing a rotation that you can apply to a 3D object. == Using Quaternions for Rotation To store a rotation in a Quaternion, you must specify two things: The angle and the axis of the rotation. * The rotation angle is defined as a multiple of the number PI. * The rotation axis is defined by a vector: Think of them in terms of "`pitch`", "`yaw`", and "`roll`". Example: [source,java] ---- /* This quaternion stores a 180 degree rolling rotation */ Quaternion roll180 = new Quaternion(); roll180.fromAngleAxis( FastMath.PI , new Vector3f(0,0,1) ); /* The rotation is applied: The object rolls by 180 degrees. */ thingamajig.setLocalRotation( roll180 ); ---- So how to choose the right numbers for the Quaternion parameters? I'll give you my cheat-sheet: [cols="3", options="header"] |=== a| *Rotation around Axis?* a| *Use this Axis Vector!* a| *Examples for this kind of rotation* a|X axis a| (1,0,0) a| A plane pitches. Nodding your head. a|Y axis a| (0,1,0) a| A plane yaws. A vehicle turns. Shaking your head. a|Z axis a| (0,0,1) a| A plane rolls or banks. Cocking your head. |=== [NOTE] ==== These are the three most common examples – technically you can rotate around any axis expressed by a vector. ==== [cols="3", options="header"] |=== a| *Angle?* a| *Use Radians!* a| *Examples*