Jump to content
  • Advertisement
Sign in to follow this  
retsgorf297

How to create a physics engine

This topic is 2108 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

Hi, I am new to this forum so please tell me if this is in the wrong place.

 

I would like to make a physics engine.  So, can u point in the right direction and/oror give me a link to some tutorials and/or books.  My preferred programming language would be Obj-C or C++, but I am sure I can probably translate it to one of those.  I am using OpenGL, if that helps.

 

Thank you so much! :D

Share this post


Link to post
Share on other sites
Advertisement

 

 

First of all: Welcome to the forum!

Thanks biggrin.png

 

 

 

If it's the first case I'd recommend against writing your own physics engine as there are a ton of excellent professional physics solutions available for use without cost. Examples of these would be Bullet or Nvidia Physx. Havok would also be an option as they have licensing options for low cost and low budget games.

Well, it is the first case, and kinda the second.  But, I would like to do it anyway.

 

 

 

Oh and by the way, your choice of graphics API (OpenGL, DirectX) doesn't really have anything to do with physics engines unless you plan on using your GPU to do some of the heavy lifting.

Ok, just wanted to make sure I gave all of the information I needed to.

 

Thanks for all of that help.  biggrin.png  That had to take you a long time to type that up. ohmy.png

 

EDIT: +1 for your answer! :D

Edited by retsgorf297

Share this post


Link to post
Share on other sites

You'll have to decide for yourself whether it's actually the game you care about or the technology behind it. Be aware that writing a physics engine of your own will take a lot longer than just a couple of months, especially if you don't have any background knowledge yet.

 

If you're actually set on building and releasing a game in the next couple of years you'd be much better off using a proven physics engine.

Share this post


Link to post
Share on other sites
Writing a solid physics engine can take quite a bit of time. What you gain, well for your first one, probably very slow physics engine that no one is going to use in real projects. If you come with something interesting though (very easy and good interface), people might start to use it and you may need to refactor and improve the code.
 
I've actually written few physics engines in my life. Both 2D and 3D, basically the math is very similar ... my first one was really bad, checking sphere vs mesh (1k triangles) took like 70 millis on Pentium D at the time (ofc I haven't dreamed about multicore back then, even when I had one of the first ones) - yup, epic fail. Then I started reading a ton of stuff about optimization, getting the code faster, several times totally refactor (e.g. rewrite) most of the code.
 
Anyways for purpose of learning, go for it. It will learn you a ton of stuff. For purpose of creating good physics engine, it will take years if you don't know the "math". If you know the math, it will still take some time, but magnitudes less.

EDIT: Finally got to finish my answer...

I presume you have some knowledge of math (vectors, matrices, etc.). Now, most physics engines are composed of two main parts - the part that handles collision detection and the part that handles collision reaction.

As for the first part, even though most cases are simple to think about and solve (or derive), it is actually a bit more complicated. Imagine you have support for 2 primitives - Sphere and Triangle. You have to have test for Sphere vs Triangle - that works, but when they start moving, it starts to become problematic. So you have to have Moving Sphere vs. Moving Triangle (for performance reasons you might also consider implementing Moving Sphere vs Triangle and Sphere vs Moving Triangle) ... note you most likely need to know exact point in the time and space where the collision occurs, not some state where they're in each other.

The next main part is collision reaction, based upon information you gathered in the previous part, you can change speed and direction of primitives. This one needs a bit of physics, and joints make it a bit more complicated. Not even mention harder concepts like fluids.

If you want to start building physics engine, start small - preferably with 2D one, report us progress and some of us can point you in good direction. If it will be enough good with good interfaces and fast, people here might consider using it or contributing into it.

Share this post


Link to post
Share on other sites

As some said, I'd strongly advise against it, yada, yada, yada.

 

But now that I think of how to implement a physics engine, let's say 2D, the first thing you should do would be to define your problem.

 

What does your engine needs to handle? Will you need only simple Gravity and small collision and friction systems, that can only handle circular or rectangular bodies and no rotation? (something like a super mario clone)

Or will you need rigid body physics with entities composite by one or more concave polygons, restitution, friction, continuous contact resolution, etc.

 

When you know exactly what you'll need, you'll be able to start something. But starting without a definite objective (or at least a good idea) will get you off with the wrong foot.

 

Maybe this forum will be helpful: http://www.gamedev.net/forum/20-math-and-physics/

Edited by dejaime

Share this post


Link to post
Share on other sites
I recommend the books Real-Time Collision Detection by Christer Ericson and Game Physics Engine Development by Ian Millington.


L. Spiro

Share this post


Link to post
Share on other sites

If you want to make a physic engine, that may be used in a real project, you should hardware accelerate your physic engine for the GPU, by OpenCL or just by OpenGL shaders( a lot harder though, and more hackish...). That's what makes PhysX and Havoks performance so good. 

As people have pointed out, the method and algorithm used in a physic engine is common across the engines. And as L. Spiro said, Real-Time Collision Detection and Game Physics Engine Development are very good books(I have both). So it is up to you, how you gonna implement the engine, however you should have a decent understanding of geometry and physic laws, that you may recall from high-school. Another thing, it takes time to create a physic engine, so it should only be made for learning purposes or as part of your CV.

Share this post


Link to post
Share on other sites

 

 

Game Physics Engine Development by Ian Millington.

I had already gotten this book.

 

Thanks for the ones who actually answered.

 

No thanks to the ones who were trying to discourage me. :P :P

Share this post


Link to post
Share on other sites


No thanks to the ones who were trying to discourage me.

 

Nobody here is trying to bring you down or anything, we're just trying to give you a realistic picture of what writing a physics engine is about. It's just a fact that if it's your goal to build a game anytime soon it's not a good idea to spend years trying to build a physics engine from scratch first, it's as simple as that.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!