{"id":301,"date":"2009-05-30T22:45:59","date_gmt":"2009-05-31T05:45:59","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=1471"},"modified":"2009-05-30T22:45:59","modified_gmt":"2009-05-31T05:45:59","slug":"quickbox2d-polys","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=301","title":{"rendered":"QuickBox2D Polys"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nimport com.actionsnippet.qbox.*;\r\n\r\n&#x5B;SWF(backgroundColor=0x000000, width=700, height=600)]\r\n\r\nvar sim:QuickBox2D = new QuickBox2D(this);\r\n\r\nsim.setDefault({fillColor:0x003366, lineColor:0x2B80D5});\r\nsim.createStageWalls();\r\n\r\nvar i:int = 0;\r\nfor (i= 0; i&lt;10; i++){\r\n  sim.addCircle({x:5 + i, y:7, radius:0.3, linearDamping:1, angularDamping:1, fillColor:0x78B4C2, isBullet:true});\t\r\n}\r\n\r\nfor (i= 0; i&lt;2; i++){\r\n\tvar poly:Array = &#x5B;];\r\n\tvar r:Number = 3;\r\n\tvar step:Number = Math.PI \/ 6;\r\n\tfor (var t:Number = 0; t&lt;=Math.PI; t+=step){\r\n\t\tpoly.push(r * Math.cos(t));\r\n\t\tpoly.push(r * Math.sin(t));\r\n\t}\r\n\tr = 2;\r\n\tfor (t = Math.PI; t &gt;= -step; t-=step){\r\n\t\tpoly.push(r * Math.cos(t));\r\n\t\tpoly.push(r * Math.sin(t));\r\n\t}\r\n\t\/\/ using points instead of verts causes QuickBox2D to triangulate the polygon\r\n\t\/\/ the wireframe boolean changes rendering style for polys\r\n\tsim.addPoly({x:4 + i *7, y:16, points:poly, wireframe:Boolean(i), linearDamping:1.5, angularDamping:1});\r\n}\r\n\r\nsim.start();\r\nsim.mouseDrag();\r\n<\/pre>\n<p>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. <\/p>\n<p>You&#8217;ll need QuickBox2D Alpha 106 or greater, if you want to test this&#8230;. <\/p>\n<p><a data-asruffle-linked=\"true\" href=\"http:\/\/www.actionsnippet.com\/swfs\/better_polys.html\" target=\"blank\"><br \/>\nor just have a look at the demo here.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/actionsnippet.com\/wp-content\/poly_blue_qb2d.gif\" \/><\/a> <span class=\"asruffle-link\" data-swf=\"{&quot;url&quot;:&quot;https:\\\/\\\/actionsnippet.com\\\/swfs\\\/better_polys.swf&quot;,&quot;title&quot;:&quot;better polys&quot;,&quot;width&quot;:700,&quot;height&quot;:600,&quot;missing&quot;:false,&quot;allowScriptAccess&quot;:false,&quot;backgroundColor&quot;:&quot;#000000&quot;}\"><button type=\"button\" hidden aria-expanded=\"false\">Play demo<span class=\"screen-reader-text\">: better polys<\/span><\/button><\/span><\/p>\n<p>This triangulation is really better suited for 3D stuff &#8211; Box2D supports multiple convex polygons in one rigid body&#8230; this algorithm makes more shapes (triangles) than Box2D needs &#8211; I&#8217;ll probably swap out the algorithm in the near future.<\/p>\n<p>Tomorrow I&#8217;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. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>import com.actionsnippet.qbox.*; &#x5B;SWF(backgroundColor=0x000000, width=700, height=600)] var sim:QuickBox2D = new QuickBox2D(this); sim.setDefault({fillColor:0x003366, lineColor:0x2B80D5}); sim.createStageWalls(); var i:int = 0; for (i= 0; i&lt;10; i++){ sim.addCircle({x:5 + i, y:7, radius:0.3, linearDamping:1, angularDamping:1, fillColor:0x78B4C2, isBullet:true}); } for (i= 0; i&lt;2; i++){ var poly:Array = &#x5B;]; var r:Number = 3; var step:Number = Math.PI \/ 6; for (var t:Number = [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,13,12],"tags":[3,4],"class_list":["post-301","post","type-post","status-publish","format-standard","hentry","category-box2d","category-motion","category-quickbox2d","tag-actionscript","tag-flash"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/301","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=301"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/301\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=301"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=301"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=301"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}