00001 #ifndef GEOMETRY_H
00002 #define GEOMETRY_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifdef __cplusplus
00014 extern "C" {
00015 #endif
00016
00017 #ifndef CONST
00018 # ifdef __cplusplus
00019 # define CONST const
00020 # else
00021 # define CONST
00022 # endif
00023 #endif
00024
00025 #ifdef unix
00026 # include <alloca.h>
00027 #endif
00028
00029 typedef struct { float x[3]; } Point;
00030 typedef struct { float q[4]; } Quat;
00031
00032 typedef struct { float m[4*4]; } Matrix;
00033
00034 #define NewA(type, count) (type *)alloca((count) * sizeof(type))
00035
00036 #ifndef COUNT
00037 # define COUNT(array) (sizeof(array) / sizeof((array)[0]))
00038 #endif
00039
00040
00041
00042
00043
00044 extern Matrix Tidentity;
00045
00046
00047
00048
00049
00050
00051 void arena_init( int nbytes );
00052
00053 void vsub( Point *dst, CONST Point *a, CONST Point *b );
00054 void vadd( Point *dst, CONST Point *a, CONST Point *b );
00055 void vcross( Point *dst, CONST Point *a, CONST Point *b );
00056 float vdot( CONST Point *a, CONST Point *b );
00057 void vscale( Point *dst, float s, CONST Point *src );
00058 void vsadd( Point *dst, CONST Point *a, float sb, CONST Point *b );
00059 void vlerp( Point *dst, float frac, CONST Point *vfrom, CONST Point *vto );
00060 void vcomb( Point *dst, float sa, CONST Point *a, float sb, CONST Point *b );
00061 float vunit( Point *dst, CONST Point *src );
00062 void vproj( Point *along, Point *perp, CONST Point *vec, CONST Point *onto );
00063
00064 float qdot( CONST Quat *q1, CONST Quat *q2 );
00065 void qnorm( Quat *qdst, CONST Quat *qsrc );
00066 void qcomb( Quat *qdst, float sa, CONST Quat *qa, float sb, CONST Quat *qb );
00067
00068
00069 float vdist( CONST Point *p1, CONST Point *p2 );
00070
00071 float iqdist( CONST Point *q1, CONST Point *q2 );
00072 float qdist( CONST Quat *q1, CONST Quat *q2 );
00073
00074 float tdist( CONST Matrix *t1, CONST Matrix *t2 );
00075
00076
00077 float vlength( CONST Point *v );
00078
00079
00080 void vtfmpoint( Point *dst, CONST Point *src, CONST Matrix *T );
00081
00082
00083 void vtfmvector( Point *dst, CONST Point *src, CONST Matrix *T );
00084 void vuntfmvector( Point *dst, CONST Point *src, CONST Matrix *T );
00085
00086
00087 void vgettranslation( Point *dst, CONST Matrix *T );
00088
00089 void vsettranslation( Matrix *T, CONST Point *src );
00090
00091 void vrotxy( Point *dst, CONST Point *src, CONST float cs[2] );
00092 void mcopy( Matrix *dst, CONST Matrix *src );
00093
00094
00095 void mmmul( Matrix *dst, CONST Matrix *a, CONST Matrix *b );
00096
00097
00098
00099
00100 void eucinv( Matrix *dst, CONST Matrix *src );
00101
00102
00103 void mconjugate( Matrix *To2wout, CONST Matrix *To2win, CONST Matrix *Tincrf,
00104 CONST Matrix *Tf2w, CONST Matrix *Tw2f,
00105 CONST Point *pcenw, CONST Point *pcenf );
00106
00107 void grotation( Matrix *Trot, CONST Point *fromaxis, CONST Point *toaxis );
00108
00109
00110
00111
00112 float tfm2iquat( Point *iquat, CONST Matrix *src );
00113 void tfm2quat( Quat *quat, CONST Matrix *src );
00114 void iquat2tfm( Matrix *dst, CONST Point *iquat );
00115 void quat2tfm( Matrix *dst, CONST Quat *quat );
00116
00117
00118 void iquat_lerp( Point *dquat, float frac, CONST Point *qfrom, CONST Point *qto );
00119 void quat_lerp( Quat *dquat, float frac, CONST Quat *qfrom, CONST Quat *qto );
00120
00121
00122 void rot2quat( Quat *quat, float degrees, CONST Point *axis );
00123 void rot2iquat( Point *iquat, float degrees, CONST Point *axis );
00124
00125
00126 void rot2tfm( Matrix *dst, float degrees, CONST Point *axis );
00127
00128
00129 void mrotation( Matrix *dst, float degrees, char xyzaxis );
00130 void mscaling( Matrix *dst, float sx, float sy, float sz );
00131 void mtranslation( Matrix *dst, float tx, float ty, float tz );
00132
00133
00134 float tfm2xyzaer( Point *xyz, float aer[3], CONST Matrix *c2w );
00135 void xyzaer2tfm( Matrix *c2w, CONST Point *xyz, CONST float aer[3] );
00136
00137
00138 void mfrustum( Matrix *Tproj, float nl, float nr, float nd, float nu, float cnear, float cfar );
00139
00140
00141 #ifdef __cplusplus
00142 }
00143 #endif
00144
00145
00146 #endif