OpenGL easier than I thought

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
davidthefat
Chaos Rift Maniac
Chaos Rift Maniac
Posts: 529
Joined: Mon Nov 10, 2008 3:51 pm
Current Project: Fully Autonomous Robot
Favorite Gaming Platforms: PS3
Programming Language of Choice: C++
Location: California
Contact:

OpenGL easier than I thought

Post 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...
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: OpenGL easier than I thought

Post 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. ;)
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Re: OpenGL easier than I thought

Post by Falco Girgis »

...question.

What does gravity have to do with OpenGL?
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: OpenGL easier than I thought

Post by dandymcgee »

GyroVorbis wrote:...question.

What does gravity have to do with OpenGL?
:lol:
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
davidthefat
Chaos Rift Maniac
Chaos Rift Maniac
Posts: 529
Joined: Mon Nov 10, 2008 3:51 pm
Current Project: Fully Autonomous Robot
Favorite Gaming Platforms: PS3
Programming Language of Choice: C++
Location: California
Contact:

Re: OpenGL easier than I thought

Post by davidthefat »

GyroVorbis wrote:...question.

What does gravity have to do with OpenGL?
Actual 3d environment... Now that you mention it... IDK really :lol:
User avatar
rolland
Chaos Rift Regular
Chaos Rift Regular
Posts: 127
Joined: Fri Dec 21, 2007 2:27 pm
Current Project: Starting an Android app soon
Favorite Gaming Platforms: PS1, N64
Programming Language of Choice: C++
Location: Michigan, US

Re: OpenGL easier than I thought

Post by rolland »

GyroVorbis wrote:...question.
What does gravity have to do with OpenGL?
That's why he couldn't figure it out. ;)
I'll write a signature once I get some creativity and inspiration...
User avatar
Ratstail91
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 8
Joined: Sun Feb 01, 2009 1:58 am

Re: OpenGL easier than I thought

Post 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.
Post Reply