Sign in to follow this  

Simple gravity in opengl

This topic is 4711 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I looked around articles but couldn't find anything related to simple gravity. I have my object, which is pretty much a quad, i am doing collision and gravity tests so i can impliment them into my game (for now, collision is a seperate thing) here's my quad, very simple..
void quadra()
{
	glBegin(GL_QUADS);									// Draw A Quad
		glColor3ub(255, 255, 255);
		glVertex3f(move2, move3, 0.0f);					
		glVertex3f(move1, move3, 0.0f);					
		glVertex3f(move1, move4, 0.0f);					
		glVertex3f(move2, move4, 0.0f);					
	glEnd();									    	
}


the move1/2/3/4 just control my collision responses. My question is: How can i make my quad 'jump', with adjustable but simplistic gravity? Thanks ahead!

Share this post


Link to post
Share on other sites
A simple but decent solution I used in writing 2D particle systems involved keeping track of 4 variables.

The X position
The Y position
The X velocity
The Y velocity

I'd then update positions something a little like...

XPos = XPos + XVel
YPos = YPos + YVel
XVel = XVel * Friction
YVel = (YVel * Friction) + Gravity

It shouldn't be too hard to apply to 3D. Friction is a number between 0 and 1 indicating how fast the object slows down (something between 0.95 and 0.99 is good) and Gravity is how fast it accelerates back towards the ground (something really low, like 0.01). Not the most accurate solution, but very easy to implement.

Share this post


Link to post
Share on other sites

This topic is 4711 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this