Sign in to follow this  
Vile V

Physics Framework

Recommended Posts

Vile V    100
Hello everyone,


I am not entirely sure this is the correct board to post this to, since it is more a design question than an actual physics question. If so, please move my ramblings to where-ever they should be :P


For the past month I've been working on a simple 2D Engine using XNA 4.0 and Irrklang for audio. It's more or less finished, apart from the physics. Because of the simplicity of the first few games I have in mind for which I will use this engine I do not require more than the very basics of Physics such as collision detection between rectangles and spheres. (that's basically it) I've been working on it quite a bit and slowly but surely it's taking shape. My main question really is, what are some "good" ways to bring all the theory and all the classes together in a solid physics framework. What I mean is, I have a class Body, a class Shape and a class World.
World contains information such as the Gravity, etc, and also all the Physics Bodies currently in the scene. Bodies have properties such as acceleration, velocity and position and Shape is the shape of the object. (for now limited to circular and rectangular) I've created game engines in the past but I've never had to work with a Physics Engine from scratch and to my dismay I didn't get the opportunity to properly work with them at my internship either. As such I am not sure that my approach is the correct one.

So far I have a single Physics World which is updated (it's an XNA game component) and which in turn updates Bodies who apply their velocities. I am mostly stuck on where and when to check for collisions. Do I check if objects colide right after translating one? Or do I simply translate everything and THEN check for possible collisions. (the latter, I think, would give problems when two fast moving objects just pass one another by) Also, what is a good way to handle these collisions? Do I use events to which objects using the PhysicsBody subscribe? Or are there "better" ways of doing this?

I hope I am making sense with this, because as you can probably see, creating an easy-to-use, fluent Physics Engine isn't exactly something I have done before. I am not really having any problems with the maths aspect of it, but simply plugging it all into my engine properly is causing hiccups on my part.


If anyone knows of any good tutorials pertaining to this quite specific problem I would be very grateful for being pointed in the right direction. I'm also well aware that "good" and "better" are all matters of perspective, but I think everyone would agree that while there are no perfect ways of handling certain problems, there are plenty of wrong ways, and mine could be one of them.
Thank you in advance ^^

Share this post


Link to post
Share on other sites
Vile V    100
[quote name='Dirk Gregorius' timestamp='1302486827' post='4796904']
Check Box2D.org. There is a version called Box2D Lite within the GDC presentation which should be a great guidance.
[/quote]


I had taken a look at it before, but when scouting for a Physics Engine to use. I'll see if I can learn anything from them than.

Thank you for the quick answer :)

Share this post


Link to post
Share on other sites
wildbunny    550
[quote name='Vile V' timestamp='1302512306' post='4797017']
[quote name='Dirk Gregorius' timestamp='1302486827' post='4796904']
Check Box2D.org. There is a version called Box2D Lite within the GDC presentation which should be a great guidance.
[/quote]


I had taken a look at it before, but when scouting for a Physics Engine to use. I'll see if I can learn anything from them than.

Thank you for the quick answer :)
[/quote]


Hi Vile V,

Did you see my article about the basic structure of a physics engine ?:

http://www.wildbunny.co.uk/blog/2011/04/06/physics-engines-for-dummies/

:)

Cheers, Paul.

Share this post


Link to post
Share on other sites
wildbunny    550
Apologies to anyone trying to follow my link above, our blog host just shut us down without warning because we were using 60% CPU of an entire server cluster :|

Doing all i can to get it back up asap :)

Cheers, Paul.

Share this post


Link to post
Share on other sites
Vile V    100
[quote name='wildbunny' timestamp='1302535171' post='4797147']
Apologies to anyone trying to follow my link above, our blog host just shut us down without warning because we were using 60% CPU of an entire server cluster :|

Doing all i can to get it back up asap :)

Cheers, Paul.


[/quote]


I only just checked it out, and it's fixed, so no inconvenience on my part :)
This resource is very useful, I just finished reading the Box2D documentation and it's helped quite a bit to get things to organise in my chaotic head. I'll read over your tutorial as well, the more information I can gather, the better.

Thanks again.

Share this post


Link to post
Share on other sites
Vile V    100
I've checked out the links and while they've been helpful I'm still having a hard time wrapping my head around the flow of it all. How would a collision resolution work? How do you get control over such a resolution when you're using the engine for a game? (because sometimes you want things to smash when they hit something for example)

If anyone can give me a clear flow I might finally get it through my thick skull lol.
What I have in mind is the following:

-World is created and has a Gravity property.
-World is updated and applies gravity to all PhysicsBodies, it then updates those PhysicsBodies, allowing them to add their velocities to their positions. And then it checks for possible collisions.
-Whenever there's a collision the CollisionStart event is raised.
-A CollisionReport struct is created containing information such as where the bodies collided.
-That report is used by the World to resolve the collision and move objects back to where they should be.

Is this a possible good approach?


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this