PDA

View Full Version : scale matrix that change vertex order of frontface



somboon
04-23-2010, 12:09 AM
How can I determine if a transformation matrix will change the vertex order of front -facing polygon ?

I know that using minus/inverse scale matrix is not a good idea.
but in my project (2.5D fighting like street fighter 4) the selected view of character model will alway facing the camera

The character model and there animation are define as a right-facing so in order to render left-facing player I have to apply scaling matrix with -1 in x axis. (using my own matrix system similiar to OpenGL fixed function)

The problem is doing so will reverse the order of front facing polygon and I have to call glFrontFace(GL_CW); in order to render correct result.

Are there any way to find out from the final transformation matrix if the matrix will change the vertex order of frontfacing polygon so that I can call glFrontFace(GL_CW) in the right situation ?

ZbuffeR
04-23-2010, 01:37 AM
Simple, if number of inverted axes is pair, no change of frontfacing (keep default GL_CCW).
If impair, need inversion (use GL_CW).

Rosario Leonardi
04-23-2010, 02:29 AM
Another way is to compute the "volume" of the transformation matrix
from the transformation matrix you can exctract the bases and then compute
vec3 XcY = cross(xBase, yBase);
float volume = dot(zBase, XcY);
if volume < 0 your matrix invert the triangle order.

I call it volume, because it's the volume of the solid that have the bases as edge.

overlay
04-23-2010, 05:33 AM
The method proposed by Rosario Leonardi is equivalent to compute the determinant of the upper-left 3x3 block of the 4x4 homogeneous matrix.


If det>0, this is an orientation-preserving transformation. If det<0, this is not an orientation-preserving transformation.

ref: http://en.wikipedia.org/wiki/Triple_product
ref: http://en.wikipedia.org/wiki/Orientation_%28mathematics%29
ref: http://mathworld.wolfram.com/Orientation-Preserving.html

somboon
04-23-2010, 06:46 AM
Everyone,Thank for answers.

I will try to implement the volume/determinant method and compare the performance with passing the stored flag (based on axis paring).