libnds
trig_lut.h File Reference

fixed point trig functions. Angle can be in the range of -32768 to More...

`#include <nds/ndstypes.h>`

## Macros

#define angleToDegrees(angle)   ((angle) * 360 / DEGREES_IN_CIRCLE)
converts an angle in the format used by libnds in the 360 degree format.

#define DEGREES_IN_CIRCLE   (1 << 15)
number of degrees in a circle.

#define degreesToAngle(degrees)   ((degrees) * DEGREES_IN_CIRCLE / 360)
convert an angle in 360 degree format to the format used by libnds.

#define fixedToFloat(n, bits)   (((float)(n)) / (float)(1<<(bits)))
converts a fixed point number to a floating point number. More...

#define fixedToInt(n, bits)   ((int)((n)>>(bits)))
convert a fixed point number to an integer. More...

#define floatToFixed(n, bits)   ((int)((n) * (float)(1<<(bits))))
converts a floating point number to a fixed point number. More...

#define floorFixed(n, bits)   ((int)((n) & ~(((1 << (bits)) - 1))))
removes the decimal part of a fixed point number. More...

#define intToFixed(n, bits)   ((int)((n)<<(bits)))
converts an integer to a fixed point number. More...

## Functions

s16 acosLerp (s16 par)
fixed point arccos More...

s16 asinLerp (s16 par)
fixed point arcsin More...

s16 cosLerp (s16 angle)
fixed point cosine More...

s16 sinLerp (s16 angle)
fixed point sine More...

s32 tanLerp (s16 angle)
fixed point tangent More...

## Detailed Description

fixed point trig functions. Angle can be in the range of -32768 to

1. There are 32768 degrees in the unit circle used by nds. To convert between standard degrees (360 per circle):

angle = degreesToAngle(angleInDegrees);

or

angle = angleInDegrees * 32768 / 360;

This unit of measure is sometimes refered to as a binary radian (brad) or binary degree. It allows for more precise representation of angle and faster calculation as the DS has no floating point processor.

## Macro Definition Documentation

 #define fixedToFloat ( n, bits ) (((float)(n)) / (float)(1<<(bits)))

converts a fixed point number to a floating point number.

Parameters
 n the fixed point number to convert. bits the number of bits used for the decimal part.
Returns
the floating point number.
 #define fixedToInt ( n, bits ) ((int)((n)>>(bits)))

convert a fixed point number to an integer.

Parameters
 n the number the number to convert. bits the number of bits used for the decimal part.
Returns
the integer part.
 #define floatToFixed ( n, bits ) ((int)((n) * (float)(1<<(bits))))

converts a floating point number to a fixed point number.

Parameters
 n the floating point number to convert. bits the number of bits used for the decimal part.
Returns
the fixed point number.
 #define floorFixed ( n, bits ) ((int)((n) & ~(((1 << (bits)) - 1))))

removes the decimal part of a fixed point number.

Parameters
 n the fixed point number. bits the number of bits used for the decimal part.
Returns
a fixed point number with 0 as a decimal part.
 #define intToFixed ( n, bits ) ((int)((n)<<(bits)))

converts an integer to a fixed point number.

Parameters
 n the integer to convert. bits the number of bits used for the decimal part.
Returns
the fixed point number.

## Function Documentation

 s16 acosLerp ( s16 par )

fixed point arccos

Parameters
 par 4.12 fixed point number with the range [-1, 1]
Returns
s16 angle (-32768 to 32767)
 s16 asinLerp ( s16 par )

fixed point arcsin

Parameters
 par 4.12 fixed point number with the range [-1, 1]
Returns
s16 angle (-32768 to 32767)
 s16 cosLerp ( s16 angle )

fixed point cosine

Parameters
 angle (-32768 to 32767)
Returns
4.12 fixed point number with the range [-1, 1]
 s16 sinLerp ( s16 angle )

fixed point sine

Parameters
 angle (-32768 to 32767)
Returns
4.12 fixed point number with the range [-1, 1]
 s32 tanLerp ( s16 angle )

fixed point tangent

Parameters
 angle (-32768 to 32767)
Returns
20.12 fixed point number with the range [-81.483, 524287.999]