Jump to content
  • Advertisement
Sign in to follow this  
ucfchuck

dx10 drawing coordinates to screen coordinates

This topic is 3506 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

what is the equation for converting a point in my imaginary created dx10 world into screen coordinates? im mostly only interested in the y component and from whats in the stock vertex shaders its something like : output.Pos = mul( input.Pos, World ); output.Pos = mul( output.Pos, View ); output.Pos = mul( output.Pos, Projection ); but i want the coordinates in my nonshader code so i mocked it up like float temp = ImageTop; temp = temp * g_World.M22; temp = temp * g_View.M22; temp = temp * g_Projection.M22; MessageBox.Show(PointToScreen(new Point(0, (int)temp)).Y.ToString()); but its not accounting for the movement from the "eye" or the "at" in View so im assuming its way wrong as most of those values show up in the .M4x regions of the view and projection.

Share this post


Link to post
Share on other sites
Advertisement
I used the following code (in c#) for converting a point in 3d space to screen coordinates.


Vector2 WorldSpaceToScreenSpace(Vector3 worldSpacePos)
{
Vector4 clipSpacePos = Vector4.Transform(new Vector4(worldSpacePos, 1.0f), viewProjMatrix);
Vector2 screenSpacePos;
screenSpacePos.x = (clipSpacePos.x / clipSpacePos.w) * 0.5f + 0.5f;
screenSpacePos.y = 1.0f - ((clipSpacePos.y / clipSpacePos.w) * 0.5f + 0.5f);
screenSpacePos.x *= viewPortWidth;
screenSpacePos.y *= viewPortHeight;
return screenSpacePos;
}


Hope it helps

Share this post


Link to post
Share on other sites
The code posted by FoDDa looks right. In case you want to do some further research and need some terms you can search for, these are the required steps:
Multiply your object space vector with the WorldViewProj Matrix
Perform homogeneous division
Apply Viewport Mapping

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!