trig_lut.h File Reference

fixed point trig functions. Angle can be in the range of -32768 to 32767. There are 32768 degrees in the unit circle used by nds. To convert between standard degrees (360 per circle): More...

#include <nds/ndstypes.h>

Defines

#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.
#define fixedToInt(n, bits)   ((int)((n)>>(bits)))
 convert a fixed point number to an integer.
#define floatToFixed(n, bits)   ((int)((n) * (float)(1<<(bits))))
 converts a floating point number to a fixed point number.
#define floorFixed(n, bits)   ((int)((n) & ~(((1 << (bits)) - 1))))
 removes the decimal part of a fixed point number.
#define intToFixed(n, bits)   ((int)((n)<<(bits)))
 converts an integer to a fixed point number.

Functions

s16 acosLerp (s16 par)
 fixed point arccos
s16 asinLerp (s16 par)
 fixed point arcsin
s16 cosLerp (s16 angle)
 fixed point cosine
s16 sinLerp (s16 angle)
 fixed point sine
s32 tanLerp (s16 angle)
 fixed point tangent

Detailed Description

fixed point trig functions. Angle can be in the range of -32768 to 32767. 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.


Define 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.
Examples:
Graphics/Printing/rotscale_text/source/main.c, and Graphics/Sprites/sprite_rotate/source/template.c.

Function Documentation

s16 acosLerp ( s16  par  ) 

fixed point arccos

Parameters:
par parameter
Returns:
s16 angle (-32768 to 32767)
s16 asinLerp ( s16  par  ) 

fixed point arcsin

Parameters:
par parameter
Returns:
s16 angle (-32768 to 32767)
s16 cosLerp ( s16  angle  ) 
s16 sinLerp ( s16  angle  ) 
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]
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines
Generated on Sat Oct 2 12:55:13 2010 for libnds by  doxygen 1.6.3