Jump to content
  • Advertisement
Sign in to follow this  
B_old

world space to screen space

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

Hi, I am trying to get the screen coordinates of a vector3. After looking at this I gave it a try.
Vector3 v3;     //whatever pos
Vector4 v4(v3); // == Vector4(v3.x, v3.y, v3.z, 1.0f);
Matrix4 m(view * proj * Matrix4::clip(-1, 1, 2, 2, 0.0f, 1.0f) * Matrix4::viewScale(0, 0, 1024, 768));

v4 = m * v4;

//the screen coords
int x = v4.x / v4.w;
int y = v4.y / v4.w;

I expected to get values like 0..1023/0..767, but sometimes I get negative values or values that are little to big. Assuming that my implementation of the functions above is correct, what could be wrong. I could post the code for the functions if you think it might help. Thanks!

Share this post


Link to post
Share on other sites
Advertisement
Perhaps this is a dumb question, but are you sure the thing you are translating is visible on the screen? If it is off of the screen, a negative (or too large) value is expected.

Geoff

Share this post


Link to post
Share on other sites
Quote:
Original post by gdunbar
Perhaps this is a dumb question, but are you sure the thing you are translating is visible on the screen? If it is off of the screen, a negative (or too large) value is expected.
Geoff

:) Yes, it is right in front of me.

Share this post


Link to post
Share on other sites
For now I am going to use D3DXVec3Project() but I'm still curious about what I did wrong...

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!