• Advertisement
Sign in to follow this  

Computing camera vectors

This topic is 4900 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've been working on my camera class for a few days now and was wondering if my math is correct. I'm trying to calculate the Up from the Right, Position, and LookAt. And I'm trying to calculate the Right from the Up, Position, and LookAt (No, I'm not trying to do these one right after another):
// For Right vector
D3DXVECTOR3 Position(0.0f, 0.0f, -5.0f);
D3DXVECTOR3 LookAt(0.0f, 0.0f, 0.0f);
D3DXVECTOR3 Up(0.0f, 1.0f, 0.0f);
D3DXVECTOR3 Right;
D3DXVec3Cross(&Right, &Up, &(LookAt - Position));
D3DXVec3Normalize(&Right, &Right);

// For Up vector
D3DXVECTOR3 Position(0.0f, 0.0f, -5.0f);
D3DXVECTOR3 LookAt(0.0f, 0.0f, 0.0f);
D3DXVECTOR3 Right(1.0f, 0.0f, 0.0f);
D3DXVECTOR3 Up;
D3DXVec3Cross(&Up, &(LookAt - Position), &Right);
D3DXVec3Normalize(&Up, &Up);

If I output this code, the first on produces Right[1.0f, 0.0f, 0.0f] and the second produces Up[0.0f, 1.0f, 0.0f] which are correct values, but I don't have any way to tell if the values output is correct of I change any of the input vectors (still working on my renderer). I've only been learning vectors for a few days now, so any help would be appreciated! Thanks!

Share this post


Link to post
Share on other sites
Advertisement
Two simple problems:

1. D3D uses a left handed coordinate system, so you will want a Left vector, not a Right vector.

2. Left = At cross Up and Up = Left cross At

Share this post


Link to post
Share on other sites
suggestion:
If looking directly at the origin, just translate everything by -Position and you'll have no zero vectors (except of course your position vector, which is fine because it doesn't get crossed by anything)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement