View Full Version : Modelview matrix check

jacktwork

06-22-2016, 03:55 PM

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

GClements

06-22-2016, 05:09 PM

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).

jacktwork

06-22-2016, 05:39 PM

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

Powered by vBulletin® Version 4.2.5 Copyright © 2018 vBulletin Solutions Inc. All rights reserved.