*/
-#include "glheader.h"
-#include "imports.h"
-#include "macros.h"
-#include "imports.h"
+#include "main/glheader.h"
+#include "main/imports.h"
+#include "main/macros.h"
+#include "main/imports.h"
#include "m_matrix.h"
r3[7] = 1.0, r3[4] = r3[5] = r3[6] = 0.0;
/* choose pivot - or die */
- if (fabs(r3[0])>fabs(r2[0])) SWAP_ROWS(r3, r2);
- if (fabs(r2[0])>fabs(r1[0])) SWAP_ROWS(r2, r1);
- if (fabs(r1[0])>fabs(r0[0])) SWAP_ROWS(r1, r0);
+ if (FABSF(r3[0])>FABSF(r2[0])) SWAP_ROWS(r3, r2);
+ if (FABSF(r2[0])>FABSF(r1[0])) SWAP_ROWS(r2, r1);
+ if (FABSF(r1[0])>FABSF(r0[0])) SWAP_ROWS(r1, r0);
if (0.0 == r0[0]) return GL_FALSE;
/* eliminate first variable */
if (s != 0.0) { r1[7] -= m1 * s; r2[7] -= m2 * s; r3[7] -= m3 * s; }
/* choose pivot - or die */
- if (fabs(r3[1])>fabs(r2[1])) SWAP_ROWS(r3, r2);
- if (fabs(r2[1])>fabs(r1[1])) SWAP_ROWS(r2, r1);
+ if (FABSF(r3[1])>FABSF(r2[1])) SWAP_ROWS(r3, r2);
+ if (FABSF(r2[1])>FABSF(r1[1])) SWAP_ROWS(r2, r1);
if (0.0 == r1[1]) return GL_FALSE;
/* eliminate second variable */
s = r1[7]; if (0.0 != s) { r2[7] -= m2 * s; r3[7] -= m3 * s; }
/* choose pivot - or die */
- if (fabs(r3[2])>fabs(r2[2])) SWAP_ROWS(r3, r2);
+ if (FABSF(r3[2])>FABSF(r2[2])) SWAP_ROWS(r3, r2);
if (0.0 == r2[2]) return GL_FALSE;
/* eliminate third variable */
}
else {
/* pure translation */
- MEMCPY( out, Identity, sizeof(Identity) );
+ memcpy( out, Identity, sizeof(Identity) );
MAT(out,0,3) = - MAT(in,0,3);
MAT(out,1,3) = - MAT(in,1,3);
MAT(out,2,3) = - MAT(in,2,3);
*/
static GLboolean invert_matrix_identity( GLmatrix *mat )
{
- MEMCPY( mat->inv, Identity, sizeof(Identity) );
+ memcpy( mat->inv, Identity, sizeof(Identity) );
return GL_TRUE;
}
if (MAT(in,0,0) == 0 || MAT(in,1,1) == 0 || MAT(in,2,2) == 0 )
return GL_FALSE;
- MEMCPY( out, Identity, 16 * sizeof(GLfloat) );
+ memcpy( out, Identity, 16 * sizeof(GLfloat) );
MAT(out,0,0) = 1.0F / MAT(in,0,0);
MAT(out,1,1) = 1.0F / MAT(in,1,1);
MAT(out,2,2) = 1.0F / MAT(in,2,2);
if (MAT(in,0,0) == 0 || MAT(in,1,1) == 0)
return GL_FALSE;
- MEMCPY( out, Identity, 16 * sizeof(GLfloat) );
+ memcpy( out, Identity, 16 * sizeof(GLfloat) );
MAT(out,0,0) = 1.0F / MAT(in,0,0);
MAT(out,1,1) = 1.0F / MAT(in,1,1);
if (MAT(in,2,3) == 0)
return GL_FALSE;
- MEMCPY( out, Identity, 16 * sizeof(GLfloat) );
+ memcpy( out, Identity, 16 * sizeof(GLfloat) );
MAT(out,0,0) = 1.0F / MAT(in,0,0);
MAT(out,1,1) = 1.0F / MAT(in,1,1);
return GL_TRUE;
} else {
mat->flags |= MAT_FLAG_SINGULAR;
- MEMCPY( mat->inv, Identity, sizeof(Identity) );
+ memcpy( mat->inv, Identity, sizeof(Identity) );
return GL_FALSE;
}
}
GLfloat m[16];
GLboolean optimized;
- s = (GLfloat) sin( angle * DEG2RAD );
- c = (GLfloat) cos( angle * DEG2RAD );
+ s = (GLfloat) _mesa_sin( angle * DEG2RAD );
+ c = (GLfloat) _mesa_cos( angle * DEG2RAD );
- MEMCPY(m, Identity, sizeof(GLfloat)*16);
+ memcpy(m, Identity, sizeof(GLfloat)*16);
optimized = GL_FALSE;
#define M(row,col) m[col*4+row]
m[2] *= x; m[6] *= y; m[10] *= z;
m[3] *= x; m[7] *= y; m[11] *= z;
- if (fabs(x - y) < 1e-8 && fabs(x - z) < 1e-8)
+ if (FABSF(x - y) < 1e-8 && FABSF(x - z) < 1e-8)
mat->flags |= MAT_FLAG_UNIFORM_SCALE;
else
mat->flags |= MAT_FLAG_GENERAL_SCALE;
void
_math_matrix_set_identity( GLmatrix *mat )
{
- MEMCPY( mat->m, Identity, 16*sizeof(GLfloat) );
+ memcpy( mat->m, Identity, 16*sizeof(GLfloat) );
if (mat->inv)
- MEMCPY( mat->inv, Identity, 16*sizeof(GLfloat) );
+ memcpy( mat->inv, Identity, 16*sizeof(GLfloat) );
mat->type = MATRIX_IDENTITY;
mat->flags &= ~(MAT_DIRTY_FLAGS|
if (mat->inv && (mat->flags & MAT_DIRTY_INVERSE)) {
matrix_invert( mat );
+ mat->flags &= ~MAT_DIRTY_INVERSE;
}
- mat->flags &= ~(MAT_DIRTY_FLAGS|
- MAT_DIRTY_TYPE|
- MAT_DIRTY_INVERSE);
+ mat->flags &= ~(MAT_DIRTY_FLAGS | MAT_DIRTY_TYPE);
}
/*@}*/
void
_math_matrix_copy( GLmatrix *to, const GLmatrix *from )
{
- MEMCPY( to->m, from->m, sizeof(Identity) );
+ memcpy( to->m, from->m, sizeof(Identity) );
to->flags = from->flags;
to->type = from->type;
matrix_invert( to );
}
else {
- MEMCPY(to->inv, from->inv, sizeof(GLfloat)*16);
+ memcpy(to->inv, from->inv, sizeof(GLfloat)*16);
}
}
}
void
_math_matrix_loadf( GLmatrix *mat, const GLfloat *m )
{
- MEMCPY( mat->m, m, 16*sizeof(GLfloat) );
+ memcpy( mat->m, m, 16*sizeof(GLfloat) );
mat->flags = (MAT_FLAG_GENERAL | MAT_DIRTY);
}
void
_math_matrix_ctr( GLmatrix *m )
{
- m->m = (GLfloat *) ALIGN_MALLOC( 16 * sizeof(GLfloat), 16 );
+ m->m = (GLfloat *) _mesa_align_malloc( 16 * sizeof(GLfloat), 16 );
if (m->m)
- MEMCPY( m->m, Identity, sizeof(Identity) );
+ memcpy( m->m, Identity, sizeof(Identity) );
m->inv = NULL;
m->type = MATRIX_IDENTITY;
m->flags = 0;
_math_matrix_dtr( GLmatrix *m )
{
if (m->m) {
- ALIGN_FREE( m->m );
+ _mesa_align_free( m->m );
m->m = NULL;
}
if (m->inv) {
- ALIGN_FREE( m->inv );
+ _mesa_align_free( m->inv );
m->inv = NULL;
}
}
_math_matrix_alloc_inv( GLmatrix *m )
{
if (!m->inv) {
- m->inv = (GLfloat *) ALIGN_MALLOC( 16 * sizeof(GLfloat), 16 );
+ m->inv = (GLfloat *) _mesa_align_malloc( 16 * sizeof(GLfloat), 16 );
if (m->inv)
- MEMCPY( m->inv, Identity, 16 * sizeof(GLfloat) );
+ memcpy( m->inv, Identity, 16 * sizeof(GLfloat) );
}
}
/*@}*/
+
+/**
+ * Transform a 4-element row vector (1x4 matrix) by a 4x4 matrix. This
+ * function is used for transforming clipping plane equations and spotlight
+ * directions.
+ * Mathematically, u = v * m.
+ * Input: v - input vector
+ * m - transformation matrix
+ * Output: u - transformed vector
+ */
+void
+_mesa_transform_vector( GLfloat u[4], const GLfloat v[4], const GLfloat m[16] )
+{
+ const GLfloat v0 = v[0], v1 = v[1], v2 = v[2], v3 = v[3];
+#define M(row,col) m[row + col*4]
+ u[0] = v0 * M(0,0) + v1 * M(1,0) + v2 * M(2,0) + v3 * M(3,0);
+ u[1] = v0 * M(0,1) + v1 * M(1,1) + v2 * M(2,1) + v3 * M(3,1);
+ u[2] = v0 * M(0,2) + v1 * M(1,2) + v2 * M(2,2) + v3 * M(3,2);
+ u[3] = v0 * M(0,3) + v1 * M(1,3) + v2 * M(2,3) + v3 * M(3,3);
+#undef M
+}