Box2d debug draw - working and simple to use

  ... the case you feel the need for a new feature or want to submit one.

Box2d debug draw - working and simple to use

Postby nazgee » Sun Nov 04, 2012 12:24 pm

Hi,

If you are interested in debugging BOX2D physics by getting the following:
joints.png
joints and bodies are visible (rope and revolution joints shown)
joints.png (189.68 KiB) Viewed 4545 times

you are kindly invited to continue reading :)

I've been using AE for quite a while now. I remember that when I tried using debug draw by skyuzo I was complaining about some problems it had (see here). He did a good job by sharing his solution, but it just was not good enough...

Few days ago I started playing with box2d again, and once again I've encountered issues with skyuzo's implementation... It just does not handle multiple and complex fixtures correctly, which can cause A LOT of frustration...

To show what I mean- pictures! This is the same scene with the same bodies (and no sprite bound to them, but who cares). As you can see the result IS quite different...

theirs-GLES2.png
skyuzo's debug draw - not working on multi-fixture bodies
theirs-GLES2.png (20.31 KiB) Viewed 4906 times

mine-GLES2.png
new debug draw in action - handles multi fixtures OK
mine-GLES2.png (23.65 KiB) Viewed 4906 times


I tried to rewrite skyuzo's implementation, but could not fix all the issues- some things were just not took into account in the first place, hence were hard to rewrite.

There is one more thing. Even if one is satisfied with how original debug draw by skyuzo works, it was still pain in the ass to use (missing primitives classes). To make life easier, RealMayo shared his solution in this post, but it requires using his branch of AE. This would be OK if his branch would be properly managed. Unfortunately it is just a huge blob with only one "initial commit", which I believe is unacceptable (makes impossible to track what and why was changed).

This is why I implemented my version of debug draw extension.

How do I use it?
Use it as regular AE shared library (e.g. AndEngineLiveWallpaperExtension), and you'll be fine:
1. Clone my project to get the code:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. git clone git://github.com/nazgee/AndEngineDebugDrawExtension.git
Parsed in 0.010 seconds, using GeSHi 1.0.8.4

2. Add my project as a library to your game, by adding this line somewhere in your project.properties file
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. android.library.reference.4=../AndEngineDebugDrawExtension
Parsed in 0.010 seconds, using GeSHi 1.0.8.4

3. Add debug renderer somewhere to your scene
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         DebugRenderer debug = new DebugRenderer(mPhysicsWorld, getVertexBufferObjectManager());
  2.         pScene.attachChild(debug);
Parsed in 0.010 seconds, using GeSHi 1.0.8.4

4. Optional: you might want to make sure that 'debug' has high zindex, so it is always visible (remember to sort stuff)

There are 5 branches available.
Most users will be interested in these two:
1. GLES2 which works with GLES2 branch of AE (default, since most people use it)
2. GLES2-AnchorCenter which works with GLES2-AnchorCenter branch of AE

If you wish to work with latest AndEnginePhysicsBox2DExtension by hrabia (here is my github fork and his original forum thread), you want to use one of these:
3. GLES2-latest-B2D which works with GLES2 branch of AE (default, since most people use it)
4. GLES2-AnchorCenter-latest-B2D which works with GLES2-AnchorCenter branch of AE

And some deprecated/dummy branches:
5. [deprecated] GLES2-old-and-broken which works with GLES2 branch of AE and contains skyuzo's implementation (if you want to test it)

This makes 4 valid configurations available:
pack 1, old B2D from nicolas, GLES2 flavour of AE
GLES2 @ https://github.com/nicolasgramlich/AndEngine
GLES2 @ https://github.com/nicolasgramlich/AndE ... DExtension
GLES2 @ https://github.com/nazgee/AndEngineDebugDrawExtension

pack 2, old B2D from nicolas, AnchorCenter flavour of AE
GLES2-AnchorCenter @ https://github.com/nicolasgramlich/AndEngine
GLES2-AnchorCenter @ https://github.com/nicolasgramlich/AndE ... DExtension
GLES2-AnchorCenter @ https://github.com/nazgee/AndEngineDebugDrawExtension

pack 3, new B2D from hrabia, GLES2 flavour of AE
GLES2 @ https://github.com/nicolasgramlich/AndEngine
GLES2 @ https://github.com/RealFictionFactory/A ... DExtension
GLES2-latest-B2D @ https://github.com/nazgee/AndEngineDebugDrawExtension

pack 4, new B2D from hrabia, AnchorCenter flavour of AE
GLES2-AnchorCenter @ https://github.com/nicolasgramlich/AndEngine
GLES2-AnchorCenter @ https://github.com/RealFictionFactory/A ... DExtension
GLES2-AnchorCenter-latest-B2D @ https://github.com/nazgee/AndEngineDebugDrawExtension

Disclaimer
Code was developed basing on GLES2-AnchorCenter branch of AE. This means, that there *might* be some minor glitches with GLES2 branch. I did a brief testing and have not noticed anything fishy, but still- you have been warned. Please let me know if something does not work as desired- should be very easy to fix (add "-" or "+360" somewhere).

What you get?
- easy to use! does not require manual patching in AE source code or using some external branches
- works fine with multiple fixtures
- shows not only bodies/fixtures, but joints too!
- comes with all required primitives (polyline and ellipse)
- I will gladly accept fixes, and maintain source code

If you do not believe me and want to test multiple fixtures on skyuzos implementation, try these (it creates 'complex' bodies from the pictures above, based on RevolutionJoint example):

- RevolutionJoint example using skyuzo's debug draw with multi-fixture bodies - GLES2
- RevolutionJoint example using my debug draw with multi-fixture bodies - GLES2
- RevolutionJoint example using my debug draw with multi-fixture bodies - GLES2-AnchorCenter

Apply these patches on top of AndEngineExamples, and you are ready to go.
Last edited by nazgee on Tue Jan 15, 2013 6:44 pm, edited 7 times in total.
Dirt Rider Mayhem is PUBLISHED now!
Image
User avatar
nazgee
 
Posts: 527
Joined: Fri Oct 21, 2011 10:31 pm
Location: Poland, Wrocław

Re: Box2d debug draw - working and simple to use

Postby korn3l » Sun Nov 04, 2012 11:48 pm

You sir are my hero !

I also tried skyuzos implementation, but didn't satisfy my needs so I ended up testing physics stuff on libgdx.
I will try this tomorrow and see how it works.
korn3l
 
Posts: 214
Joined: Thu Apr 12, 2012 4:20 pm
Location: Iasi, Romania

Re: Box2d debug draw - working and simple to use

Postby OzLark » Mon Nov 05, 2012 2:55 am

As usual, great work nazgee. Thanks for sharing!
Did this post help you? Feel free to return the gesture by downloading Ninja Bees, creating a level (or more) and sharing it to the Ninja Bees website!

Ninja Bees - Our latest Android game, check it out on Google Play (free) or paid with no ads
OzLark
 
Posts: 1130
Joined: Sun Feb 05, 2012 3:19 am

Re: Box2d debug draw - working and simple to use

Postby jaym » Mon Nov 05, 2012 3:48 am

Nice work!

I'd looked into the old implementation of debug draw but had never made the time to fix/alter code in order to use it within my projects. I appreciate the effort, especially considering it could have otherwise taken quite some time before debug draw made its way to the AnchorCenter branch.

Cheers.
AndEngine for Android Game Development Cookbook - Based on AndEngine's latest, greatest, GLES2.0 AnchorCenter branch!
jaym
 
Posts: 690
Joined: Wed May 04, 2011 10:08 pm

Re: Box2d debug draw - working and simple to use

Postby OzLark » Thu Nov 15, 2012 7:33 am

nazgee wrote:Disclaimer
Code was developed basing on GLES2-AnchorCenter branch of AE. This means, that there *might* be some minor glitches with GLES2 branch. I did a brief testing and have not noticed anything fishy, but still- you have been warned. Please let me know if something does not work as desired- should be very easy to fix (add "-" or "+360" somewhere).


Good disclaimer :). I just tested the GLES2 version and it does in fact have issues. When dynamic bodies rotate things go all nasty (the drawn body totally disconnects from the polygon it's rendering)..
Did this post help you? Feel free to return the gesture by downloading Ninja Bees, creating a level (or more) and sharing it to the Ninja Bees website!

Ninja Bees - Our latest Android game, check it out on Google Play (free) or paid with no ads
OzLark
 
Posts: 1130
Joined: Sun Feb 05, 2012 3:19 am

Re: Box2d debug draw - working and simple to use

Postby OzLark » Thu Nov 15, 2012 7:41 am

I just has a quick look at your debug renderer and you can fix it by commenting out line number 79 for stock GLES2:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. //renderOfBody.setRotationCenter(body.getMassData().center.x * PhysicsConnector.PIXEL_TO_METER_RATIO_DEFAULT, body.getMassData().center.y * PhysicsConnector.PIXEL_TO_METER_RATIO_DEFAULT);
  2.  
Parsed in 0.010 seconds, using GeSHi 1.0.8.4
Did this post help you? Feel free to return the gesture by downloading Ninja Bees, creating a level (or more) and sharing it to the Ninja Bees website!

Ninja Bees - Our latest Android game, check it out on Google Play (free) or paid with no ads
OzLark
 
Posts: 1130
Joined: Sun Feb 05, 2012 3:19 am

Re: Box2d debug draw - working and simple to use

Postby nazgee » Thu Nov 15, 2012 9:01 am

Fixed. Thanks!
(I have no idea why it works, but I need to head off to work- I've already missed few buses)
Dirt Rider Mayhem is PUBLISHED now!
Image
User avatar
nazgee
 
Posts: 527
Joined: Fri Oct 21, 2011 10:31 pm
Location: Poland, Wrocław

Re: Box2d debug draw - working and simple to use

Postby OzLark » Mon Nov 19, 2012 1:35 pm

Hey nazgee,

I've added support for edge shapes here: physics-box2d-extension/new-version-of-box2d-t9908.html#p42595 if you'd like to chuck that into your repo...

I expect supporting ChainShapes is just a copy/paste of PolyShape with the type and cast to ChainShape instead of PolyShape.
Did this post help you? Feel free to return the gesture by downloading Ninja Bees, creating a level (or more) and sharing it to the Ninja Bees website!

Ninja Bees - Our latest Android game, check it out on Google Play (free) or paid with no ads
OzLark
 
Posts: 1130
Joined: Sun Feb 05, 2012 3:19 am

Re: Box2d debug draw - working and simple to use

Postby nazgee » Sat Dec 01, 2012 9:30 pm

Thanks OzLark!

Updated first post with the following information:

There are 5 branches available.
Most users will be interested in these two:
1. GLES2 which works with GLES2 branch of AE (default, since most people use it)
2. GLES2-AnchorCenter which works with GLES2-AnchorCenter branch of AE

If you wish to work with latest AndEnginePhysicsBox2DExtension by hrabia (here is my github fork and his original forum thread), you want to use one of these:
3. GLES2-latest-B2D which works with GLES2 branch of AE (default, since most people use it)
4. GLES2-AnchorCenter-latest-B2D which works with GLES2-AnchorCenter branch of AE

And some deprecated/dummy branches:
5. [deprecated] GLES2-old-and-broken which works with GLES2 branch of AE and contains skyuzo's implementation (if you want to test it)


I also made some minor refactoring- hope everything stays intact.
Dirt Rider Mayhem is PUBLISHED now!
Image
User avatar
nazgee
 
Posts: 527
Joined: Fri Oct 21, 2011 10:31 pm
Location: Poland, Wrocław

Re: Box2d debug draw - working and simple to use

Postby nazgee » Wed Jan 02, 2013 2:58 am

Joints are now supported (see the screenshot in first post of this thread) :)

I tested it only on GLES2-AnchorCenter-latest-B2D, but the rest (GLES2-latest-B2D, GLES2-AnchorCenter and GLES2) should work as well. Let me know if I broke anything ;)
Dirt Rider Mayhem is PUBLISHED now!
Image
User avatar
nazgee
 
Posts: 527
Joined: Fri Oct 21, 2011 10:31 pm
Location: Poland, Wrocław

Next

Return to Features

Who is online

Users browsing this forum: No registered users and 6 guests