Jump to content
  • Advertisement

Archived

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

logout

vector rotation

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

Okay im going to to use a unit vector to store my players direction. This is in 2d top down. Now the thing is that i have to rotate the player based on input from the user. The input is like rotate more CW, or rotate more CCW. And I need to update the vector to reflect these changes. And I also need to be able to collect the angle the vector is facing.( I could probly figure this out myself, but anyone would be kind enoght to at least point me in the right direction i would be greatefull )

Share this post


Link to post
Share on other sites
Advertisement


#define radtodeg(x) (x) * 180.0f / 3.146
#define degtorad(x) (x) * 3.146 / 180.0f

void Vector2D::Rotate(float a)
{
a = degtorad(a);
float px = x*(cos(a)) - y*(sin(a));
y = x*(sin(a)) + y*(cos(a));
x = px;
}


Then, to rotating the player is a simple matter of:

if( LEFT_KEY ) PlayerO.Rotate( -5 * tf ); //Rotate - 5 degrees
if( RIGHT_KEY ) PlayerO.Rotate( -5 * tf ); //Rotate 5 degrees

tf is the ''time factor'' when going with frame-rate independent movement. If you lock your framerate then no need to bother with that.

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!