Physics mods?

Monkey Archive Forums/Monkey Discussion/Physics mods?

GfK(Posted 2013) [#1]
What's the best physics mod for Monkey? Seems to be just Chipmunk and Box2D?

I tried Box2D but the demo code does not compile (there is no Function Main()), and I can't be assed to fix it - be nice if stuff worked out-of-the-box!

Any recommendations? Fancy having a play around with physics.


Skn3(Posted 2013) [#2]
You could checkout flixel, which has basic physics. I think there is a box2d screen/scene in playniax?


AdamRedwoods(Posted 2013) [#3]
to quote ilovepixel:
To run the demo of box2d create a new monkey file and write:

Import box2d.demo

Function Main:Int()
	New MainDemo()
	Return 0
End


...and more monkey Box2D demos at the end of this thread:
http://monkeycoder.co.nz/Community/posts.php?topic=1704


AdamRedwoods(Posted 2013) [#4]
...also fantomEngine (MikeHart) is working on a Box2D integration. not sure how far along he is.


Volker(Posted 2013) [#5]
There is although Fling, a port of the physaxe 2D physics library.
http://www.monkeycoder.co.nz/Community/posts.php?topic=580


rIKmAN(Posted 2013) [#6]
Sounds like you tried to run the actual Box2D file?
You need to do what Adam says and it should all work fine.

There is a Box2D scene in Playniax, but it is just using the existing Box2D mod, it is not tied into the Framework.


GfK(Posted 2013) [#7]
I ran the one called 'demo.monkey', which imported 'maindemo.monkey', so I thought it'd run by doing that.

I'll try out the above suggestion.


muddy_shoes(Posted 2013) [#8]
From the homepage:

"See the QuickStart page for instructions on getting the demo running."

Where "QuickStart" is a link: https://code.google.com/p/monkeybox2d/wiki/QuickStart


Nobuyuki(Posted 2013) [#9]
I also highly recommend reading the box2d manual, since it steps you through the basic terminology and concepts of the engine, including a "hello world" app. This is what I used to start learning it! Just be aware there are a few subtle differences between the official box2d version, and the one that Monkey uses:

1. CreateFixture doesn't have 2 overloads, there is a separate CreateFixture2 method for making a fast fixturedef from a shape.
2. (For now), the const b2_dynamicBody in box2d.Monkey is just b2_Body.


GfK(Posted 2013) [#10]
All working now... incredibly hard to follow with all those demos rolled into one, though. Think I'm starting to understand the basics now.

Thanks!

One thing bewilders me, though. I've just been playing around with stuff using DrawDebugData. Suppose I have a 64x64 image of a crate, what's the approved way of creating a box2D "body" appropriate to the exact size of the image?


Volker(Posted 2013) [#11]
You can use PhysicsEditor:
http://www.codeandweb.com/physicseditor
I haven't updated the last view month, but exporting to
Box2d generic xml is pretty buggy.
I have to flip the shapes vertically and have do some manual adjustments to get it working.
Some helping code here:
http://www.monkeycoder.co.nz/Community/posts.php?topic=3106


GfK(Posted 2013) [#12]
Hm, thanks!!

Oddly enough, I bought TexturePacker from there a few weeks ago. Wasn't bothering with physics at the time though, so I didn't notice PhysicsEditor.


muddy_shoes(Posted 2013) [#13]
Suppose I have a 64x64 image of a crate, what's the approved way of creating a box2D "body" appropriate to the exact size of the image?


It's entirely up to you how you scale from the physics units to your screen pixel units. You shouldn't attempt to scale the physics objects up to match a desired pixel size. Box2D functions best with objects from roughly 0.1m to 10m in either dimension.

I'd suggest deciding how physically large you want the "crate" to be in the simulation and then scaling that size in meters to 64 pixels.


GfK(Posted 2013) [#14]
Thanks, but I don't really understand. Surely the object in the simulation needs to match the pixel dimensions of the graphic it represents?

I haven't attempted anything with "proper" physics before so I am (clearly) a complete idiot on the subject, and would like the methodology to be explained to me with that in mind, if you could. :)


Shinkiro1(Posted 2013) [#15]
I found these videos a while ago: http://www.kerp.net/box2d/
If you want to measure everything in pixels you could do:
Const RADIO:Float = 30
and then divide everything by that value.


muddy_shoes(Posted 2013) [#16]
The physics simulation doesn't measure size in "pixels". It's in meters. If you have a 1m wide crate and you want to draw it using a 64-pixel square image or as a 64 pixel square box then you just scale the physics world by 64 when rendering.

The Demo debug draw has a SetDrawScale Method for doing just this.


Volker(Posted 2013) [#17]
Gfk, you should read this thread:
http://www.monkeycoder.co.nz/Community/posts.php?topic=3106
CopperCircle has added some scaling to his box2d framework.
Take a look at it to get started.