Japanese
SGL User's ManualPROGRAMMER'S TUTORIAL
BackForward
PROGRAMMER'S TUTORIAL

11. Arithmetic functions


This chapter introduces the various calculation library functions supported by SGL.

11-1. General arithmetic functions

First, we will introduce general arithmetic functions.

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

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

[FIXED slSquartFX ( FIXED sqrtfx );]
Returns the square root of an unsigned fixed-point number (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 the 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 calculation functions

This section introduces special arithmetic functions.

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

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

Figure 11-3 Vector inner product return value
┌─● Vector inner 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 expressed in BCD code to hexadecimal code.

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

[Uint16 slAng2Hex (ANGLE ang);]
Converts the angle value represented by ANGLE code to hexadecimal code.
Converted values are returned in the range 0x000 to 0x167.

[Uint16 slAng2Dec (ANGLE ang);]
Converts the angle value represented by ANGLE code to BCD code.
Converted values are returned in the range 0x000 to 0x359.

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

Table 11-1 Examples of numerical notation using each numerical notation method
decimal number B.C.D. hexadecimal number
Notation 92 0x92 0x5CH

Additional notes: SGL library functions that appeared in this chapter

In this chapter, we explained the functions in the table below.

Table 11-2 SGL library functions that appeared in this chapter
 functional type
 Function name
 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 the 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 it.
FIXED slInnerProduct VECTOR a,VECTOR b Take the inner product of vectors
Uint32 slDec2Hex Uint32 val Conversion from BCD code to hexadecimal code
Uint32 slHex2Dec Uint32 val Conversion from hex code to BCD code
Uint16 slAng2Hex ANGLE ang Converting ANGLE code to hex 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 TUTORIAL
Copyright SEGA ENTERPRISES, LTD., 1997