Jump to content
  • Advertisement
Sign in to follow this  
recon6

Problem with speed

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

Hi. I'm using SDL to create a shape that moves in an anti-clockwise direction which increases it's radius after one revolution. The problem is that after each increase in the radius, the circle moves faster than it did in the previous revolution. How can i get it to move at the same speed all the time? while (gameRunning ) { if (SDL_PollEvent(&event)) { if (event.type == SDL_QUIT) { gameRunning = false; } SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); xpos2 = (r2*cos(angle2) + centreX); ypos2 = (r2*sin(angle2) + centreY); angle2 -=0.02; if (angle2 <= -4.71) { angle2 = 1.57; ypos2 +=10; r2 +=10; } filledCircleRGBA(screen, xpos2, ypos2, 5, 20, 250, 30, 255); SDL_Flip(screen); } Where r and centreX & Y are globally defined variables.

Share this post


Link to post
Share on other sites
Advertisement
Your angular speed is constant. To get a constant vectorial speed, divide your angular speed by your radius.

Share this post


Link to post
Share on other sites
Quote:
Original post by recon6
How can i get it to move at the same speed all the time?

By normalizing your angular velocity.

You have your object cover an angle t at a radius r. When r increases, but t remains constant, you've increased effective angular velocity. To keep it constant:

t2 = t1 * r1/r2

where t1 and r1 are initial and t2 and r2 are final angle and radius, respectively. Or, simply always divide your vector displacements (in x and y) by the radius, as ToohrVyk said.

Share this post


Link to post
Share on other sites
Quote:
Original post by Oluseyi
You have your object cover an angle t at a radius r. When r increases, but t remains constant, you've increased effective angular velocity.


I may be wrong, but don't you mean "you've increase the linear velocity"? I was under the impression that constant angular velocity means that you rotate the same angle per unit time.

Thus, a 30 degree rotation over 1 unit of time at radius 1 would be a smaller distance traveled than a 30 degree rotation over 1 unit of time at radius 2. The distance traveled over the same time span in the second case is more, but the angle traveled is the same. His angle isn't changing.

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.

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!