{"id":374,"date":"2009-08-09T23:22:13","date_gmt":"2009-08-10T06:22:13","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=1975"},"modified":"2009-08-09T23:22:13","modified_gmt":"2009-08-10T06:22:13","slug":"quickbox2d-revolute-ragdoll","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=374","title":{"rendered":"QuickBox2D Revolute Ragdoll"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nimport com.actionsnippet.qbox.*;\r\nimport Box2D.Common.Math.*;\r\n\r\n&#x5B;SWF (backgroundColor=0x000000, width=700, height=600, frameRate=60)]\r\n\r\nvar sim:QuickBox2D = new QuickBox2D(this,{debug:false, frim:true, gravityY:1});\r\n\r\nsim.setDefault({fillColor:0x113366, fillAlpha:0.8, lineColor:0x3355AA});\r\n\r\nsim.createStageWalls();\r\n\r\nvar circle:QuickObject = sim.addCircle({x:10, y:10, radius:3});\r\nvar head:QuickObject = sim.addCircle({x:5, y:5, radius:0.5});\r\nvar torsoA:QuickObject = sim.addBox({x:5, y:6, width:1.5, height:0.8})\r\nvar torsoB:QuickObject = sim.addBox({x:5, y:6.5, width:1.25, height:0.8})\r\nvar torsoC:QuickObject = sim.addBox({x:5, y:7, width:1.0, height:0.8})\r\nvar pelvis:QuickObject = sim.addBox({x:5, y:7.5, width:1.0, height:0.8})\r\nvar leftLegA:QuickObject = sim.addBox({x:4.75, y:8.5, width:0.4, height:1.75});\r\nvar leftLegB:QuickObject = sim.addBox({x:4.75, y:9.75, width:0.4, height:1.5});\r\nvar rightLegA:QuickObject = sim.addBox({x:5.29, y:8.5, width:0.4, height:1.75});\r\nvar rightLegB:QuickObject = sim.addBox({x:5.29, y:9.75, width:0.4, height:1.5});\r\nvar leftArmA:QuickObject = sim.addBox({x:3.6, y:5.8, width:1.3, height:0.35});\r\nvar leftArmB:QuickObject = sim.addBox({x:2.5, y:5.8, width:1.25, height:0.35});\r\nvar rightArmA:QuickObject = sim.addBox({x:6.4, y:5.8, width:1.3, height:0.35});\r\nvar rightArmB:QuickObject = sim.addBox({x:7.5, y:5.8, width:1.25, height:0.35});\r\n\r\ntorsoA.body.SetLinearVelocity(new b2Vec2(0, 50));\r\n\r\nvar anchor:b2Vec2 = new b2Vec2();\r\nfunction connect(a:QuickObject, b:QuickObject, lower:Number, upper:Number, offX:Number=0, offY:Number = 0):QuickObject{\r\n\t var min:Number = Math.min(a.y, b.y);\r\n     var max:Number = Math.max(a.y, b.y);\r\n     anchor.y = min + (max - min) * 0.5 + offY;\r\n     min = Math.min(a.x, b.x);\r\n     max = Math.max(a.x, b.x);\r\n     anchor.x = min + (max - min) * 0.5 + offX;\r\n\treturn sim.addJoint({a:a.body, b:b.body, x1:anchor.x, y1:anchor.y, lowerAngle:lower, upperAngle:upper});\r\n}\r\n\r\nsim.setDefault({type:&quot;revolute&quot;, collideConnected:false, enableLimit:true, lineColor:0xFFFFFF});\r\n\r\nconnect(head, torsoA, -.2, .2);\r\nconnect(torsoA, torsoB,-.2, .2);\r\nconnect(torsoC, torsoB,-.2, .2);\r\nconnect(torsoC, pelvis,-.2, .2);\r\n\r\nconnect(pelvis, leftLegA, -1, 1, 0, -0.5);\r\nconnect(leftLegA, leftLegB, -1, 1);\r\n\r\nconnect(pelvis, rightLegA, -1, 1, 0, -0.5);\r\nconnect(rightLegA, rightLegB, -1, 1);\r\n\r\nconnect(torsoA, leftArmA, -2, 1);\r\nconnect(leftArmA, leftArmB, -2, 1);\r\n\r\nconnect(torsoA, rightArmA, -1, 2)\r\nconnect(rightArmA, rightArmB, -1, 2)\r\n\r\nsim.start();\r\nsim.mouseDrag();\r\n \r\n\r\n<\/pre>\n<p><a href=\"https:\/\/actionsnippet.com\/?page_id=1391\" target=\"blank\">QuickBox2D alpha 108<\/a> is finally finished and different types of joints are now possible. I&#8217;ll be auto-posting joint demos over the next few days for each type of Box2D joint. Box2D joints are pretty confusing, I struggled a bit to decide on a good way to handle them in QuickBox2D, any suggestions are welcome.<\/p>\n<p><a data-asruffle-linked=\"true\" href=\"http:\/\/www.actionsnippet.com\/swfs\/revolute_ragdoll.html\" target=\"blank\" ><br \/>\nHave a look at the swf:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/actionsnippet.com\/wp-content\/revolute_rag.gif\" \/><\/a> <span class=\"asruffle-link\" data-swf=\"{&quot;url&quot;:&quot;https:\\\/\\\/actionsnippet.com\\\/swfs\\\/demoRevoluteRagDoll.swf&quot;,&quot;title&quot;:&quot;demoRevoluteRagDoll&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\">: demoRevoluteRagDoll<\/span><\/button><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>import com.actionsnippet.qbox.*; import Box2D.Common.Math.*; &#x5B;SWF (backgroundColor=0x000000, width=700, height=600, frameRate=60)] var sim:QuickBox2D = new QuickBox2D(this,{debug:false, frim:true, gravityY:1}); sim.setDefault({fillColor:0x113366, fillAlpha:0.8, lineColor:0x3355AA}); sim.createStageWalls(); var circle:QuickObject = sim.addCircle({x:10, y:10, radius:3}); var head:QuickObject = sim.addCircle({x:5, y:5, radius:0.5}); var torsoA:QuickObject = sim.addBox({x:5, y:6, width:1.5, height:0.8}) var torsoB:QuickObject = sim.addBox({x:5, y:6.5, width:1.25, height:0.8}) var torsoC:QuickObject = sim.addBox({x:5, y:7, width:1.0, height:0.8}) var pelvis:QuickObject [&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,14,15,4,16],"class_list":["post-374","post","type-post","status-publish","format-standard","hentry","category-box2d","category-motion","category-quickbox2d","tag-actionscript","tag-as3","tag-box2d","tag-flash","tag-quickbox2d"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/374","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=374"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/374\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=374"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=374"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=374"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}