The model with all its objects is rotated during the game play. Objects itself are rotated within the model. This page gives an overview about the rotation used in Mario Kart Wii.
Rotation Vectors and Matrices
For transformations, the rotation vector are used together with a scaling and a translation vector to create a transformation matrix and its inverse. The advantage of a transformation matrix is the simple and fast arithmetic (multiplication and addition only, but no Sinus or Cosinus operation) to get the transformed vectors. Sinus or Cosinus are only needed once to create the matrix.
Kind of Rotation
A rotation in Mario Kart Wii is done as right-handed rotation with Euler angles (in degree) and x-y-z convention. The x-y-z convention means, that the rotation is logical done in 3 independent steps:
- Right-handed rotation around the x-axis using the x-coordinate of the 3D vector.
- Right-handed rotation around the y-axis using the y-coordinate of the 3D vector.
- Right-handed rotation around the z-axis using the z-coordinate of the 3D vector.
If a rotation is combined with scaling and translation, it is executed in the following 3 steps:
- Scaling is done by doing 3 separated multiplication, one for each axis.
- 3 Rotations are done in x, y and z order (see above).
- Translation is done by doing 3 separated additions, one for each axis.
In this coding example we have a position vector pos, which should be scaled by scale, rotated by rotate and moved by translate:
# scale the position vector by multiplying pos.x *= scale.x pos.y *= scale.y pos.z *= scale.z # rotate the position vector by special and complex rotation functions pos = X_ROTATE(pos,rotate.x) pos = Y_ROTATE(pos,rotate.y) pos = Z_ROTATE(pos,rotate.z) # translate the position vector by adding pos.x += translate.x pos.y += translate.y pos.z += translate.z
Roll, Pitch and Yaw
The roll–pitch–yaw model used in flight dynamics has a different mathematical model. In the Cartesian coordinate system used by Mario Kart Wii, the vertical axis is the y-axis, but in roll–pitch–yaw model it is the z-axis. Adapated into Mario Kart coordinate system, the roll–pitch–yaw model uses the x-z-y convention instead of the x-y-z convention. This difference is important, because the order of rotation calculations is changed.
Degrees and Radians
In Mario Kart Wii, all rotation values are stored as single float (32 bit) in degrees (360° for a full circle). Programming languages normally use radians (2π for a full circle).
Before calling the library functions sin(), cos() or tan(), the degree values must be transformed into radians. The radian results of the library functions asin(), acos(), atan() and atan2() must be converted into degrees:
radians = degrees * (π/180.0) degrees = radians * (180.0/π)
Most desk calculators allow to switch between degree and radian calculations. You can test the active mode by entering 'acos(0)'. It either returns 1.5708 (π/2, radian mode) or 90° (degree mode).