# world space to screen space

## Recommended Posts

B_old    689
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 on other sites
gdunbar    2198
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 on other sites
B_old    689
Quote:
 Original post by gdunbarPerhaps 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 on other sites
B_old    689
For now I am going to use D3DXVec3Project() but I'm still curious about what I did wrong...