dx10 drawing coordinates to screen coordinates
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.
I used the following code (in c#) for converting a point in 3d space to screen coordinates.
Hope it helps
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
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
Multiply your object space vector with the WorldViewProj Matrix
Perform homogeneous division
Apply Viewport Mapping
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement