Page 1 of 1

OpenGL easier than I thought

Posted: Fri Jul 31, 2009 4:07 pm
by davidthefat
But how would you end up doing gravity? just add a constant loop to y -0.1 or some other value to simulate gravity?? I know gravity is way more complex than that though...

g = 9.8 m/s2 = 32.2 ft/s2 thats the earth's gravity...

Re: OpenGL easier than I thought

Posted: Fri Jul 31, 2009 4:52 pm
by dandymcgee
There's a few ways to simulate gravity:

Easy:
The easiest way is to simply change the velocity to negative and have the object fall at a constant speed.
In many cases it won't look much different and this method will suffice.

Realistic:
Create a scale for your game. For instance 5 pixels might equal a meter.

Velocity = Acceleration * Time
Distance = Velocity * Time

Code: Select all

//Where time is equal to the number of seconds since the last loop: (SDL_GetTicks() - oldTime) / 1000
yVelocity = yVelocity + ((9.81 * 5) * time);     //Multiply by number of pixels in a meter
yPosition = yPosition + (yVelocity * time)       //Calculate new position
Eventually it hits the ground and your collision takes over (or it falls off the screen).

EDIT: Done editing. ;)

Re: OpenGL easier than I thought

Posted: Fri Jul 31, 2009 5:22 pm
by Falco Girgis
...question.

What does gravity have to do with OpenGL?

Re: OpenGL easier than I thought

Posted: Fri Jul 31, 2009 5:44 pm
by dandymcgee
GyroVorbis wrote:...question.

What does gravity have to do with OpenGL?
:lol:

Re: OpenGL easier than I thought

Posted: Fri Jul 31, 2009 6:00 pm
by davidthefat
GyroVorbis wrote:...question.

What does gravity have to do with OpenGL?
Actual 3d environment... Now that you mention it... IDK really :lol:

Re: OpenGL easier than I thought

Posted: Sat Aug 01, 2009 11:12 pm
by rolland
GyroVorbis wrote:...question.
What does gravity have to do with OpenGL?
That's why he couldn't figure it out. ;)

Re: OpenGL easier than I thought

Posted: Wed Aug 05, 2009 6:20 am
by Ratstail91
HUH? why does everything go over my head all the time?

not that you'd use it but, I'd do this.

Code: Select all

float fspeed = 0;
while(falling == true)
{
    fspeed += 0.1;
    y -= fspeed;
}
yeah, whatever.