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();
}
Simple gravity in opengl
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..
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!
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
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
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?
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.
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.
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement