Advertisement Jump to content
Sign in to follow this  
dawberj3

Adding a strafe function to the Quaternion Camera Class

This topic is 4903 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 have a simple boolean that sees which direction you are currently strafing. -1 is LEFT, 1 ir RIGHT. In the SetPerspective function, before the translate i added the line: // Strafe m_Position.x += strafing; (strafing is either 1.0f or -1.0f depending on the boolean) but this only works in the x axis, how do i change this so it strafes left/right from whichever direction it is facing. The direction vector is: m_DirectionVector; This maybe a simple fix but Im still getting the hand of quaternions and matrices. Thx

Share this post


Link to post
Share on other sites
Advertisement
The Quaternion itself is only concerned with orientation of the 'camera', that is, Roll, Pitch and Yaw. Strafing would be related to positional information, which may also be part of your camera class.

What you need is the Cross product of the viewing vector and the up vector (which may simply always be <0, 0, 1> in your case.) The results will be a translation vector perpendicular to the view vector, ie Strafing. Depending on whether you do view cross up, or up cross view, this vector will either point right or left (I beleive that view cross up yeilds a right facing vector, but I'm not 100%.)


[edit]
I've double-checked my assumption and it seems that I was correct, which is prettuy good considering that I've only been awake for about 30 minutes. View cross Up will provide a rightward strafe vector. Calculate it and simply add it to your position vector :D

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!