Screen to projection

Started by
0 comments, last by iedoc 12 years, 2 months ago
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
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

This topic is closed to new replies.

Advertisement