PDA

View Full Version : Physics lib


svero
08-18-2005, 01:40 AM
Any good 2d physics libs that one could link to and use without them being built into a game engine? Just a pure match/physics library that can handle springs and ropes, and collision of surfaces.. maybe some fluid stuff.

digriz
08-18-2005, 01:52 AM
I'm lead to believe that ODE is pretty good. http://ode.org/ and i understand that it will do 2d stuff quite easily.

It's also worth looking at Tokamak too.. http://www.tokamakphysics.com/

ManuelFLara
08-18-2005, 02:00 AM
There's DynaMo (http://home.iae.nl/users/starcat/dynamo/), used to develop BreakQuest.

Bad Sector
08-18-2005, 07:01 AM
i used to believe that ODE was the perfect solution for physics...

...until i tried to build a game (Scorched 3D (http://www.scorched3d.co.uk/), btw, an opensource 3D version of scorched earth which is very good) in my Linux box running in 64bit mode and i saw stuff like:


node->setUserData((int)dataPointer);

and

Data *ptr = (Data*)node->getUserData();


Type and function names are marginal but the practice of typecasting pointers to int and back is heavylly used in ODE. For x86 (and other platforms) it's ok since "int" and pointers are 32bit long. However for x86_64 it isn't since "int" is 32bit long while pointers are 64bit long.

Note that i used the ODE version that comes with the game - i don't know if the latest and greatest ODE still uses this...

Jim Buck
08-18-2005, 09:20 AM
The thing about ODE is that you have the source and can potentially update the "data" functions to accept/return 64-bit values. Other than that, when I was researching some physics libraries, ODE did seem pretty solid. However, the Newton physics library seems *far* more "game ready" in its feature set as compared to ODE, which is more for simulation purposes. I would recommend people checking it out.

milo
08-18-2005, 10:34 AM
Type and function names are marginal but the practice of typecasting pointers to int and back is heavylly used in ODE.
Eww. Why would anyone write code like that? Are there any interesting C compilers left that don't grok (void*)?

--milo
http://www.starshatter.com

Bad Sector
08-18-2005, 10:44 AM
I remember having issues with Borland's free C/C++ compiler with plain "void*", but beyond that... i don't know :-)

Martoon
08-18-2005, 10:57 AM
Unfortunately, there isn't a decent 2D physics library out there that I know of. I think there's a real need for this, and I've considered writing one myself and releasing it. I still might, if I win the lottery and no longer have to invest so much time in this pesky "making-a-living" thing.

All of the libraries mentioned above are 3D, which can be used for 2D, but you should be warned that they're hardly efficient for that. For one thing, a 3D library is dealing with 6 degrees of freedom, when you only need 3 DOF for 2D. What's much worse is that in order to use a 3D physics engine for 2D, you need to place a constraint on 3 DOF for each body, and the processing cost of simulation increases exponentially with the total number of contraints on an interacting group of bodies. So constraining all bodies in a 3D physics engine to two dimensions seriously increases the simulation time cost.

Still, if your simulation is fairly simple, you'll do fine with any of the 3D libraries mentioned. It's just that the CPU will spend several times as long on the physics code using a 3D library than it would if you actually used 2D code.

I've used ODE (for 3D) in a commercial game, and was generally pleased with it. I had to tweak a few things in the source code to serve my purposes, but this was easily done. The source is well-commented and understandable. And no, you don't need to be a physics guru to get under the hood and tweak the code.

gcarlton
08-18-2005, 05:18 PM
The thing about ODE is that you have the source and can potentially update the "data" functions to accept/return 64-bit values. Other than that, when I was researching some physics libraries, ODE did seem pretty solid. However, the Newton physics library seems *far* more "game ready" in its feature set as compared to ODE, which is more for simulation purposes. I would recommend people checking it out.

It is possible to do that in ODE with some work. One problem area is in Opcode, the triangle collision library. It stores references as int32 for efficiency, which for systems today means that its interchangeable with pointers. There is a patch to change this to int64 but it has not been accepted into the mainline - mainly because there was disagreement about whether a better solution would be to use a base pointer with int32 offsets to keep the current efficiency.

DangerCode
08-18-2005, 08:01 PM
There's DynaMo (http://home.iae.nl/users/starcat/dynamo/), used to develop BreakQuest.

Well, that's a pretty strong endorsement. I wonder how much work was needed to get it working with BreakQuest.

DangerCode
08-18-2005, 09:03 PM
Here are some awesome physics / collision detection demos (source included) that I've found. And they are in 2D only.

Olivier's Code Junkyard (http://uk.geocities.com/olivier_rebellion/)

Click on "2D swept+overlap polygonal collision and response"

Deux
08-18-2005, 11:18 PM
now that is some awsome 2d physics !

Thanks for that link

digriz
08-18-2005, 11:55 PM
If you're after a good collision detection library thats free try 'coldet'.

http://photoneffect.com/coldet/

NuriumGames
08-19-2005, 05:09 AM
Sorry for not answering, I'm in half vacation mode and not fully following the forums.

DynaMo is a 3D physics engine that handles all the math for you. this includes springs, ropes and all kind of junctions. I'm very happy with it, the thesis that comes with the engine explains not only the library but the concepts you need to know to work with it.

The does not do collision detection, but provides collision respones, that is you provide the system with the collision information (collision points of each object and collision normal) and it will handle the rest.

To convert from a 3D physics engine to a 2D one just call once in a while a function to adjust Z parameters to 0 (to avoid numerical artifacts) and don't use the third dimension.

There are a few caveats, but I can share the Dynamo related source code, is about 1000 lines and you can get a fast start.

get the code here (http://www.nurium.com/other/dynamo_code.txt)