Box2D - examples help

BlitzMax Forums/Brucey's Modules/Box2D - examples help

Brucey(Posted 2008) [#1]
I've been trying to port the Bridge example, and everything appears to be working fine apart from the actual drawing of the graphics.
It seems that Box2D is designed to work at a specific scale (where 1 pixel is not equal to 1 Box2D unit). So, it needs some kind of scaling to display the graphics properly.

Anyhoo, if anyone wants to see where I'm going wrong with the example, the code's in SVN at the usual place.

The mod isn't finished yet, but I tend to write my mods and examples at the same time to check that the wrap is working.

:-)


Armitage 1982(Posted 2008) [#2]
Incredible ! You really work on it :)
That's an excellent and very promising news !

I know what you mean about the scale problem.
Some of the Box2D community tend to scale the Box2D unit to 1 pixel but in that particular case using a 10 pixels cube was like playing with a huge building and of course reduce the quality of the simulation.

I did have a look to the Bridge example in the actual SVN and i must say the visual result is pretty strange indeed.

What i'm about to say it's probably not very helpful but if the problem is around scale maybe using the Cairo Mod and by this using Vectorial defined graphics "could" maybe ease the process of conversion.

Now the Bridge example "practically" finished, do you thing the overall wrapper is still very possible or did you predict some difficulties (other than this scale problem which is in fact a feature of Box2D).

All in all i'm very happy to see you're working on this and wish you the best for this work !

I will lurk in the box2d community just to see if i can report some informations about the scale problem.

Thanks :)


Brucey(Posted 2008) [#3]
do you thing the overall wrapper is still very possible or did you predict some difficulties


For the library itself, I don't foresee any major difficulties. Callbacks are usually easy to add, of which I think there are a few in Box2D. So, mostly the contacts and listener stuff still to do.

Perhaps we just need to come up with our own scaling mechanism. Hopefully not a big task.


Armitage 1982(Posted 2008) [#4]
Excellent news then ! :)

By the way, as you probably notice, there is a new version 2.0.1 which fix some important points (including a rollback to separate CreateStaticBody and CreateDynamicBody functions as 2.0.0 CreateBody with null mass were causing problems) and add numerous of cool examples.

http://www.box2d.org/forum/viewtopic.php?f=2&t=711

Maybe it's worth to work with this one as it's an official release.

I stay tuned with great interest to this topic and worklog :)


Brucey(Posted 2008) [#5]
Actually, I've been getting the Box2D source directly from SVN, so it should generally be up-to or at least newer than the current official release.

Hopefully :-)


Armitage 1982(Posted 2008) [#6]
Good to hear that :)
I feel good about box2d. Nice documentation and huge community will definitely be a plus !


Armitage 1982(Posted 2008) [#7]
Hi Brucey :)

I was wondering if you found time to fix the scales problems around Box2D ?

Have a nice weekend ;)


Brucey(Posted 2008) [#8]
I've finally sorted out the issues with regards drawing using the debugdraw stuff, which has urged me on to work harder on this module again.
There are currently about 5 working examples ported from the box2d testbed app, and all appear to work as expected.

Still lots of functionality to implement, but it's moving along nicely again.

:-)


Armitage 1982(Posted 2008) [#9]
Hello Brucey :-)

Any news around the Box2d Module ?
Thanks !


Brucey(Posted 2008) [#10]
Other than b2DestructionListener, is there anything significant outstanding from the API?

There are still some examples to port, and the documentation needs a bit of work still - I've been porting the Box2d manual, which is quite large.


Space_guy(Posted 2008) [#11]
Sounds good. Im using chipmunk and even though im quite pleased with the results, some times I just feel held back either by poor documentation and lack of activity and development of chipmunk it self or code that works almost like i want it but not fully.

I dont know if box2d will change any of that but it would be interessting to try out


Armitage 1982(Posted 2008) [#12]
@Brucey:

Effectively I miss a few updates lately ^^
Actually I didn't notice that the whole API were (probably) ported (except for b2DestructionListener then but this is not primordial at this moment for me).

Very good idea to put the manual inside the documentation !
I didn't fall on a missing method since I resumed my work

I am very pleased to continue my project thanks to you.

@Space_guy:
Well you should definitely look at Box2d as Chipmunk is based on box2d (lite I think) have some bugs (with restitution for example) and miss a lot of interesting features :)
I have switch from Brucey chipmunk module to the Brucey Box2D and I'm more than happy for the moment !


Armitage 1982(Posted 2008) [#13]
@Brucey:

Though I have absolutely no idea how to use the ContactListener !

1)How to implement ContactListener method Add/Persist/Remove/Result ?
When extends a new type with b2ContactLister and implementing those methods nothing happen ?
CollisionProcessing example cover that part and Test.cpp implement those method.


In the same area there is filtering.

2)Shape filtering the documentation say "Box2D supports 16 Collision categories" I know it can't be 0. In the example we have $0002 $0004 etc. but in Max it's converted with short value.
1..16 ?


3) And finally does shapeDef.GetFilter().SetCategoryBits(myFilterCategory) is the only good way to setup Filter in Max ? SetFilter() (and maybe others setters) won't work as intended. Or maybe it's used internally ?


I know it's lot of questions but they are asked from the more to the less important ^^ Only answer to the first one will be enough (as it worked well for the rest).

Thanks


Brucey(Posted 2008) [#14]
2) the data type used is a uint16, which equates to a BM short (more or less), where $FFFF would set all 16 categories. Remember, it's a bit-mask.

3) I've added a collisionfiltering example, and fixed an issue with b2FilterData ;-)


I'm looking into 1) still :-p


Brucey(Posted 2008) [#15]
When running examples, "C" now toggles on the displaying of contact points, implementing 1) in your list.

:-)


Space_guy(Posted 2008) [#16]
Im trying to place a body after its created and in the documentation it tells me about a method called SetXForm. Its seems to be missing though, GetXForm exists but not Set.

Is there any otehr way to move an object to a specified position after creation?


Armitage 1982(Posted 2008) [#17]
Hey hey :)

Thanks Brucey !

Just a few things again :

A) I don't know if it's normal but there is a problem with the mouseJoint. I need to shift the cursor around any object to grab it. Maybe a scaling problem with ConvertScreenToWorld as it's related to the middle of the screen ?

B) Is the collisionFiltering example work correctly ? Every shapes collide with each others.

I have still some little things to do with my level loader first then I will use the ContactListener Type. Hope I can give you feedback around this point too :-)

I don't know about SetXform since I let Box2d doing all the movement for the moment... Sorry.

Thanks for the update.


Brucey(Posted 2008) [#18]
A) I haven't quite managed to get that right yet, as you've noticed... there's some scaling off somewhere. Any ideas? :-p

B) Yes it is actually... what you really need to do is make the big square fall off and roll towards the big triangle... they'll not collide. Well, they didn't in the "real" testbed app... I really need to add that bullet firing functionality to the examples.

The more feedback the better :-)


Armitage 1982(Posted 2008) [#19]
I will look at the mouseJoint. Who knows ^^

I suppose you know that but DrawPoint isn't registered as callback. This split a little the actual "framework" even if this is trivial ;)

Also I don't know if it's only with my game but the glPointSize command won't work with plot when using others drawing commands in larger project (even if glmax2d framework is selected) so I change the DrawPoint method like this
	Method DrawPoint(p:b2Vec2, size:Float, color:b2Color)
		Local MBlend:Int, MR:Int, MG:Int, MB:Int
		MBlend = GetBlend()
		SetBlend(SOLIDBLEND)
		GetColor(MR, MG, MB)
		SetColor(color.red, color.green, color.blue)
		DrawRect (p.x() * xScale) - (size / 2), (p.y() * (- yScale)) - (size / 2), size, size
		SetBlend(MBlend)
		SetColor(MR, MG, MB)
	End Method

I like backup my rendering settings so I can use a 0.5 Alpha Blend over all other game rending (and see collision points/shapes).
This is just little accommodations I know this file will probably change in the future.


Brucey(Posted 2008) [#20]
I suppose you know that but DrawPoint isn't registered as callback.

Yeah, it's only a part of the "render" stuff in the examples.