Game Development Reference
In-Depth Information
Figure 70 - Rotation about a pivot p.
Wewilladdavectortothe quad objectwhichwewillcall m_pivot .Recallfromthesection
Matrix Concatenation that the order in which we apply transformations will affect the end
result.Inorderrotate thequadaroundagivenpivot,wefirstwillwanttotranslate thequad
by that pivot's vector, and after apply the rotation transform.
Since rotating a quad by a pivot is an operation we will likely want to do often, we will
addthefeature tothe quad class.Wewilladda vector3 member totheclasscalled m_pivot
which we will initialize to zero, this will preserve the default behavior ofrotating the quad,
which is to rotate about the center of the quad.
Beforerenderingthequad,wewillcalculateitstransform,firstwewillcreateapivottrans-
form, which we will then transform by the user provided world transform.
matrix transform = matrix::CreateTranslation(m_pivot) * world;
In our example, our arrow image is taller than it is wider, the pivot transformation will
define how much we translate the image from its origin, so in order to bring the pivot to
the point at which the arrow needs to rotate, we need to move it about ¾ of its height in the
y-axis. That is to say, the pivot is relative to the center of the quad, where -0.5,-0.5 would
be the top left corner, and 0.5,0.5 the bottom right.
Search WWH ::




Custom Search