PDA

View Full Version : Gravity



vos
06-04-2002, 04:54 PM
I need help making an object fall under gravity. Please help!

chowe6685
06-04-2002, 04:59 PM
more detail would help, but all you need to do is store its downward speed, and increment that every second

vos
06-04-2002, 06:05 PM
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?

Mazy
06-04-2002, 09:49 PM
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

coredump
06-05-2002, 04:06 AM
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

Jeffry J Brickley
06-05-2002, 12:45 PM
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....

IronRaph
06-06-2002, 05:30 AM
hehe lol
Ec=1/2*m*vē
Ep=m*g*h

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

Jeffry J Brickley
06-06-2002, 12:06 PM
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;
}

IronRaph
06-08-2002, 12:20 PM
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 http://www.opengl.org/discussion_boards/ubb/wink.gif you will learn this in physique in a few years http://www.opengl.org/discussion_boards/ubb/wink.gif

Jeffry J Brickley
06-08-2002, 06:07 PM
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-=(velocity*dt)+(0.5*9.8*dt*dt);
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.

rhmazza
06-10-2002, 09:22 AM
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();