QuickBox2D Polys

Actionscript:
1. import com.actionsnippet.qbox.*;
2.
3. [SWF(backgroundColor=0x000000, width=700, height=600)]
4.
5. var sim:QuickBox2D = new QuickBox2D(this);
6.
7. sim.setDefault({fillColor:0x003366, lineColor:0x2B80D5});
8. sim.createStageWalls();
9.
10. var i:int = 0;
11. for (i= 0; i<10; i++){
13. }
14.
15. for (i= 0; i<2; i++){
16.     var poly:Array = [];
17.     var r:Number = 3;
18.     var step:Number = Math.PI / 6;
19.     for (var t:Number = 0; t<=Math.PI; t+=step){
20.         poly.push(r * Math.cos(t));
21.         poly.push(r * Math.sin(t));
22.     }
23.     r = 2;
24.     for (t = Math.PI; t>= -step; t-=step){
25.         poly.push(r * Math.cos(t));
26.         poly.push(r * Math.sin(t));
27.     }
28.     // using points instead of verts causes QuickBox2D to triangulate the polygon
29.     // the wireframe boolean changes rendering style for polys
30.     sim.addPoly({x:4 + i *7, y:16, points:poly, wireframe:Boolean(i), linearDamping:1.5, angularDamping:1});
31. }
32.
33. sim.start();
34. sim.mouseDrag();

I just uploaded QuickBox2D Alpha 106 which includes a few bug fixes and support for compound shapes and easier polys. I used the algorithm from yesterdays post to significantly simplify the way QuickBox2D handles the description of polygons.

You'll need QuickBox2D Alpha 106 or greater, if you want to test this....

or just have a look at the demo here.

This triangulation is really better suited for 3D stuff - Box2D supports multiple convex polygons in one rigid body... this algorithm makes more shapes (triangles) than Box2D needs - I'll probably swap out the algorithm in the near future.

Tomorrow I'll be posting a demo about the way QuickBox2D simplifies compound shapes. I have yet to update the docs to include the new features of Alpha 106. That will happen along with tomorrows post.

1. Ponce
Posted September 30, 2009 at 6:46 am | Permalink

Hello Zevan, I found little bug to try move objects. I do not know exactly how to reproduce it, it happens when you try to move an object against each other at some point the objects are caught in something invisible ..
Sorry for my english

2. Posted September 30, 2009 at 6:58 am | Permalink

Hey ponce - this is a box2D thing… and you can probably fix it by turning on CCD or setting the isBullet property = true in the params object….

3. Ponce
Posted September 30, 2009 at 9:48 am | Permalink

thanks!! =)

4. Mikha
Posted March 5, 2010 at 1:32 am | Permalink

hi zevan

is there a way to add the vertice just like the ordinary box2d way?

like [[1,1],[1,-1],[-1,-1],[-1,1]]

thanks