head 1.3; access; symbols; locks; strict; comment @# @; 1.3 date 2002.09.07.01.50.38; author curt; state Exp; branches; next 1.2; 1.2 date 2002.08.31.19.01.55; author curt; state Exp; branches; next 1.1; 1.1 date 2002.08.31.18.54.01; author curt; state Exp; branches; next ; desc @@ 1.3 log @Updated doxygen docs. @ text @
Main Page Class Hierarchy Compound List File List Compound Members File Members

# mat3.h

    00001 /* Copyright 1988, Brown Computer Graphics Group.  All Rights Reserved. */
    00002
    00003 /* -------------------------------------------------------------------------
    00004                        Public MAT3 include file
    00005    ------------------------------------------------------------------------- */
    00006
    00007 #ifndef MAT3_HAS_BEEN_INCLUDED
    00008 #define MAT3_HAS_BEEN_INCLUDED
    00009
    00010 /* -----------------------------  Constants  ------------------------------ */
    00011
    00012 /*
    00013  * Make sure the math library .h file is included, in case it wasn't.
    00014  */
    00015
    00016 #ifndef HUGE
    00017 #include <math.h>
    00018 #endif
    00019 #include <stdio.h>
    00020
    00021 #include <string.h>
    00022 #include <simgear/math/fg_memory.h>
    00023
    00024 #ifdef __cplusplus
    00025 extern "C" {
    00026 #endif
    00027
    00028
    00029 #define MAT3_DET0       -1                      /* Indicates singular mat */
    00030 #define MAT3_EPSILON    1e-12                   /* Close enough to zero   */
    00031
    00032 #ifdef M_PI
    00033 #  define  MAT3_PI    M_PI
    00034 #else
    00035 #  define  MAT3_PI    3.14159265358979323846
    00036 #endif
    00037
    00038 #define USE_XTRA_MAT3_INLINES
    00039
    00040 #if defined(i386)
    00041 #define USE_X86_ASM
    00042 #endif
    00043
    00044 #if defined(USE_X86_ASM)
    00045 static __inline__ int FloatToInt(float f)
    00046 {
    00047    int r;
    00048    __asm__ ("fistpl %0" : "=m" (r) : "t" (f) : "st");
    00049    return r;
    00050 }
    00051 #elif  defined(__MSC__) && defined(__WIN32__)
    00052 static __inline int FloatToInt(float f)
    00053 {
    00054    int r;
    00055    _asm {
    00056      fld f
    00057      fistp r
    00058     }
    00059    return r;
    00060 }
    00061 #else
    00062 #define FloatToInt(F) ((int) ((F) < 0.0f ? (F)-0.5f : (F)+0.5f))
    00063 #endif
    00064
    00065 /* ------------------------------  Types  --------------------------------- */
    00066
    00067 typedef double MAT3mat[4][4];           /* 4x4 matrix                    */
    00068 typedef double MAT3vec[3];              /* Vector                        */
    00069 typedef double MAT3hvec[4];             /* Vector with homogeneous coord */
    00070
    00071 /* ------------------------------  Macros  -------------------------------- */
    00072
    00073 extern MAT3mat identityMatrix;
    00074
    00075 /* Tests if a number is within EPSILON of zero */
    00076 #define MAT3_IS_ZERO(N)         ((N) < MAT3_EPSILON && (N) > -MAT3_EPSILON)
    00077
    00078 /* Sets a vector to the three given values */
    00079 #define MAT3_SET_VEC(V,X,Y,Z)   ((V)[0]=(X), (V)[1]=(Y), (V)[2]=(Z))
    00080
    00081 /* Tests a vector for all components close to zero */
    00082 #define MAT3_IS_ZERO_VEC(V)     (MAT3_IS_ZERO((V)[0]) && \
    00083                                  MAT3_IS_ZERO((V)[1]) && \
    00084                                  MAT3_IS_ZERO((V)[2]))
    00085
    00086 /* Dot product of two vectors */
    00087 #define MAT3_DOT_PRODUCT(V1,V2) \
    00088                         ((V1)[0]*(V2)[0] + (V1)[1]*(V2)[1] + (V1)[2]*(V2)[2])
    00089
    00090 /* Copy one vector to other */
    00091 #define MAT3_COPY_VEC(TO,FROM)  ((TO)[0] = (FROM)[0], \
    00092                                  (TO)[1] = (FROM)[1], \
    00093                                  (TO)[2] = (FROM)[2])
    00094
    00095 /* Normalize vector to unit length, using TEMP as temporary variable.
    00096  * TEMP will be zero if vector has zero length */
    00097 #define MAT3_NORMALIZE_VEC(V,TEMP) \
    00098         if ((TEMP = sqrt(MAT3_DOT_PRODUCT(V,V))) > MAT3_EPSILON) { \
    00099            TEMP = 1.0 / TEMP; \
    00100            MAT3_SCALE_VEC(V,V,TEMP); \
    00101         } else TEMP = 0.0
    00102
    00103 /* Scale vector by given factor, storing result vector in RESULT_V */
    00104 #define MAT3_SCALE_VEC(RESULT_V,V,SCALE) \
    00105         MAT3_SET_VEC(RESULT_V, (V)[0]*(SCALE), (V)[1]*(SCALE), (V)[2]*(SCALE))
    00106
    00107 /* Adds vectors V1 and V2, storing result in RESULT_V */
    00108 #define MAT3_ADD_VEC(RESULT_V,V1,V2) \
    00109         MAT3_SET_VEC(RESULT_V, (V1)[0]+(V2)[0], (V1)[1]+(V2)[1], \
    00110                                (V1)[2]+(V2)[2])
    00111
    00112 /* Subtracts vector V2 from V1, storing result in RESULT_V */
    00113 #define MAT3_SUB_VEC(RESULT_V,V1,V2) \
    00114         MAT3_SET_VEC(RESULT_V, (V1)[0]-(V2)[0], (V1)[1]-(V2)[1], \
    00115                                (V1)[2]-(V2)[2])
    00116
    00117 /* Multiplies vectors V1 and V2, storing result in RESULT_V */
    00118 #define MAT3_MULT_VEC(RESULT_V,V1,V2) \
    00119         MAT3_SET_VEC(RESULT_V, (V1)[0]*(V2)[0], (V1)[1]*(V2)[1], \
    00120                                (V1)[2]*(V2)[2])
    00121
    00122 /* Sets RESULT_V to the linear combination of V1 and V2, scaled by
    00123  * SCALE1 and SCALE2, respectively */
    00124 #define MAT3_LINEAR_COMB(RESULT_V,SCALE1,V1,SCALE2,V2) \
    00125         MAT3_SET_VEC(RESULT_V,  (SCALE1)*(V1)[0] + (SCALE2)*(V2)[0], \
    00126                                 (SCALE1)*(V1)[1] + (SCALE2)*(V2)[1], \
    00127                                 (SCALE1)*(V1)[2] + (SCALE2)*(V2)[2])
    00128
    00129 /* Several of the vector macros are useful for homogeneous-coord vectors */
    00130 #define MAT3_SET_HVEC(V,X,Y,Z,W) ((V)[0]=(X), (V)[1]=(Y), \
    00131                                   (V)[2]=(Z), (V)[3]=(W))
    00132
    00133 #define MAT3_COPY_HVEC(TO,FROM) ((TO)[0] = (FROM)[0], \
    00134                                  (TO)[1] = (FROM)[1], \
    00135                                  (TO)[2] = (FROM)[2], \
    00136                                  (TO)[3] = (FROM)[3])
    00137
    00138 #define MAT3_SCALE_HVEC(RESULT_V,V,SCALE) \
    00139         MAT3_SET_HVEC(RESULT_V, (V)[0]*(SCALE), (V)[1]*(SCALE), \
    00140                                 (V)[2]*(SCALE), (V)[3]*(SCALE))
    00141
    00142 #define MAT3_ADD_HVEC(RESULT_V,V1,V2) \
    00143         MAT3_SET_HVEC(RESULT_V, (V1)[0]+(V2)[0], (V1)[1]+(V2)[1], \
    00144                                 (V1)[2]+(V2)[2], (V1)[3]+(V2)[3])
    00145
    00146 #define MAT3_SUB_HVEC(RESULT_V,V1,V2) \
    00147         MAT3_SET_HVEC(RESULT_V, (V1)[0]-(V2)[0], (V1)[1]-(V2)[1], \
    00148                                 (V1)[2]-(V2)[2], (V1)[3]-(V2)[3])
    00149
    00150 #define MAT3_MULT_HVEC(RESULT_V,V1,V2) \
    00151         MAT3_SET_HVEC(RESULT_V, (V1)[0]*(V2)[0], (V1)[1]*(V2)[1], \
    00152                                 (V1)[2]*(V2)[2], (V1)[3]*(V2)[3])
    00153
    00154 /* ------------------------------  Entries  ------------------------------- */
    00155
    00156
    00157 #define MAT3identity(mat)    fgmemcpy( mat, identityMatrix, sizeof(MAT3mat) )
    00158 #define MAT3zero(mat)        fgmemzero( mat, sizeof(MAT3mat) )
    00159 #define MAT3copy(to, from)   fgmemcpy( to, from, sizeof(MAT3mat) )
    00160
    00161 #if defined( USE_XTRA_MAT3_INLINES )
    00162
    00163 #  define MAT3mult_vec( result_vec, vec, mat) { \
    00164    MAT3vec tempvec; \
    00165    tempvec[0]=vec[0]*mat[0][0]+vec[1]*mat[1][0]+vec[2]*mat[2][0]+mat[3][0]; \
    00166    tempvec[1]=vec[0]*mat[0][1]+vec[1]*mat[1][1]+vec[2]*mat[2][1]+mat[3][1]; \
    00167    tempvec[2]=vec[0]*mat[0][2]+vec[1]*mat[1][2]+vec[2]*mat[2][2]+mat[3][2]; \
    00168    result_vec[0] = tempvec[0]; \
    00169    result_vec[1] = tempvec[1]; \
    00170    result_vec[2] = tempvec[2]; \
    00171 }
    00172
    00173 #  define MAT3cross_product(result_vec, vec1, vec2)  { \
    00174    MAT3vec tempvec; \
    00175    tempvec[0] = vec1[1] * vec2[2] - vec1[2] * vec2[1]; \
    00176    tempvec[1] = vec1[2] * vec2[0] - vec1[0] * vec2[2]; \
    00177    tempvec[2] = vec1[0] * vec2[1] - vec1[1] * vec2[0]; \
    00178    result_vec[0] = tempvec[0]; \
    00179    result_vec[1] = tempvec[1]; \
    00180    result_vec[2] = tempvec[2]; \
    00181 }
    00182
    00183 #  define MAT3mult( result_mat,  mat1,  mat2) { \
    00184    register int i, j; \
    00185    MAT3mat      tmp_mat; \
    00186    for (i = 0; i < 4; i++) \
    00187       for (j = 0; j < 4; j++) \
    00188          tmp_mat[i][j] = (mat1[i][0] * mat2[0][j] + \
    00189                           mat1[i][1] * mat2[1][j] + \
    00190                           mat1[i][2] * mat2[2][j] + \
    00191                           mat1[i][3] * mat2[3][j]); \
    00192    fgmemcpy(result_mat, tmp_mat, sizeof(MAT3mat)); \
    00193 }
    00194
    00195 #else // !defined( USE_XTRA_MAT3_INLINES )
    00196
    00197 /* In MAT3mat.c */
    00198 void    MAT3mult(MAT3mat result, MAT3mat, MAT3mat);
    00199 void    MAT3mult_vec(MAT3vec result_vec, MAT3vec vec, MAT3mat mat);
    00200 void    MAT3cross_product(MAT3vec result,MAT3vec,MAT3vec);
    00201
    00202 #endif // defined( USE_XTRA_MAT3_INLINES )
    00203
    00204 /* In MAT3geom.c */
    00205 void    MAT3direction_matrix (MAT3mat result_mat, MAT3mat mat);
    00206 int     MAT3normal_matrix (MAT3mat result_mat, MAT3mat mat);
    00207 void    MAT3rotate (MAT3mat result_mat, MAT3vec axis, double angle_in_radians);
    00208 void    MAT3translate (MAT3mat result_mat, MAT3vec trans);
    00209 void    MAT3scale (MAT3mat result_mat, MAT3vec scale);
    00210 void    MAT3shear(MAT3mat result_mat, double xshear, double yshear);
    00211
    00212 void    MAT3transpose (MAT3mat result, MAT3mat);
    00213 int     MAT3invert (MAT3mat result, MAT3mat);
    00214 void    MAT3print (MAT3mat, FILE *fp);
    00215 void    MAT3print_formatted (MAT3mat, FILE *fp,
    00216                              char *title, char *head, char *format, char *tail);
    00217 int     MAT3equal( void );
    00218 double  MAT3trace( void );
    00219 int     MAT3power( void );
    00220 int     MAT3column_reduce( void );
    00221 int     MAT3kernel_basis( void );
    00222
    00223 /* In MAT3vec.c */
    00224 int     MAT3mult_hvec (MAT3hvec result_vec, MAT3hvec vec, MAT3mat mat, int normalize);
    00225 void    MAT3perp_vec(MAT3vec result_vec, MAT3vec vec, int is_unit);
    00226
    00227 #ifdef __cplusplus
    00228 }
    00229 #endif
    00230
    00231
    00232 #endif /* MAT3_HAS_BEEN_INCLUDED */
    00233

@ 1.2 log @Oops, try again. @ text @d242 1 a242 1