Jump to content
  • Advertisement
Sign in to follow this  
shoez

Screen to projection

This topic is 2499 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Just confirming the followin formula is the one I'm looking for. It was prodded by tsus.

What I'm wanting to do it pass in window client area screen coordinates and have them transformed into projection space to be mapped to the screen within my d3d window using
X [-1,1]
y [-1,1]

float2 screenToPostProjection(float2 screen, float2 ViewPort)
{
float2 normalizedScreen = float2( screen.x / ViewPort.x, screen.y / ViewPort.y);
float2 postProjection = normalizedScreen * 2.0 - 1.0; // mapping from [0,1] to [-1,1]
postProjection.y *= -1; // window origin is in different corner.
return postProjection;
}


My Screen Coordinates Im Passing in are the following:
top left vertex: ( 100, 300 )
top right vertex: ( 700, 300 )
bottom right vertex: ( 700, 800 )
bottom left vertex: ( 100, 800 )

Performing the above transformation on each vertex yields the following results:

top left vertex: ( -.6875, -.25 )
top right vertex: ( 1.1875, -.25 )
bottom right vertex: ( 1.1875, -2.333 )
bottom left vertex: ( -.6875, -2.3333 )

something is not right :( some of the values above are outside of the [-1 - 1] range that they must be provided within

Share this post


Link to post
Share on other sites
Advertisement
the function is correct. Your viewport.x is 640 from the looks of it, and you are specifying the right corners at 700, which is over 640, so the answer is going to be greater than 1, which also means that it is off the screen or viewport

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!