math.c

Go to the documentation of this file.
00001 
00012 #include <math.h>
00013 #include <allegro.h>
00014 #include "alleggl.h"
00015 #include "allglint.h"
00016 
00017 
00018 #ifndef M_PI
00019    #define M_PI   3.14159265358979323846
00020 #endif
00021 
00022 
00023 #define ALGL_NOCONV(x) x
00024 
00025 #define TRANSLATE_AL_TO_GL(al_type, gl_type, convertor) \
00026     void allegro_gl_##al_type##_to_##gl_type (al_type *m, gl_type gl[16]) \
00027     { \
00028         int col, row; \
00029         for (col = 0; col < 3; col++) \
00030             for (row = 0; row < 3; row++) \
00031                 gl[col*4+row] = convertor (m->v[col][row]); \
00032         for (row = 0; row < 3; row++) \
00033             gl[12+row] = convertor (m->t[row]); \
00034         for (col = 0; col < 3; col++) \
00035             gl[4*col + 3] = 0; \
00036         gl[15] = 1; \
00037     }
00038 
00039 
00040 
00063 TRANSLATE_AL_TO_GL(MATRIX, GLfloat, fixtof)
00064 
00065 
00066     
00067 
00079 TRANSLATE_AL_TO_GL(MATRIX, GLdouble, fixtof)
00080 
00081     
00082 
00095 TRANSLATE_AL_TO_GL(MATRIX_f, GLfloat, ALGL_NOCONV)
00096 
00097 
00098 
00111 TRANSLATE_AL_TO_GL(MATRIX_f, GLdouble, ALGL_NOCONV)
00112 
00113 
00114     
00115 #define TRANSLATE_GL_TO_AL(gl_type, al_type, convertor) \
00116     void allegro_gl_##gl_type##_to_##al_type (gl_type gl[16], al_type *m) \
00117     { \
00118         int col, row; \
00119         for (col = 0; col < 3; col++) \
00120             for (row = 0; row < 3; row++) \
00121                 m->v[col][row] = convertor (gl[col*4+row]); \
00122         for (row = 0; row < 3; row++) \
00123             m->t[row] = convertor (gl[12+row]); \
00124     }
00125 
00126 
00127 
00140 TRANSLATE_GL_TO_AL(GLfloat, MATRIX, ftofix)
00141 
00142 
00143 
00144 
00156 TRANSLATE_GL_TO_AL(GLdouble, MATRIX, ftofix)
00157 
00158 
00159 
00172 TRANSLATE_GL_TO_AL(GLfloat, MATRIX_f, ALGL_NOCONV)
00173 
00174     
00175 
00189 TRANSLATE_GL_TO_AL(GLdouble, MATRIX_f, ALGL_NOCONV)
00190 
00191 
00192 #undef ALGL_NOCONV
00193 
00194 
00195 #ifndef RAD_2_DEG
00196     #define RAD_2_DEG(a) ((a) * 180 / M_PI)
00197 #endif
00198 
00199     
00200 
00201 /* void allegro_gl_apply_quat(QUAT *q) */
00219 void allegro_gl_apply_quat(QUAT *q) {
00220 
00221     float theta;
00222     ASSERT(q);
00223     ASSERT(__allegro_gl_valid_context);
00224 
00225     theta = RAD_2_DEG(2 * acos(q->w));
00226     if (q->w < 1.0f && q->w > -1.0f) 
00227         glRotatef(theta, q->x, q->y, q->z); 
00228 
00229     return;
00230 }
00231 
00232 
00233 
00234 /* void allegro_gl_quat_to_glrotatef(QUAT *q, float *angle, float *x, float *y, float *z) */
00255 void allegro_gl_quat_to_glrotatef(QUAT *q, float *angle, float *x, float *y, float *z) {
00256 
00257     ASSERT(q);
00258     ASSERT(angle);
00259     ASSERT(x);
00260     ASSERT(y);
00261     ASSERT(z);
00262 
00263     *angle = RAD_2_DEG(2 * acos(q->w));
00264     *x = q->x;
00265     *y = q->y;
00266     *z = q->z;
00267 
00268     return;
00269 }
00270 
00271 
00272 
00273 /* void allegro_gl_quat_to_glrotated(QUAT *q, double *angle, double *x, double *y, double *z) */
00287 void allegro_gl_quat_to_glrotated(QUAT *q, double *angle, double *x, double *y, double *z) {
00288 
00289     ASSERT(q);
00290     ASSERT(angle);
00291     ASSERT(x);
00292     ASSERT(y);
00293     ASSERT(z);
00294 
00295     *angle = RAD_2_DEG(2 * acos(q->w));
00296     *x = q->x;
00297     *y = q->y;
00298     *z = q->z;
00299 
00300     return;
00301 }
00302 

Generated on Mon Apr 3 18:20:13 2006 for AllegroGL by  doxygen 1.4.6