geometry.h 2.93 KiB
#ifndef GEOMETRY_H
#define GEOMETRY_H
#ifdef __cplusplus
extern "C" {
#endif
#ifndef CONST
# ifdef __cplusplus
# define CONST const
# else
# define CONST
# endif
#endif
#ifdef unix
# include <alloca.h>
#else /*WIN32*/
# include <windows.h>
# include <malloc.h>
# include <float.h>
# define finite(v) _finite(v)
# define M_PI 3.14159265358979 /* stupid windows math.h */
#endif
typedef struct { float x[3]; } Point;
typedef struct { float m[4*4]; } Matrix;
#define NewA(type, count) (type *)alloca((count) * sizeof(type))
#define COUNT(array) (sizeof(array) / sizeof((array)[0]))
/*
* Global Constants
*/
extern Matrix Tidentity;
/*
* Global variables
*/
void arena_init( int nbytes );
void vsub( Point *dst, CONST Point *a, CONST Point *b );
void vadd( Point *dst, CONST Point *a, CONST Point *b );
void vcross( Point *dst, CONST Point *a, CONST Point *b );
float vdot( CONST Point *a, CONST Point *b );
void vscale( Point *dst, float s, CONST Point *src );
void vsadd( Point *dst, CONST Point *a, float sb, CONST Point *b );
void vlerp( Point *dst, float frac, CONST Point *vfrom, CONST Point *vto );
void vcomb( Point *dst, float sa, CONST Point *a, float sb, CONST Point *b );
float vunit( Point *dst, CONST Point *src );
void vproj( Point *along, Point *perp, CONST Point *vec, CONST Point *onto );
float vdist( CONST Point *p1, CONST Point *p2 );
float qdist( CONST Point *q1, CONST Point *q2 );
float tdist( CONST Matrix *t1, CONST Matrix *t2 );
float vlength( CONST Point *v );
void vuntfmvector( Point *dst, CONST Point *src, CONST Matrix *T );
void vtfmvector( Point *dst, CONST Point *src, CONST Matrix *T );
void vtfmpoint( Point *dst, CONST Point *src, CONST Matrix *T );
void vgettranslation( Point *dst, CONST Matrix *T );
void vsettranslation( Matrix *T, CONST Point *src );
void vrotxy( Point *dst, CONST Point *src, CONST float cs[2] );
void eucinv( Matrix *dst, CONST Matrix *src );
void mconjugate( Matrix *To2wout, CONST Matrix *To2win, CONST Matrix *Tincrf,
CONST Matrix *Tf2w, CONST Matrix *Tw2f,
CONST Point *pcenw, CONST Point *pcenf );
void grotation( Matrix *Trot, CONST Point *fromaxis, CONST Point *toaxis );
void mcopy( Matrix *dst, CONST Matrix *src );
void mmmul( Matrix *dst, CONST Matrix *a, CONST Matrix *b );
float tfm2quat( Point *iquat, CONST Matrix *src );
void quat2tfm( Matrix *dst, CONST Point *iquat );
void quat_lerp( Point *dquat, float frac, CONST Point *qfrom, CONST Point *qto );
void rot2tfm( Matrix *dst, float degrees, CONST Point *axis );
void rot2quat( Point *iquat, float degrees, CONST Point *axis );
void mrotation( Matrix *dst, float degrees, char xyzaxis );
void mscaling( Matrix *dst, float sx, float sy, float sz );
void mtranslation( Matrix *dst, float tx, float ty, float tz );
/* cam2world <-> az(Y) el(X) roll(Z) + translation */
void tfm2xyzaer( Point *xyz, float aer[3], CONST Matrix *c2w );
void xyzaer2tfm( Matrix *c2w, CONST Point *xyz, CONST float aer[3] );
#ifdef __cplusplus
}
#endif
#endif