# Gravity

more detail would help, but all you need to do is store its downward speed, and increment that every second

i understand that, but how do you make say a cube fall to a plane? do you need to update the frames continuely to make it look like its falling?

You allways have to update the frame to show changes in the scenery… no matter what you want to move/animate you need to update the whole scene

sounds like a simple physics engine. you need a good timing system. at the beginning of each frame, get the amount of time that passed since the last frame and use this time in your physics calculations.

b

There is an explosion.c particle engine example running around somewhere here that has exactly what you are looking for, multiple particles updated everyframe, and the even bounce off the plane…

hehe lol
Ec=1/2m
Ep=mgh

and Ep+Ec=cste (vetor)

and g=9.81N.kg-1

very easy but don’t forget the opposites forces (F) like aire so Ep+Ec!=cste and Ep+Ec+F!=cste

if you are going to get that fancy, there is always this:

/* Simple variable gravity calculation

|
| Purpose: Simple variable gravity calculation based on squared
| distance fall-off from center of a round-earth.
|
|_______________________________________________________________________
/
/
>>—[ Gravity() ]-------[ 05-10-01 14:02PM ]—/
/ return value:
/ double ; Approximate gravity at distance.
/ parameters:
/ double z ; Elevation above spherical Earth surface
/ local vars:
/-------------------------------------------------------------------<<*/
double Gravity(double z)
{
double G,
eZ;
const double ER = 6378150.0;
const double ER2 = 6378150.0 * 6378150.0;

``````eZ = ER + z;
G = 9.81 * ER2 / (eZ * eZ);
return G;
``````

}

hum it is just the G force and it will not sole his problem so when you have the G force you must do something like I say upper you will learn this in physique in a few years

my comments were more directed at the list of functions you gave. I use them, but a beginner shouldn’t need to, only the original motion equation. Eventually he will get into drag and other forces. Perhaps I should have posted a modified Euler equation or Runge-Kutta?

// where dt== delta time.
z-=(velocitydt)+(0.59.8dtdt);
velocity+=(9.8*dt);

is good enough for most particle engines; adding the other involved forces only confuses the issue until he is ready for them.

I appologize for my earlier post, even variable G is too much for a beginner, I was just going along with your wonderful lists of forces by modifying one.

Okay, so for the sake of redundancy, but also because with more examples it is more apparent how something works –

If you use three vectors, which just have a component for x, y, and z, it is really simple. You just need a simple vector class; even if you don’t have one, this shows you how it works, just declare the components as float variables. Also, this doesn’t take into account time, but if that becomes an issue because you have variable framerates, then just multiply the time between frames by the acceleration when adding to the velocity, and then by the velocity when adding to the position.

Keep in mind this is the bear minimum below, but it’s probably just what you’re looking for. Then you can get fancy and take into account gravitational falloff and the cosmological constant and affects of dark energy… Some people toss that stuff in right away and don’t explain it well, when all you need is a really simple explanation.

float gravity = -9.8; // or whatever works for you
float fallHeight = 100.0; // the height object starts at

Vector3D position = Vector3D(0,fallHeight,0);
Vector3D velocity = Vector3D(0,0,0);
Vector3D acceleration = Vector3D(0,gravity,0);

and each frame, just do this:

velocity += acceleration;
position += velocity;

glPushMatrix();
glTranslatef(position.x, position.y, position.z);
// draw object here
glPopMatrix();