Results 1 to 3 of 3

Thread: Modelview matrix check

  1. #1
    Newbie Newbie
    Join Date
    Jun 2016
    Posts
    4

    Modelview matrix check

    What is this code checking? If zz > 0 what does that imply? I am guessing it means that we are looking at the object from the rear not front perspective?

    glGetFloatv(GL_MODELVIEW_MATRIX, M);

    zz= (M[6]*M[1]-M[2]*M[5])*M[12]+
    (M[2]*M[4]-M[6]*M[0])*M[13]+
    (M[5]*M[0]-M[4]*M[1])*M[14];

    if(zz>0) do something

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    3,100
    Quote Originally Posted by jacktwork View Post
    What is this code checking? If zz > 0 what does that imply?
    zz is the determinant of M, simplified using the assumption that the bottom row is [0 0 -1 0], which is true for the matrices generated by gluPerspective() and glFrustum(). Note that the expression doesn't use any of the elements from the bottom row or from the third column.

    Which is rather odd, as perspective transformations are normally applied to the projection matrix rather than the model-view matrix (apart from anything else, the fixed-function lighting calculations rely upon the model-view matrix being affine, with no projective component).

    It's possible that the determinant calculation was copied from code which used it for the projection matrix without realising that the calculation is incorrect for a typical model-view matrix.

    If a matrix has a negative determinant, it will turn objects inside out, changing the orientation of faces from clockwise to counter-clockwise and vice versa. The model-view matrix typically has a positive determinant while the projection matrix typically has a negative determinant (this effectively flips the direction of the Z axis; in eye coordinates the +Z direction is behind the viewpoint, in NDC it's in front).

  3. #3
    Newbie Newbie
    Join Date
    Jun 2016
    Posts
    4
    Quote Originally Posted by GClements View Post
    this effectively flips the direction of the Z axis; in eye coordinates the +Z direction is behind the viewpoint, in NDC it's in front
    So my guess was correct. That zz > 0 implies front vs back.

    What this guy does is a maneuver like this.

    for(i=0;i<_nslices;i++) {
    j=i;
    if(zz>0) j= _nslices-1-i;

    ... a bunch of texture applications based on j

Similar Threads

  1. Clarification (Projection Matrix & ModelView Matrix)?
    By CroCodile in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 10-01-2013, 11:43 AM
  2. Lightning: ModelView matrix or just Model Matrix?
    By bliss in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 01-14-2011, 02:38 PM
  3. Texture Matrix vs. Modelview Matrix
    By PhilY in forum OpenGL: Advanced Coding
    Replies: 12
    Last Post: 03-03-2003, 03:13 AM
  4. modelview matrix
    By incus in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 09-15-2002, 05:19 AM
  5. Difference between Modelview matrix and projection matrix
    By aphlai in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 08-22-2001, 07:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean