Tutorial
FM4, S6E2DH/S6E2DF/S6E2D5/S6E2D3 Series, 32-Bit Microcontroller, Graphic Driver User Manual, Doc. No. 002-04387 Rev. *A
63
utMat4x4Translate(m_m44Pre, 1.0f, 1.0f, 0);
/* An OpenGL like perspective calculation */
utMat4x4Perspective(m_m44Pre, s_fLensAngle, (float)GetWidth() / GetHeight(), (float)0.1, 100.0);
/* get a distance to the object */
utMat4x4Translate(m_m44Pre, 0, 0, s_fViewDist);
/* Now the cover movement */
/* Turn the view center point a little bit down */
utMat4x4RotX(m44, s_fViewAngle);
/* Move a little bit over the scene */
utMat4x4Translate(m44, 0, s_fViewPoint, 0);
/* Push the image on a circle */
utMat4x4Translate(m44, s_fCircleRadius * cos_angle, 0, s_fCircleRadius * sin_angle);
/* to get the 2-D lock we turn the cover here to correct the s_fViewAngle */
utMat4x4RotX(m44, -s_fViewAngle);
/* Scale it */
utMat4x4Scale(m44, s_fCoverScaling, s_fCoverScaling, 1.0f);
/* Now the post matrix */
/* Translate it to -1, -1. The center point is now 0 ,0 */
utMat4x4Translate(m_m44Post, -1.0f, -1.0f, 0);
/* Scale the cover bitmap of a size 0..2 */
utMat4x4Scale(m_m44Post, (float)2 / COVER_SIZE, (float)2 / COVER_SIZE, 1.0f);
As described all operations must be calculated for each frame for each cover. To reduce the effort it is spit into 3
parts. The pre and post matrix is constant over the scene. That’s why it can be calculated once during the
initialization. Only the dynamic part must be calculated for each cover. The final matrix is:
M = Mpre * Mdynamic * Mpost
For transformation of the 4
∗
4 to a 3
∗
2 matrix we use a utility function. The idea is just to remove the z component for
the matrix. The z values are stored in the 3 line and 3 row.
Beside this the 4 line of the matrix must be removed. Such a conversion assumes that the 4x4 matrix realizes only
affine transformations. This is only realized if the values are (0 0 1 Vscale). All matrix elements must be divided by
Vscale.
utMat4x4ToMat3x2(mat44[0], pos.mat32);