This may be of use to some. I just had to figure this out in order to ensure I’m performing the correct face culling. Face culling is based on the face’s winding direction (clockwise/ccw) and handedness affects this order.
I figured I could determine handedness by checking the current scale vector to see the number of negative vs positive components. If I have one axis in the negative, then we’re left-handed, if I have two, right-handed, three, left handed, and if they’re all positive then it is by default right-handed. So by multiplying the 3 components of the scale vector together, we can see if the total number of negative numbers is odd or even.
This is a simple idea but it’s not so simple to know the scale vector at any given moment. There is a complex process know as matrix decomposition which can extract translation, rotation, and scale given the gl model-view matrix.
Luckily, oF’s matrix4x4 class has decomposition built in, amazing!
So here’s how it all works:
GLfloat modl; glGetFloatv( GL_MODELVIEW_MATRIX, modl); // get the current modelview matrix ofVec3f scale,t; ofQuaternion a,b; // throw-away variables, we only care about scale //decompose the modelview ofMatrix4x4(modl).decompose(t, a, scale, b); if(scale.x*scale.y*scale.z > 0) ;//right handed world! else ;//left handed world!
assuming that the matrix decomposition algorithm oF uses can reliably extract the scale, which is apparently quite hard to do, this should always work.
I am so glad I don’t have to write a matrix decomposition routine, thanks OF!