PDA

View Full Version : Projection problem



enigmagame
12-02-2008, 06:32 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.

Jackis
12-02-2008, 09:32 AM
How do you place these yellow numbers onto screen?
Because there is a major difference in Y coordinate appearance: in Windows GDI zero is on the top, and growing direction is down. On the other hand, in OpenGL zero is down corner, and direction is upward.
So, it's not surprising, that you get image, flipped vertically, if you draw your numbers via GDI calls.

enigmagame
12-02-2008, 09:43 AM
How do you place these yellow numbers onto screen?

No, the yellow numbers are drawed manually (with paint). The problem is that the projected vertices aren't correct.
The returned vertices:


747.298394 507.298394
532.701606 507.298394
747.298394 292.701606

If you check this coordinate on the first image, you can check that are wrongs.
Thanks.

Jackis
12-02-2008, 10:10 AM
enigmagame,

as I understand your code, you do perspective division after viewport transformation (TM matrix in your notation).
This is not correct. Graphics pipelines usually do viewport transform at the very last stage, after perspective division.

enigmagame
12-02-2008, 10:26 AM
Ok, but if I made viewport transformation after the perspective divisione, the result is the same and wrong.
For example:


v1 = (2.0, 2.0, 2.0);
v1O = (v1, 1.0); //(2.0, 2.0, 2.0, 1.0);

v1O = PM * MM * V1O;
v1 = v1O.perspectiveDivision();

v1.x = (v1.x * 640) + 640;
v1.y = (v1.y * 400) + 400;

The results is the same, but why the projected coordinate aren't correct?
Thanks.

Jackis
12-02-2008, 10:43 AM
That's strange.
The way you do is exactly the way OpenGL does.
May be something wrong with projection matrix??
Try moving your points away from screen, remaining X and Y the same. May be, your projection matrix and OpenGL projection matrix differ somehow?
Try getting all these matrices via glGetFloatv() just to ensure they are the same.

dletozeun
12-03-2008, 09:43 AM
Why these coordinates are not correct? Taking the origin at the bottom left corner I have found that your manually-drawn-with-paint points are at the coordinates you have shown above, they are the good ones with a +1 or -1 inacurracy.
Moreover the painted points are not really points, zooming closer to them they looks more a disc.
One, question, How did succeed to place these points at right location in pixel coordinates without knowing them in the OpenGL viewport space?
About, the perspective division, Jackis is completely right, in your case you obtained the same results because I think that you an orthographic projection.

yooyo
12-03-2008, 05:06 PM
Why dont you use gluProject? If you need source, get mesa source and dig gluProject function source.