PDA

View Full Version : OpenGL game engine physics



01-31-2003, 02:45 AM
If programming OpenGL in C++ would it be possible to create a header for a game engine which would use something like newton's laws or any other laws of physics???

just a question, came up with the idea in science class

KOOLKAT

nexusone
01-31-2003, 04:35 AM
nehe.gamedev.net

just put up a tutor on physics and openGL. Gravity, spring, speed/mass.


Originally posted by koolkat:
If programming OpenGL in C++ would it be possible to create a header for a game engine which would use something like newton's laws or any other laws of physics???

just a question, came up with the idea in science class

KOOLKAT

Jan
01-31-2003, 04:38 AM
If you ask like that, it means, that you seem not to know anything about OpenGL or C++. So i advise you not to try it.

To answer your question: Yes, of course, everything is possible with C++. However OpenGL has nothing to do with physics, only with graphics.

However learning C++ needs some time, so if you donīt have any experience (and you donīt seem to have any), you wonīt be able to do it.

Jan.

jebus
01-31-2003, 04:40 AM
sure! i see this question asked quite often, but some people may not realize just how easy it is. let's take the simple case. (you'll prolly remember these equations from your high school physics classes)

F = m * a // Force = mass * acceleration

here, your object has a constant mass, and the force could be anything (gravity, wind, a super punch!) simple elgebra gives you the objects accelration.

v = v0 + (a * t) // velocity = original velocity + (accelration * time)

here, you'd take the time that passed (between frames, maybe) and multiply it with the acceleration, adding any original velocity (if any). this gets you your objects acceleration. Finally

x = x0 + (v * t) // position = original position + (velocity * time)

you can see how this is progressing. say you have a generic object class. make everything you want to follow these laws of physics a derived class off of your object class. to update the position of all your objects in your scene:



object::update(float dt) // dt is the time that passed since we last updated
{
sum up all the forces acting on the object
get acceleration // a = F / m
get velocity // v = v0 + (a * dt)
get new position // x = x0 + (v * dt)
}


you can add all forces together to get a resulting force, and use thihs force in the equation. note that all forces, velocity, accel and position should be 3d vectors, so you'll need to know your vector math. this is for a very simple physics engine (no friction, although that's just another force http://www.opengl.org/discussion_boards/ubb/smile.gif) good luck!

jebus