2D Rigid Body Dynamics
2D Rigid Body Dynamics
2D rigid body dynamics source code
All in FreeBASIC. No additional libraries needed. Program will compile/run under fb.15, fb.16, win32/linux.
Download Source: rigid_source.zip 19K
It supports the following:
* linear and angular momentum in 2D
* Collision detection/resolution for object/world and object/object interactions
* Scene files to describe shapes and objects to be used in the simulation
* Elastics which can be added realtime during the simulation either object to object or object to world. using the mouse.
* Controls for zooming/panning the scene, restarting, and deleting all eleastics.
All instructions are in the readme.txt, but here's a summary:
make with `mkrigid.bat' or `./mkrigid.sh'
run with `rigid [scenefilename]'
where [scenefilename] is the name of a scene. Defaults to default.ini if not present. I have included four simple scenes to try out in addition to the default.
There are many problems yet to solve in this physics engine, so if you are thinking adding physics to a game, you should also watch the topic Newton Game Dynamics for developments as it is a very powerful physics engine.
Download Source: rigid_source.zip 36K
All in FreeBASIC. No additional libraries needed. Program will compile/run under fb.15, fb.16, win32/linux.
Download Source: rigid_source.zip 19K
It supports the following:
* linear and angular momentum in 2D
* Collision detection/resolution for object/world and object/object interactions
* Scene files to describe shapes and objects to be used in the simulation
* Elastics which can be added realtime during the simulation either object to object or object to world. using the mouse.
* Controls for zooming/panning the scene, restarting, and deleting all eleastics.
All instructions are in the readme.txt, but here's a summary:
make with `mkrigid.bat' or `./mkrigid.sh'
run with `rigid [scenefilename]'
where [scenefilename] is the name of a scene. Defaults to default.ini if not present. I have included four simple scenes to try out in addition to the default.
There are many problems yet to solve in this physics engine, so if you are thinking adding physics to a game, you should also watch the topic Newton Game Dynamics for developments as it is a very powerful physics engine.
Download Source: rigid_source.zip 36K
Last edited by coderJeff on Apr 01, 2006 15:28, edited 1 time in total.
-
- Posts: 10
- Joined: Mar 10, 2006 9:46
Thanks to everyone who tried it out and sorry I didn't post back sooner.
Getting to the next step is harder than I thought. The simulation mostly works but not always. (Which is just another way of saying it doesn't work). All of the math used so far can be applied to a 3D simulation except for rotation I think I'll make a 3D version after I work out the problems in 2D first.
I have added a 2D BSP model for the world. So collision detection is pretty much perfect. Actually, that part of the simulation is very robust. I can accurately and reliably detect collisions between objects and world. And singular collisions seem to resolve just fine. What I can't do at the moment, is properly resolve multiple simultaneous collisions. So what sometimes happens is that objects get in to a state where the collision resolver can't compute a way out of it and the simulation hangs.
I've read a few more papers and found a few more snippets of code in C/C++ on the subject this week and am going to try and implement something new for multiple collision resolution.
Getting to the next step is harder than I thought. The simulation mostly works but not always. (Which is just another way of saying it doesn't work). All of the math used so far can be applied to a 3D simulation except for rotation I think I'll make a 3D version after I work out the problems in 2D first.
I have added a 2D BSP model for the world. So collision detection is pretty much perfect. Actually, that part of the simulation is very robust. I can accurately and reliably detect collisions between objects and world. And singular collisions seem to resolve just fine. What I can't do at the moment, is properly resolve multiple simultaneous collisions. So what sometimes happens is that objects get in to a state where the collision resolver can't compute a way out of it and the simulation hangs.
I've read a few more papers and found a few more snippets of code in C/C++ on the subject this week and am going to try and implement something new for multiple collision resolution.
Dr_D, I hear what you are saying. It seems that that's the least of my problems at the moment though. I think taking the midpoint helps to reduce the effects caused by one point hitting "first" followed by another point, when actually both are occuring at the same time.
I've been working quite a bit on this project. Thankfully it is interesting to me even if it is not completely working right. It some ways it's now better. There are a few situations that really give me problems. For example the hammer shape, which is thin and can rotate quickly sometimes tunnels in to other shapes. Which means I should be doing a swept test for collision rather than an overlap.
Anyway, I updated the download and the screen image in the first post. The scenes are still basic testing scenes.
New features:
* Added 2D BSP (very basic)
* Many changes to scene files
* right mouse button/drag forces an object to move. Mouse wheel will rotate the object
* Added a caption each scene to explain what it is I'm trying to test:
Download Source: rigid_source.zip 36K
Web page on this project is here: http://frontpage.execulink.com/coder/fr ... /rigid.asp
Also, it seems there is a rigid body dynamics ninja stickman fighting game called 'N' available here: http://www.harveycartel.org/metanet/n.html. NO source code but some very good on-line interactive tutorials about collision detection.
I've been working quite a bit on this project. Thankfully it is interesting to me even if it is not completely working right. It some ways it's now better. There are a few situations that really give me problems. For example the hammer shape, which is thin and can rotate quickly sometimes tunnels in to other shapes. Which means I should be doing a swept test for collision rather than an overlap.
Anyway, I updated the download and the screen image in the first post. The scenes are still basic testing scenes.
New features:
* Added 2D BSP (very basic)
* Many changes to scene files
* right mouse button/drag forces an object to move. Mouse wheel will rotate the object
* Added a caption each scene to explain what it is I'm trying to test:
Download Source: rigid_source.zip 36K
Web page on this project is here: http://frontpage.execulink.com/coder/fr ... /rigid.asp
Also, it seems there is a rigid body dynamics ninja stickman fighting game called 'N' available here: http://www.harveycartel.org/metanet/n.html. NO source code but some very good on-line interactive tutorials about collision detection.
-
- Posts: 605
- Joined: Feb 18, 2006 13:30
- Location: Alexandria / Egypt
- Contact:
thanks, voodooattack and rdc
They should be able to still move with the mouse though. That's my fall back plan for now. When objects get in to a situation where the collisions can't be resolved, I just set the velocity for that object to zero. Not very realistic I know, but at least it's better than the simulation hanging up. It should only happen when objects are pinned against the world. I think I can fix it by prioritizing the collisions and resolving them in the "proper" order. (which should also handle with situations like stacking)voodooattack wrote:when u take the ball and throw it at a wall, it will bounce fine..
but when it hits other dynamic objects, it'll simply "freeze", looks strange
Ok, I get an error too here, looks like I didn't test the most recent version with -exx and it dies on startup.
EDIT: Nevermind, that was just FB15 throwing an error on GetMouse. Don't know mambazo. It works here with fb15/16 win32 and fb16 linux.
What happens when you try this:
EDIT: Nevermind, that was just FB15 throwing an error on GetMouse. Don't know mambazo. It works here with fb15/16 win32 and fb16 linux.
What happens when you try this:
Code: Select all
rigid scene3.ini