Gravity Implementation Help

Started by
3 comments, last by rgirard413 22 years ago
Im trying to implement gravity to my engine, im not quite sure how i can do that. my current scene render looks like this and i have a timer running to get fps and the such...where and how would i put gravity calculations in to simulate the 9.8m/sec^2...
  
int Render()						
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();

	Update_Camera();

	camera.position = collision.CheckCollisions(camera.position, camera.velocity, &Map);

	camera.velocity = Vector(0.0f, 0.0f, 0.0f);

	g_Frustum.CalculateFrustum();

	Map.Draw_Map(&g_Frustum);

	return TRUE;						
}
  
camera.velocity is make in winmain when i push up or down.. if (keys[VK_UP]) { camera.velocity.x = -(float)sin(yrot*piover180) * 0.05f; camera.velocity.z = -(float)cos(yrot*piover180) * 0.05f; } if (keys[VK_DOWN]) { camera.velocity.x = (float)sin(yrot*piover180) * 0.05f; camera.velocity.z = (float)cos(yrot*piover180) * 0.05f; } thanks for any help
http://www.thedizzle.com
Advertisement
The simpliest way, is to use timer to increase camera.velocity<vertical> by 9.8 per second, of by 9.8/NTicks, per 1 tick.

Best regards!
Actually, the best way is to apply the downward acceleration due to gravity, the upward acceleration due to surface reaction, and whatever other forces are incident every frame. If an object is situated on the floor, then the accelerations of gravity and surface reaction cancel out.

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! | Asking Smart Questions | Internet Acronyms ]
Thanks to Kylotan for the idea!
quote:

Actually, the best way is to apply the downward acceleration due to gravity, the upward acceleration due to surface reaction, and whatever other forces are incident every frame



Sure, but only in that case, if frames are not called in cicle, but actually in timer - in other case, the accseleration would be different on different computers
quote:Original post by Anonymous Poster
Sure, but only in that case, if frames are not called in cicle, but actually in timer - in other case, the accseleration would be different on different computers

You should never tie your physics into the framerate, so you''re right. It should be on timer.

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! | Asking Smart Questions | Internet Acronyms ]
Thanks to Kylotan for the idea!

This topic is closed to new replies.

Advertisement