# Computing camera vectors

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

## 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 on other sites
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 on other sites
Well, the first isn't really a problem since D3D has support for both, but I do use the left-handed CCS, so a left vector would make more sense, huh?

Thanks JohnBolton!

##### 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 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)

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633725
• Total Posts
3013558
×