HOOPS/3dGS I.M. Interface

     << Back      Full Index      Forward >>


lod_math.h

00001 #ifndef MXMATH_INCLUDED
00002 #define MXMATH_INCLUDED
00003 
00004 /************************************************************************
00005 
00006   Standard math include file for the MixKit library.
00007   Also, type definitions for various vectors and matrices
00008 
00009   Copyright (C) 1998 Michael Garland.  See "COPYING.txt" for details.
00010   
00011   $Id: lod__math_8h-source.html,v 1.4 2008-02-21 21:41:00 stage Exp $
00012 
00013  ************************************************************************/
00014 
00015 #include <math.h>
00016 
00017 
00018 typedef struct Vec4_TAG
00019 {
00020     double elt[4];
00021 } Vec4;
00022 
00023 typedef struct Vec3_TAG
00024 {
00025     double elt[3];
00026 } Vec3;
00027 
00028 typedef struct Vec2_TAG
00029 {
00030     double elt[2];
00031 } Vec2;
00032 
00033 typedef struct Mat4_TAG
00034 {
00035     Vec4 row[4];
00036 } Mat4;
00037 
00038 typedef struct Mat3_TAG
00039 {
00040     Vec3 row[3];
00041 } Mat3;
00042 
00043 typedef struct Mat2_TAG
00044 {
00045     Vec2 row[2];
00046 } Mat2;
00047 
00048 typedef int MxBool;
00049 
00050 
00051 /* some operations specific to 3x3 matrices */
00052 extern double invert33( Mat3 *, const Mat3 * );
00053 extern void col33( Vec3 *v_out, const Mat3 *m1, int i );
00054 extern void vecmul33( Vec3 *v_out, const Mat3 *m1, const Vec3 *v1);
00055 
00056 /* some operations specific to 4x4 matrices */
00057 extern void adjoint44( Mat4 *out, const Mat4 *in );
00058 extern void matmul44( Mat4 *out, const Mat4 *m1, const Mat4 *m2 );
00059 extern void vecmul44( Vec4 *, const Mat4 * m1, const Vec4 * v);
00060 
00061 
00062 /* variable length vector operations */
00063 
00064 extern void   mxv_add( double *r, const double *u, const double *v, int dim );
00065 extern void   mxv_sub( double *r, const double *u, const double *v, int dim );
00066 extern void   mxv_mul( double *r, const double *u, const double d, int dim );
00067 extern void   mxv_div( double *r, const double *u, const double d, int dim );
00068 extern void   mxv_neg ( double *r, const double *u, int dim);
00069 extern void   mxv_set ( double *r, const double d, int dim);
00070 extern void   mxv_setv ( double *r, const double *u, int dim);
00071 extern double  mxv_dot(const double *u, const double *v, int dim);
00072 extern void   mxv_cross(double *r, const double *u, const double *v, int dim);
00073 extern double  mxv_len(const double *v, int dim);
00074 extern double  mxv_len2(const double *v, int dim); 
00075 extern int  mxv_unitize(double *v, int dim);
00076 extern MxBool mxv_exact_equal(const double *u, const double *v, int dim);
00077 extern MxBool mxv_equal(const double *u, const double *v, int dim);
00078 extern void   mxv_basis(double *r, int b, int dim);
00079 
00080 
00081 
00082 /* test for "not a number" (assumes type double coming in) */
00083 #define isNaN(x) (!((x)==(volatile double)(x)))
00084 
00085 /*
00086  * constants and definitions for cross-platform
00087  */
00088 
00089 /* Some systems use HUGE_VAL instead of HUGE*/
00090 #if !defined(HUGE) && defined(HUGE_VAL)
00091 #define HUGE HUGE_VAL
00092 #endif
00093 
00094 /* Handle platforms, such as Win32, which don't define M_PI in <math.h>*/
00095 #ifndef M_PI
00096 #define M_PI 3.141592653589793238462643383279502884197169399375105820974944592308
00097 #endif
00098 
00099 /* inline bool FEQ(double a,double b,double eps) { return fabs(a-b)<eps; } */
00100 #define MxFEQ(a,b,eps) ((fabs((a)-(b))<(eps)))
00101 
00102 #ifndef MIX_NO_AXIS_NAMES
00103 enum Axis {X=0, Y=1, Z=2, W=3};
00104 #endif
00105 
00106 
00107 /* from the old mxgeom3d.h */
00108 extern double triangle_area(const Vec3 *, const Vec3 *, const Vec3 * );
00109 extern void  triangle_raw_normal( Vec3 *, const Vec3 *, const Vec3 *, const Vec3 * );
00110 extern int  triangle_normal( Vec3 *, const Vec3 *, const Vec3 *, const Vec3 * );
00111 extern int  triangle_plane( Vec4 *, const Vec3 *, const Vec3 *, const Vec3 * );
00112 extern void  triangle_raw_plane( Vec4 *, const Vec3 *, const Vec3 *, const Vec3 * );
00113 extern double triangle_compactness( const Vec3 *, const Vec3 *, const Vec3 * );
00114 extern void  mx3d_box_corners( Vec3 [], const Vec3 *, const Vec3 * );
00115 
00116 
00117 
00118 /* MXMATH_INCLUDED*/
00119 #endif
Main Index
HOOPS/3dGS I.M. Interface

     << Back      Full Index      Forward >>