I am writing a project in OpenGL in C ++.

Given an inclined plane on which the ball rolls and then stops. There is a ball, a plane (there is no problem to draw them). The case is left for small, so that the ball rolls down and stops ... but how to do it? (I know that the formula of attraction must also be applied)

Help me please!

  • Py sy, mine does not knit a little name with common sense, si in opengl? can the other way around? OpenGL in C - Vladimir Klykov
  • one
    In general, OpenGL has nothing to do with it. Physics is the same everywhere. - gammaker
  • Support)) - Vladimir Klykov

3 answers 3

Yes, there is no need for formulas of attraction, just increase the speed, something like
speed + = 5; positionX = x + speed; positionY = y + speed;

I haven’t been writing with ++ for a long time, but I think the essence is clear ...
If the task is to get the ball together - there is no point in bothering about the law ...
You could also advise about the slopes, but you have not recorded what angles you have ...
Anyway good luck ...

PS: Nastya . Magadan this to what? ^^

    During the ball rolling:

    speed.x+=g*cos(a); speed.y-=g*sin(a); pos.x+=speed.x; pos.y+=speed.y; 

    g is the acceleration of free fall, depends on the scale and speed of rolling. a is the angle of inclination of the plane in radians. Possibly cos and sin need to be swapped.

    To stop the ball, you need to deduct the friction force from its speed.

    • one
      As far as I remember from the physics course, the acceleration during a fall does not depend on the mass. The force of attraction depends on the mass. And the acceleration for all bodies is the same. Friction can be neglected. We are not real physical processes model. In addition, rolling friction is not great. - skegg
    • one
      It is the same, and made of cotton and metal. Another thing is air resistance. The ball of wool because of the loose structure is experiencing greater resistance. In a vacuum, they will fall the same. The experiences of Galileo, 16th century. And rolling under the force of gravity is the same as free fall. My dear, what was your physics? - skegg
    • 3
      Well, enter the aerodynamic equations, take into account turbulence, random gusts of wind, surface friction, the fact that Annushka spilled oil, etc. Bon Voyage. Maybe for Christmas and count something. Unless otherwise specified, we model by the simplest option. The art of modeling is the art of simplification. - skegg
    • one
      @AlexWindHope It’s strange that you don’t see the point of counting anything without knowing the masses. There is a task, it can be solved - so why not do it? . The mass of the ball here affects only the time that passes before the end of its movement, because the friction force depends on this very mass. - Costantino Rupert
    • 3
      I do not understand what the market is about. The task is as simple as possible. If other conditions are not specified, the movement occurs in a vacuum, the acceleration of movement is constant, the friction on the surface is absent, the surface is perfectly smooth, the ball is perfectly round, etc. And do not fuss on an empty place. - skegg pm

    I wrote 3H on delfe, if you need a physical model, I advise you to look in the direction of Nehe’s lessons there are collisions (so as not to fall through objects), and gravity and many examples according to OpenGL + C ++ + physics ....