Gravity

Started by
16 comments, last by ARID 23 years, 2 months ago
I am haveing problems creating gravity for my program. Dose anyone have a realy fast way of doing this. Give me the math or point me to a website that will give me a good idea of how to accomplish this. A man walks into a bar.....ouch!?! Ya get it, do ya huh huh well....awww I give up.
A man walks into a bar.....ouch!?! Ya get it, do ya huh huh well....awww I give up.
Advertisement
Gravity is just a form of acceleration. If you keep the fps at constant speed will you avoid a lot of trouble.
Where is a good place to learn how to keep your fps at a constant rate. Nate''s page used to have it but he took it down.
A man walks into a bar.....ouch!?! Ya get it, do ya huh huh well....awww I give up.
         #define gravity 9.8program_speed = (1/frames_rendered)*time_since_start_in_seconds;speed.y -= gravity*program_speed;object.y += speed.y;      


If your model is scaled so that one unit is one meter, then I think that is right. Things fall at a rate of 9.8 metres per second on earth. If you don't use metric, then a) you'll need to convert gravity to some other number and b) you must have a hard time with opengl (kind of hard to use fractions, feet, and inches). You can add speed*program_speed to something to make it move at a rate of speed units per second.

Edited by - £~{ÿùÖ² on ƒUƒP£ÖÿÜ -2342112, 25223 64:123:21 £m

Edited by - smart_idiot on February 1, 2001 1:25:31 PM
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
sorry but i think you''re wrong....

s = 1/2 * a * t^2

s = the distance...
a = 9.81m(eter)/s^2 //const.
t = time in seconds

i won''t explain this becaus my english isn''t good enough... :-)
but this works only for the case, that the object hasn''t speed in the -y(or what ever...) direction...
else:
s = v * t + 1/2 * a * t^2

v = velocity in the same direction wich the object has already...
hope you could understand me.... :-)
questions about physics?? email me....
I think that the code smart_idiot showed is OK if the framerate is constant. If you start with Physiks formulas will you end in something like that code.
Right, you can remove program_speed.

Several of the NeHe tutorials is timed like lesson 23.
Small tutorial with full source code and a demo including gravity detection & response: Physics - Gravity

(ps: It''s about a "perfect" animation - not a fast approximation)

Thanks for all your suggestions they were quite helpfull. I have been reading quite alot about physics and I have a very basic routine set up. It should do for now ounce I refine the engin a little I will add an increaseing velocity (mine is currently constant).
A man walks into a bar.....ouch!?! Ya get it, do ya huh huh well....awww I give up.
It could be wrong, but I looks right to me.

In my programs after 100 frames I calculate the speed, average it with the old speed, then I reset the start time and elapsed frame counters.

It seems to work. The idea is that if you add up the sum after rendering all the frames for one second, it adds up to one. I did it this strange way because I couldn''t figure out how to get a timer that was more accutate than 1/18th of a second. There was probably an easier way, but this works for me. You may have different needs.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
Acceleration is not linear so it is not that easy. Perhaps your test program did have an almost constant speed?

This topic is closed to new replies.

Advertisement