Sign in to follow this  

world space to screen space

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
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.

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

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this