Jump to content
  • Advertisement
Sign in to follow this  
Programmer16

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.

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
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 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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!