libnds
Macros | Functions
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);
#define degreesToAngle(degrees)
Convert an angle in 360 degree format to the format used by libnds.
Definition: trig_lut.h:78

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

◆ fixedToFloat

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

Converts a fixed point number to a floating point number.

Parameters
nThe fixed point number to convert.
bitsThe number of bits used for the decimal part.
Returns
The floating point number.

◆ fixedToInt

#define fixedToInt (   n,
  bits 
)    ((int)((n) >> (bits)))

Convert a fixed point number to an integer.

Parameters
nThe number the number to convert.
bitsThe number of bits used for the decimal part.
Returns
The integer part.

◆ floatToFixed

#define floatToFixed (   n,
  bits 
)    ((int)((n) * (float)(1 << (bits))))

Converts a floating point number to a fixed point number.

Parameters
nThe floating point number to convert.
bitsThe number of bits used for the decimal part.
Returns
The fixed point number.

◆ floorFixed

#define floorFixed (   n,
  bits 
)    ((int)((n) & ~(((1 << (bits)) - 1))))

Removes the decimal part of a fixed point number.

Parameters
nThe fixed point number.
bitsThe number of bits used for the decimal part.
Returns
A fixed point number with 0 as a decimal part.

◆ intToFixed

#define intToFixed (   n,
  bits 
)    ((int)((n) << (bits)))

Converts an integer to a fixed point number.

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

Function Documentation

◆ acosLerp()

s16 acosLerp ( s16  par)

Fixed point arccos.

Parameters
par4.12 fixed point number with the range [-1, 1].
Returns
s16 Angle (-32768 to 32767).

◆ asinLerp()

s16 asinLerp ( s16  par)

Fixed point arcsin.

Parameters
par4.12 fixed point number with the range [-1, 1].
Returns
s16 Angle (-32768 to 32767).

◆ cosLerp()

s16 cosLerp ( s16  angle)

Fixed point cosine.

Parameters
angleAngle (-32768 to 32767).
Returns
4.12 fixed point number with the range [-1, 1].

◆ sinLerp()

s16 sinLerp ( s16  angle)

Fixed point sine.

Parameters
angleAngle (-32768 to 32767).
Returns
4.12 fixed point number with the range [-1, 1].

◆ tanLerp()

s32 tanLerp ( s16  angle)

Fixed point tangent.

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