Jump to content


Projection problem


2 replies to this topic

#1 enigma

    Member

  • Members
  • PipPip
  • 58 posts

Posted 02 December 2008 - 04:28 PM

Hi,
I've a problem with vertices projection. See this image:
Posted Image
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)
Posted Image
Why the order is wrong? And way the second coordinate is wrong?
Thanks.

#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 4782 posts
  • LocationBellevue, WA

Posted 02 December 2008 - 05:44 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.
reedbeta.com - developer blog, OpenGL demos, and other projects

#3 enigma

    Member

  • Members
  • PipPip
  • 58 posts

Posted 03 December 2008 - 04:02 AM

Reedbeta said:

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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users