This chapter explains the matrix that is the basis for constructing 3D graphics.
The first half explains matrix operations and their concepts, and the second half explains how to construct objects with a hierarchical structure using stack matrices.
In particular, the hierarchical structure of the matrix is an important element in 3D graphics expression on the Sega Saturn, so please read and understand it carefully.
A matrix is a group of numbers with n rows and m columns, and although it is different from normal numerical operations, it is also possible to perform four arithmetic operations between matrices (for details, please refer to specialized books).
The figure below is an example of multiplication between 2-row x 2-column matrices.
In the case of SGL, in order to accurately represent 3D space, a 4 row x 3 column matrix is used as a matrix variable (to realize XYZ coordinate values and various transformation operations).
< Figure 5-1 General concepts and calculation examples of matrices>
The modeling transformation explained in “ Chapter 4 Coordinate Transformation ” actually creates a new polygon vertex data sequence by multiplying the polygon vertex data sequence represented as a matrix by various transformation matrices (rotation, translation, scale, etc.) is.
< Figure 5-2 Stack image model>
< Figure 5-3 Image model of hierarchical structure>
< Figure 5-4 Example of moving objects without using a hierarchical structure >
<Figure 5-5 Example of object conversion using hierarchical structure>
/*------------------------------------------------ ----------------------*/ /* Double Cube Circle Action */ /*------------------------------------------------ ----------------------*/ #include "sgl.h" #define DISTANCE_R1 40 #define DISTANCE_R2 40 extern PDATA PD_CUBE; static void set_star(ANGLE ang[XYZ] , FIXED pos[XYZ]) { slTranslate(pos[X] , pos[Y] , pos[Z]); slRotX(ang[X]); slRotY(ang[Y]); slRotZ(ang[Z]); } void ss_main(void) { static ANGLE ang1[XYZ] , ang2[XYZ]; static FIXED pos1[XYZ] , pos2[XYZ]; static ANGLE tmp = DEGtoANG(0.0); slInitSystem(TV_320x224,NULL,1); slPrint("Sample program 5.2" , slLocate(6,2)); ang1[X] = ang2[X] = DEGtoANG(30.0); ang1[Y] = ang2[Y] = DEGtoANG(45.0); ang1[Z] = ang2[Z] = DEGtoANG( 0.0); pos2[X] = toFIXED(DISTANCE_R2); pos2[Y] = toFIXED(0.0); pos2[Z] = toFIXED(0.0); while(-1){ slUnitMatrix(CURRENT); slPushMatrix(); { pos1[X] = DISTANCE_R1 * slSin(tmp); pos1[Y] = toFIXED(30.0); pos1[Z] = toFIXED(220.0) + DISTANCE_R1 * slCos(tmp); set_star(ang1 , pos1); slPutPolygon(&PD_CUBE); slPushMatrix(); { set_star(ang2, pos2); slPutPolygon(&PD_CUBE); } slPopMatrix(); } slPopMatrix(); ang1[Y] += DEGtoANG(1.0); ang2[Y] -= DEGtoANG(1.0); tmp += DEGtoANG(1.0); slSynch(); } }
functional type | function name | parameters | function |
---|---|---|---|
void | slLoadMatrix | MATRIX mtpr | Copy specified matrix to current matrix |
Bool | slPushMatrix | void | Temporary reservation of matrix |
Bool | slPushUintMatrix | void | Temporarily allocate the identity matrix on the stack |
void | slGetMatrix | MATRIX mtpr | Copy current matrix to specified matrix |
void | slInitMatrix | void | Initialization of matrix variables and buffers |
void | slMultiMatrix | MATRIX mptr | Multiply the current matrix by the specified matrix |
Bool | slPopMatrix | void | Restoring a temporarily saved matrix |
void | slUintMatrix | MATRIX mptr | Make the specified matrix an identity matrix |