#include "sgl.h"
void slInitMatrix (void)
void --Do not give anything.
void --Nothing is returned.
Initialization of variables and buffers used in matrix operations
Initializes the matrix buffer.
slInitMatrix ();
#include "sgl.h"
Bool slPushMatrix (void)
void --Do not give anything.
Bool --Returns NG if an error occurs and OK if successful.
Advance the pointer on the matrix stack and copy the current matrix to it.
You can nest up to 20 matrices, but if you exceed this, an error will be returned.
Save the current matrix to the matrix stack and use the contents of that matrix for the next process.
slPushMatrix ();
{
slScale (...);
::
This function is used when you want to save the past current matrix information such as a hierarchical model.
#include "sgl.h"
Bool slPushUnitMatrix (void)
void --Do not give anything.
Bool --Returns NG if an error occurs and OK if successful.
Advance the pointer on the matrix stack and set the identity matrix there.
If it is over-nested, it will return an error.
Save the unit matrix in the matrix buffer.
slPushUnitMatrix ();
{
slTranslate (...);
::
slPutPolygonX (...);
}
slPopMatrix ();
At this point, the current matrix becomes an identity matrix.
#include "sgl.h"
Bool slIncMatrixPtr (void)
void --Do not give anything.
Bool --Returns NG if an error occurs and OK if successful.
Advance the pointer on the matrix stack.
You can nest up to 20 matrices, but if you exceed this, an error will be returned.
Advance the pointer of the matrix stack by one and check if stack overflow has occurred.
if ( slIncMatrixPtr () == NG ) {
/ * Stack Over flow. * /
} else {
/ * Stack safty. * /
}
#include "sgl.h"
Bool slPopMatrix (void)
void --Do not give anything.
Bool --Returns NG if an error occurs and OK if successful.
Returns one pointer on the matrix stack.
If it is returned too much, an error will be returned.
The matrix saved in the current matrix is restored and reused.
slPushMatrix (); <-(A)
{
slTranslate (..);
::
}
slPopMatrix (); <-(B)
At the time of (B), the current matrix is in the same state as (A).
#include "sgl.h"
Bool slDecMatrixPtr (void)
void --Do not give anything.
Bool --Returns NG if an error occurs and OK if successful.
Returns one pointer on the matrix stack.
If it is returned too much, an error will be returned.
Return one pointer to the matrix stack and check if stack underflow is occurring.
if ( slDecMatrixPtr () == NG ) {
/ * Stack underflow. * /
} else {
/ * Stack safty. * /
}
slPushMatrix ();
{
::
}
slDecMatrixPtr ();
This function has the same function as slPopMatrix.
#include "sgl.h"
MATRIX * mtptr;
void slUnitMatrix (mtptr)
MATRIX * mtptr-Pointer to the MATRIX data type that represents the matrix you want to be the identity matrix
void --Nothing is returned.
Makes the specified matrix an identity matrix. If CURRENT is specified for the matrix, the current matrix of the matrix stack is targeted.
#include "sgl.h"
MATRIX * mtptr;
void slUnitAngle (mtptr)
MATRIX * mtptr-Pointer to the MATRIX data type that represents the matrix you want to unitize
void --Nothing is returned.
Make the rotating part (3 × 3) of the matrix an identity matrix. The translation part is not changed.
If CURRENT is specified for the matrix, the current matrix will be changed.
#include "sgl.h"
MATRIX * mtptr;
void slUnitTranslate (mtptr)
MATRIX * mtptr --A pointer to the MATRIX data type that represents the matrix for which you want the parallel component to be zero.
void --Nothing is returned.
Set the parallel movement part of the matrix to 0. The rotating part does not change.
If CURRENT is specified for the matrix, the current matrix will be changed.
Set the translation component of the matrix to 0.
MATRIX matr
::
slUnitTranslate (& matr);
#include "sgl.h"
MATRIX * mtptr;
void slLoadMatrix (mtptr)
MATRIX * mtptr --A pointer to the MATRIX data type that indicates the matrix you want to copy to the current matrix.
void --Nothing is returned.
Copies the specified matrix to the current matrix.
Copy the contents of the specified matrix to the current matrix.
MATRIX matr = {
::
};
slPushMatrix ();
{
slLoadMatrix (& matr);
slRotX (...);
::
}
slPopMatrix ();
#include "sgl.h"
Bool slCopyMatrix (void)
void --Do not give anything.
Bool --Returns NG if an error occurs and OK if successful.
Copy the previous matrix to the current matrix.
Returns an error if the matrix is not nested.
Put the contents of the matrix stack on the current matrix and decrement the pointer on the matrix stack by one.
: <-(A)
slPushMatrix ();
{<-(B)
slTranslate (..);
::
slCopyMatrix (); <-(C)
}
slPopMatrix ();
: <-(D)
At the time of (C), the current matrix is in the same state as (A).
However, since the pointer of the matrix stack is not manipulated, the state of the matrix stack at the time of (C) is the same as that of (B) and not the same as that of (A). Starting at the time of (D),
It will be in the same state as (A).
#include "sgl.h"
MATRIX * mtptr;
void slRegistMatrix (mtptr)
MATRIX * mtptr --A pointer to the MATRIX data type that represents the matrix you want to register on the matrix stack.
void --Nothing is returned.
Copies the specified matrix to the matrix buffer.
If CURRENT is specified for the matrix, the current matrix of the matrix stack is targeted.
Register the specified matrix on the matrix stack.
MATRIX matr;
::
slRegistMatrix (& matr);
#include "sgl.h"
MATRIX * mtptr;
void slGetMatrix (mtptr)
MATRIX * mtptr --A pointer to MATRIX type data that copies the contents of the current matrix.
void --Nothing is returned. (However, the result of processing is reflected in the MATRIX data indicated by the argument mtptr.)
Copies the current matrix to the specified matrix.
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 ] --A pointer to a FIXED type array that stores the extracted parallel components.
void --Nothing is returned. (However, the result of processing is reflected in the FIXED type data indicated by the argument pos.)
Extracts the translation component from the current matrix and copies it to the specified buffer.
#include "sgl.h"
FIXED x_dif, y_dif, z_dif;
void slLoadTranslate (x_dif, y_dif, z_dif)
FIXED x_dif --The X value of the translation component.
FIXED y_dif --The Y value of the translation component.
FIXED z_dif --Z value of the translation component.
void --Nothing is returned.
Updates only the translated part of the current matrix.
#include "sgl.h"
void slInversMatrix (void)
void --Do not give anything.
void --Nothing is returned.
Make the current matrix inverse.
#include "sgl.h"
void slTransposeMatrix (void)
void --Do not give anything.
void --Nothing is returned.
Makes the current matrix a transposed matrix.
#include "sgl.h"
ANGLE angx;
void slRotX (angx)
ANGLE angx --Rotation angle
void --Nothing is returned.
Multiply the current matrix by the rotation matrix around the X axis.
The rotation matrix is 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 --The value of sin given during rotational transformation.
FIXED cos-The value of cos given during rotational transformation.
void --Nothing is returned.
Specify the sine and cosine to rotate around the X axis.
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 --Nothing is returned.
Multiply the current matrix by the rotation matrix around the Y axis.
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 --The value of sin given during rotational transformation.
FIXED cos-The value of cos given during rotational transformation.
void --Nothing is returned.
Specify the sine and cosine to rotate around the Y axis.
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 --Nothing is returned.
Multiply the current matrix by the rotation matrix around the Z axis.
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 --The value of sin given during rotational transformation.
FIXED cos-The value of cos given during rotational transformation.
void --Nothing is returned.
Specify the sine and cosine to rotate around the Z axis.
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 components of the vector representing the rotation axis ANGLE ang - rotation angle
void --Nothing is returned.
Rotate around an arbitrary axis passing through the origin. The axis is specified by the unit vector.
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.0
Nx, Ny, and Nz are components of the unit vector that represents the axis.
C stands for cosine and S stands for sine.
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 - translation X component FIXED Y_dif - translation of the Y component FIXED Z_dif - Z component of the translation
void --Nothing is returned.
Translates the current matrix.
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 - translation X component FIXED Y_dif - translation of the Y component FIXED Z_dif - Z component of the translation
void --Nothing is returned.
Copies the translated translation of the matrix buffer into the current matrix. However, the matrix buffer does not change.
#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 the Y direction.
FIXED scl_z --Scale value in the Z direction.
void --Nothing is returned.
Scale with respect to the current matrix.
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 --The matrix you want to multiply by the current matrix.
void --Nothing is returned.
Multiplies the current matrix by the specified matrix.
#include "sgl.h"
FIXED camera [ XYZ ];
FIXED target [ XYZ ];
ANGLE angz;
void slLookAt (camera, target, angz)
FIXED camera [ XYZ ] --Camera (viewpoint position)
FIXED target [ XYZ ] --A vector that represents the direction of the line of sight.
ANGLE angz --Rotating component with respect to the line-of-sight direction.
void --Nothing is returned.
Multiply the current matrix by the matrix that looks in the target direction from the camera position.
At that time, it also rotates around the Z axis.
In the direction along the Y axis, the vector on the XZ plane becomes small and may not be calculated correctly.
mtptr |
#include "sgl.h"
FIXED obj [ XYZ ];
FIXED size;
FIXED slCheckOnScreen (obj, size)
FIXED obj [ XYZ ] --The position of the object.
FIXED size-The radius of the object.
Z position of the FIXED object. When off the screen, a negative number is returned.
Converts the position of the specified object through the current matrix
Tests if an object of the specified size is displayed on the screen at that position and returns the result.
Returns -1 (FFFFFFFF) if it is in front of the screen, -2 (FFFFFFFE) if it is up, down, left or right, and Z position if it is in the screen.
if ( slCheckOnScreen (obj, obj_size) < toFIXED (0.0)) {
/ * Do not draw because it is not displayed on the screen. * /
} else {
slPutPolygonX (...);
}
slCheckOnScreen0 | slConvert3Dto2DFX | slConvert3Dto2D | mtptr |
#include "sgl.h"
FIXED size [ XYZ ];
FIXED slCheckOnScreen0 (size)
FIXED size-The radius of the object.
Z position of the FIXED object. When off the screen, a negative number is returned.
Tests if the object at position (0,0,0) is displayed on the screen with the specified size and returns the result.
Returns -1 (FFFFFFFF) if it is in front of the screen, -2 (FFFFFFFE) if it is up, down, left or right, and Z position if it is in the 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 --The point you want to convert with the current matrix.
FIXED ans [ XYZ ] --FIXED type array to store the operation result.
void --Nothing is returned. (However, the result of the operation is in the ans given as an argument.)
Returns the result of coordinate transformation of the specified point in the current matrix to the buffer.
→
a = (pos_x, pos_y, pos_z)
→
b = ans
When the current matrix is M,
→→
b = M · a
Is calculated.
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 coordinates in the coordinate space given by the current matrix, that is, the relative coordinates.)
FIXED Ans_si [ XY ] - add the result of the operation FIXED -type sequence.
FIXED Ans_fx [ XY ] - add the result of the operation FIXED -type sequence.
FIXED The Z position of the given coordinates. (The operation result is returned to ans given to the argument.)
Returns the screen coordinate values ans_fx / ans_si when actually displayed on the screen from the 3D relative coordinate pos using the current matrix. Returns the Z value as a function value.
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 ( debugtoANG (20.0));
slRotY (ang_para_y);
slRotZ (ang_para_z);
slPutPolygon (...);
slConvert3Dto2D (pos, ans);
}
slPopMatrix ();
slCheckOnScreen | slCheckOnScreen0 | mtptr |