Japanese
SGL User's ManualPROGRAMMER'S TUTORIAL
BackForward
PROGRAMMER'S TUTORIAL/1.About Sega Saturn 3D game library

1-2. Precautions when using the library

Numbers used in the library

SGL does not support floating point numbers.
Therefore, we have established the following three variable types based on fixed-point numbers.

In fact, conversion from floating-point numbers to fixed-point numbers is supported in the form of macro definitions, so there is no need for individual conversion by each individual (see "Table 1-1: Macro examples for numeric type conversion").

  1. Fixed-point numbers (used for values such as coordinate positions and trigonometric functions)
    Model name: FIXED
    32 bits (signed) where the upper 16 bits are the integer part and the lower 16 bits are the decimal part.

    Example) When representing 16.5

    16.5 → 0x0010_8000 | | | | | Decimal part Integer part

  2. Angle (used for all angle value expressions such as rotation angle)
    Model name: ANGLE
    Expressing 360 degrees in 16 bits

    Figure 1-4 Angle represented by ANGLE

  3. Matrix (used for all matrix variables such as transformation matrices)
    Model name: MATRIX
    The numbers are a 4-row x 3-column matrix using FIXED (see the figure below for memory location)

Figure 1-5 Memory arrangement of matrices

The following table is a list of macros for numerical conversion supported by SGL.
In addition to these, SGL supports several macros depending on the purpose.
The macros supported by SGL are defined in the header files "sgl.h" and "sl_def.h" (for details, please refer to "Structure Reference" in the reference manual).

Table 1-1 Macro example for numeric type conversion
 conversion type
 macro name
 Macro content
    how to use
FIXED toFIXED(p) ((FIXED)((p)*65536.0)) Converting a number to FIXED type
ANGLE DEGtoANG(d) ((ANGLE)((d)*65536.0/360.0)) Conversion of DEG type angular value to ANGLE type
FIXED POStoFIXED(x,y,z) {toFIXED(x),toFIXED(y),toFIXED(z)} Converting XYZ coordinates to FIXED type
Note) Macros are defined in the include files “sgl.h” and “sl_def.h”.

The sample programs in this book may also use these macros without notice.

Coordinate system

Sega Saturn generally uses a coordinate system called a right-handed coordinate system.
Also, when using a rotation matrix, the positive direction of the angle is clockwise rotation with respect to the axis.

Figure 1-6 Coordinate system on Sega Saturn
a) Coordinate system used by Sega Saturn (right-handed system) b) Positive direction of rotation about the Z axis
・When the positive Z direction is placed at the back of the screen, the positive Y direction extends downward and the positive X direction extends toward the right of the screen.
・The positive direction of rotation is to the right of the axis

BackForward
SGL User's ManualPROGRAMMER'S TUTORIAL
Copyright SEGA ENTERPRISES, LTD., 1997