00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <math.h>
00025 #include <string.h>
00026
00027 #ifdef _MSC_VER
00028 # define INLINE __forceinline
00029 #elif defined(__GNUC_GNU_INLINE__) || defined(__GNUC_STDC_INLINE__)
00030 # define INLINE inline __attribute__((gnu_inline))
00031 #else
00032 # define INLINE inline
00033 #endif
00034
00035 extern INLINE void gluMult4v_4v(GLUvec4 *result,
00036 const GLUvec4 *v1, const GLUvec4 *v2)
00037 {
00038 result->values[0] = v1->values[0] * v2->values[0];
00039 result->values[1] = v1->values[1] * v2->values[1];
00040 result->values[2] = v1->values[2] * v2->values[2];
00041 result->values[3] = v1->values[3] * v2->values[3];
00042 }
00043
00044
00045 extern INLINE void gluDiv4v_4v(GLUvec4 *result,
00046 const GLUvec4 *v1, const GLUvec4 *v2)
00047 {
00048 result->values[0] = v1->values[0] / v2->values[0];
00049 result->values[1] = v1->values[1] / v2->values[1];
00050 result->values[2] = v1->values[2] / v2->values[2];
00051 result->values[3] = v1->values[3] / v2->values[3];
00052 }
00053
00054
00055 extern INLINE void gluAdd4v_4v(GLUvec4 *result,
00056 const GLUvec4 *v1, const GLUvec4 *v2)
00057 {
00058 result->values[0] = v1->values[0] + v2->values[0];
00059 result->values[1] = v1->values[1] + v2->values[1];
00060 result->values[2] = v1->values[2] + v2->values[2];
00061 result->values[3] = v1->values[3] + v2->values[3];
00062 }
00063
00064
00065 extern INLINE void gluSub4v_4v(GLUvec4 *result,
00066 const GLUvec4 *v1, const GLUvec4 *v2)
00067 {
00068 result->values[0] = v1->values[0] - v2->values[0];
00069 result->values[1] = v1->values[1] - v2->values[1];
00070 result->values[2] = v1->values[2] - v2->values[2];
00071 result->values[3] = v1->values[3] - v2->values[3];
00072 }
00073
00074
00075 extern INLINE void gluMult4v_f(GLUvec4 *result,
00076 const GLUvec4 *v1, GLfloat f)
00077 {
00078 result->values[0] = v1->values[0] * f;
00079 result->values[1] = v1->values[1] * f;
00080 result->values[2] = v1->values[2] * f;
00081 result->values[3] = v1->values[3] * f;
00082 }
00083
00084
00085 extern INLINE void gluDiv4v_f(GLUvec4 *result,
00086 const GLUvec4 *v1, GLfloat f)
00087 {
00088 result->values[0] = v1->values[0] / f;
00089 result->values[1] = v1->values[1] / f;
00090 result->values[2] = v1->values[2] / f;
00091 result->values[3] = v1->values[3] / f;
00092 }
00093
00094
00095 extern INLINE void gluAdd4v_f(GLUvec4 *result,
00096 const GLUvec4 *v1, GLfloat f)
00097 {
00098 result->values[0] = v1->values[0] + f;
00099 result->values[1] = v1->values[1] + f;
00100 result->values[2] = v1->values[2] + f;
00101 result->values[3] = v1->values[3] + f;
00102 }
00103
00104
00105 extern INLINE void gluSub4v_f(GLUvec4 *result,
00106 const GLUvec4 *v1, GLfloat f)
00107 {
00108 result->values[0] = v1->values[0] - f;
00109 result->values[1] = v1->values[1] - f;
00110 result->values[2] = v1->values[2] - f;
00111 result->values[3] = v1->values[3] - f;
00112 }
00113
00114
00115 extern INLINE void gluMult4m_f(GLUmat4 *result,
00116 const GLUmat4 *m, GLfloat f)
00117 {
00118 GLUmat4 temp;
00119
00120 gluMult4v_f(& temp.col[0], & m->col[0], f);
00121 gluMult4v_f(& temp.col[1], & m->col[1], f);
00122 gluMult4v_f(& temp.col[2], & m->col[2], f);
00123 gluMult4v_f(& temp.col[3], & m->col[3], f);
00124 *result = temp;
00125 }
00126
00127
00128 extern INLINE void gluMult4m_4v(GLUvec4 *result,
00129 const GLUmat4 *m, const GLUvec4 *v)
00130 {
00131 GLUvec4 temp[6];
00132 unsigned i;
00133
00134 for (i = 0; i < 4; i++) {
00135 gluMult4v_f(& temp[i], & m->col[i], v->values[i]);
00136 }
00137
00138 gluAdd4v_4v(& temp[4], & temp[0], & temp[1]);
00139 gluAdd4v_4v(& temp[5], & temp[2], & temp[3]);
00140 gluAdd4v_4v(result, & temp[4], & temp[5]);
00141 }
00142
00143
00144 extern INLINE void gluAdd4m_4m(GLUmat4 *result,
00145 const GLUmat4 *m1, const GLUmat4 *m2)
00146 {
00147 GLUmat4 temp;
00148
00149 gluAdd4v_4v(& temp.col[0], & m1->col[0], & m2->col[0]);
00150 gluAdd4v_4v(& temp.col[1], & m1->col[1], & m2->col[1]);
00151 gluAdd4v_4v(& temp.col[2], & m1->col[2], & m2->col[2]);
00152 gluAdd4v_4v(& temp.col[3], & m1->col[3], & m2->col[3]);
00153 *result = temp;
00154 }
00155
00156 extern INLINE void gluSub4m_4m(GLUmat4 *result,
00157 const GLUmat4 *m1, const GLUmat4 *m2)
00158 {
00159 GLUmat4 temp;
00160
00161 gluSub4v_4v(& temp.col[0], & m1->col[0], & m2->col[0]);
00162 gluSub4v_4v(& temp.col[1], & m1->col[1], & m2->col[1]);
00163 gluSub4v_4v(& temp.col[2], & m1->col[2], & m2->col[2]);
00164 gluSub4v_4v(& temp.col[3], & m1->col[3], & m2->col[3]);
00165 *result = temp;
00166 }
00167
00168 extern INLINE GLfloat gluDot4_4v(const GLUvec4 *v1, const GLUvec4 *v2)
00169 {
00170 return v1->values[0] * v2->values[0]
00171 + v1->values[1] * v2->values[1]
00172 + v1->values[2] * v2->values[2]
00173 + v1->values[3] * v2->values[3];
00174 }
00175
00176
00177 extern INLINE GLfloat gluDot3_4v(const GLUvec4 *v1, const GLUvec4 *v2)
00178 {
00179 return v1->values[0] * v2->values[0]
00180 + v1->values[1] * v2->values[1]
00181 + v1->values[2] * v2->values[2];
00182 }
00183
00184
00185 extern INLINE GLfloat gluDot2_4v(const GLUvec4 *v1, const GLUvec4 *v2)
00186 {
00187 return v1->values[0] * v2->values[0]
00188 + v1->values[1] * v2->values[1];
00189 }
00190
00191
00192 extern INLINE void gluCross4v(GLUvec4 *result,
00193 const GLUvec4 *v1, const GLUvec4 *v2)
00194 {
00195 GLUvec4 temp;
00196
00197 temp.values[0] = (v1->values[1] * v2->values[2])
00198 - (v1->values[2] * v2->values[1]);
00199 temp.values[1] = (v1->values[2] * v2->values[0])
00200 - (v1->values[0] * v2->values[2]);
00201 temp.values[2] = (v1->values[0] * v2->values[1])
00202 - (v1->values[1] * v2->values[0]);
00203 temp.values[3] = 0.0;
00204 *result = temp;
00205 }
00206
00207
00208 extern INLINE void gluOuter4v(GLUmat4 *result,
00209 const GLUvec4 *v1, const GLUvec4 *v2)
00210 {
00211 GLUmat4 temp;
00212
00213 gluMult4v_f(& temp.col[0], v1, v2->values[0]);
00214 gluMult4v_f(& temp.col[1], v1, v2->values[1]);
00215 gluMult4v_f(& temp.col[2], v1, v2->values[2]);
00216 gluMult4v_f(& temp.col[3], v1, v2->values[3]);
00217 *result = temp;
00218 }
00219
00220
00221 extern INLINE GLfloat gluLengthSqr4v(const GLUvec4 *v)
00222 {
00223 return gluDot4_4v(v, v);
00224 }
00225
00226
00227 extern INLINE GLfloat gluLength4v(const GLUvec4 *v)
00228 {
00229 return (GLfloat) sqrt(gluLengthSqr4v(v));
00230 }
00231
00232
00233 extern INLINE void gluNormalize4v(GLUvec4 *result, const GLUvec4 *v)
00234 {
00235 gluDiv4v_f(result, v, gluLength4v(v));
00236 }
00237
00238
00239
00240 extern INLINE void gluTranspose4m(GLUmat4 *result, const GLUmat4 *m)
00241 {
00242 unsigned i;
00243 unsigned j;
00244 GLUmat4 temp;
00245
00246 for (i = 0; i < 4; i++) {
00247 for (j = 0; j < 4; j++) {
00248 temp.col[i].values[j] = m->col[j].values[i];
00249 }
00250 }
00251
00252 *result = temp;
00253 }
00254
00255
00256 extern INLINE void gluMult4m_4m(GLUmat4 *result,
00257 const GLUmat4 *m1, const GLUmat4 *m2)
00258 {
00259 GLUmat4 temp;
00260 unsigned i;
00261
00262 for (i = 0; i < 4; i++) {
00263 gluMult4m_4v(& temp.col[i], m1, & m2->col[i]);
00264 }
00265
00266 *result = temp;
00267 }
00268
00269
00270
00271 extern INLINE void gluTranslate3f(GLUmat4 *result,
00272 GLfloat x, GLfloat y, GLfloat z)
00273 {
00274 memcpy(result, & gluIdentityMatrix, sizeof(gluIdentityMatrix));
00275 result->col[3].values[0] = x;
00276 result->col[3].values[1] = y;
00277 result->col[3].values[2] = z;
00278 }
00279
00280
00281 #ifdef __cplusplus
00282 extern INLINE GLfloat gluDot4(const GLUvec4 &v1, const GLUvec4 &v2)
00283 {
00284 return v1.values[0] * v2.values[0]
00285 + v1.values[1] * v2.values[1]
00286 + v1.values[2] * v2.values[2]
00287 + v1.values[3] * v2.values[3];
00288 }
00289
00290
00291 extern INLINE GLfloat gluDot3(const GLUvec4 &v1, const GLUvec4 &v2)
00292 {
00293 return v1.values[0] * v2.values[0]
00294 + v1.values[1] * v2.values[1]
00295 + v1.values[2] * v2.values[2];
00296 }
00297
00298
00299 extern INLINE GLfloat gluDot2(const GLUvec4 &v1, const GLUvec4 &v2)
00300 {
00301 return v1.values[0] * v2.values[0]
00302 + v1.values[1] * v2.values[1];
00303 }
00304
00305
00306 INLINE GLUvec4 GLUvec4::operator+(const GLUvec4 &v) const
00307 {
00308 return GLUvec4(values[0] + v.values[0],
00309 values[1] + v.values[1],
00310 values[2] + v.values[2],
00311 values[3] + v.values[3]);
00312 }
00313
00314
00315 INLINE GLUvec4 GLUvec4::operator-(const GLUvec4 &v) const
00316 {
00317 return GLUvec4(values[0] - v.values[0],
00318 values[1] - v.values[1],
00319 values[2] - v.values[2],
00320 values[3] - v.values[3]);
00321 }
00322
00323
00324 INLINE GLUvec4 GLUvec4::operator*(const GLUvec4 &v) const
00325 {
00326 return GLUvec4(values[0] * v.values[0],
00327 values[1] * v.values[1],
00328 values[2] * v.values[2],
00329 values[3] * v.values[3]);
00330 }
00331
00332
00333 INLINE GLUvec4 GLUvec4::operator*(GLfloat f) const
00334 {
00335 return GLUvec4(values[0] * f,
00336 values[1] * f,
00337 values[2] * f,
00338 values[3] * f);
00339 }
00340
00341
00342 INLINE GLUvec4 GLUvec4::operator*(const GLUmat4 &m) const
00343 {
00344 return GLUvec4(gluDot4(*this, m.col[0]),
00345 gluDot4(*this, m.col[1]),
00346 gluDot4(*this, m.col[2]),
00347 gluDot4(*this, m.col[3]));
00348 }
00349
00350
00351 INLINE GLUmat4 GLUmat4::operator+(const GLUmat4 &m) const
00352 {
00353 GLUmat4 temp;
00354
00355 gluAdd4m_4m(& temp, this, &m);
00356 return temp;
00357 }
00358
00359
00360 INLINE GLUmat4 GLUmat4::operator-(const GLUmat4 &m) const
00361 {
00362 return GLUmat4(col[0] - m.col[0],
00363 col[1] - m.col[1],
00364 col[2] - m.col[2],
00365 col[3] - m.col[3]);
00366 }
00367
00368
00369 INLINE GLUmat4 GLUmat4::operator*(GLfloat f) const
00370 {
00371 GLUmat4 temp;
00372
00373 gluMult4m_f(& temp, this, f);
00374 return temp;
00375 }
00376
00377
00378 INLINE GLUvec4 GLUmat4::operator*(const GLUvec4 &v) const
00379 {
00380 return (col[0] * v.values[0])
00381 + (col[1] * v.values[1])
00382 + (col[2] * v.values[2])
00383 + (col[3] * v.values[3]);
00384 }
00385
00386
00387 INLINE GLUmat4 GLUmat4::operator*(const GLUmat4 &m) const
00388 {
00389 GLUmat4 temp;
00390
00391 gluMult4m_4m(& temp, this, &m);
00392 return temp;
00393 }
00394
00395
00396 #endif