Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Vectors and lateral movement

This topic is 6091 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

Ok, I''m having trouble coming up with an equation to try and calculate lateral movement with vectors. Here is the general information... cpos = camera position vector cview = camera view vector And here is my code: GLvoid CAMERA::StrafeCamera(GLfloat speed) { CAMVECT vect1, tempvect1; vect1.x = cview.x - cpos.x; vect1.y = cview.y - cpos.y; vect1.z = cview.z - cpos.z; tempvect1.x = (float)(sin(90)*vect1.x+cos(90)*vect1.z); tempvect1.z = (float)(cos(90)*vect1.x-sin(90)*vect1.z); cpos.x += tempvect1.x * speed; cpos.z += tempvect1.z * speed; cview.x += tempvect1.x * speed; cview.z += tempvect1.z * speed; } I have the idea that the problem lies in the use of 90, but I dont know how to fix it. Can anyone help me?

Share this post

Link to post
Share on other sites
The C/C++ trig functions take radian angles as their arguments. The conversion from degrees to radian is angle/180 * PI. So you can define a conversion macro in C:
// expects M_PI to be defined with the value of PI
#ifndef M_PI
// this is too much precision; you should probably use the first 10 digits or so
#define M_PI 3.1415926535897932384626433832795
#define deg2rad(x) ((x / 180) * M_PI)

or a template inline function in C++:
const int _PI = 3.1415926535897932384626433832795;
inline template <class T> deg2rad(T x) { return ((x / 180) * _PI); }

You can now use either version in your program (but not both!) like so:
float rad = deg2rad(deg); 


I wanna work for Microsoft!

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!