1.3 Passing the Transformation Matrix to the RSP

Once the transformation matrix has been created as described above, you need to send it to the RSP. To do this you use the gSPMatrix command.

The gSPMatrix command takes not only the pointer to the matrix you want to pass to the RSP, but also the type of the transformation matrix, and the flag that specifies operations to the matrix stack. For the flag, do a bitwise OR of the following constants:

G_MTX_MODELVIEW Load the model view transformation matrix
G_MTX_PROJECTION Load the projection transformation matrix
G_MTX_LOAD Load matrix to top of the matrix stack
G_MTX_MUL Multiply matrix to top of the matrix stack
(The result becomes the new top of the stack)
G_MTX_PUSH Push matrix to stack before matrix operation
G_MTX_NOPUSH Do not push matrix to stack before matrix operation

When vertices are loaded, the RSP transforms the vertex coordinates and normal vectors. Those vectors are transformed based on the transformation matrix that is set at the time, so you should set the matrix before loading the vertices.

List 1-2

  /* Specify a projection transformation matrix  */
  gSPMatrix(glistp++,
            &projection,
            G_MTX_PROJECTION |
            G_MTX_LOAD |
            G_MTX_NOPUSH);
  /* Specify a model transformation matrix  */
  gSPMatrix(glistp++,
            &modeling,
            G_MTX_MODELVIEW |
            G_MTX_LOAD |
            G_MTX_NOPUSH);
  /* Scaling of homogeneous coordinates  */
  gSPPerspNormalize(glistp++, &perspNorm);

There are three other points you need to be aware of in relation to the gSPMatrix command. These are explained below:

1. The pointer to the matrix is a segment address
As described in Chapters 9 and 10 of the Programming Manual, the address passed to the RSP is an RSP segment address. However, in the samples in this Graphics tutorial, the first command in the display list is:

gSPSegment(glistp++, 0, 0);

thus, there is no problem even when a KSEG0 virtual address is passed as is to the RSP. See Chapters 9 and 10 of the Programming Manual to learn more about these kinds of memory management topics.

2. Cache writeback is performed
The RSP cannot directly read/write the contents of RDRAM, so data is transferred using DMA. As noted in the Programming Manual (for example, in Section 3.6.2 Data Cache), there is the chance of invalid data being transferred if the data stored in data cache is DMA transferred without writing back to RDRAM.

3. The matrix has fixed-point format
When handling a floating-point format matrix, you must remember to convert it into fixed point format before passing it to gSPMatrix.