Sign in to follow this  
Programmer16

Computing camera vectors

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
Ok, the algo
Left - LookAt x Up
works great unless I'm looking directly at the origin (which I understand since multiplication by 0), but how do I fix this (or will I ever have to worry about it)?

Any help would be great, I'll continue working/searching.

Thanks

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

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