ReactOS 0.4.15-dev-8116-gf69e256
matrix.h File Reference
#include "types.h"
Include dependency graph for matrix.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void gl_analyze_modelview_matrix (GLcontext *ctx)
 
void gl_analyze_projection_matrix (GLcontext *ctx)
 
void gl_analyze_texture_matrix (GLcontext *ctx)
 
void gl_rotation_matrix (GLfloat angle, GLfloat x, GLfloat y, GLfloat z, GLfloat m[])
 
void gl_Frustum (GLcontext *ctx, GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble nearval, GLdouble farval)
 
void gl_Ortho (GLcontext *ctx, GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble nearval, GLdouble farval)
 
void gl_PushMatrix (GLcontext *ctx)
 
void gl_PopMatrix (GLcontext *ctx)
 
void gl_LoadIdentity (GLcontext *ctx)
 
void gl_LoadMatrixf (GLcontext *ctx, const GLfloat *m)
 
void gl_MatrixMode (GLcontext *ctx, GLenum mode)
 
void gl_MultMatrixf (GLcontext *ctx, const GLfloat *m)
 
void gl_Viewport (GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height)
 
void gl_Rotatef (GLcontext *ctx, GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
 
void gl_Scalef (GLcontext *ctx, GLfloat x, GLfloat y, GLfloat z)
 
void gl_Translatef (GLcontext *ctx, GLfloat x, GLfloat y, GLfloat z)
 

Function Documentation

◆ gl_analyze_modelview_matrix()

void gl_analyze_modelview_matrix ( GLcontext ctx)

Definition at line 420 of file matrix.c.

421{
422 const GLfloat *m = ctx->ModelViewMatrix;
423 if (is_identity(m)) {
424 ctx->ModelViewMatrixType = MATRIX_IDENTITY;
425 }
426 else if ( m[4]==0.0F && m[ 8]==0.0F
427 && m[1]==0.0F && m[ 9]==0.0F
428 && m[2]==0.0F && m[6]==0.0F && m[10]==1.0F && m[14]==0.0F
429 && m[3]==0.0F && m[7]==0.0F && m[11]==0.0F && m[15]==1.0F) {
430 ctx->ModelViewMatrixType = MATRIX_2D_NO_ROT;
431 }
432 else if ( m[ 8]==0.0F
433 && m[ 9]==0.0F
434 && m[2]==0.0F && m[6]==0.0F && m[10]==1.0F && m[14]==0.0F
435 && m[3]==0.0F && m[7]==0.0F && m[11]==0.0F && m[15]==1.0F) {
436 ctx->ModelViewMatrixType = MATRIX_2D;
437 }
438 else if (m[3]==0.0F && m[7]==0.0F && m[11]==0.0F && m[15]==1.0F) {
439 ctx->ModelViewMatrixType = MATRIX_3D;
440 }
441 else {
442 ctx->ModelViewMatrixType = MATRIX_GENERAL;
443 }
444
445 invert_matrix( ctx->ModelViewMatrix, ctx->ModelViewInv );
446 ctx->NewModelViewMatrix = GL_FALSE;
447}
static void invert_matrix(const GLfloat *m, GLfloat *out)
Definition: matrix.c:290
static GLboolean is_identity(const GLfloat m[16])
Definition: matrix.c:402
#define MATRIX_GENERAL
Definition: types.h:1242
#define MATRIX_2D_NO_ROT
Definition: types.h:1247
#define MATRIX_3D
Definition: types.h:1248
#define MATRIX_IDENTITY
Definition: types.h:1243
#define MATRIX_2D
Definition: types.h:1246
float GLfloat
Definition: gl.h:161
#define GL_FALSE
Definition: gl.h:173
const GLfloat * m
Definition: glext.h:10848

Referenced by gl_Begin(), gl_ClipPlane(), gl_Lightfv(), gl_RasterPos4f(), gl_TexGenfv(), and gl_windowpos().

◆ gl_analyze_projection_matrix()

void gl_analyze_projection_matrix ( GLcontext ctx)

Definition at line 455 of file matrix.c.

456{
457 /* look for common-case ortho and perspective matrices */
458 const GLfloat *m = ctx->ProjectionMatrix;
459 if (is_identity(m)) {
460 ctx->ProjectionMatrixType = MATRIX_IDENTITY;
461 }
462 else if ( m[4]==0.0F && m[8] ==0.0F
463 && m[1]==0.0F && m[9] ==0.0F
464 && m[2]==0.0F && m[6]==0.0F
465 && m[3]==0.0F && m[7]==0.0F && m[11]==0.0F && m[15]==1.0F) {
466 ctx->ProjectionMatrixType = MATRIX_ORTHO;
467 }
468 else if ( m[4]==0.0F && m[12]==0.0F
469 && m[1]==0.0F && m[13]==0.0F
470 && m[2]==0.0F && m[6]==0.0F
471 && m[3]==0.0F && m[7]==0.0F && m[11]==-1.0F && m[15]==0.0F) {
472 ctx->ProjectionMatrixType = MATRIX_PERSPECTIVE;
473 }
474 else {
475 ctx->ProjectionMatrixType = MATRIX_GENERAL;
476 }
477
478 ctx->NewProjectionMatrix = GL_FALSE;
479}
#define MATRIX_ORTHO
Definition: types.h:1244
#define MATRIX_PERSPECTIVE
Definition: types.h:1245

Referenced by gl_Begin(), and gl_RasterPos4f().

◆ gl_analyze_texture_matrix()

void gl_analyze_texture_matrix ( GLcontext ctx)

Definition at line 487 of file matrix.c.

488{
489 const GLfloat *m = ctx->TextureMatrix;
490 if (is_identity(m)) {
491 ctx->TextureMatrixType = MATRIX_IDENTITY;
492 }
493 else if ( m[ 8]==0.0F
494 && m[ 9]==0.0F
495 && m[2]==0.0F && m[6]==0.0F && m[10]==1.0F && m[14]==0.0F
496 && m[3]==0.0F && m[7]==0.0F && m[11]==0.0F && m[15]==1.0F) {
497 ctx->TextureMatrixType = MATRIX_2D;
498 }
499 else if (m[3]==0.0F && m[7]==0.0F && m[11]==0.0F && m[15]==1.0F) {
500 ctx->TextureMatrixType = MATRIX_3D;
501 }
502 else {
503 ctx->TextureMatrixType = MATRIX_GENERAL;
504 }
505
506 ctx->NewTextureMatrix = GL_FALSE;
507}

Referenced by gl_RasterPos4f(), and gl_transform_vb_part2().

◆ gl_Frustum()

void gl_Frustum ( GLcontext ctx,
GLdouble  left,
GLdouble  right,
GLdouble  bottom,
GLdouble  top,
GLdouble  nearval,
GLdouble  farval 
)

Definition at line 511 of file matrix.c.

515{
516 GLfloat x, y, a, b, c, d;
517 GLfloat m[16];
518
519 if (nearval<=0.0 || farval<=0.0) {
520 gl_error( ctx, GL_INVALID_VALUE, "glFrustum(near or far)" );
521 }
522
523 x = (2.0*nearval) / (right-left);
524 y = (2.0*nearval) / (top-bottom);
525 a = (right+left) / (right-left);
526 b = (top+bottom) / (top-bottom);
527 c = -(farval+nearval) / ( farval-nearval);
528 d = -(2.0*farval*nearval) / (farval-nearval); /* error? */
529
530#define M(row,col) m[col*4+row]
531 M(0,0) = x; M(0,1) = 0.0F; M(0,2) = a; M(0,3) = 0.0F;
532 M(1,0) = 0.0F; M(1,1) = y; M(1,2) = b; M(1,3) = 0.0F;
533 M(2,0) = 0.0F; M(2,1) = 0.0F; M(2,2) = c; M(2,3) = d;
534 M(3,0) = 0.0F; M(3,1) = 0.0F; M(3,2) = -1.0F; M(3,3) = 0.0F;
535#undef M
536
537 gl_MultMatrixf( ctx, m );
538
539
540 /* Need to keep a stack of near/far values in case the user push/pops
541 * the projection matrix stack so that we can call Driver.NearFar()
542 * after a pop.
543 */
544 ctx->NearFarStack[ctx->ProjectionStackDepth][0] = nearval;
545 ctx->NearFarStack[ctx->ProjectionStackDepth][1] = farval;
546
547 if (ctx->Driver.NearFar) {
548 (*ctx->Driver.NearFar)( ctx, nearval, farval );
549 }
550}
void gl_error(GLcontext *ctx, GLenum error, const char *s)
Definition: context.c:1421
void gl_MultMatrixf(GLcontext *ctx, const GLfloat *m)
Definition: matrix.c:785
#define M(row, col)
#define GL_INVALID_VALUE
Definition: gl.h:695
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
const GLubyte * c
Definition: glext.h:8905
GLdouble GLdouble GLdouble GLdouble top
Definition: glext.h:10859
GLdouble GLdouble right
Definition: glext.h:10859
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLint left
Definition: glext.h:7726
GLint GLint bottom
Definition: glext.h:7726
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
#define d
Definition: ke_i.h:81
#define a
Definition: ke_i.h:78
#define c
Definition: ke_i.h:80
#define b
Definition: ke_i.h:79

Referenced by execute_list(), and init_exec_pointers().

◆ gl_LoadIdentity()

void gl_LoadIdentity ( GLcontext ctx)

Definition at line 709 of file matrix.c.

710{
711 if (INSIDE_BEGIN_END(ctx)) {
712 gl_error( ctx, GL_INVALID_OPERATION, "glLoadIdentity" );
713 return;
714 }
715 switch (ctx->Transform.MatrixMode) {
716 case GL_MODELVIEW:
717 MEMCPY( ctx->ModelViewMatrix, Identity, 16*sizeof(GLfloat) );
718 MEMCPY( ctx->ModelViewInv, Identity, 16*sizeof(GLfloat) );
719 ctx->ModelViewMatrixType = MATRIX_IDENTITY;
720 ctx->NewModelViewMatrix = GL_FALSE;
721 break;
722 case GL_PROJECTION:
723 MEMCPY( ctx->ProjectionMatrix, Identity, 16*sizeof(GLfloat) );
724 ctx->ProjectionMatrixType = MATRIX_IDENTITY;
725 ctx->NewProjectionMatrix = GL_FALSE;
726 break;
727 case GL_TEXTURE:
728 MEMCPY( ctx->TextureMatrix, Identity, 16*sizeof(GLfloat) );
729 ctx->TextureMatrixType = MATRIX_IDENTITY;
730 ctx->NewTextureMatrix = GL_FALSE;
731 break;
732 default:
733 gl_problem(ctx, "Bad matrix mode in gl_LoadIdentity");
734 }
735}
void gl_problem(const GLcontext *ctx, const char *s)
Definition: context.c:1394
static GLfloat Identity[16]
Definition: matrix.c:127
#define GL_TEXTURE
Definition: gl.h:247
#define GL_INVALID_OPERATION
Definition: gl.h:696
#define GL_PROJECTION
Definition: gl.h:246
#define GL_MODELVIEW
Definition: gl.h:245
#define MEMCPY(DST, SRC, BYTES)
Definition: macros.h:231
#define INSIDE_BEGIN_END(CTX)
Definition: macros.h:135

Referenced by execute_list(), and init_exec_pointers().

◆ gl_LoadMatrixf()

void gl_LoadMatrixf ( GLcontext ctx,
const GLfloat m 
)

Definition at line 738 of file matrix.c.

739{
740 if (INSIDE_BEGIN_END(ctx)) {
741 gl_error( ctx, GL_INVALID_OPERATION, "glLoadMatrix" );
742 return;
743 }
744 switch (ctx->Transform.MatrixMode) {
745 case GL_MODELVIEW:
746 MEMCPY( ctx->ModelViewMatrix, m, 16*sizeof(GLfloat) );
747 ctx->NewModelViewMatrix = GL_TRUE;
748 break;
749 case GL_PROJECTION:
750 MEMCPY( ctx->ProjectionMatrix, m, 16*sizeof(GLfloat) );
751 ctx->NewProjectionMatrix = GL_TRUE;
752 {
753 float n,f,c,d;
754
755#define M(row,col) m[col*4+row]
756 c = M(2,2);
757 d = M(2,3);
758#undef M
759 n = d / (c-1);
760 f = d / (c+1);
761
762 /* Need to keep a stack of near/far values in case the user
763 * push/pops the projection matrix stack so that we can call
764 * Driver.NearFar() after a pop.
765 */
766 ctx->NearFarStack[ctx->ProjectionStackDepth][0] = n;
767 ctx->NearFarStack[ctx->ProjectionStackDepth][1] = f;
768
769 if (ctx->Driver.NearFar) {
770 (*ctx->Driver.NearFar)( ctx, n, f );
771 }
772 }
773 break;
774 case GL_TEXTURE:
775 MEMCPY( ctx->TextureMatrix, m, 16*sizeof(GLfloat) );
776 ctx->NewTextureMatrix = GL_TRUE;
777 break;
778 default:
779 gl_problem(ctx, "Bad matrix mode in gl_LoadMatrixf");
780 }
781}
#define GL_TRUE
Definition: gl.h:174
GLdouble n
Definition: glext.h:7729
GLfloat f
Definition: glext.h:7540
#define f
Definition: ke_i.h:83

Referenced by execute_list(), and init_exec_pointers().

◆ gl_MatrixMode()

void gl_MatrixMode ( GLcontext ctx,
GLenum  mode 
)

Definition at line 584 of file matrix.c.

585{
586 if (INSIDE_BEGIN_END(ctx)) {
587 gl_error( ctx, GL_INVALID_OPERATION, "glMatrixMode" );
588 return;
589 }
590 switch (mode) {
591 case GL_MODELVIEW:
592 case GL_PROJECTION:
593 case GL_TEXTURE:
594 ctx->Transform.MatrixMode = mode;
595 break;
596 default:
597 gl_error( ctx, GL_INVALID_ENUM, "glMatrixMode" );
598 }
599}
#define GL_INVALID_ENUM
Definition: gl.h:694
GLenum mode
Definition: glext.h:6217

Referenced by execute_list(), and init_exec_pointers().

◆ gl_MultMatrixf()

void gl_MultMatrixf ( GLcontext ctx,
const GLfloat m 
)

Definition at line 785 of file matrix.c.

786{
787 if (INSIDE_BEGIN_END(ctx)) {
788 gl_error( ctx, GL_INVALID_OPERATION, "glMultMatrix" );
789 return;
790 }
791 switch (ctx->Transform.MatrixMode) {
792 case GL_MODELVIEW:
793 matmul( ctx->ModelViewMatrix, ctx->ModelViewMatrix, m );
794 ctx->NewModelViewMatrix = GL_TRUE;
795 break;
796 case GL_PROJECTION:
797 matmul( ctx->ProjectionMatrix, ctx->ProjectionMatrix, m );
798 ctx->NewProjectionMatrix = GL_TRUE;
799 break;
800 case GL_TEXTURE:
801 matmul( ctx->TextureMatrix, ctx->TextureMatrix, m );
802 ctx->NewTextureMatrix = GL_TRUE;
803 break;
804 default:
805 gl_problem(ctx, "Bad matrix mode in gl_MultMatrixf");
806 }
807}
static void matmul(GLfloat *product, const GLfloat *a, const GLfloat *b)
Definition: matrix.c:154

Referenced by execute_list(), gl_Frustum(), gl_Ortho(), gl_Rotatef(), and init_exec_pointers().

◆ gl_Ortho()

void gl_Ortho ( GLcontext ctx,
GLdouble  left,
GLdouble  right,
GLdouble  bottom,
GLdouble  top,
GLdouble  nearval,
GLdouble  farval 
)

Definition at line 553 of file matrix.c.

557{
558 GLfloat x, y, z;
559 GLfloat tx, ty, tz;
560 GLfloat m[16];
561
562 x = 2.0 / (right-left);
563 y = 2.0 / (top-bottom);
564 z = -2.0 / (farval-nearval);
565 tx = -(right+left) / (right-left);
566 ty = -(top+bottom) / (top-bottom);
567 tz = -(farval+nearval) / (farval-nearval);
568
569#define M(row,col) m[col*4+row]
570 M(0,0) = x; M(0,1) = 0.0F; M(0,2) = 0.0F; M(0,3) = tx;
571 M(1,0) = 0.0F; M(1,1) = y; M(1,2) = 0.0F; M(1,3) = ty;
572 M(2,0) = 0.0F; M(2,1) = 0.0F; M(2,2) = z; M(2,3) = tz;
573 M(3,0) = 0.0F; M(3,1) = 0.0F; M(3,2) = 0.0F; M(3,3) = 1.0F;
574#undef M
575
576 gl_MultMatrixf( ctx, m );
577
578 if (ctx->Driver.NearFar) {
579 (*ctx->Driver.NearFar)( ctx, nearval, farval );
580 }
581}
GLbyte GLbyte tz
Definition: glext.h:8756
GLbyte ty
Definition: glext.h:8756
GLdouble GLdouble z
Definition: glext.h:5874

Referenced by execute_list(), and init_exec_pointers().

◆ gl_PopMatrix()

void gl_PopMatrix ( GLcontext ctx)

Definition at line 653 of file matrix.c.

654{
655 if (INSIDE_BEGIN_END(ctx)) {
656 gl_error( ctx, GL_INVALID_OPERATION, "glPopMatrix" );
657 return;
658 }
659 switch (ctx->Transform.MatrixMode) {
660 case GL_MODELVIEW:
661 if (ctx->ModelViewStackDepth==0) {
662 gl_error( ctx, GL_STACK_UNDERFLOW, "glPopMatrix");
663 return;
664 }
665 ctx->ModelViewStackDepth--;
666 MEMCPY( ctx->ModelViewMatrix,
667 ctx->ModelViewStack[ctx->ModelViewStackDepth],
668 16*sizeof(GLfloat) );
669 ctx->NewModelViewMatrix = GL_TRUE;
670 break;
671 case GL_PROJECTION:
672 if (ctx->ProjectionStackDepth==0) {
673 gl_error( ctx, GL_STACK_UNDERFLOW, "glPopMatrix");
674 return;
675 }
676 ctx->ProjectionStackDepth--;
677 MEMCPY( ctx->ProjectionMatrix,
678 ctx->ProjectionStack[ctx->ProjectionStackDepth],
679 16*sizeof(GLfloat) );
680 ctx->NewProjectionMatrix = GL_TRUE;
681
682 /* Device driver near/far values */
683 {
684 GLfloat nearVal = ctx->NearFarStack[ctx->ProjectionStackDepth][0];
685 GLfloat farVal = ctx->NearFarStack[ctx->ProjectionStackDepth][1];
686 if (ctx->Driver.NearFar) {
687 (*ctx->Driver.NearFar)( ctx, nearVal, farVal );
688 }
689 }
690 break;
691 case GL_TEXTURE:
692 if (ctx->TextureStackDepth==0) {
693 gl_error( ctx, GL_STACK_UNDERFLOW, "glPopMatrix");
694 return;
695 }
696 ctx->TextureStackDepth--;
697 MEMCPY( ctx->TextureMatrix,
698 ctx->TextureStack[ctx->TextureStackDepth],
699 16*sizeof(GLfloat) );
700 ctx->NewTextureMatrix = GL_TRUE;
701 break;
702 default:
703 gl_problem(ctx, "Bad matrix mode in gl_PopMatrix");
704 }
705}
#define GL_STACK_UNDERFLOW
Definition: gl.h:698

Referenced by execute_list(), and init_exec_pointers().

◆ gl_PushMatrix()

void gl_PushMatrix ( GLcontext ctx)

Definition at line 603 of file matrix.c.

604{
605 if (INSIDE_BEGIN_END(ctx)) {
606 gl_error( ctx, GL_INVALID_OPERATION, "glPushMatrix" );
607 return;
608 }
609 switch (ctx->Transform.MatrixMode) {
610 case GL_MODELVIEW:
611 if (ctx->ModelViewStackDepth>=MAX_MODELVIEW_STACK_DEPTH-1) {
612 gl_error( ctx, GL_STACK_OVERFLOW, "glPushMatrix");
613 return;
614 }
615 MEMCPY( ctx->ModelViewStack[ctx->ModelViewStackDepth],
616 ctx->ModelViewMatrix,
617 16*sizeof(GLfloat) );
618 ctx->ModelViewStackDepth++;
619 break;
620 case GL_PROJECTION:
621 if (ctx->ProjectionStackDepth>=MAX_PROJECTION_STACK_DEPTH) {
622 gl_error( ctx, GL_STACK_OVERFLOW, "glPushMatrix");
623 return;
624 }
625 MEMCPY( ctx->ProjectionStack[ctx->ProjectionStackDepth],
626 ctx->ProjectionMatrix,
627 16*sizeof(GLfloat) );
628 ctx->ProjectionStackDepth++;
629
630 /* Save near and far projection values */
631 ctx->NearFarStack[ctx->ProjectionStackDepth][0]
632 = ctx->NearFarStack[ctx->ProjectionStackDepth-1][0];
633 ctx->NearFarStack[ctx->ProjectionStackDepth][1]
634 = ctx->NearFarStack[ctx->ProjectionStackDepth-1][1];
635 break;
636 case GL_TEXTURE:
637 if (ctx->TextureStackDepth>=MAX_TEXTURE_STACK_DEPTH) {
638 gl_error( ctx, GL_STACK_OVERFLOW, "glPushMatrix");
639 return;
640 }
641 MEMCPY( ctx->TextureStack[ctx->TextureStackDepth],
642 ctx->TextureMatrix,
643 16*sizeof(GLfloat) );
644 ctx->TextureStackDepth++;
645 break;
646 default:
647 gl_problem(ctx, "Bad matrix mode in gl_PushMatrix");
648 }
649}
#define MAX_MODELVIEW_STACK_DEPTH
Definition: config.h:66
#define MAX_TEXTURE_STACK_DEPTH
Definition: config.h:72
#define MAX_PROJECTION_STACK_DEPTH
Definition: config.h:69
#define GL_STACK_OVERFLOW
Definition: gl.h:697

Referenced by execute_list(), and init_exec_pointers().

◆ gl_Rotatef()

void gl_Rotatef ( GLcontext ctx,
GLfloat  angle,
GLfloat  x,
GLfloat  y,
GLfloat  z 
)

Definition at line 927 of file matrix.c.

929{
930 GLfloat m[16];
931 gl_rotation_matrix( angle, x, y, z, m );
932 gl_MultMatrixf( ctx, m );
933}
void gl_rotation_matrix(GLfloat angle, GLfloat x, GLfloat y, GLfloat z, GLfloat m[])
Definition: matrix.c:814
GLfloat angle
Definition: glext.h:10853

Referenced by init_exec_pointers().

◆ gl_rotation_matrix()

void gl_rotation_matrix ( GLfloat  angle,
GLfloat  x,
GLfloat  y,
GLfloat  z,
GLfloat  m[] 
)

Definition at line 814 of file matrix.c.

816{
817 /* This function contributed by Erich Boleyn (erich@uruk.org) */
818 GLfloat mag, s, c;
819 GLfloat xx, yy, zz, xy, yz, zx, xs, ys, zs, one_c;
820
821 s = sin( angle * DEG2RAD );
822 c = cos( angle * DEG2RAD );
823
824 mag = GL_SQRT( x*x + y*y + z*z );
825
826 if (mag == 0.0) {
827 /* generate an identity matrix and return */
828 MEMCPY(m, Identity, sizeof(GLfloat)*16);
829 return;
830 }
831
832 x /= mag;
833 y /= mag;
834 z /= mag;
835
836#define M(row,col) m[col*4+row]
837
838 /*
839 * Arbitrary axis rotation matrix.
840 *
841 * This is composed of 5 matrices, Rz, Ry, T, Ry', Rz', multiplied
842 * like so: Rz * Ry * T * Ry' * Rz'. T is the final rotation
843 * (which is about the X-axis), and the two composite transforms
844 * Ry' * Rz' and Rz * Ry are (respectively) the rotations necessary
845 * from the arbitrary axis to the X-axis then back. They are
846 * all elementary rotations.
847 *
848 * Rz' is a rotation about the Z-axis, to bring the axis vector
849 * into the x-z plane. Then Ry' is applied, rotating about the
850 * Y-axis to bring the axis vector parallel with the X-axis. The
851 * rotation about the X-axis is then performed. Ry and Rz are
852 * simply the respective inverse transforms to bring the arbitrary
853 * axis back to it's original orientation. The first transforms
854 * Rz' and Ry' are considered inverses, since the data from the
855 * arbitrary axis gives you info on how to get to it, not how
856 * to get away from it, and an inverse must be applied.
857 *
858 * The basic calculation used is to recognize that the arbitrary
859 * axis vector (x, y, z), since it is of unit length, actually
860 * represents the sines and cosines of the angles to rotate the
861 * X-axis to the same orientation, with theta being the angle about
862 * Z and phi the angle about Y (in the order described above)
863 * as follows:
864 *
865 * cos ( theta ) = x / sqrt ( 1 - z^2 )
866 * sin ( theta ) = y / sqrt ( 1 - z^2 )
867 *
868 * cos ( phi ) = sqrt ( 1 - z^2 )
869 * sin ( phi ) = z
870 *
871 * Note that cos ( phi ) can further be inserted to the above
872 * formulas:
873 *
874 * cos ( theta ) = x / cos ( phi )
875 * sin ( theta ) = y / sin ( phi )
876 *
877 * ...etc. Because of those relations and the standard trigonometric
878 * relations, it is pssible to reduce the transforms down to what
879 * is used below. It may be that any primary axis chosen will give the
880 * same results (modulo a sign convention) using thie method.
881 *
882 * Particularly nice is to notice that all divisions that might
883 * have caused trouble when parallel to certain planes or
884 * axis go away with care paid to reducing the expressions.
885 * After checking, it does perform correctly under all cases, since
886 * in all the cases of division where the denominator would have
887 * been zero, the numerator would have been zero as well, giving
888 * the expected result.
889 */
890
891 xx = x * x;
892 yy = y * y;
893 zz = z * z;
894 xy = x * y;
895 yz = y * z;
896 zx = z * x;
897 xs = x * s;
898 ys = y * s;
899 zs = z * s;
900 one_c = 1.0F - c;
901
902 M(0,0) = (one_c * xx) + c;
903 M(0,1) = (one_c * xy) - zs;
904 M(0,2) = (one_c * zx) + ys;
905 M(0,3) = 0.0F;
906
907 M(1,0) = (one_c * xy) + zs;
908 M(1,1) = (one_c * yy) + c;
909 M(1,2) = (one_c * yz) - xs;
910 M(1,3) = 0.0F;
911
912 M(2,0) = (one_c * zx) - ys;
913 M(2,1) = (one_c * yz) + xs;
914 M(2,2) = (one_c * zz) + c;
915 M(2,3) = 0.0F;
916
917 M(3,0) = 0.0F;
918 M(3,1) = 0.0F;
919 M(3,2) = 0.0F;
920 M(3,3) = 1.0F;
921
922#undef M
923}
_STLP_DECLSPEC complex< float > _STLP_CALL cos(const complex< float > &)
_STLP_DECLSPEC complex< float > _STLP_CALL sin(const complex< float > &)
#define DEG2RAD(degree)
Definition: precomp.h:76
GLdouble s
Definition: gl.h:2039
#define GL_SQRT(X)
Definition: mmath.h:63
int xx
Definition: npserver.c:29

Referenced by gl_Rotatef(), and gl_save_Rotatef().

◆ gl_Scalef()

void gl_Scalef ( GLcontext ctx,
GLfloat  x,
GLfloat  y,
GLfloat  z 
)

Definition at line 940 of file matrix.c.

941{
942 GLfloat *m;
943
944 if (INSIDE_BEGIN_END(ctx)) {
945 gl_error( ctx, GL_INVALID_OPERATION, "glScale" );
946 return;
947 }
948 switch (ctx->Transform.MatrixMode) {
949 case GL_MODELVIEW:
950 m = ctx->ModelViewMatrix;
951 ctx->NewModelViewMatrix = GL_TRUE;
952 break;
953 case GL_PROJECTION:
954 m = ctx->ProjectionMatrix;
955 ctx->NewProjectionMatrix = GL_TRUE;
956 break;
957 case GL_TEXTURE:
958 m = ctx->TextureMatrix;
959 ctx->NewTextureMatrix = GL_TRUE;
960 break;
961 default:
962 gl_problem(ctx, "Bad matrix mode in gl_Scalef");
963 return;
964 }
965 m[0] *= x; m[4] *= y; m[8] *= z;
966 m[1] *= x; m[5] *= y; m[9] *= z;
967 m[2] *= x; m[6] *= y; m[10] *= z;
968 m[3] *= x; m[7] *= y; m[11] *= z;
969}

Referenced by execute_list(), and init_exec_pointers().

◆ gl_Translatef()

void gl_Translatef ( GLcontext ctx,
GLfloat  x,
GLfloat  y,
GLfloat  z 
)

Definition at line 976 of file matrix.c.

977{
978 GLfloat *m;
979 if (INSIDE_BEGIN_END(ctx)) {
980 gl_error( ctx, GL_INVALID_OPERATION, "glTranslate" );
981 return;
982 }
983 switch (ctx->Transform.MatrixMode) {
984 case GL_MODELVIEW:
985 m = ctx->ModelViewMatrix;
986 ctx->NewModelViewMatrix = GL_TRUE;
987 break;
988 case GL_PROJECTION:
989 m = ctx->ProjectionMatrix;
990 ctx->NewProjectionMatrix = GL_TRUE;
991 break;
992 case GL_TEXTURE:
993 m = ctx->TextureMatrix;
994 ctx->NewTextureMatrix = GL_TRUE;
995 break;
996 default:
997 gl_problem(ctx, "Bad matrix mode in gl_Translatef");
998 return;
999 }
1000
1001 m[12] = m[0] * x + m[4] * y + m[8] * z + m[12];
1002 m[13] = m[1] * x + m[5] * y + m[9] * z + m[13];
1003 m[14] = m[2] * x + m[6] * y + m[10] * z + m[14];
1004 m[15] = m[3] * x + m[7] * y + m[11] * z + m[15];
1005}

Referenced by execute_list(), and init_exec_pointers().

◆ gl_Viewport()

void gl_Viewport ( GLcontext ctx,
GLint  x,
GLint  y,
GLsizei  width,
GLsizei  height 
)

Definition at line 1014 of file matrix.c.

1016{
1017 if (width<0 || height<0) {
1018 gl_error( ctx, GL_INVALID_VALUE, "glViewport" );
1019 return;
1020 }
1021 if (INSIDE_BEGIN_END(ctx)) {
1022 gl_error( ctx, GL_INVALID_OPERATION, "glViewport" );
1023 return;
1024 }
1025
1026 /* clamp width, and height to implementation dependent range */
1027 width = CLAMP( width, 1, MAX_WIDTH );
1028 height = CLAMP( height, 1, MAX_HEIGHT );
1029
1030 /* Save viewport */
1031 ctx->Viewport.X = x;
1032 ctx->Viewport.Width = width;
1033 ctx->Viewport.Y = y;
1034 ctx->Viewport.Height = height;
1035
1036 /* compute scale and bias values */
1037 ctx->Viewport.Sx = (GLfloat) width / 2.0F;
1038 ctx->Viewport.Tx = ctx->Viewport.Sx + x;
1039 ctx->Viewport.Sy = (GLfloat) height / 2.0F;
1040 ctx->Viewport.Ty = ctx->Viewport.Sy + y;
1041
1042 ctx->NewState |= NEW_ALL; /* just to be safe */
1043
1044 /* Check if window/buffer has been resized and if so, reallocate the
1045 * ancillary buffers.
1046 */
1048}
#define MAX_WIDTH
Definition: config.h:130
#define MAX_HEIGHT
Definition: config.h:131
void gl_ResizeBuffersMESA(GLcontext *ctx)
Definition: context.c:1497
#define NEW_ALL
Definition: types.h:1236
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
GLint GLint GLsizei width
Definition: gl.h:1546
#define CLAMP(f, min, max)
Definition: tif_color.c:177

Referenced by execute_list(), init_exec_pointers(), and sw_SetContext().