{"id":317,"date":"2009-06-15T23:20:12","date_gmt":"2009-06-16T06:20:12","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=1538"},"modified":"2009-06-15T23:20:12","modified_gmt":"2009-06-16T06:20:12","slug":"quickbox2d-frim","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=317","title":{"rendered":"QuickBox2D FRIM"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nimport com.actionsnippet.qbox.*;\r\nimport Box2D.Common.Math.*;\r\n\r\n\/\/ try altering your frame rate\r\n&#x5B;SWF(backgroundColor=0x000000, width=700, height=600, frameRate=30)]\r\n\/\/ try setting frim to false\r\nvar sim:QuickBox2D = new QuickBox2D(this, {iterations:20, timeStep:1 \/ 60, frim:true});\r\n\r\nsim.setDefault({fillColor:0x003366, lineAlpha:0});\r\nsim.createStageWalls();\r\n\r\nsim.addBox({x:10, y:18, height:3, density:0});\r\n\r\nsim.setDefault({fillColor:0x004466, lineColor:0x2B80F5});\r\n\r\nvar cVel:b2Vec2 = new b2Vec2();\r\n\r\nfor (var i:int = 0; i&lt;32; i++){\r\n\tvar c:QuickObject = sim.addCircle({x:13 + i % 8, y:10 + int(i \/ 8), friction:0.01, radius:0.2 + Math.random()*0.3, angularDamping:1});\r\n\tcVel.x = Math.random() * 4 - 2;\r\n\tcVel.y = Math.random() * 4 - 2;\r\n\tc.body.SetLinearVelocity(cVel);\r\n}\r\n\r\nvar box:QuickObject = sim.addBox({x:3, y:16, width:2, height: 2});\r\nvar boxVel:b2Vec2 = new b2Vec2(15, -25);\r\n\r\nsim.start();\r\n\r\n\/\/ shoot the box from left to right\r\nsetTimeout(positionBox, 200);\r\nfunction positionBox():void{\r\n\t\/\/ reset box position\r\n\tbox.x = 3, box.y = 16;\r\n\tsetTimeout(shootBox, 500);\r\n}\r\nfunction shootBox():void{\r\n\tbox.body.SetLinearVelocity(boxVel);\r\n\tbox.body.SetAngularVelocity(10);\r\n\t\/\/ shoot the box again\r\n\tsetTimeout(positionBox, 4000);\r\n}\r\n<\/pre>\n<p>You&#8217;ll need to download the latest version of <a href=\"https:\/\/actionsnippet.com\/?page_id=1391\" target=\"blank\">QuickBox2D<\/a> in order to run this snippet (alpha 107 as of this post). I recommend checking out the demo below first though&#8230;<\/p>\n<p>The most notable feature of this release is FRIM (frame rate independent motion). FRIM is used to attempt to keep the speed of the Box2D simulation constant no matter what frame rate the swf is running at. This is good because frame rates will vary from browser to browser and from computer to computer. <\/p>\n<p><a href=\"http:\/\/mrdoob.com\/\" target=\"blank\">Mr.Doob<\/a> suggested that I implement this feature in QuickBox2D. If you haven&#8217;t seen <a href=\"http:\/\/mrdoob.com\/\" target=\"blank\">his site<\/a> I highly recommend checking it out &#8211; really great stuff there.<\/p>\n<p>I created a demo to illustrate the FRIM feature&#8230; this demo is basically the same as the above snippet with a few extra buttons added to control frame rate and toggle FRIM.<\/p>\n<p><a data-asruffle-linked=\"true\" href=\"https:\/\/actionsnippet.com\/swfs\/qbox_FRIM.html\" target=\"blank\"><br \/>\nTake a look at the demo here&#8230;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/actionsnippet.com\/wp-content\/qbox_frim.gif\" \/><\/a> <span class=\"asruffle-link\" data-swf=\"{&quot;url&quot;:&quot;https:\\\/\\\/actionsnippet.com\\\/swfs\\\/qbox_FRIM.swf&quot;,&quot;title&quot;:&quot;qbox FRIM&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\">: qbox FRIM<\/span><\/button><\/span><\/p>\n<p>While this new feature seems to be working, I believe there still may be room for improvement. Please let me know if the demo doesn&#8217;t work correctly on your machine. As of now, I&#8217;ve only tested it on my 2.5 Ghz Intel Core 2 Duo.<\/p>\n<p>Also, any suggestions to improve the clarity of this demo are appreciated&#8230; I found it kind of hard to think of a good demo to show FRIM in action. The original demo really didn&#8217;t make much sense&#8230; so I gave <a href=\"http:\/\/www.oreillynet.com\/pub\/au\/2392\" target=\"blank\">Rich Shupe<\/a> a call and he helped me come up with the idea for the current demo.<\/p>\n<p>UPDATE:<br \/>\n<em>I just updated the demo so that the simulation restarts when you change the frame rate (as per Mr.doob&#8217;s suggestion below)<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>import com.actionsnippet.qbox.*; import Box2D.Common.Math.*; \/\/ try altering your frame rate &#x5B;SWF(backgroundColor=0x000000, width=700, height=600, frameRate=30)] \/\/ try setting frim to false var sim:QuickBox2D = new QuickBox2D(this, {iterations:20, timeStep:1 \/ 60, frim:true}); sim.setDefault({fillColor:0x003366, lineAlpha:0}); sim.createStageWalls(); sim.addBox({x:10, y:18, height:3, density:0}); sim.setDefault({fillColor:0x004466, lineColor:0x2B80F5}); var cVel:b2Vec2 = new b2Vec2(); for (var i:int = 0; i&lt;32; i++){ var c:QuickObject = sim.addCircle({x:13 [&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,125],"class_list":["post-317","post","type-post","status-publish","format-standard","hentry","category-box2d","category-motion","category-quickbox2d","tag-actionscript","tag-as3","tag-box2d","tag-flash","tag-frim"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/317","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=317"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/317\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=317"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=317"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=317"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}