Box2d - EdgeShape

Monkey Forums/Monkey Programming/Box2d - EdgeShape

Volker(Posted 2011) [#1]
How do I create an EdgeShape?
The TestEdges demo is broken.
This code throws an error while creating the fixture.
Method CreateEdgeShape:Void()
	Local es:b2EdgeShape=new b2EdgeShape (new b2Vec2(400,100),new b2Vec2(500,100))
	if es=Null Then Error("es=Null")

	
	Local b :b2Body
        Local fd :b2FixtureDef = New b2FixtureDef()		
       	Local bd :b2BodyDef = New b2BodyDef()
   	fd.shape=es
	bd.type=b2Body.b2_staticBody 
'	   	bd.type = b2Body.b2_Body	
	bd.position.Set(150,100)
	b=Self.world.CreateBody(bd)
		'
        fd.density = 1.0 
        fd.friction = 0.5
        fd.restitution = 0.1
	b.CreateFixture(fd)
End Method



muddy_shoes(Posted 2011) [#2]
I seem to remember that the test case wasn't active in the original flash code I converted from. I'll take a look at it at some point in the next day or so.

There are bound to be a number of these sorts of un-tested areas, due in large part to Monkey's behaviour of not compiling anything that isn't actively referenced. That "feature" makes writing and maintaining libraries of any size a bit of a pig.


Volker(Posted 2011) [#3]
I'll take a look at it at some point in the next day or so.

Nice to hear.


muddy_shoes(Posted 2011) [#4]
I wouldn't get too excited. A look at the box2dflash code confirms that the test case wasn't active. It also included an SVG parser that was used to define part of the simulation. I'm highly unlikely to get into porting that as it's just not relevant to me or to Monkey as a whole really.

I'll see what the current box2d C++ lib is doing as far as line segments. If that's easy enough to port then I'll do that. At some point I'll have to bring the monkey port into line with the C++ version anyway as the flash version is out-of-date. That's not going to happen until after I've finished my current project though.


muddy_shoes(Posted 2011) [#5]
Well, digging through the code all I can find is a bunch of TODOs and commented out sections. As far as I can tell, the EdgeShape stuff wasn't finished in the version of the code I ported from. I'll hunt around to see if there's an updated version, but I'm sure that I looked last time.

What I can do is fix up the SetAsEdge call in b2PolygonShape so that you can create line segments. Implementing the chained edges of newer box2d iterations isn't likely to happen very soon.


Volker(Posted 2011) [#6]
Ok, thanks for feedback. No urgent need for that.
Line segments would be fine. I'm still looking for
something to build the level background. ATM I'm simply
using cubes and triangles, and it looks like box2d
can handel a LOT of static bodies.


Armitage1982(Posted 2011) [#7]
As far as I can tell, the EdgeShape stuff wasn't finished in the version of the code I ported from.


Ouch, that's bad :(

Porting libraries from C/C++ to other languages.
Then using the most up-to-date and similar one to create Monkey Modules.
After porting them again to each platform, check if everything is working (probably not on every machines) and finally taking a long time to optimize each trans.

Did someone fell intimidated like me?
Certainly because I don't have enough experiences with all the target, but in a way extending Monkey shouldn't be that hard...

it looks like box2d
can handel a LOT of static bodies


Yeah but IMO it's harder to get a correct simulation with only cubes and triangles as ground object (if it's relevant of course). For example, I remember having problems with contiguous tiled platform object. I know it's doable but less practical without edgeshape.

I have to check the SetAsEdge function in b2PolygonShape.
Anyway, thanks for the module muddy_shoes, it's already a massive amount of work you did there ;)


muddy_shoes(Posted 2011) [#8]
I've committed the minor changes needed to patch up SetAsEdge. I've only done a very simple test of adding one edge to a world and checking that things collide with it. It's very likely that there are other bits that need fixing too.

I can certainly see that having the ability to easily define edge chains is useful for many types of game. In particular if you're writing some sort of side-scroller with the character running/driving/whatever across an uneven landscape. I just don't have the time right now to get into what will likely be several days of effort to understand the new box2d code and then port it.

My current project only uses polygons and circles and I have to prioritise getting that finished before I get into any major reworking of the box2d module.