New version of Box2D

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

New version of Box2D

Postby hrabia » Mon Nov 19, 2012 1:00 am

I have made a port of new Box2D for AndEngine. You can find it here:

https://github.com/RealFictionFactory/A ... DExtension

11.12.2012: I have added two new methods: createEdgeBody and createChainBody to the PhysicsFactory class.

For debug rendering please use Nazgee's AndEngineDebugDrawExtension:

https://github.com/nazgee/AndEngineDebugDrawExtension

Just let me know if there are any problems.

[UPDATE 11.12.2012] Both GLES2 and GLES2-AnchorCenter branches are supported.
Last edited by hrabia on Tue Dec 11, 2012 10:58 am, edited 3 times in total.
hrabia
 
Posts: 9
Joined: Sat Jul 14, 2012 5:10 pm

Re: New version of Box2D

Postby OzLark » Mon Nov 19, 2012 1:27 am

That's fantastic, can't wait to try it out!

Does it not work with nazgee's new debug draw extension? features/box2d-debug-draw-working-and-simple-to-use-t9791.html

Thanks a lot for sharing!

Cheers.
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: New version of Box2D

Postby hrabia » Mon Nov 19, 2012 9:56 am

I haven't tried it yet. I have implemented RealMayo's debugdraw. But it seems that Nazgee's solution may be a little smoother as it does not require AndEngine modification.

I will take a look on it.
Last edited by hrabia on Mon Nov 19, 2012 11:48 am, edited 1 time in total.
hrabia
 
Posts: 9
Joined: Sat Jul 14, 2012 5:10 pm

Re: New version of Box2D

Postby OzLark » Mon Nov 19, 2012 10:18 am

@hrabia, I've incorporated your version of box2d and it seems to work just fine for me (no regressions form the original).

But it doesn't work with nazgee's debug draw extension:

java.lang.ClassCastException: com.badlogic.gdx.physics.box2d.EdgeShape cannot be cast to com.badlogic.gdx.physics.box2d.PolygonShape

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. 11-19 18:42:15.097: E/AndroidRuntime(14969): FATAL EXCEPTION: UpdateThread
  2. 11-19 18:42:15.097: E/AndroidRuntime(14969): java.lang.ClassCastException: com.badlogic.gdx.physics.box2d.EdgeShape cannot be cast to com.badlogic.gdx.physics.box2d.PolygonShape
  3. 11-19 18:42:15.097: E/AndroidRuntime(14969):    at org.andengine.extension.debugdraw.DebugRenderer$RenderOfPolyFixture.<init>(DebugRenderer.java:187)
  4. 11-19 18:42:15.097: E/AndroidRuntime(14969):    at org.andengine.extension.debugdraw.DebugRenderer$RenderOfBody.<init>(DebugRenderer.java:224)
  5. 11-19 18:42:15.097: E/AndroidRuntime(14969):    at org.andengine.extension.debugdraw.DebugRenderer.onManagedUpdate(DebugRenderer.java:64)
  6. 11-19 18:42:15.097: E/AndroidRuntime(14969):    at org.andengine.entity.Entity.onUpdate(Entity.java:1167)
  7. 11-19 18:42:15.097: E/AndroidRuntime(14969):    at org.andengine.entity.Entity.onManagedUpdate(Entity.java:1402)
  8. 11-19 18:42:15.097: E/AndroidRuntime(14969):    at org.andengine.entity.scene.Scene.onManagedUpdate(Scene.java:284)
  9. 11-19 18:42:15.097: E/AndroidRuntime(14969):    at org.andengine.entity.Entity.onUpdate(Entity.java:1167)
  10. 11-19 18:42:15.097: E/AndroidRuntime(14969):    at org.andengine.engine.Engine.onUpdateScene(Engine.java:590)
  11. 11-19 18:42:15.097: E/AndroidRuntime(14969):    at org.andengine.engine.Engine.onUpdate(Engine.java:585)
  12. 11-19 18:42:15.097: E/AndroidRuntime(14969):    at com.larku.andengine.utils.FixedStepMaxFPSEngine.onUpdate(FixedStepMaxFPSEngine.java:72)
  13. 11-19 18:42:15.097: E/AndroidRuntime(14969):    at org.andengine.engine.Engine.onTickUpdate(Engine.java:547)
  14. 11-19 18:42:15.097: E/AndroidRuntime(14969):    at org.andengine.engine.Engine$UpdateThread.run(Engine.java:819)
Parsed in 0.014 seconds, using GeSHi 1.0.8.4


Thanks again for this contribution - it's going to be handy to be able to use edge & chain shapes..
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: New version of Box2D

Postby hrabia » Mon Nov 19, 2012 11:29 am

I have justr tried and it seems to work for me.

Have you removed Box2dDebugRenderer.java file from the Box2D plugin project?

Could you provide me with more details, what have you tested, the sourcecode you have vritten to implement debug dwawing woyld be helpful.
hrabia
 
Posts: 9
Joined: Sat Jul 14, 2012 5:10 pm

Re: New version of Box2D

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

hrabia wrote:I have justr tried and it seems to work for me.

Have you removed Box2dDebugRenderer.java file from the Box2D plugin project?

Could you provide me with more details, what have you tested, the sourcecode you have vritten to implement debug dwawing woyld be helpful.



It's a large mature project that's been using the original box2d extension and both recastrodiaz's debug draw (that's what is in RealMayo's repo) and nazgee's new debug draw extension without issue. I enable the debug draw using:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. DebugRenderer debug = new DebugRenderer(mPhysicsWorld, vertexBufferObjectManager);
  2. attachChild(debug);
Parsed in 0.011 seconds, using GeSHi 1.0.8.4


Not much can go wrong there...

The body types I'm using are:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. //
  2. // Factory created
  3. //
  4. PhysicsFactory.createBoxBody(...) // static and dynamic
  5. PhysicsFactory.createTrianglulatedBody(...) // only static
  6. PhysicsFactory.createLineBody(...) // only static
  7. PhysicsFactory.createCircleBody(...) // only dynamic
  8.  
  9. //
  10. //Hand constructed
  11. //
  12. com.badlogic.gdx.physics.box2d.PolygonShape(...) // dynamic
  13. com.badlogic.gdx.physics.box2d.CircleShape(...) // dynamic
Parsed in 0.012 seconds, using GeSHi 1.0.8.4


I expect the issue is with PhysicsFactory.createLineBody(...) as that creates EdgeShapes - and since AE's support for Box2d didn't include EdgeShapes before I assume that the debug renderer does not expect/support these.
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: New version of Box2D

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

I fixed nazgee's debug renderer for edge shapes by adding:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         /**
  2.          * Polygonal fixture representation
  3.          * @author OzLark
  4.          */
  5.         private static class RenderOfEdgeFixture extends RenderOfFixture {
  6.                 public RenderOfEdgeFixture(Fixture fixture, VertexBufferObjectManager pVBO) {
  7.                         super(fixture);
  8.  
  9.                         EdgeShape fixtureShape = (EdgeShape) fixture.getShape();
  10.                        
  11.                         float[] xPoints = new float[2];
  12.                         float[] yPoints = new float[2];
  13.  
  14.                         Vector2 vertex = Vector2Pool.obtain();
  15.  
  16.                         fixtureShape.getVertex1(vertex);
  17.                         xPoints[0] = vertex.x * PhysicsConnector.PIXEL_TO_METER_RATIO_DEFAULT;
  18.                         yPoints[0] = vertex.y * PhysicsConnector.PIXEL_TO_METER_RATIO_DEFAULT;
  19.  
  20.                         fixtureShape.getVertex2(vertex);
  21.                         xPoints[1] = vertex.x * PhysicsConnector.PIXEL_TO_METER_RATIO_DEFAULT;
  22.                         yPoints[1] = vertex.y * PhysicsConnector.PIXEL_TO_METER_RATIO_DEFAULT;
  23.  
  24.                         Vector2Pool.recycle(vertex);
  25.  
  26.                         entity = new PolyLine(0, 0, xPoints, yPoints, pVBO);
  27.                 }
  28.         }
Parsed in 0.012 seconds, using GeSHi 1.0.8.4


And modifying:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public RenderOfBody(Body pBody, VertexBufferObjectManager pVBO) {
  2.                         ArrayList<Fixture> fixtures = pBody.getFixtureList();
  3.  
  4.                         /**
  5.                          * Spawn all IRenderOfFixture for this body that are out there,
  6.                          * and bind them to this RenderOfBody
  7.                          */
  8.                         for (Fixture fixture : fixtures) {
  9.                                 IRenderOfFixture renderOfFixture;
  10.                                 if (fixture.getShape().getType() == Type.Circle) {
  11.                                         renderOfFixture = new RenderOfCircleFixture(fixture, pVBO);
  12.                                 }
  13.                                 //
  14.                                 // OzLark: Added the following condition for edge shapes
  15.                                 //
  16.                                 else if (fixture.getShape().getType() == Type.Edge) {
  17.                                         renderOfFixture = new RenderOfEdgeFixture(fixture, pVBO);
  18.                                 } else {
  19.                                         renderOfFixture = new RenderOfPolyFixture(fixture, pVBO);
  20.                                 }
  21.  
  22.                                 updateColor();
  23.                                 mRenderFixtures.add(renderOfFixture);
  24.                                 this.attachChild(renderOfFixture.getEntity());
  25.                         }
  26.                 }
Parsed in 0.012 seconds, using GeSHi 1.0.8.4



This still doesn't handle Chain shapes - I don't use them at the moment so that's not an issue for me, but similar will need to be done for them.
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: New version of Box2D

Postby hrabia » Mon Nov 19, 2012 1:36 pm

Yes, you are right. New Box2D introduced EdgeShape to replace PolygonShape used to draw lines. It requires DebugRenderers to be updated.
hrabia
 
Posts: 9
Joined: Sat Jul 14, 2012 5:10 pm

Re: New version of Box2D

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

I just had another quick look and it seems that supporting ChainShapes is just a copy/paste of PolyShape with the type and cast to ChainShape instead of PolyShape.

I don't use any chain shapes so I don't have anything to test against quickly...
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: New version of Box2D

Postby korn3l » Mon Nov 19, 2012 1:56 pm

I think that this extension should work with the original branch of andengine since most people are hesitant when it comes to using other branches. I also don't see why it is necessary to use it, you can always use nazgee's debug draw extension witch works really nice.
korn3l
 
Posts: 214
Joined: Thu Apr 12, 2012 4:20 pm
Location: Iasi, Romania

Next

Return to Features

Who is online

Users browsing this forum: No registered users and 10 guests