• Advertisement
Sign in to follow this  

Simple gravity in opengl

This topic is 4787 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
Advertisement
x_t = x_0 + t*v_0 + a/2*t^2
v_t = v_0 + a*t

x_0 is the current position
v_0 is the current valocity
a is the acceleration
t is the change in time
x_t is the new position
v_t is the new valocity

Share this post


Link to post
Share on other sites
hah Mike, how would i use that in this situation tho? When the person presses space (my current jump key), do i just set the velocity?

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
Quote:
Original post by Jovan
When the person presses space (my current jump key), do i just set the velocity?

yes

and the acceleration is the amount of gravity

Share this post


Link to post
Share on other sites
Quote:
Original post by Jovan
so in my case it should be a negative number? :P

the velocity should be the opposite of acceleration when the player jumps

the direction of the acceleration is game dependent

Share this post


Link to post
Share on other sites
Okay mike, but one small problem, its not doing anything :( i set the velocity and acceleration, but it wont do anything :(

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement