Screenspace confusion

This topic is 4121 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I'm making a topdown 2d in 3d kind of shooter and I'm really confused by screen coordinates. In Direct3D the Z axis goes into the screen. So for my topdown shooter it made sense to me to make the up vector for my view matrix to be <0, 0, -1>. But then nothing I draw at (0, 0, 0) shows up on the screen? Here is my full view transformation set up:
    D3DXVECTOR3 eye(0, 0, -25);
D3DXVECTOR3 at(0, 0, 0);
// D3DXVECTOR3 up(0.0f, -1.0f, 0.0f);
D3DXVECTOR3 up(0.0f, 0.0f, -1.0f);

D3DXMATRIXA16 view;
D3DXMatrixLookAtLH(&view, &eye, &at, &up);

You can see the commented out line, through trial and error I found that that (and <0, 1, 0>) is the only thing I can set the up vector equal to in order for something drawn at (0, 0, 0) to be visible. I'm hoping someone can explain away my confusion here.

Share on other sites
The 'look at' algorithm used by DirectX and OpenGL fails when the up vector is parallel or nearly parallel to the look vector, which is the case in your example when the up vector is made parallel to the z axis. Using the +y axis should (and apparently does) give you the correct results.

Remember, it's the camera up vector. Typically, when you're looking at the screen, +y is up (or maybe -y, depending), so it makes sense that you would want to use one of these two vectors as the up argument to the 'look at' function.

Share on other sites
Quote:
 Original post by jykRemember, it's the camera up vector. Typically, when you're looking at the screen, +y is up (or maybe -y, depending), so it makes sense that you would want to use one of these two vectors as the up argument to the 'look at' function.

Ahh! Of course. I was thinking of it as my 'worlds' up vector. Thanks!