PDA

View Full Version : Projection problem


enigma
12-02-2008, 08:28 AM
Hi,
I've a problem with vertices projection. See this image:
http://img239.imageshack.us/img239/7760/weight1sm7.th.jpg (http://img239.imageshack.us/my.php?image=weight1sm7.jpg)
There are three points in this order:
-Red point (2.0, 2.0, 2.0)
-Green point (-2.0, 2.0, 2.0)
-Blue point (2.0, -2.0, 2.0)
Ok, now I need the projected coordinate of this three vertices. I proceed in this manner:

V1 = (2.0, 2.0, 2.0);
PM; //Is the projection matrix
MM; //Is the modelview matrix
TM = {(0.5 * 1024.0), 0.0, 0.0, 0.0, 0.0, (0.5 * 800.0), 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, (0.5 * 1024.0), (0.5 * 800.0), 0.0, 1.0};

V1O = (2.0, 2.0, 2.0, 1.0);

V1O = TM*PM*MM*V1O;

V1 = V1O.perspectiveDivision();

In this manner I obtain a wrong result, because the resulting coordinate are these: (yellow numbers)
http://img201.imageshack.us/img201/5079/weight111jf5.th.jpg (http://img201.imageshack.us/my.php?image=weight111jf5.jpg)
Why the order is wrong? And way the second coordinate is wrong?
Thanks.

Reedbeta
12-02-2008, 09:44 AM
It looks to me like you just need to flip the Y axis. This is because in D3D or OpenGL post-projective coordinates the Y axis goes up, but in pixel coordinates the Y axis goes down. So just make the second row of your TM matrix negative.

enigma
12-02-2008, 08:02 PM
It looks to me like you just need to flip the Y axis. This is because in D3D or OpenGL post-projective coordinates the Y axis goes up, but in pixel coordinates the Y axis goes down. So just make the second row of your TM matrix negative.
Yes, it's correct.
Thanks.