SGL User's ManualPROGRAMMER'S STRUCT
BackForward
PROGRAMMER'S STRUCT

11. Arithmetic functions


This chapter introduces the library functions for various operations supported by SGL.

11-1. General arithmetic functions

First, I will introduce general arithmetic functions.

[FIXED slDivFX (FIXED a, FIXED b);]
Divides between the specified parameters (b / a).

[FIXED slMulFX (FIXED a, FIXED b);]
Multiplies between the specified parameters (a * b).

[FIXED slSquartFX (FIXED sqrtfx);]
Returns the square root of an unsigned fixed point (FIXED type).

[Uint32 slSquart (Uint32 sqrt);]
Returns the square root of an unsigned integer value.

11-2. Trigonometric functions

Introducing arithmetic functions related to trigonometric functions.

[FIXED slSin (ANGLE angs);]
Returns a sine value for the specified angle (ANGLE type).

[FIXED slCos (ANGLE angc);]
Returns the cosine value for the specified angle (ANGLE type).

[FIXED slTan (ANGLE angt);]
Returns the tangent value for the specified angle (ANGLE type).

Figure 11-1 Trigonometric function image

[ANGLE slAtan (FIXED tx, FIXED ty);]
Returns the angle in the specified direction.

Figure 11-2 “slAtan” image

11-3. Special arithmetic functions

Here, we will introduce a special arithmetic function.

[FIXED slCalcPoint (FIXED cx, FIXED cy, FIXED cz, FIXED * ret);]
Multiplies the current matrix by the specified points and assigns the calculation result to the parameter "ret".

[FIXED slInnerProduct (VECTOR a, VECTOR b);]
Takes the dot product of the vectors between the specified parameters.
The return value shown in Figure 11-3 is returned.

Figure 11-3 Vector dot product return value
┌─ ● Vector dot product return value ● ───────────────────────────┐
│ A (X1, Y1, Z1) * B (X2, Y2, Z2) = X1 * X2 + Y1 * Y2 + Z1 * Z2 │
│ = Return Value │
└─────────────────────────────────────────┘

[Uint32 slDec2Hex (Uint32 val);]
Converts a number represented by BCD code to hexadecimal code.

[Uint32 slHex2Dec (Uint32 val);]
Converts a number represented by hexadecimal code to BCD code.

[Uint 16 slAng2Hex (ANGLE ang);]
Converts the angle value represented by the ANGLE code to hexadecimal code.
The converted value is returned in the range 0x000-0x167.

[Uint 16 slAng2Dec (ANGLE ang);]
Converts the angle value represented by the ANGLE code into a BCD code.
The converted value is returned in the range 0x000-0x359.

[FIXED slAng2FX (ANGLE ang);]
Converts the angle value represented by the ANGLE code to the FIXED code.
Converted values are returned in the range 0.0-359.99.

Table 11-1 Numerical notation examples using each numerical notation
Decimal BCD Hexadecimal
labels 92 0x92 0x5CH

Appendix SGL library functions that appeared in this chapter

In this chapter, the functions in the following table are explained.

Table 11-2 SGL library functions introduced in this chapter
 Functional type
 Seki several people
 Parameter
         function
FIXED slDivFX FIXED a, FIXED b Division (a / b)
FIXED slMulFX FIXED a, FIXED b Multiplication (a * b)
FIXED slSquartFX FIXED sqrtfx Unsigned fixed-point square root
Uint32 slSquart Uint32 sqrt Square root of unsigned integer
FIXED slSin ANGLE angs Returns a sine value for the specified angle
FIXED slCos ANGLE angc Returns the cosine value for the specified angle
FIXED slTan ANGLE angt Returns the tangent value for the specified angle
ANGLE slAtan FIXED tx, FIXED ty Returns the angle in the specified direction
FIXED slCalcPoint FIXED zx, cy, cz, FIXED * ret Multiplies the current matrix by the specified point and returns
FIXED slInnerProduct VECTOR a, VECTOR b Take the inner product of the vectors
Uint32 slDec2Hex Uint32 val Conversion from BCD code to hexadecimal code
Uint32 slHex2Dec Uint32 val Conversion from hexadecimal code to BCD code
Uint16 slAng2Hex ANGLE ang Conversion from ANGLE code to hexadecimal code
Uint16 slAng2Dec ANGLE ang Conversion from ANGLE code to BCD code
FIXED slAng2FX ANGLE ang Conversion from ANGLE code to FIXED code


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