<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Everyday 3D &#187; JigLibFlash</title>
	<atom:link href="http://www.everyday3d.com/blog/index.php/category/jiglibflash/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.everyday3d.com/blog</link>
	<description>3D user experience on the web. Design, technology news. A blog by Bartek Drozdz.</description>
	<lastBuildDate>Thu, 02 Sep 2010 19:36:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>FOTB&#8217;09 presentation: 3D Bowling demo</title>
		<link>http://www.everyday3d.com/blog/index.php/2009/09/29/fotb09-3d-bowling-demo/</link>
		<comments>http://www.everyday3d.com/blog/index.php/2009/09/29/fotb09-3d-bowling-demo/#comments</comments>
		<pubDate>Tue, 29 Sep 2009 11:17:02 +0000</pubDate>
		<dc:creator>bartek drozdz</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[JigLibFlash]]></category>
		<category><![CDATA[News & Events]]></category>
		<category><![CDATA[Papervision3D]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[bowling game]]></category>
		<category><![CDATA[brighton]]></category>
		<category><![CDATA[conference]]></category>
		<category><![CDATA[elevator pitch]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[flash on the beach]]></category>
		<category><![CDATA[fotb]]></category>
		<category><![CDATA[physics]]></category>
		<category><![CDATA[presentation]]></category>

		<guid isPermaLink="false">http://www.everydayflash.com/blog/?p=573</guid>
		<description><![CDATA[UPDATE Nov 2009 There is a better quality video posted by John from Flash On The Beach. It is available here: http://vimeo.com/7292505. As I promised during my "3 minutes" in Brighton, I publish all the sources of my presentation. I added some comments in the code and removed the part with the slides. Here's also [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.vimeo.com/6768982"><img width="520" height="259" src="http://www.everydayflash.com/flash/fotb/fotb09bowling.png" alt="Video of 3D Bowling Demo, Flash on the Beach 2009" border="0"/></a></p>
<p><strong>UPDATE Nov 2009</strong> <em>There is a better quality video posted by John from Flash On The Beach. It is available here: <a href="http://vimeo.com/7292505">http://vimeo.com/7292505</a>.</em></p>
<p>As I promised during my <strong>"3 minutes"</strong> in Brighton, I publish all the <a href="http://www.everydayflash.com/flash/fotb/fotb09bowling.zip">sources</a> of my presentation. I added some comments in the code and removed the part with the slides.</p>
<p>Here's also the <a href="http://www.everyday3d.com/flash/fotb/"> demo</a> and a <a href="http://www.vimeo.com/6768982">video of the mini-session</a>. The demo is pretty rudimentary - I made so because I wanted to keep things simple during the presentation. I hope that it will be a solid base for someone who wish to create a full featured bowling game in Flash.</p>
<p>There were a few <strong>other implementations</strong> of a bowling game in <a href="http://www.jiglibflash.com/blog/">JigLibFlash</a> and <a href="http://blog.papervision3d.org/">Papervision3D</a>. Initially, guys a <strong>Blitz Agency</strong> published a few <a href="http://labs.blitzagency.com/?p=634">interesting experiments</a> with JigLibFlash, including a simple bowling simulation. <a href="http://blog.onebyonedesign.com/">Devon O. Wolfgang</a> has written a <a href="http://www.thetechlabs.com/tutorials/3d/create-a-3d-bowling-game-with-jiglibflash-and-papervision-3d/">great tutorial</a> about building such a game on <a href="http://www.thetechlabs.com/">Tech Labs</a> - be sure to check it out. I found it only after the presentation and since the tutorial explains a lot of things in details I felt like I was reinventing the wheel here. But hopefully there are still a couple of things I can add. </p>
<p>Thanks to the <a href="http://code.google.com/p/jiglibflash/wiki/New_API_Very_Short_Tutorial">new plugin API</a> we developped some time ago, setting up a scene with JigLib and an 3D engine has got a bit less complicated. However, tweaking the engine can be a hell. Here's a few things I found out:</p>
<p><strong>1. Simulation speed</strong></p>
<p>When you create the physics engine instance, the default speed of the simulation is 1. This is <strong>very slow</strong> and unrealistic. It will look much more natural if the speed is increased. Beware however - at higher speeds the collision detection system can be <strong>very inaccurate</strong> and result in objects running through each other without any collision being detected. I don't think there is a single setting that works fine in every situation, but for this case 9 worked fine for the regular speed simulation, and 2 for the "slow speed". <strong>You should always try different settings.</strong></p>
<p><strong>2. Mass</strong></p>
<p>Each rigid body has a mass property. It's easy to forget about it since it has a default value and it never complains if you don't change it. However, setting the masses right is crucial for a <strong>realistic simulation</strong>. In real world object have different masses, and so they should in a simulation. This is particularly important for a bowling game, where the ball is pretty heavy and the bins are not (I guess... has anyone ever had a bowling pin in his hands?) The trick is that the <strong>masses are relative to each other</strong>, so the more different objects you have the more you need to tweak the masses to get the results right. Also remember the effect of any forces applied to an object is related to it's mass.</p>
<p><strong>3. Physics material</strong></p>
<p>Each rigid body has a property called material which is an instance of the <a href="http://www.jiglibflash.com/docs/jiglib/physics/MaterialProperties.html">MaterialProperties</a> class. It has two properties: <strong>friction and restitution</strong>. I found out that playing with this values has a quite big impact on the simulation. Ex. setting a high value of the restitution results in the object becoming <strong>bouncy</strong> - I used this for the ball in my older <a href="http://www.everydayflash.com/blog/index.php/2009/04/23/jiglibflash-3d-physics/">ping-pong example</a>. In the bowling demo I used lower friction on the ball to make it <strong>slide</strong> more - just as a real bowling ball does. </p>
<p><strong>4. Object rotation</strong></p>
<p>Once a DisplayObject is wrapped into a physics rigid body you can't rely on it's <strong>rotationX, rotationY and rotation</strong>Z propeties anymore - because they <strong>are not being set</strong>. The physics engine sets the transformation matrix directly on the DisplayObject, so if you need to check it's rotation you need to <strong>extract it from the matrix</strong>. Fortunately, there's an easy way to do this:</p>
<div class="igBar"><span id="lactionscript-3"><a href="#" onclick="javascript:showPlainTxt('actionscript-3'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-3">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> p:DisplayObject3D = physics.<span style="color: #006600;">getMesh</span><span style="color: #66cc66;">&#40;</span>pins<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">var</span> h:Number3D = Matrix3D.<span style="color: #006600;">matrix2euler</span><span style="color: #66cc66;">&#40;</span>p.<span style="color: #006600;">transform</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// h.x is the rotationX of the object in this case. </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p><strong>5. Object activity</strong></p>
<p>As a result of multiple forces being applied to an object and multiple collisions sometimes the objects are left in a state where the shake a bit endlessly. This can also happen when the objects are initially positioned. Calling the RigidBody.setInactive() will fix that. And you can call more than once.</p>
<p><strong>Important conclusion: tweak, tweak, tweak...</strong></p>
<p>It is generally agreed that <strong>hardcoded ("magic") numbers</strong> are not a good coding practice. However in 3D animations, and especially with physics the important thing is <strong>not the beauty of the code, but the what you see at the end</strong>. If you browse the source code from this demo you will notice that I not only hardcoded a lot of values, I even left ugly lines like that: </p>
<div class="igBar"><span id="lactionscript-4"><a href="#" onclick="javascript:showPlainTxt('actionscript-4'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">Actionscript:</span>
<div id="actionscript-4">
<div class="actionscript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">force = <span style="color: #66cc66;">&#40;</span>speed == <span style="color: #cc66cc;color:#800000;">9</span><span style="color: #66cc66;">&#41;</span> ? <span style="color: #cc66cc;color:#800000;">5000</span> : <span style="color: #cc66cc;color:#800000;">3000</span> * <span style="color: #cc66cc;color:#800000;">8</span> * <span style="color: #cc66cc;color:#800000;">4</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>In fact this is what I like the most in doing all those demos and experiments - the moment when code stops being just a list of instructions for the machine and becomes an <strong>art of making things look good</strong> by adding little tweaks here and there. If you tend to write very clean code and use all possible standards and conventions, from time to time <strong>make it ugly</strong>... you'll see how good it feels :)</p>
<p>I hope that this few tips will help you with your <strong>next JigLib project</strong>!</p>
<p>Last but not least, I'd like to say thanks to everyone who woke up early to see the <strong>Elevator Pitch session</strong>. It was a great experience being there and talking to you. <strong>The Brighton Dome</strong> packed with people can be intimidating and 3 minutes is not much time, so there was no place for mistakes. Fortunately, the <strong>FOTB technical crew</strong> made it all seamless. Great job guys! </p>
<p>Finally, I would like to give a special thanks to <strong>John Davey</strong> for inviting me to <strong>Flash On The Beach</strong> and for making this great conference happen! </p>
<p>Hope to see you next year!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.everyday3d.com/blog/index.php/2009/09/29/fotb09-3d-bowling-demo/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Exploring JigLibFlash &#8211; the AS3 3D physics library</title>
		<link>http://www.everyday3d.com/blog/index.php/2009/04/23/jiglibflash-3d-physics/</link>
		<comments>http://www.everyday3d.com/blog/index.php/2009/04/23/jiglibflash-3d-physics/#comments</comments>
		<pubDate>Thu, 23 Apr 2009 08:38:27 +0000</pubDate>
		<dc:creator>bartek drozdz</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Away3D]]></category>
		<category><![CDATA[JigLibFlash]]></category>
		<category><![CDATA[Papervision3D]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[physics]]></category>
		<category><![CDATA[physics simulation]]></category>
		<category><![CDATA[pingpong]]></category>

		<guid isPermaLink="false">http://www.everydayflash.com/blog/?p=204</guid>
		<description><![CDATA[JigLibFlash is a new library for 3D physics simulation in Flash. It is ported from a C++ open source engine. It's been around for a few months now, and if you haven't heard about it, you need to catch up! I believe physics simulation is the next step in the Flash 3D world, so I [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.everydayflash.com/flash/jiglib/pingpong.html" target="_blank"><img src="http://www.everydayflash.com/flash/jiglib/pingpong.jpg" width="520" height="245" border="0" alt=""></a></p>
<p><strong>JigLibFlash</strong> is a new library for 3D physics simulation in Flash. It is ported from a <strong>C++ open source engine</strong>. It's been around for a few months now, and if you haven't heard about it, you need to catch up!</p>
<p>I believe physics simulation is the <strong>next step</strong> in the Flash 3D world, so I got very excited when Ringo from <a href="http://www.flashbookmarks.com/" target="_blank">FlashBookmarks</a> invited me <strong>join the JigLibFlash team</strong> a couple of months ago. One little problem: I am perfectly lame when it comes to physics... In this situation, the only logical thing to do was to join the team and learn all the stuff I need to know about it in the meantime. Sounds like a challenge! </p>
<p>Now I slowly fill my knowledge gap. However, I also managed to do some actual work on the library. Together with <a href="http://blog.reyco1.com/" target="_blank">Reyco</a> we remodeled the API. We started by making it more <strong>Flash developer</strong> friendly, less C-style and more AS-style. All the methods start with a lowercase letter now, and instead of having to set the position and rotation using vectors and matrices, the new API offers simple getter/setters for properties like x/y/z and rotationX/Y/Z just like in <a href="http://blog.papervision3d.org/" target="_blank">Papervision3D</a> or in the new Flash Player 10 API. </p>
<p>Last but not least, we also created a plugin system to <strong>easily integrate</strong> <strong>JigLibFlash </strong>with the popular 3D engines like <a href="http://blog.papervision3d.org/" target="_blank">Papervision3D</a> or <a href="http://away3d.com/" target="_blank">Away3D</a>. Now there are <strong>specialized classes</strong> to interact with those two engines and it should be pretty easy to create a plugin for another engine if one needs. If you worked with <a href="http://code.google.com/p/as3dmod/" target="_blank">AS3Dmod</a> you should notice that the concept is similar to the plugin architecture in there. <em>Update: I just saw in the sources that someone already created a plugin for Sandy3D.</em></p>
<p>To learn more about these changes you can refer to the <a href="http://code.google.com/p/jiglibflash/wiki/New_API_Very_Short_Tutorial" target="_blank">tutorial</a> I wrote which is posted on the projects wiki page. Reyco also wrote a <a href="http://blog.reyco1.com/jiglibflash-papervision3d-quick-run-through/" target="_blank">great article</a> about this on his blog.</p>
<p>The <a href="/flash/jiglib/pingpong.html" target="_blank">demo above</a> is my <strong>first little experiment</strong> with JigLibFlash and <a href="http://blog.papervision3d.org/" target="_blank">Papervision3D</a>. My idea was to integrate a <strong>Collada object with the physics system</strong> and to add some interactivity to it. I extended the <a href="http://code.google.com/p/jiglibflash/source/browse/trunk/fp9/src/jiglib/plugin/papervision3d/constraint/MouseConstraint.as" target="_blank">Mouse constraint class</a> created by Reyco to control the racket. I encountered some problems with stabilizing it in the long run. After having bounced the ball a few times the racket starts to rotate as if the constraints were broken... well, I still need to do some research on that. </p>
<p><strong>Source code</strong>. You can browse the sources for the demo <a href="http://code.google.com/p/barteksplayground/source/browse/#svn/trunk/fp10/src/com/everydayflash/jiglib/pong" target="_blank">here</a>.</p>
<p><strong>Links</strong>. Some links to get you started with JigLibFlash:</p>
<ul>
<li><a href="http://www.jiglibflash.com/blog/" target="_blank">Official blog</a>, <a href="http://code.google.com/p/jiglibflash/" target="_blank">Google code</a></li>
<li><a href="http://code.google.com/p/jiglibflash/wiki/New_API_Very_Short_Tutorial" target="_blank">Wiki tutorial on new API</a> and <a href="http://blog.reyco1.com/jiglibflash-papervision3d-quick-run-through/" target="_blank">Reyco's article</a></li>
<li><a href="http://blog.zupko.info/?p=273" target="_blank">Really cool demo by Andy Zupko</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.everyday3d.com/blog/index.php/2009/04/23/jiglibflash-3d-physics/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
	</channel>
</rss>
