Lines Matching refs:MAT
105 * \param mat a pointer to a GLmatrix structure.
111 #define TEST_MAT_FLAGS(mat, a) \
112 ((MAT_FLAGS_GEOMETRY & (~(a)) & ((mat)->flags) ) == 0)
206 * \param mat pointer to a GLmatrix structure containing the left multiplication
214 static void matrix_multf( GLmatrix *mat, const GLfloat *m, GLuint flags )
216 mat->flags |= (flags | MAT_DIRTY_TYPE | MAT_DIRTY_INVERSE);
218 if (TEST_MAT_FLAGS(mat, MAT_FLAGS_3D))
219 matmul34( mat->m, mat->m, m );
221 matmul4( mat->m, mat->m, m );
305 _mesa_debug(NULL, "Mat * Inverse:\n");
323 #define MAT(m,r,c) (m)[(c)*4+(r)]
340 * \param mat pointer to a GLmatrix structure. The matrix inverse will be
352 static GLboolean invert_matrix_general( GLmatrix *mat )
354 const GLfloat *m = mat->m;
355 GLfloat *out = mat->inv;
362 r0[0] = MAT(m,0,0), r0[1] = MAT(m,0,1),
363 r0[2] = MAT(m,0,2), r0[3] = MAT(m,0,3),
366 r1[0] = MAT(m,1,0), r1[1] = MAT(m,1,1),
367 r1[2] = MAT(m,1,2), r1[3] = MAT(m,1,3),
370 r2[0] = MAT(m,2,0), r2[1] = MAT(m,2,1),
371 r2[2] = MAT(m,2,2), r2[3] = MAT(m,2,3),
374 r3[0] = MAT(m,3,0), r3[1] = MAT(m,3,1),
375 r3[2] = MAT(m,3,2), r3[3] = MAT(m,3,3),
452 MAT(out,0,0) = r0[4]; MAT(out,0,1) = r0[5],
453 MAT(out,0,2) = r0[6]; MAT(out,0,3) = r0[7],
454 MAT(out,1,0) = r1[4]; MAT(out,1,1) = r1[5],
455 MAT(out,1,2) = r1[6]; MAT(out,1,3) = r1[7],
456 MAT(out,2,0) = r2[4]; MAT(out,2,1) = r2[5],
457 MAT(out,2,2) = r2[6]; MAT(out,2,3) = r2[7],
458 MAT(out,3,0) = r3[4]; MAT(out,3,1) = r3[5],
459 MAT(out,3,2) = r3[6]; MAT(out,3,3) = r3[7];
468 * \param mat pointer to a GLmatrix structure. The matrix inverse will be
480 static GLboolean invert_matrix_3d_general( GLmatrix *mat )
482 const GLfloat *in = mat->m;
483 GLfloat *out = mat->inv;
491 t = MAT(in,0,0) * MAT(in,1,1) * MAT(in,2,2);
494 t = MAT(in,1,0) * MAT(in,2,1) * MAT(in,0,2);
497 t = MAT(in,2,0) * MAT(in,0,1) * MAT(in,1,2);
500 t = -MAT(in,2,0) * MAT(in,1,1) * MAT(in,0,2);
503 t = -MAT(in,1,0) * MAT(in,0,1) * MAT(in,2,2);
506 t = -MAT(in,0,0) * MAT(in,2,1) * MAT(in,1,2);
515 MAT(out,0,0) = ( (MAT(in,1,1)*MAT(in,2,2) - MAT(in,2,1)*MAT(in,1,2) )*det);
516 MAT(out,0,1) = (- (MAT(in,0,1)*MAT(in,2,2) - MAT(in,2,1)*MAT(in,0,2) )*det);
517 MAT(out,0,2) = ( (MAT(in,0,1)*MAT(in,1,2) - MAT(in,1,1)*MAT(in,0,2) )*det);
518 MAT(out,1,0) = (- (MAT(in,1,0)*MAT(in,2,2) - MAT(in,2,0)*MAT(in,1,2) )*det);
519 MAT(out,1,1) = ( (MAT(in,0,0)*MAT(in,2,2) - MAT(in,2,0)*MAT(in,0,2) )*det);
520 MAT(out,1,2) = (- (MAT(in,0,0)*MAT(in,1,2) - MAT(in,1,0)*MAT(in,0,2) )*det);
521 MAT(out,2,0) = ( (MAT(in,1,0)*MAT(in,2,1) - MAT(in,2,0)*MAT(in,1,1) )*det);
522 MAT(out,2,1) = (- (MATMAT(in,2,1) - MAT(in,2,0)*MAT(in,0,1) )*det);
523 MAT(out,2,2) = ( (MAT(in,0,0)*MAT(in,1,1) - MAT(in,1,0)*MAT(in,0,1) )*det);
526 MAT(out,0,3) = - (MAT(in,0,3) * MAT(out,0,0) +
527 MAT(in,1,3) * MAT(out,0,1) +
528 MAT(in,2,3) * MAT(out,0,2) );
529 MAT(out,1,3) = - (MAT(in,0,3) * MAT(out,1,0) +
530 MAT(in,1,3) * MAT(out,1,1) +
531 MAT(in,2,3) * MAT(out,1,2) );
532 MAT(out,2,3) = - (MAT(in,0,3) * MAT(out,2,0) +
533 MAT(in,1,3) * MAT(out,2,1) +
534 MAT(in,2,3) * MAT(out,2,2) );
542 * \param mat pointer to a GLmatrix structure. The matrix inverse will be
552 static GLboolean invert_matrix_3d( GLmatrix *mat )
554 const GLfloat *in = mat->m;
555 GLfloat *out = mat->inv;
557 if (!TEST_MAT_FLAGS(mat, MAT_FLAGS_ANGLE_PRESERVING)) {
558 return invert_matrix_3d_general( mat );
561 if (mat->flags & MAT_FLAG_UNIFORM_SCALE) {
562 GLfloat scale = (MAT(in,0,0) * MAT(in,0,0) +
563 MAT(in,0,1) * MAT(in,0,1) +
564 MAT(in,0,2) * MAT(in,0,2));
572 MAT(out,0,0) = scale * MAT(in,0,0);
573 MAT(out,1,0) = scale * MAT(in,0,1);
574 MAT(out,2,0) = scale * MAT(in,0,2);
575 MAT(out,0,1) = scale * MAT(in,1,0);
576 MAT(out,1,1) = scale * MAT(in,1,1);
577 MAT(out,2,1) = scale * MAT(in,1,2);
578 MAT(out,0,2) = scale * MAT(in,2,0);
579 MAT(out,1,2) = scale * MAT(in,2,1);
580 MAT(out,2,2) = scale * MAT(in,2,2);
582 else if (mat->flags & MAT_FLAG_ROTATION) {
584 MAT(out,0,0) = MAT(in,0,0);
585 MAT(out,1,0) = MAT(in,0,1);
586 MAT(out,2,0) = MAT(in,0,2);
587 MAT(out,0,1) = MAT(in,1,0);
588 MAT(out,1,1) = MAT(in,1,1);
589 MAT(out,2,1) = MAT(in,1,2);
590 MAT(out,0,2) = MAT(in,2,0);
591 MAT(out,1,2) = MAT(in,2,1);
592 MAT(out,2,2) = MAT(in,2,2);
597 MAT(out,0,3) = - MAT(in,0,3);
598 MAT(out,1,3) = - MAT(in,1,3);
599 MAT(out,2,3) = - MAT(in,2,3);
603 if (mat->flags & MAT_FLAG_TRANSLATION) {
605 MAT(out,0,3) = - (MAT(in,0,3) * MAT(out,0,0) +
606 MAT(in,1,3) * MAT(out,0,1) +
607 MAT(in,2,3) * MAT(out,0,2) );
608 MAT(out,1,3) = - (MAT(in,0,3) * MAT(out,1,0) +
609 MAT(in,1,3) * MAT(out,1,1) +
610 MAT(in,2,3) * MAT(out,1,2) );
611 MAT(out,2,3) = - (MAT(in,0,3) * MAT(out,2,0) +
612 MAT(in,1,3) * MAT(out,2,1) +
613 MAT(in,2,3) * MAT(out,2,2) );
616 MAT(out,0,3) = MAT(out,1,3) = MAT(out,2,3) = 0.0;
625 * \param mat pointer to a GLmatrix structure. The matrix inverse will be
632 static GLboolean invert_matrix_identity( GLmatrix *mat )
634 memcpy( mat->inv, Identity, sizeof(Identity) );
641 * \param mat pointer to a GLmatrix structure. The matrix inverse will be
648 static GLboolean invert_matrix_3d_no_rot( GLmatrix *mat )
650 const GLfloat *in = mat->m;
651 GLfloat *out = mat->inv;
653 if (MAT(in,0,0) == 0 || MAT(in,1,1) == 0 || MAT(in,2,2) == 0 )
657 MAT(out,0,0) = 1.0F / MAT(in,0,0);
658 MAT(out,1,1) = 1.0F / MAT(in,1,1);
659 MAT(out,2,2) = 1.0F / MAT(in,2,2);
661 if (mat->flags & MAT_FLAG_TRANSLATION) {
662 MAT(out,0,3) = - (MAT(in,0,3) * MAT(out,0,0));
663 MAT(out,1,3) = - (MAT(in,1,3) * MAT(out,1,1));
664 MAT(out,2,3) = - (MAT(in,2,3) * MAT(out,2,2));
673 * \param mat pointer to a GLmatrix structure. The matrix inverse will be
681 static GLboolean invert_matrix_2d_no_rot( GLmatrix *mat )
683 const GLfloat *in = mat->m;
684 GLfloat *out = mat->inv;
686 if (MAT(in,0,0) == 0 || MAT(in,1,1) == 0)
690 MAT(out,0,0) = 1.0F / MAT(in,0,0);
691 MAT(out,1,1) = 1.0F / MAT(in,1,1);
693 if (mat->flags & MAT_FLAG_TRANSLATION) {
694 MAT(out,0,3) = - (MAT(in,0,3) * MAT(out,0,0));
695 MAT(out,1,3) = - (MAT(in,1,3) * MAT(out,1,1));
703 static GLboolean invert_matrix_perspective( GLmatrix *mat )
705 const GLfloat *in = mat->m;
706 GLfloat *out = mat->inv;
708 if (MAT(in,2,3) == 0)
713 MAT(out,0,0) = 1.0F / MAT(in,0,0);
714 MAT(out,1,1) = 1.0F / MAT(in,1,1);
716 MAT(out,0,3) = MAT(in,0,2);
717 MAT(out,1,3) = MAT(in,1,2);
719 MAT(out,2,2) = 0;
720 MAT(out,2,3) = -1;
722 MAT(out,3,2) = 1.0F / MAT(in,2,3);
723 MAT(out,3,3) = MAT(in,2,2) * MAT(out,3,2);
732 typedef GLboolean (*inv_mat_func)( GLmatrix *mat );
757 * \param mat pointer to a GLmatrix structure. The matrix inverse will be
766 static GLboolean matrix_invert( GLmatrix *mat )
768 if (inv_mat_tab[mat->type](mat)) {
769 mat->flags &= ~MAT_FLAG_SINGULAR;
772 mat->flags |= MAT_FLAG_SINGULAR;
773 memcpy( mat->inv, Identity, sizeof(Identity) );
794 _math_matrix_rotate( GLmatrix *mat,
862 /* no rotation, leave mat as-is */
960 matrix_multf( mat, m, MAT_FLAG_ROTATION );
966 * \param mat matrix to apply the projection.
974 * Creates the projection matrix and multiplies it with \p mat, marking the
978 _math_matrix_frustum( GLmatrix *mat,
1000 matrix_multf( mat, m, MAT_FLAG_PERSPECTIVE );
1006 * \param mat matrix to apply the projection.
1014 * Creates the projection matrix and multiplies it with \p mat, marking the
1018 _math_matrix_ortho( GLmatrix *mat,
1047 matrix_multf( mat, m, (MAT_FLAG_GENERAL_SCALE|MAT_FLAG_TRANSLATION));
1053 * \param mat matrix.
1058 * Multiplies in-place the elements of \p mat by the scale factors. Checks if
1064 _math_matrix_scale( GLmatrix *mat, GLfloat x, GLfloat y, GLfloat z )
1066 GLfloat *m = mat->m;
1073 mat->flags |= MAT_FLAG_UNIFORM_SCALE;
1075 mat->flags |= MAT_FLAG_GENERAL_SCALE;
1077 mat->flags |= (MAT_DIRTY_TYPE |
1084 * \param mat matrix.
1089 * Adds the translation coordinates to the elements of \p mat in-place. Marks
1094 _math_matrix_translate( GLmatrix *mat, GLfloat x, GLfloat y, GLfloat z )
1096 GLfloat *m = mat->m;
1102 mat->flags |= (MAT_FLAG_TRANSLATION |
1130 * \param mat matrix.
1136 _math_matrix_set_identity( GLmatrix *mat )
1138 memcpy( mat->m, Identity, 16*sizeof(GLfloat) );
1139 memcpy( mat->inv, Identity, 16*sizeof(GLfloat) );
1141 mat->type = MATRIX_IDENTITY;
1142 mat->flags &= ~(MAT_DIRTY_FLAGS|
1197 * \param mat matrix.
1201 static void analyse_from_scratch( GLmatrix *mat )
1203 const GLfloat *m = mat->m;
1216 mat->flags &= ~MAT_FLAGS_GEOMETRY;
1221 mat->flags |= MAT_FLAG_TRANSLATION;
1226 mat->type = MATRIX_IDENTITY;
1229 mat->type = MATRIX_2D_NO_ROT;
1232 mat->flags |= MAT_FLAG_GENERAL_SCALE;
1239 mat->type = MATRIX_2D;
1244 mat->flags |= MAT_FLAG_GENERAL_SCALE;
1248 mat->flags |= MAT_FLAG_GENERAL_3D;
1250 mat->flags |= MAT_FLAG_ROTATION;
1254 mat->type = MATRIX_3D_NO_ROT;
1260 mat->flags |= MAT_FLAG_UNIFORM_SCALE;
1264 mat->flags |= MAT_FLAG_GENERAL_SCALE;
1274 mat->type = MATRIX_3D;
1279 mat->flags |= MAT_FLAG_UNIFORM_SCALE;
1283 mat->flags |= MAT_FLAG_GENERAL_SCALE;
1291 mat->flags |= MAT_FLAG_ROTATION;
1293 mat->flags |= MAT_FLAG_GENERAL_3D;
1296 mat->flags |= MAT_FLAG_GENERAL_3D; /* shear, etc */
1300 mat->type = MATRIX_PERSPECTIVE;
1301 mat->flags |= MAT_FLAG_GENERAL;
1304 mat->type = MATRIX_GENERAL;
1305 mat->flags |= MAT_FLAG_GENERAL;
1314 static void analyse_from_flags( GLmatrix *mat )
1316 const GLfloat *m = mat->m;
1318 if (TEST_MAT_FLAGS(mat, 0)) {
1319 mat->type = MATRIX_IDENTITY;
1321 else if (TEST_MAT_FLAGS(mat, (MAT_FLAG_TRANSLATION |
1325 mat->type = MATRIX_2D_NO_ROT;
1328 mat->type = MATRIX_3D_NO_ROT;
1331 else if (TEST_MAT_FLAGS(mat, MAT_FLAGS_3D)) {
1335 mat->type = MATRIX_2D;
1338 mat->type = MATRIX_3D;
1345 mat->type = MATRIX_PERSPECTIVE;
1348 mat->type = MATRIX_GENERAL;
1355 * \param mat matrix.
1363 _math_matrix_analyse( GLmatrix *mat )
1365 if (mat->flags & MAT_DIRTY_TYPE) {
1366 if (mat->flags & MAT_DIRTY_FLAGS)
1367 analyse_from_scratch( mat );
1369 analyse_from_flags( mat );
1372 if (mat->inv && (mat->flags & MAT_DIRTY_INVERSE)) {
1373 matrix_invert( mat );
1374 mat->flags &= ~MAT_DIRTY_INVERSE;
1377 mat->flags &= ~(MAT_DIRTY_FLAGS | MAT_DIRTY_TYPE);
1449 * \param mat matrix.
1455 _math_matrix_loadf( GLmatrix *mat, const GLfloat *m )
1457 memcpy( mat->m, m, 16*sizeof(GLfloat) );
1458 mat->flags = (MAT_FLAG_GENERAL | MAT_DIRTY);