Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


2D Coordinates from 3D View and Projection Matricies


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Your1 Nightmare   Members   -  Reputation: 100

Like
0Likes
Like

Posted 25 March 2012 - 03:06 PM

In a game I am developing with a team I ran into some issues regarding Matricies and finding coordinates in the game world based off of a resolution. I am trying to constrict a ship so that it does not leave the game screen, however these bounds will change based off of the resolution of the game screen. This is what we have been thinking so far:

V = view Matrix
P = projection Matrix
M = V * P

s = screen space coordinates
w = game world space coordinates

w * M = s

I then took the inverse of M with s so i could figure out the corner of the screen in "w". I split the coordinates using x = w.X * w.W and y = w.Y * w.W, because it was a 4th dimentional vector.

w= M^-1 * s

Sponsor:

#2 pilarsor   Members   -  Reputation: 130

Like
0Likes
Like

Posted 28 March 2012 - 03:00 PM

Keep in mind, that your matrix M transforms each point into homogeneous clip space HCS, ranging from
x=-w..w, y=-w..w, z=-w..w,w=z, so you might want to devide each projected coordinate additionally by w, to get
your screen values in range x=-1..1,y=-1..1,z=-1..1, the normalized device coords ( NDC ).

So:

M*w = c (in HCS)
s = c / c.w ( divide by homogeneous coordinate c.w )


To get back into world space, store your c.w per fragment/pixel/screen coord.

For each screen coord:
c = s * c.w
w = M^-1 * c




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS