PROGRAMMER'S GUIDEMathematical calculation library
■ | Advance
Mathematical calculation library

1. 1. guide


1.1 Purpose

The math library is a set of routines for easy 3D display, 3D object movement calculations, 32-bit fixed-point arithmetic, and more.
These routines fall into the following categories:

● Trigonometric functions
Extract the sin and cos values from the table. The table is registered in units of 1 degree, and linear completion is performed during 1 degree.

● Matrix arithmetic processing
Manages the matrix stack and performs matrix composition processing.

● 3D coordinate conversion processing by DSP
Hidden surface determination, brightness calculation, and coordinate conversion processing of polygon data used in the sprite 3D display library are collectively performed by DSP.

● Perspective conversion processing
Performs perspective transformation from 3D to 2D screen in the viewpoint coordinate system.
The viewpoint position is the origin, and the screen position is -1.0 on the Z axis.

● Random number generation processing
Generate random numbers used in the game in the range of 0 to 0xffffffff.

● Spline curve calculation process
This curve calculation function uses a cubic spline curve and has the following characteristics.
(1) Supports 2D and 3D coordinates
(2) Tangent vector at each output coordinate can be acquired As shown in Fig. 1, it is possible to acquire a point on a curve that smoothly passes through that point by specifying a small number of points. Figure 1 shows that if you specify the input coordinate array P0 to 3, the number of arrays 4, and the number of output coordinates 10, you can obtain an array of output coordinates that smoothly passes through that point as c0 to 9. You can also get the tangent vector at each output coordinate by using the tangent function. The tangent vector can be used for the direction of travel of the character.

Figure 1 Conceptual diagram of curve calculation

● Fixed-point arithmetic
There are routines and macros that perform multiplication and division of 32-bit fixed-point data (16-bit integer part + 16-bit decimal part) and mutual type conversion with integer and floating-point data.

● Other functions
Other numerical calculation functions other than the above.


■ | Advance
PROGRAMMER'S GUIDEMathematical calculation library
Copyright SEGA ENTERPRISES, LTD., 1997