Jump to content
  • Advertisement
Sign in to follow this  
AbsolutDew

Screenspace confusion

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

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites
Quote:
Original post by jyk
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.



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

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!