extern Fixed * tanTable;
extern Fixed * cotanTable;
extern Fixed * invSinTable;
extern Fixed * invCosTable;
inline Fixed int2Fixed (int x ) {
return ((long) x ) « 16;
}
inline int fraction2Fixed (int a, int b ) {
return (long)( (((long) a) « 16) / (long) b );
}
inline Fixed float2Fixed (float x ) {
return (long)( 65536.0 * x );
}
inline int fixed2lnt ( Fixed x ) {
return (int) ( x » 16 );
}
inline float fixed2Float ( Fixed x ) {
return ((float)x)/65536.0;
}
inline Fixed fixAbs ( Fixed x ) {
return x > 0 ? x : -x;
}
inline Fixed frac ( Fixed x ) {
return x & OxFFFFI;
Приложение. Вычисления с фиксированной т
inline Fixed sine ( Angle angle )
return sinTable [ angle » 3 ]; inline Fixed cosine (Angle angle )
return cosTable [ angle » 3 ]; inline Fixed tang (Angle angle )
return tanTable [ angle » 3 ]; inline Fixed coTang (Angle angle )
return cotanTable [ angle >> 3 ]; inline Fixed invSine (Angle angle )
return invSinTable [ angle » 3 ]; inline Fixed invCosine ( Angle angle )
return invCosTable [ angle » 3 ]; inline Angle rad2Angle (float angle )
return (Angle)(32768.0 * angle / M_PI); inline float angle2Rad ( Angle angle )
return ((float) angle) * M_PI / 32768.0;
void initFixMath (); #endif
[SI // File Fixmath.cpp #include <alloc.h> #include <math.h> #include "FixMath.h"
Fixed * sinTable; Fixed * cosTable; Fixed * tanTable; Fixed * cotanTable; Fixed * invSinTable; Fixed * invCosTable;
void initFixMath () {
sinTable = new Fixed [8192]; cosTable = new Fixed [8192]; tanTable = new Fixed [8192]; cotanTable = new Fixed [8192];
Компьютерная графика. Полигональные модели
invSinTable = new Fixed [8192]; invCosTable = new Fixed [8192];
for (int i = 0; i < 8192; i++ ) {
float x = i* 2* M_PI/ (8192.0); float sx = sin ( x ); float cx = cos ( x ); float tx = tan ( x );
sinTable [i] = float2Fixed ( sx ); cosTable [i] = float2Fixed ( cx ); tanTable [i] = float2Fixed (tx );