#include "sgl.h" void slInitMatrix( void )
void - gives nothing.
void - returns nothing.
Initialize the matrix buffer.
slInitMatrix ();
#include "sgl.h" Bool slPushMatrix( void )
void - gives nothing.
Bool - Returns NG if an error occurs, OK if successful.
Save the current matrix in the matrix stack and use the contents of that matrix for the next process.
slPushMatrix (); { slScale (...); :
#include "sgl.h" Bool slPushUnitMatrix( void )
void - gives nothing.
Bool - Returns NG if an error occurs, OK if successful.
Save the unit matrix to the matrix buffer.
slPushUnitMatrix (); { slTranslate ( ... ); : slPutPolygonX ( ... ); } slPopMatrix (); At this point, the current matrix becomes an identity matrix.
#include "sgl.h" Bool slIncMatrixPtr( void )
void - gives nothing.
Bool - Returns NG if an error occurs, OK if successful.
Advance the matrix stack pointer by one and check whether a stack overflow has occurred.
if ( slIncMatrixPtr () == NG ) { /* Stack Overflow. */ } else { /* Stack safety. */ }
#include "sgl.h" Bool slPopMatrix( void )
void - gives nothing.
Bool - Returns NG if an error occurs, OK if successful.
The matrix evacuated to the current matrix is restored and reused.
slPushMatrix (); <-- (A) { slTranslate ( .. ); : } slPopMatrix (); <-- (B) At time (B), the current matrix is in the same state as in (A).
#include "sgl.h" Bool slDecMatrixPtr( void )
void - gives nothing.
Bool - Returns NG if an error occurs, OK if successful.
Return one pointer to the matrix stack and check whether a stack underflow has occurred.
if ( slDecMatrixPtr () == NG ) { /* Stack underflow. */ } else { /* Stack safety. */ } slPushMatrix (); { : } slDecMatrixPtr ();
#include "sgl.h" MATRIX *mtptr; void slUnitMatrix( mtptr )
MATRIX *mtptr - pointer to the MATRIX data type representing the matrix you want to be the identity matrix
void - returns nothing.
#include "sgl.h" MATRIX *mtptr; void slUnitAngle( mtptr )
MATRIX *mtptr - pointer to the MATRIX data type representing the matrix you want to unitize
void - returns nothing.
#include "sgl.h" MATRIX *mtptr; void slUnitTranslate( mtptr )
MATRIX *mtptr - Pointer to the MATRIX data type representing the matrix whose parallel components you want to zero out.
void - returns nothing.
Set the parallel component of the matrix to 0.
MATRIX matr : slUnitTranslate( &matr );
#include "sgl.h" MATRIX *mtptr; void slLoadMatrix( mtptr )
MATRIX *mtptr - Pointer to MATRIX data type indicating the matrix you want to copy to the current matrix.
void - returns nothing.
Copies the contents of the specified matrix to the current matrix.
MATRIX matr = { : }; slPushMatrix (); { slLoadMatrix ( &matr ); slRotX ( ... ); : } slPopMatrix ();
#include "sgl.h" Bool slCopyMatrix( void )
void - gives nothing.
Bool - Returns NG if an error occurs, OK if successful.
Puts the contents of the matrix stack into the current matrix and decrements the matrix stack pointer by one.
: <-- (A) slPushMatrix (); { <-- (B) slTranslate ( .. ); : slCopyMatrix (); <-- (C) } slPopMatrix (); : <-- (D) At point (C), the current matrix is in the same state as (A).
However, since the matrix stack pointer is not manipulated, the state of the matrix stack at the time of (C) is the same as that of (B), but not the same as that of (A). Starting at point (D), The situation will be the same as in (A).
#include "sgl.h" MATRIX *mtptr; void slRegistMatrix( mtptr )
MATRIX *mtptr - Pointer to the MATRIX data type representing the matrix you want to register on the matrix stack.
void - returns nothing.
Registers the specified matrix to the matrix stack.
MATRIX matr; : slRegistMatrix ( &matr );
#include "sgl.h" MATRIX *mtptr; void slGetMatrix( mtptr )
MATRIX *mtptr - Pointer to MATRIX type data to copy the contents of the current matrix.
void - returns nothing. (However, the processing results are reflected in the MATRIX data indicated by the argument mtptr.)
Copy the contents of the current matrix to another location.
MATRIX *matr; slGetMatrix ( matr ); The contents of the current matrix are copied to matr.
#include "sgl.h" FIXED pos[ XYZ ] void slGetTranslate( pos )
FIXED pos[ XYZ ] - Pointer to FIXED type array to store retrieved parallel components.
void - returns nothing. (However, the processing result is reflected in the FIXED type data indicated by the argument pos.)
#include "sgl.h" FIXED x_dif, y_dif, z_dif; void slLoadTranslate( x_dif, y_dif, z_dif )
FIXED x_dif - X value of the translation component.
FIXED y_dif - Y value of the translation component.
FIXED z_dif - Z value of the translation component.
void - returns nothing.
#include "sgl.h" void slInversMatrix( void )
void - gives nothing.
void - returns nothing.
#include "sgl.h" void slTransposeMatrix( void )
void - gives nothing.
void - returns nothing.
#include "sgl.h" ANGLE angx; void slRotX( angx )
ANGLE angx - rotation angle
void - returns nothing.
1.0 0.0 0.0 0.0 0.0 cosΘ sinΘ 0.0 0.0 -sinΘ cosΘ 0.0 0.0 0.0 0.0 1.0
slRotXSC | slRotY | slRotYSC | slRotZ |
slRotZSC | slRotAX | slZrotR | mtptr |
#include "sgl.h" FIXED sin; FIXED cos; void slRotXSC( sin, cos )
FIXED sin - value of sin to give during rotation transformation.
FIXED cos - Cos value given during rotation transformation.
void - returns nothing.
1.0 0.0 0.0 0.0 0.0 cos sin 0.0 0.0 -sin cos 0.0 0.0 0.0 0.0 1.0
slRotX | slRotY | slRotYSC | slRotZ |
slRotZSC | slRotAX | slZrotR | mtptr |
#include "sgl.h" ANGLE Angy; void slRotY(angy)
ANGLE angy - rotation angle
void - returns nothing.
cosΘ 0.0 -sinΘ 0.0 0.0 1.0 0.0 0.0 sinΘ 0.0 cosΘ 0.0 0.0 0.0 0.0 1.0
slRotX | slRotXSC | slRotYSC | slRotZ |
slRotZSC | slRotAX | slZrotR | mtptr |
#include "sgl.h" FIXED sin; FIXED cos; void slRotYSC( sin, cos )
FIXED sin - value of sin to give during rotation transformation.
FIXED cos - Cos value given during rotation transformation.
void - returns nothing.
cos 0.0 -sin 0.0 0.0 1.0 0.0 0.0 sin 0.0 cos 0.0 0.0 0.0 0.0 1.0
slRotX | slRotXSC | slRotY | slRotZ |
slRotZSC | slRotAX | slZrotR | mtptr |
#include "sgl.h" ANGLE angz; void slRotZ( angz )
ANGLE angz - rotation angle
void - returns nothing.
cosΘ sinΘ 0.0 0.0 -sinΘ cosΘ 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0
slRotX | slRotXSC | slRotY | slRotYSC |
slRotZSC | slRotAX | slZrotR | mtptr |
#include "sgl.h" FIXED sin; FIXED cos; void slRotZSC( FIXED sin , FIXED cos )
FIXED sin - value of sin to give during rotation transformation.
FIXED cos - Cos value given during rotation transformation.
void - returns nothing.
cos sin 0.0 0.0 -sin cos 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0
slRotX | slRotXSC | slRotY | slRotYSC |
slRotZ | slRotAX | slZrotR | mtptr |
#include "sgl.h" FIXED vecx, vecy, vecz; ANGLE ang; void slRotAX( vecx, vecy, vecz, ang )
FIXED vecx - X component of the vector representing the rotation axis
FIXED vecy - Y component of the vector representing the rotation axis
FIXED vecz - Z component of the vector representing the rotation axis
ANGLE ang - Rotation angle
void - returns nothing.
NxNx(1-C)+C NxNy(1-C)+NzS NxNz(1-C)-NyS 0.0 NyNx(1-C)-NzS NyNy(1-C)+C NyNz(1-C)+NxS 0.0 NzNx(1-C)+NyS NzNy(1-C)-NxS NzNz(1-C)+C 0.0 0.0 0.0 0.0 1.0Nx, Ny, Nz are the components of the unit vector representing the axis.
slRotX | slRotXSC | slRotY | slRotYSC |
slRotZ | slRotZSC | slZrotR | mtptr |
#include "sgl.h" FIXED x_dif, y_dif, z_di;f void slTranslate( x_dif, y_dif, z_dif )
FIXED x_dif - X component of translation
FIXED y_dif - Y component of translation
FIXED z_dif - Z component of translation
void - returns nothing.
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 tx ty tz 1.0
slGetTranslate | slRegistTranslate | mtptr |
#include "sgl.h" FIXED x_dif, y_dif, z_di;f void slRegistTranslate( x_dif, y_dif, z_dif )
FIXED x_dif - X component of translation
FIXED y_dif - Y component of translation
FIXED z_dif - Z component of translation
void - returns nothing.
#include "sgl.h" FIXED scl_x, scl_y, scl_z; void slScale( FIXED scl_x, FIXED scl_y, FIXED scl_z )
FIXED scl_x - Scale value in the X direction.
FIXED scl_y - Scale value in Y direction.
FIXED scl_z - Scale value in Z direction.
void - returns nothing.
scl_x 0.0 0.0 0.0 0.0 scl_y 0.0 0.0 0.0 0.0 scl_z 0.0 0.0 0.0 0.0 1.0
mtptr |
#include "sgl.h" MATRIX mtrx void slMultiMatrix( mtrx )
MATRIX mtrx - Matrix to be applied to the current matrix.
void - returns nothing.
#include "sgl.h" FIXED camera[ XYZ ]; FIXED target[ XYZ ]; ANGLE angz; void slLookAt( camera, target, angz )
FIXED camera[ XYZ ] - Camera (view position) FIXED target[ XYZ ] - A vector representing the viewing direction.
ANGLE angz - Rotational component relative to viewing direction.
void - returns nothing.
mtptr |
#include "sgl.h" FIXED obj[ XYZ ]; FIXED size; FIXED slCheckOnScreen( obj, size )
FIXED obj[ XYZ ] - Object position. FIXED size - radius of the object.
FIXED Z position of object. Returns a negative number when off-screen.
if ( slCheckOnScreen ( obj, obj_size ) < toFIXED ( 0.0 ) ) { /* It is not displayed on the screen, so it is not drawn. */ } else { slPutPolygonX ( ... ); }
slCheckOnScreen0 | slConvert3Dto2DFX | slConvert3Dto2D | mtptr |
#include "sgl.h" FIXED size[ XYZ ]; FIXED slCheckOnScreen0( size )
FIXED size - radius of the object.
FIXED Z position of object. Returns a negative number when off-screen.
slCheckOnScreen | slConvert3Dto2DFX | slConvert3Dto2D | mtptr |
#include "sgl.h" FIXED pos_x, pos_y, pos_z; FIXED ans[ XYZ ]; void slCalcPoint( pos_x, pos_y, pos_z, ans )
FIXED pos_x, pos_y, pos_z - Points you want to transform in the current matrix.
FIXED ans[ XYZ ] - FIXED type array for storing operation results.
void - returns nothing. (However, the result of the operation is stored in ans given as an argument.)
→ a = (pos_x, pos_y, pos_z) → b = ans When the current matrix is M, → → b = M・a Calculations will be made.
slPushMatrix (); { slScale ( ... ); : slPutPolygonX ( ... ); slCalcPoint ( ... ); } slPopMatrix ();
mtptr |
#include "sgl.h" FIXED pos[ XYZ ]; FIXED ans_fx[ XY ]; Sint32 ans_si[ XY ]; FIXED slConvert3Dto2DFX( pos, ans_fx ); FIXED slConvert3Dto2D( pos, ans_si );
FIXED pos[ XYZ ] - Coordinates to be converted to screen coordinates (However, the coordinate values in the coordinate space given by the current matrix are relative coordinates.) FIXED ans_si[ XY ] - FIXED type array containing the result of the operation.
FIXED ans_fx[ XY ] - FIXED type array containing the result of the operation.
FIXED Z position of given coordinates. (The operation result is returned to ans given as the argument.)
Find the screen coordinates of the center position of a model.
FIXED pos[ XYZ ] = { toFIXED ( 1.0 ), toFIXED ( 2.0 ), toFIXED ( 3.0 ) }; FIXED ans[ XY ]; : slPushMatrix (); { slTranslate ( toFIXED ( 3.5 ), toFIXED ( 6.2 ), toFIXED ( 2.1 ) ); slRotX ( DEGtoANG ( 20.0 ) ); slRotY ( ang_para_y ); slRotZ ( ang_para_z ); slPutPolygon ( ... ); slConvert3Dto2D ( pos, ans ); } slPopMatrix ();
slCheckOnScreen | slCheckOnScreen0 | mtptr |