<?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>Nick Darnell&#039;s Blog</title>
	<atom:link href="http://www.nickdarnell.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.nickdarnell.com</link>
	<description>If you give a mouse a cookie...</description>
	<lastBuildDate>Tue, 07 Feb 2012 05:12:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Global Game Jam 2012 Wrap-Up</title>
		<link>http://www.nickdarnell.com/2012/02/global-game-jam-2012-wrap-up/</link>
		<comments>http://www.nickdarnell.com/2012/02/global-game-jam-2012-wrap-up/#comments</comments>
		<pubDate>Tue, 07 Feb 2012 04:51:37 +0000</pubDate>
		<dc:creator>NickDarnell</dc:creator>
				<category><![CDATA[Awesome]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[2012]]></category>
		<category><![CDATA[Game Jam]]></category>
		<category><![CDATA[Global Game Jam]]></category>
		<category><![CDATA[XNA]]></category>

		<guid isPermaLink="false">http://www.nickdarnell.com/?p=1938</guid>
		<description><![CDATA[The 2012 Global Game Jam is over and it was another year of awesome games in the Raleigh-Durham &#8211; North Carolina area.  This week I wanted to put the spotlight on all the games lovingly crafted by our crack squad of jammers – especially mine, Low Power! :D The Theme The Ouroboros – but no [...]]]></description>
			<content:encoded><![CDATA[<p>The 2012 Global Game Jam is over and it was another year of awesome games in the <a href="http://www.trianglegamejam.com/global-game-jam-2012/" target="_blank">Raleigh-Durham &#8211; North Carolina</a> area.  This week I wanted to put the spotlight on all the games lovingly crafted by our crack squad of jammers – especially mine, Low Power! :D</p>
<h1>The Theme</h1>
<p><a href="http://www.nickdarnell.com/wp-content/uploads/2012/02/theme.png"><img style="background-image: none; margin: 5px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="theme" src="http://www.nickdarnell.com/wp-content/uploads/2012/02/theme_thumb.png" alt="theme" width="240" height="239" border="0" /></a></p>
<p>The Ouroboros – but no explanation was given.  We just showed the jammers the image and it was up to them to interprete it.</p>
<h1><a href="http://www.trianglegamejam.com/global-game-jam-2012/lotr-body-snatching/" target="_blank">LOTR Body Snatching</a></h1>
<p>Rock, Paper, Scissors with body snatching!<br />
Avoid or possess enemies to stay alive and win.</p>

<object width="550" height="445">
<param name="allowfullscreen" value="true" />
<param name="allowscriptaccess" value="always" />
<param name="movie" value="http://www.youtube.com/v/_UTZHepSNO8&autoplay=0&loop=0&rel=0" />
<param name="wmode" value="transparent">
<embed src="http://www.youtube.com/v/_UTZHepSNO8&autoplay=0&loop=0&rel=0" type="application/x-shockwave-flash" wmode="transparent" allowfullscreen="true" allowscriptaccess="always" width="550" height="445">
</embed>
</object>


<h1><a href="http://www.trianglegamejam.com/global-game-jam-2012/low-power/" target="_blank">Low Power</a></h1>
<p>In order to survive Low Power you must consume yourself (like the Ouroboros) to survive.  You control a robot whose battery is constantly draining but there are valuable energy cores scattered throughout the level that will sustain your life.  There are all kinds of dangerous environmental hazards that unless you enable your sensors/abilities (lights, shield, ground sensor, microphone) you’ll never survive.  However enabling the different systems will drain your battery even faster!</p>

<object width="550" height="445">
<param name="allowfullscreen" value="true" />
<param name="allowscriptaccess" value="always" />
<param name="movie" value="http://www.youtube.com/v/PBw0g5rVPvQ&autoplay=0&loop=0&rel=0" />
<param name="wmode" value="transparent">
<embed src="http://www.youtube.com/v/PBw0g5rVPvQ&autoplay=0&loop=0&rel=0" type="application/x-shockwave-flash" wmode="transparent" allowfullscreen="true" allowscriptaccess="always" width="550" height="445">
</embed>
</object>


<h1><a href="http://www.trianglegamejam.com/global-game-jam-2012/parasite/" target="_blank">Parasite</a></h1>
<p>You are a Parasite that leeches off battle ships. Enemies will constantly come in formations to destroy the ship you are occupying. Using the possessed ship, you must defeat your enemies! However, as you leech your ship it slowly dies, you will constantly need to take control of and leech of another ship. With out a ship for protection you are helpless!</p>

<object width="550" height="445">
<param name="allowfullscreen" value="true" />
<param name="allowscriptaccess" value="always" />
<param name="movie" value="http://www.youtube.com/v/VD2FlSpbu-A&autoplay=0&loop=0&rel=0" />
<param name="wmode" value="transparent">
<embed src="http://www.youtube.com/v/VD2FlSpbu-A&autoplay=0&loop=0&rel=0" type="application/x-shockwave-flash" wmode="transparent" allowfullscreen="true" allowscriptaccess="always" width="550" height="445">
</embed>
</object>


<h1><a href="http://www.trianglegamejam.com/global-game-jam-2012/planes-on-a-snake/" target="_blank">Planes on a Snake</a></h1>
<p>A rift in spacetime has resulted in a large number of World War II era planes getting stuck on the world snake.  Join the frequent fliers club of Ouroboros Airlines, racking up points while taking advantage of the torus nature of your new environment.</p>

<object width="550" height="445">
<param name="allowfullscreen" value="true" />
<param name="allowscriptaccess" value="always" />
<param name="movie" value="http://www.youtube.com/v/UHdp0cqIcMY&autoplay=0&loop=0&rel=0" />
<param name="wmode" value="transparent">
<embed src="http://www.youtube.com/v/UHdp0cqIcMY&autoplay=0&loop=0&rel=0" type="application/x-shockwave-flash" wmode="transparent" allowfullscreen="true" allowscriptaccess="always" width="550" height="445">
</embed>
</object>


<h1><a href="http://www.trianglegamejam.com/global-game-jam-2012/roller-snake/" target="_blank">Roller Snake: The Quest for Chili Dogs</a></h1>
<p>Control “Hardy the Hoop Snake, Jr., III, IV, and V” in his quest to eat as many chili dogs as possible while winding through ‘Catastrophe Canyon’</p>

<object width="550" height="445">
<param name="allowfullscreen" value="true" />
<param name="allowscriptaccess" value="always" />
<param name="movie" value="http://www.youtube.com/v/WofSQtdaPm4&autoplay=0&loop=0&rel=0" />
<param name="wmode" value="transparent">
<embed src="http://www.youtube.com/v/WofSQtdaPm4&autoplay=0&loop=0&rel=0" type="application/x-shockwave-flash" wmode="transparent" allowfullscreen="true" allowscriptaccess="always" width="550" height="445">
</embed>
</object>


<h1><a href="http://www.trianglegamejam.com/global-game-jam-2012/snake-run/" target="_blank">Snake Run</a></h1>
<p>You are the snake’s guardian, you must ensure that balance is maintained.  Let enough creatures be eaten by the snake to ensure he doesn’t starve, but not enough that he frenzies and destroys everything.  All the while outrunning him!</p>

<object width="550" height="445">
<param name="allowfullscreen" value="true" />
<param name="allowscriptaccess" value="always" />
<param name="movie" value="http://www.youtube.com/v/WN8FaRJ00Zg&autoplay=0&loop=0&rel=0" />
<param name="wmode" value="transparent">
<embed src="http://www.youtube.com/v/WN8FaRJ00Zg&autoplay=0&loop=0&rel=0" type="application/x-shockwave-flash" wmode="transparent" allowfullscreen="true" allowscriptaccess="always" width="550" height="445">
</embed>
</object>


]]></content:encoded>
			<wfw:commentRss>http://www.nickdarnell.com/2012/02/global-game-jam-2012-wrap-up/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Global Game Jam 2012: Friday!</title>
		<link>http://www.nickdarnell.com/2012/01/global-game-jam-2012-friday/</link>
		<comments>http://www.nickdarnell.com/2012/01/global-game-jam-2012-friday/#comments</comments>
		<pubDate>Thu, 26 Jan 2012 14:46:47 +0000</pubDate>
		<dc:creator>NickDarnell</dc:creator>
				<category><![CDATA[Awesome]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[Game Jam]]></category>
		<category><![CDATA[Global Game Jam]]></category>
		<category><![CDATA[Triangle Game Jam]]></category>

		<guid isPermaLink="false">http://www.nickdarnell.com/?p=1932</guid>
		<description><![CDATA[I&#8217;ve been spending a lot of time lately rebuilding the old Triangle Game Jam website. Now that it&#8217;s done I can get back to new articles. The new site is up at http://www.trianglegamejam.com.  It&#8217;s where we&#8217;ll be archiving all Raleigh/Durham/Chapel Hill &#8211; Global and Triangle game jams.  All the past years works that I could [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been spending a lot of time lately rebuilding the old Triangle Game Jam website. Now that it&#8217;s done I can get back to new articles. The new site is up at <a href="http://www.trianglegamejam.com" target="_blank">http://www.trianglegamejam.com</a>.  It&#8217;s where we&#8217;ll be archiving all Raleigh/Durham/Chapel Hill &#8211; Global and Triangle game jams.  All the past years works that I could get my hands on are up there and worth taking a look at.  It&#8217;s amazing what people with a goal can create in a weekend.</p>
<p>In other news &#8211; The global game jam starts this Friday (January 27th).  You should <a href="http://globalgamejam.org/" target="_blank">signup and find a local jam site you can attend</a>.  It&#8217;s totally worth a weekend of your time.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nickdarnell.com/2012/01/global-game-jam-2012-friday/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating Kinect Controls for Angry Birds</title>
		<link>http://www.nickdarnell.com/2011/12/creating-kinect-controls-for-angry-birds/</link>
		<comments>http://www.nickdarnell.com/2011/12/creating-kinect-controls-for-angry-birds/#comments</comments>
		<pubDate>Thu, 08 Dec 2011 15:51:10 +0000</pubDate>
		<dc:creator>NickDarnell</dc:creator>
				<category><![CDATA[Activate3D]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[Motion Gaming]]></category>
		<category><![CDATA[Angry Birds]]></category>
		<category><![CDATA[Kinect]]></category>
		<category><![CDATA[NUI]]></category>

		<guid isPermaLink="false">http://www.nickdarnell.com/?p=1861</guid>
		<description><![CDATA[Before I begin let me give you a little background.  About a month ago we decided to try and create NUI (Natural User Interface) or Kinect controls for Angry Birds.  Partially as a learning experience but also as proof of concept that games like Angry Birds (ex. applications that lend themselves to touchscreen devices) can [...]]]></description>
			<content:encoded><![CDATA[<p>Before I begin let me give you a little background.  About a month ago we decided to try and create NUI (Natural User Interface) or Kinect controls for Angry Birds.  Partially as a learning experience but also as proof of concept that games like Angry Birds (ex. applications that lend themselves to touchscreen devices) can work in a gestural / depth camera environment better than has been demonstrated.  In the end we tried many different input methods that would be possible with a Kinect and I wanted to catalog that experience.</p>
<p>I&#8217;ll start with the worst input paradigm we tried go from there.</p>
<h3>#5 The Faux Mouse</h3>
<p><strong>The Idea<br />
</strong>First we just tried mapping the hands to the screen as if they were each a mouse or finger.  Each would control a hand like cursor and move it around the screen.  Clicks could either be performed by grasping the hands or pushing towards the screen.  The game would be played normally &#8211; except you&#8217;d click on everything using your hand.</p>
<p><img class="alignnone" src="http://media.tested.com/uploads/0/5/6432-minorityreport_600_super.jpg" alt="" width="480" height="240" /></p>
<p><strong>The Reality<br />
</strong>This input method was by far the worst.  Your hands are simply not mice, they get tired much faster and are not as dexterous.  Even with heavy filtering and snap-able buttons, the interaction is just too nuanced and motor skill intensive an operation to click on a button or object on the screen using your hands as mice.  The time it took us to play a level vs. someone playing it on the iPhone was an order of magnitude or longer a task.</p>
<p>When pushing towards the screen a lot of care had to be taken to deal with user drift.  When a user pushes towards the screen, they may in fact be pushing towards many possible locations.  They may drift towards the TV, or the camera if that&#8217;s their focus.  They may also consciously attempt to maintain a straight hand as they push forward.  No matter the case &#8211; a user will drift even off their intended target.</p>
<p>When we tried grasp detection using computer vision &#8211; again we saw drift.  When a user opens and closes their hand the volume of the hand is changed from the point of view of the camera.  The result ends up displacing the center of mass of the hand causing it to shift downward when the hand is closed.  There are solutions to this problem such as eliminating the fingers from the hand volume calculation but this is a difficult problem given the quality of the data.</p>
<p>In the end the drift issues prevented us from playing as well as we could with the real mouse or on the iPhone and since Angry Birds is both a game of quick victory and defeat as well as a game of precision.  Having both large problems with precision and game play progression speed &#8211; we ditched this idea.</p>
<h3>#4 Voice</h3>
<p><strong>The Idea<br />
</strong>This one is exactly what you might expect &#8211; firing the bird using your voice.  Either by saying &#8220;Fire!&#8221; or maybe&#8230; &#8220;Ca Cah!&#8221;.</p>
<p><img class="alignnone size-full wp-image-1908" src="http://www.nickdarnell.com/wp-content/uploads/2011/12/fire_anime.png" alt="" width="440" height="224" /></p>
<p><strong>The Reality<br />
</strong>We really were not sure how this method would perform.  The voice portion was layered onto the mouse control system.  Essentially you would click on the slingshot &#8211; move your hand to aim and exclaim viciously to let loose the birds of war.  The hope was that it would alleviate the drift problems, which it did.  Without having to push your hand forward to fire the drift was eliminated from firing.</p>
<p>However there were other problems, there was delay in the speech recognition and often outright failure if you didn&#8217;t say the words just right.  We tried several tricks, like using multiple words to identify &#8220;Fire&#8221;.  One good way to generate that list is to take the top 10 words it mistakened someone saying fire for and add those to the dictionary as triggers for firing the bird.</p>
<h3>Moving Away From Faux Mouse</h3>
<p>After the failures with both #4 and #5 we went back to the drawing board.  We needed to get away from the mouse or touch device centered thinking.  The worlds are simply too different to treat it the same.  So we prototyped 3 other solutions that ended up all being better than the mouse style interface.</p>
<p>The ideas all stem from an understanding that when you go to port an application from a touch enabled world you need to think about 2 things primarily,</p>
<ul>
<li><strong>Context</strong></li>
<li><strong>Automation</strong></li>
</ul>
<p><strong>Context</strong> &#8211; How can you reduce and scope the options to the user so that a broad array of options can be presented to the user &#8211; but with only a few usable at any given time with a small vocabulary of motions.</p>
<p>An example from Angry Birds is all the options the user can perform in the game:</p>
<ul>
<li>Fire Bird</li>
<li>Activate Bird Special Attack</li>
<li>Restart</li>
<li>Pan</li>
<li>Zoom</li>
<li>Return to the Menu</li>
</ul>
<p>We needed to find a way to contextualize these options when moving away from a mouse driven style interface.</p>
<p><strong>Automation</strong> &#8211; Find the items in the application that everyone does without thinking about it and automate them.  If they aren&#8217;t relevant to game play find a way to make them irrelevant in a NUI application.</p>
<p>An example from Angry Birds is activating the slingshot.  You probably don&#8217;t think about it when playing the game but to fire a bird you must first place your finger on the slingshot before drawing back the bird to fire it.  While this is unbelievably trivial to the point of not thinking about it on an iPhone, it&#8217;s a huge pain in an environment where you have to get a virtual hand cursor over it, even more so if you then need to push forward to activate it.</p>
<p>So we needed to find a way to automate clicking the slingshot.  That way instead of clicking the slingshot explicitly it would be implicitly activated by performing some gesture to begin the act of firing a bird, that would be disconnected from the onscreen location of the hand relative to the slingshot on the screen.</p>
<h3>#3 Arclight</h3>
<p><strong>The Idea<br />
</strong>You would draw back the slingshot by bringing your hands together.  Then bring your hands apart and rotate them around your center of mass to change the firing angle on the slingshot.  Then once you&#8217;ve settled on the firing angle, bring your hands together fast to trigger the fire.</p>
<p><img class="alignnone size-full wp-image-1897" src="http://www.nickdarnell.com/wp-content/uploads/2011/12/arc_light1.png" alt="" width="550" height="266" /></p>
<p><strong>The Reality<br />
</strong>The problem with this kind of activation of the slingshot was the drift when the hands come together.  This can be partially accounted for but it&#8217;s heuristically based and can be erroneous.  Additionally activating the bird&#8217;s special power was difficult.  You would have to choose a different kind of interaction to activate the special power which would complicate the process.</p>
<h3>#2 Stretch and Snap</h3>
<p><strong>The Idea</strong><br />
This idea grew out of the Arclight firing system.  To attempt to solve the problem of drift, have the slingshot fire as soon as the arms reach a certain distance apart.</p>
<p><img class="alignnone size-full wp-image-1898" style="margin: 5px" src="http://www.nickdarnell.com/wp-content/uploads/2011/12/stretch_snap.png" alt="" width="376" height="266" /></p>
<p><strong>The Reality<br />
</strong>With this firing system you still have the problem of determining how to activate the bird special power.  You also introduce a new problem &#8211; all birds are fired at maximum drawback.  You also need to make sure to provide the user with feedback so that they know how close the user is to the *snap*, some kind of progress firing bar.</p>
<h3>#1 Axis Separated</h3>
<p><strong>The Idea</strong><br />
For this idea I separated the functions of the hands into distinct responsibilities.  Your left hand activates the slingshot by pushing forward (doesn&#8217;t matter where).  After a threshold is crossed the slingshot is activated, from then on an angle is calculated between the shoulder location and the left hand&#8217;s location relative to it, to produce the slingshot firing angle.  To fire the bird the right hand is pushed forward and pulled back, this sends the bird flying.  To activate the bird&#8217;s special power you again push the right hand forward.</p>
<p><img class="alignnone size-full wp-image-1888" src="http://www.nickdarnell.com/wp-content/uploads/2011/12/domain_separated.png" alt="" width="265" height="275" /></p>
<p><strong>The Reality<br />
</strong>This method ended up working perfectly.  It doesn&#8217;t result in any drift when firing is activated.  It is also easy to perform because all the motions can be performed with your arms down by your sides, reducing exhaustion in long game play sessions.</p>
<h3>Lessons Learned</h3>
<p>You hear it all the time but it is critically important to prototype ideas when it comes to creating Kinect controls.  They simply don&#8217;t work as well as you would like in reality as they do in your head.  Here&#8217;s a demonstration video of the end result,</p>
<p><a href="http://www.nickdarnell.com/2011/12/creating-kinect-controls-for-angry-birds/"><em>Click here to view the embedded video.</em></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.nickdarnell.com/2011/12/creating-kinect-controls-for-angry-birds/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Kinect, Anthropometry and You</title>
		<link>http://www.nickdarnell.com/2011/11/kinect-anthropometry-and-you/</link>
		<comments>http://www.nickdarnell.com/2011/11/kinect-anthropometry-and-you/#comments</comments>
		<pubDate>Tue, 08 Nov 2011 07:45:44 +0000</pubDate>
		<dc:creator>NickDarnell</dc:creator>
				<category><![CDATA[Motion Gaming]]></category>
		<category><![CDATA[Anthropometry]]></category>
		<category><![CDATA[Kinect]]></category>

		<guid isPermaLink="false">http://www.nickdarnell.com/?p=1852</guid>
		<description><![CDATA[Anthropometry (Greek anthropos (άνθρωπος &#8211; &#34;man&#34;) and metron (μέτρον &#8211; &#34;measure&#34;) therefore &#34;measurement of man&#34;) refers to the measurement of the human individual. Ask any Kinect developer what the hardest problem is developing a game or application that uses the Kinect – or any other depth camera.&#160; The answer you’ll get most often will be [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p><b>Anthropometry</b> (Greek <i>anthropos</i> (άνθρωπος &#8211; &quot;man&quot;) and <i>metron</i> (μέτρον &#8211; &quot;measure&quot;) therefore &quot;measurement of man&quot;) refers to the measurement of the human individual.</p>
</blockquote>
<p>Ask any Kinect developer what the hardest problem is developing a game or application that uses the Kinect – or any other depth camera.&#160; The answer you’ll get most often will be creating something that works well for 95% of target users.</p>
<p>This is something you have to consider for all your gestures, poses, and UI interaction.</p>
<ul>
<li>Is this gesture too difficult for your average user?</li>
<li>Does this pose require too much flexibility?</li>
<li>Is this UI interaction comfortable and easy to perform?</li>
</ul>
<p>One area that can benefit from anthropometry data is UI interaction.&#160; When you think about UI interaction with Kinect you’ve got to picture it as a real world space (box, sphere, cylinder, other) located somewhere around the body that you’re mapping the hand position in that space to the 2D or 3D UI coordinate plane.</p>
<p>When determining the size and location of this real world space and how it maps user hand locations onto the UI coordinate system the largest question you need to consider is:</p>
<h4>Where will they be most comfortable?</h4>
<p>Generally speaking you want a space that minimizes upper arm movement – as that is much more strenuous compared to forearm movements.</p>
<p>However, since the 3d position we’re mapping into our 2d/3d UI coordinate system varies based upon user skeleton size we can’t choose a single set of real world dimensions that will work for everyone.&#160; We’ll have to make educated guesses about the size and location of our real world UI coordinate frame based on size and location of the users bones.</p>
<h4>So how does anthropometry fit in?</h4>
<p>Because the skeleton you get from Kinect – and other SDKs can be unreliable in certain poses you often find yourself heavily filtering any kind of data you’re tracking about the user.&#160; Especially things like the user’s arm length – <strong>which can vary dramatically over a session</strong>.</p>
<p>So one thing I prefer to do is use anthropometry tables to ensure a more consistent size and location and doesn’t fluctuate as much as the user’s skeleton.&#160; Using anthropometry tables we can estimate the users arm length or hand size based on other bones in their body, bones that are more stable in your skeleton SDK of choice (Kinect, OpenNI, Iisu, Omek…etc).</p>
<p>You can also use anthropometry tables to estimate the size of body parts that the skeleton SDK you’re using doesn’t provide – such as the size of the users hand.</p>
<h4>But where do you find that kind of anthropometry data?</h4>
<p>Luckily such a resource has already been painstakingly cataloged for us by the FAA – <a href="http://files.nickdarnell.com/hfe_design_guide.pdf">The Human Factors Design Guide</a>.&#160; The HFDG was put together so that planes could be constructed so that almost anyone would fit and be able to operate anything from their seat.</p>
<p>The anthropometry data that’s valuable to us starts in chapter 14, page 791.&#160; For example, these lovely tables from page 818 show the functional reach and the extended functional reach of men and women broken down by population percentiles.</p>
<p><a href="http://www.nickdarnell.com/wp-content/uploads/2011/11/hfdg_reach.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 5px auto; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top: 0px; border-right: 0px; padding-top: 0px" title="hfdg_reach" border="0" alt="hfdg_reach" src="http://www.nickdarnell.com/wp-content/uploads/2011/11/hfdg_reach_thumb.png" width="450" height="330" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.nickdarnell.com/2011/11/kinect-anthropometry-and-you/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making Your Files Merge Friendly</title>
		<link>http://www.nickdarnell.com/2011/10/making-your-files-merge-friendly/</link>
		<comments>http://www.nickdarnell.com/2011/10/making-your-files-merge-friendly/#comments</comments>
		<pubDate>Mon, 24 Oct 2011 14:00:45 +0000</pubDate>
		<dc:creator>NickDarnell</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Merging]]></category>
		<category><![CDATA[Revision Control]]></category>

		<guid isPermaLink="false">http://www.nickdarnell.com/?p=1754</guid>
		<description><![CDATA[Merging is a fact of life for most of us.&#160; Eventually two users touch the same files and a conflict must be resolved.&#160; For programmers merging is a daily activity, but what about the content creators? If two artists touch the same level, have your tools programmers made enough of an effort to make merging [...]]]></description>
			<content:encoded><![CDATA[<p>Merging is a fact of life for most of us.&#160; Eventually two users touch the same files and a conflict must be resolved.&#160; For programmers merging is a daily activity, but what about the content creators?</p>
<p>If two artists touch the same level, have your tools programmers made enough of an effort to make merging possible and if possible as painless as can be?</p>
<p>Here’s a handy checklist,</p>
<h3>1 &#8211; Use XML/JSON (or some other text based file format)</h3>
<p>It’s slower, it’s bigger but it’s going to make merging possible.&#160; If your level files are binary blobs merging without a custom tool just isn’t going to be possible.&#160; Using XML or JSON are the simplest text based alternatives because there are already many libraries for reading and writing them.</p>
<h3>2 &#8211; For XML – Give Each Attribute a Line</h3>
<p>If you’re using XML, you should make sure to write out the files such that every element and every attribute receives its own line.&#160; If you don’t do this it will make conflicts a lot more likely if two users touch the same object.</p>
<p>If you’re using JSON, having each attribute on its own line is the norm unless the library is attempting to keep the text compact.</p>
<p>Here’s a quick example, note that after separating the attributes the merge tool handles the conflict correctly while it fails to do so when they are on the same line.</p>
<p align="center"><a href="http://www.nickdarnell.com/wp-content/uploads/2011/10/nonewline.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 5px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="nonewline" border="0" alt="nonewline" src="http://www.nickdarnell.com/wp-content/uploads/2011/10/nonewline_thumb.png" width="500" height="190" /></a>    <br />Figure 1 &#8211; Attributes all on the same line</p>
<p align="center"><a href="http://www.nickdarnell.com/wp-content/uploads/2011/10/newline.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 5px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="newline" border="0" alt="newline" src="http://www.nickdarnell.com/wp-content/uploads/2011/10/newline_thumb.png" width="500" height="248" /></a>    <br />Figure 2 &#8211; Attributes on different lines</p>
<p>If you’re using .Net this can be achieved very easily by changing the default XmlWriterSettings with the NewLineOnAttribute property set to true.</p>

<div class="wp_syntax_wrapper"><span class="wp_syntax_lang">C#</span><div class="wp_syntax"><div class="code"><pre class="csharp" style="color: #FFF; font-family:&quot;Consolas&quot;,monospace,&quot;Courier New&quot;">var settings <span style="color: #CCC;">=</span> <span style="color: #996699;">new</span> XmlWriterSettings<span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#41;</span>
<span style="color: #CCC;">&#123;</span>
    NewLineOnAttributes <span style="color: #CCC;">=</span> <span style="color: #3D9EDD;">true</span>
<span style="color: #CCC;">&#125;</span><span style="color: #CCC;">;</span>
&nbsp;
<span style="color: #3D9EDD;">using</span> <span style="color: #CCC;">&#40;</span>XmlWriter writer <span style="color: #CCC;">=</span> XmlWriter<span style="color: #CCC;">.</span><span style="color: #FFF;">Create</span><span style="color: #CCC;">&#40;</span>filestream, settings<span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#41;</span>
<span style="color: #CCC;">&#123;</span>
    <span style="color: #999;">// Write out document...</span>
<span style="color: #CCC;">&#125;</span></pre></div></div></div>

<h3>3 &#8211; Maintain Order</h3>
<p>Always write out the order of the data the same.&#160; This one is pretty easy, the only real pitfall is to make sure your data structure and undo/redo system are working correctly.&#160; For example, if you happen to store your objects in a list and someone removes and object at the front, but when it’s undone it’s inserted at the end of the list (Even if the UI doesn’t reflect this) this could affect your output order.</p>
<h3>4 &#8211; Don’t Add New Objects At The End</h3>
<p>When you go to save the entities don’t write them out in the order they were created.&#160; This will definitely result in a merge conflict.&#160; Because it ensures that if two users edit the file and both add an entity they’ll both show up in the same location and confuse the merge tool.</p>
<p>One thing you could do is to sort them based on a GUID that is stored as part of the objects data.&#160; Sorting based on GUID ensures a lower probability of collisions occurring when two users both add objects.</p>
<p>Alternatively a sorting based on a string containing the machine name of the original creator of the object is another idea.&#160; It would ensure every user touching the file would be inserting to their own section of the file instead of everyone inserting to the tail.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nickdarnell.com/2011/10/making-your-files-merge-friendly/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Robust Inside and Outside Solid Voxelization</title>
		<link>http://www.nickdarnell.com/2011/09/robust-inside-and-outside-solid-voxelization/</link>
		<comments>http://www.nickdarnell.com/2011/09/robust-inside-and-outside-solid-voxelization/#comments</comments>
		<pubDate>Sat, 24 Sep 2011 06:27:43 +0000</pubDate>
		<dc:creator>NickDarnell</dc:creator>
				<category><![CDATA[Game Industry]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[Graphics]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Rendering]]></category>
		<category><![CDATA[Hierarchical Z-Buffer]]></category>
		<category><![CDATA[Occlusion Culling]]></category>
		<category><![CDATA[OpenGL]]></category>
		<category><![CDATA[Solid Voxelization]]></category>
		<category><![CDATA[Voxel]]></category>
		<category><![CDATA[Voxelization]]></category>

		<guid isPermaLink="false">http://www.nickdarnell.com/?p=1678</guid>
		<description><![CDATA[While wrapping up my post for generating simplified occluders for Hierarchical Z-Buffer Occlusion Culling, I was pointed to a paper called Complete Polygonal Scene Voxelization.  Afterwards I found time to read it thoroughly and implement it as a replacement for my existing ray casting based solid voxelization method. The problem with the solid voxelization technique [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.14.6993" target="_blank"><img style="background-image: none; margin: 5px; padding-left: 0px; padding-right: 0px; display: inline; float: right; padding-top: 0px; border-width: 0px;" title="complete_polygonal_scene_voxelization" src="http://www.nickdarnell.com/wp-content/uploads/2011/09/complete_polygonal_scene_voxelization.png" alt="complete_polygonal_scene_voxelization" width="170" height="240" align="right" border="0" /></a></p>
<p>While wrapping up my post for generating simplified occluders for <a href="http://www.nickdarnell.com/2011/06/hierarchical-z-buffer-occlusion-culling-generating-occlusion-volumes/" target="_blank">Hierarchical Z-Buffer Occlusion Culling</a>, I was pointed to a paper called <a href="http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.14.6993" target="_blank">Complete Polygonal Scene Voxelization</a>.  Afterwards I found time to read it thoroughly and implement it as a replacement for my existing ray casting based solid voxelization method.</p>
<p>The problem with the solid voxelization technique I was using previously was that it used ray casting; making it impossible to perform solid voxelization unless the mesh is watertight in addition to having no anomalies like intersecting geometry.</p>
<p>However, that restriction makes it an unrealistic solution in the real world because game art typically has holes in the locations players never see; such as the bottom cap on a building, which is rarely modeled.</p>
<h3>The New Solution</h3>
<p>The <a href="http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.14.6993" target="_blank">Complete Polygonal Scene Voxelization</a> paper’s solution to voxelizing a scene is pretty clever; It applies a heuristic model to the problem of determining the inside/outside status of each voxel or octree cell.  Allowing it to overcome the problem of holes and intersecting geometry making it suitable as a real world solution.</p>
<h3>How It Works</h3>
<p><a href="http://www.nickdarnell.com/wp-content/uploads/2011/09/bunny_octree_32.png" target="_blank"><img style="background-image: none; margin: 5px; padding-left: 0px; padding-right: 0px; display: inline; float: right; padding-top: 0px; border-width: 0px;" title="bunny_octree_3" src="http://www.nickdarnell.com/wp-content/uploads/2011/09/bunny_octree_3_thumb2.png" alt="bunny_octree_3" width="200" height="187" align="right" border="0" /></a></p>
<p>You can download the paper and read it for yourself, but let me go ahead and summarize the algorithm for brevity&#8217;s sake so that the rest of the article makes sense.</p>
<p>The algorithm takes place in 3 stages:</p>
<ol>
<li>Create Octree</li>
<li>Find Seed Cell</li>
<li>Propagate Seed Cell</li>
</ol>
<h4>Create Octree</h4>
<p>First you create an octree around the mesh that continues to subdivide each cell until either the cell no longer intersects with any triangle or a maximum depth is reached.  A typical maximum octree depth that will work for most meshes is 5.  If the mesh has some exceptionally thin walls that you want the cells to be small enough to fill you may need to go as high as 7 or 8.</p>
<p>I was having some problems with the GPU AABB/Triangle overlap test I used for voxelization in the <a href="http://www.nickdarnell.com/2011/06/hierarchical-z-buffer-occlusion-culling-generating-occlusion-volumes/" target="_blank">Hierarchical Z-Buffer Occlusion Culling</a> article and so I ended up porting the <a href="http://fileadmin.cs.lth.se/cs/Personal/Tomas_Akenine-Moller/code/" target="_blank">Möller implementation of AABB/Triangle overlap test</a> to C# and just used it instead.</p>
<p>Also if you ever need to lookup how an intersection is performed I highly recommend the <a href="http://www.realtimerendering.com/intersections.html" target="_blank">gigantic matrix of intersections over at realtimerendering.com</a>.  It was a handy resource since I don’t keep the algorithm for AABB/Triangle overlap stored in my brain.</p>
<p>After you’ve created the octree we need to process each cell that wasn’t intersecting with a triangle to determine if it is inside or outside.</p>
<h4>Find Seed Cell</h4>
<p>Before we can determine if a cell is inside or outside the mesh we need to find a seed cell.  The seed cell is sort of the ground truth example cell that we use to propagate its status to the other cells that it can see.  The seed cell’s status is determined by rendering a cube map centered inside the cell with the near plane placed at the cell edge.</p>
<p>When rendering each side of the cube map, you render the scene such that all front facing polygons are blue and all back facing polygons are red.  You then read back each cube map surface from the GPU and determine the percentage of red and blue pixels seen at each face.</p>
<p>If at least 4 sides of the cube map contain red pixels, the cell is determined to be inside the mesh.</p>
<p>The paper says that NO red pixels can be seen for a seed cell to be determined to be outside however I found this problematic since occasionally a red pixel can be seen just through tiny rendering artifacts.</p>
<p>So I feel a better solution is one like the following:</p>

<div class="wp_syntax_wrapper"><span class="wp_syntax_lang">C#</span><div class="wp_syntax"><div class="code"><pre class="csharp" style="color: #FFF; font-family:&quot;Consolas&quot;,monospace,&quot;Courier New&quot;">MIN_INSIDE_FACES <span style="color: #CCC;">=</span> <span style="color: #FFCC00;">4</span><span style="color: #CCC;">;</span>
MIN_INSIDE_PERCENTAGE <span style="color: #CCC;">=</span> 0<span style="color: #CCC;">.</span>03f<span style="color: #CCC;">;</span>
&nbsp;
<span style="color: #99FFFF;">int</span> cubemap_sides_seeing_inside <span style="color: #CCC;">=</span> <span style="color: #FFCC00;">0</span><span style="color: #CCC;">;</span>
&nbsp;
<span style="color: #3D9EDD;">for</span> <span style="color: #CCC;">&#40;</span><span style="color: #99FFFF;">int</span> i <span style="color: #CCC;">=</span> <span style="color: #FFCC00;">0</span><span style="color: #CCC;">;</span> i <span style="color: #CCC;">&lt;</span> <span style="color: #FFCC00;">6</span><span style="color: #CCC;">;</span> i<span style="color: #CCC;">++</span><span style="color: #CCC;">&#41;</span>
<span style="color: #CCC;">&#123;</span>
    RenderCubeMapSide<span style="color: #CCC;">&#40;</span>i<span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
    <span style="color: #99FFFF;">float</span> backfacePercentage <span style="color: #CCC;">=</span> CalculateBackfacePercentage<span style="color: #CCC;">&#40;</span>i<span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
&nbsp;
    <span style="color: #3D9EDD;">if</span> <span style="color: #CCC;">&#40;</span>backfacePercentage <span style="color: #CCC;">&gt;</span> MIN_INSIDE_PERCENTAGE<span style="color: #CCC;">&#41;</span>
        cubemap_sides_seeing_inside<span style="color: #CCC;">++;</span>
<span style="color: #CCC;">&#125;</span>
&nbsp;
<span style="color: #3D9EDD;">if</span> <span style="color: #CCC;">&#40;</span>cubemap_sides_seeing_inside <span style="color: #CCC;">&gt;=</span> MIN_INSIDE_FACES <span style="color: #CCC;">||</span> cubemap_sides_seeing_inside <span style="color: #CCC;">==</span> <span style="color: #FFCC00;">0</span><span style="color: #CCC;">&#41;</span>
<span style="color: #CCC;">&#123;</span>
    <span style="color: #3D9EDD;">if</span> <span style="color: #CCC;">&#40;</span>cubemap_sides_seeing_inside <span style="color: #CCC;">&gt;=</span> MIN_INSIDE_FACES<span style="color: #CCC;">&#41;</span>
        cell<span style="color: #CCC;">.</span><span style="color: #FFF;">Status</span> <span style="color: #CCC;">=</span> CellStatus<span style="color: #CCC;">.</span><span style="color: #FFF;">Inside</span><span style="color: #CCC;">;</span>
    <span style="color: #3D9EDD;">else</span> <span style="color: #999;">// cubemap_sides_seeing_inside == 0</span>
        cell<span style="color: #CCC;">.</span><span style="color: #FFF;">Status</span> <span style="color: #CCC;">=</span> CellStatus<span style="color: #CCC;">.</span><span style="color: #FFF;">Outside</span><span style="color: #CCC;">;</span>
&nbsp;
    <span style="color: #999;">// Propagate cell status...</span>
<span style="color: #CCC;">&#125;</span>
<span style="color: #3D9EDD;">else</span>
<span style="color: #CCC;">&#123;</span>
    <span style="color: #999;">// Unable to solve status exactly.</span>
<span style="color: #CCC;">&#125;</span></pre></div></div></div>

<p>Where you don’t count a face as inside unless at least 3% of the total red and blue pixels are red.  The percentage is just something I picked out of thin air, it feels like a number small enough to be easily overcome by any truly inside cube face, but high enough to allow me to ignore tiny artifacts.</p>
<h4>Propagate Seed Cell</h4>
<p>The last step is to propagate the seed cell’s status to other cells.  After classifying a seed cell you need to test every unknown cell against each the depth map and frustum of each cube map surface.</p>
<p>You’re performing a test to see if any of the 8 corners of the octree cell when projected into the camera space of each cube face are closer than the depth value at that pixel.  If it is, then then the entire octree cell likely visible.</p>
<p>If the cell is visible from the seed cell, then in all likelihood the cell has the same status as the seed cell.  However because having holes means 2 seed cells (one inside and one outside) can potentially see the same cell you want several seed cells to confirm the status of a cell before committing to it.</p>
<p>So once you’ve determined a cell is visible from the seed cell you’ll increment a counter on the cell for that status.  Once one of the statuses reaches a threshold, like for example 16 you’ll change the status of the cell from Unknown to whatever status counter overcame the threshold and no longer process that cell.</p>
<p>It should be noted that only seed cells propagate their status.  Cells that you propagate to do not propagate their own status.</p>
<h4>Repeat</h4>
<p>After you’ve found a seed cell and propagated its status you’ll continue to repeat finding a seed cell and propagating the seed cell until all cells have a status of inside, outside or intersecting.  You can rarely end up with some cells whose status simply can’t be determined so make sure your code can handle that scenario and not loop forever.</p>
<h3>Improvements</h3>
<p>While implementing the paper I made some additional improvements to the proposed solution.  I sped up the process by taking advantage of hardware improvements to render the scene using a single pass.  I also improved the conservativeness of the algorithm in situations where you&#8217;re using square voxels. When a mesh is wider than it is tall in those sitations there will be padding below the mesh; if the bottom of the mesh is uncapped it can lead to inside cells &#8216;leaking&#8217; their status outside.</p>
<h4>Single Pass Rendering</h4>
<p>The paper was published back in 2002 and due to limitations at the time the simplest method of rendering front faces one color and back faces another was to render the scene twice and flip the winding order and the color of the triangles being rendered.  However this method is slower than just using a simple pixel shader to change the color of front/back faces.</p>
<p>In OpenGL you can use <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/gl_FrontFacing.xml" target="_blank">gl_FrontFacing</a> and in DirectX 11 you can use <a href="http://msdn.microsoft.com/en-us/library/bb509647%28v=vs.85%29.aspx" target="_blank">SV_IsFrontFace</a>.</p>

<div class="wp_syntax_wrapper"><span class="wp_syntax_lang">GLSL</span><div class="wp_syntax"><div class="code"><pre class="glsl" style="color: #FFF; font-family:&quot;Consolas&quot;,monospace,&quot;Courier New&quot;"><span style="color: #996699;">void</span> main<span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#41;</span>
<span style="color: #CCC;">&#123;</span>
     <span style="color: #551111;">gl_FragColor</span> <span style="color: #CCC;">=</span> <span style="color: #551111;">gl_FrontFacing</span> <span style="color: #CCC;">?</span> <span style="color: #996699;">vec4</span><span style="color: #CCC;">&#40;</span><span style="color: #FFCC00;">0</span><span style="color: #CCC;">,</span><span style="color: #FFCC00;">0</span><span style="color: #CCC;">,</span><span style="color: #FFCC00;">1</span><span style="color: #CCC;">,</span><span style="color: #FFCC00;">1</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">:</span> <span style="color: #996699;">vec4</span><span style="color: #CCC;">&#40;</span><span style="color: #FFCC00;">1</span><span style="color: #CCC;">,</span><span style="color: #FFCC00;">0</span><span style="color: #CCC;">,</span><span style="color: #FFCC00;">0</span><span style="color: #CCC;">,</span><span style="color: #FFCC00;">1</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
<span style="color: #CCC;">&#125;</span></pre></div></div></div>

<h4>
Intersect Mesh Bounds and Clip To Bounds</h4>
<p>One problem I found is that when a mesh (like a building) is uncapped at its base but is wider than it is tall there will be several cells below the base of the mesh.  Cells that will have the status of inside spread to them, even though a human could easily see those cells are outside.</p>
<p>So one improvement I ended up adding is that when testing for triangle intersection, you should also test against intersection against the mesh bounds.  Additionally you immediately mark a cell as Outside if is outside the mesh bounds, since it simply is not possible for that cell to be inside the mesh, but don’t treat that cell like it’s a seed cell; just mark it as outside and move on.</p>
<p>I needed some real game art to properly test the solution so I exported a roof structure from the Necropolis map from <a href="http://www.udk.com/" target="_blank">UDK</a>’s UTGame sample.  Here you can really see the difference it makes to clip to the bounds of the mesh.  Note how many additional voxel/octree cells (purple lines) are determined to be ‘inside’ because of how many backfaces (red triangles) they can see.</p>
<p align="center"><a href="http://www.nickdarnell.com/wp-content/uploads/2011/09/udk_necropolis_roof_not_fixed1.png" target="_blank"><img style="background-image: none; margin: 5px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="udk_necropolis_roof_not_fixed" src="http://www.nickdarnell.com/wp-content/uploads/2011/09/udk_necropolis_roof_not_fixed_thumb1.png" alt="udk_necropolis_roof_not_fixed" width="600" height="318" border="0" /></a><br />
Figure 1 – Roof Inner Voxelization Not Bounded (Before)</p>
<p align="center"><a href="http://www.nickdarnell.com/wp-content/uploads/2011/09/udk_necropolis_roof_fixed1.png" target="_blank"><img style="background-image: none; margin: 5px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="udk_necropolis_roof_fixed" src="http://www.nickdarnell.com/wp-content/uploads/2011/09/udk_necropolis_roof_fixed_thumb1.png" alt="udk_necropolis_roof_fixed" width="600" height="318" border="0" /></a><br />
Figure 2 – Roof Inner Voxelization Bounded (After)</p>
<h3 align="left">Future Improvements</h3>
<p>When the cube map for each seed cell is processed it’s read back from the GPU and each pixel is checked on the CPU.  This is wildly inefficient when all we care about is the percentage of red to blue pixels on each face.</p>
<p>So that processing can be moved to OpenCL to improve the performance significantly.  I would prefer to have all cells be seed cells since that makes it easier to define the rules of what cells are inside vs. outside.  Allowing the cells to propagate has a higher potential to cause problems I suspect on meshes with very nasty artifacts.  Giving each cell the ability to individually determine their status will be more stable and more predictable.</p>
<p>Currently my cube map rendering is performed in 6 passes.  Shifting over to a single pass method using the geometry shader will likely add additional speed improvements, but I don’t know for sure.</p>
<p>If I move enough of the processing to the GPU it may allow me to make more cells seed cells (perhaps all?) and still maintain an acceptable performance footprint for tool time usage.  For offline usage though this method is already very acceptable (a few seconds for an average mesh and a maximum depth of 5) even with all the CPU read-backs I’m performing.</p>
<h3>Sample Code</h3>
<p>I’m still working on an improved version of the Generating Occluders for Hierarchical Z-Buffer Occlusion Culling sample.  So the code is a bit tied up at the moment.  However the next post I do on generating the occluders will contain it, which should be soon.</p>
<p><a href="http://altdevblogaday.com/?p=17300" target="_blank">Robust Inside and Outside Solid Voxelization @ altdevblogaday.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.nickdarnell.com/2011/09/robust-inside-and-outside-solid-voxelization/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Trip Report: Gamefest 2011 &#8211; Seattle</title>
		<link>http://www.nickdarnell.com/2011/09/trip-report-gamefest-2011-seattle/</link>
		<comments>http://www.nickdarnell.com/2011/09/trip-report-gamefest-2011-seattle/#comments</comments>
		<pubDate>Fri, 09 Sep 2011 18:55:44 +0000</pubDate>
		<dc:creator>NickDarnell</dc:creator>
				<category><![CDATA[Game Industry]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[Graphics]]></category>
		<category><![CDATA[Machine Learning]]></category>
		<category><![CDATA[Motion Gaming]]></category>
		<category><![CDATA[Rendering]]></category>
		<category><![CDATA[Conference]]></category>
		<category><![CDATA[DirectX 11]]></category>
		<category><![CDATA[Gamefest]]></category>
		<category><![CDATA[Kinect]]></category>

		<guid isPermaLink="false">http://www.nickdarnell.com/?p=1658</guid>
		<description><![CDATA[I managed make it out to Seattle this year for Gamefest and figured I&#8217;d share my thoughts on some of the different presentations I saw. They are not available yet, but it looks like Microsoft is going to be posting the slides/audio for the different presentations here soon. Tiled Resources for Xbox 360 and Direct3D [...]]]></description>
			<content:encoded><![CDATA[<p>I managed make it out to Seattle this year for Gamefest and figured I&#8217;d share my thoughts on some of the different presentations I saw. They are not available yet, but it looks like Microsoft is going to be posting the slides/audio for the different presentations <a href="http://www.microsoftgamefest.com/seattle_conferencedetails.htm" target="_blank">here</a> soon.</p>
<h3>Tiled Resources for Xbox 360 and Direct3D 11 &#8211; Matt Lee</h3>
<p>This talk was about mega-texturing in DirectX 11/Xbox 360.  Matt Lee was showing a new DirectX SDK sample that&#8217;s coming in the next SDK release giving a reference implementation of a mega-texturing run-time.  I&#8217;ve only skimmed mega-texturing papers so I got a lot out of this talk since he walked through all the steps in the run-time.</p>
<p>The sample shows off how you begin by creating different tiles for different resource formats.  Each pool is dedicated to a different texture format.  The tiles in the pool are all the same size; However the tiles may vary in size depending upon the texture format to maximize cache efficiency.  When you render the scene you have a shader that can write out texture look-up failures.  When the UV coordinates and mip level are not found to be resident in memory a failure is added to this list.  After the shader completes you read back the failures and proceed to load the tiles that will fit in your established pools.</p>
<p>Unlike most texture streaming systems you&#8217;re not loading an entire mip level or the entire mip chain of the texture.  You&#8217;re only ever loading into the tiles a sub-region of a texture (like a 64&#215;64 pixel region), which overcomes one common texture streaming problem, texture memory fragmentation.  Because the tile pools you create are never deallocated you don&#8217;t have to worry about fragmenting your texture memory because of different sized textures being streamed in and out.</p>
<p>Now the sample is not without its short comings, but that is mostly due to hardware limitations.  Ideally the virtual texture system would be transparent, you wouldn&#8217;t need to write a shader that recorded look-up failures.  The GPU and DirectX would simply report when a failure occurred and allow you to handle it.  Maybe some day&#8230;</p>
<h3>Gesture Detection Using Machine Learning &#8211; Claude Marais</h3>
<p>If you have ever been interested in machine learning this is a worthwhile presentation to check out when the slides are posted.  Claude Marais talked about a case study they performed to try and use machine learning to detect a Punch and a Kick.  For their experiment they used <a href="http://en.wikipedia.org/wiki/AdaBoost" target="_blank">Adaboost</a> which is a machine learning technique that combines thousands of weak classifiers that &#8216;boost&#8217; each other and provide you with a high degree of accuracy in the results.</p>
<p>The classifiers are all extremely simple things, for example you may have a classifier like:</p>

<div class="wp_syntax_wrapper"><span class="wp_syntax_lang">C++</span><div class="wp_syntax"><div class="code"><pre class="cpp" style="color: #FFF; font-family:&quot;Consolas&quot;,monospace,&quot;Courier New&quot;"><span style="color: #3D9EDD;">if</span> <span style="color: #CCC;">&#40;</span>elbow_joint_angle <span style="color: #CCC;">&gt;</span> ANGLE<span style="color: #CCC;">&#41;</span>
    <span style="color: #3D9EDD;">return</span> <span style="color: #FFCC00;">1</span><span style="color: #CCC;">;</span>
<span style="color: #3D9EDD;">return</span> <span style="color: #CCC;">-</span><span style="color: #FFCC00;">1</span><span style="color: #CCC;">;</span></pre></div></div></div>

<p>Then simply create a macro and have 180 variants of this classifier one for each ANGLE.  If you can imagine all the different things you could measure about the skeleton, creating simple variants of the kernels for each of the possible test cases will explode the number of weak classifiers you have; Claude had around 21,000 weak classifiers for his system.</p>
<p>The training phase looks at labeled data sets to know what examples of punches look like (positive examples) and what -not- punches look like (negative examples).  It uses the +1/-1 scores each weak classifier provides to determine the weights to apply to each classifier.  After it has determined the best weak classifiers to detect a punch and not detect a negative example as a punch on accident you can use the classifiers at run-time with the weights applied to detect a punch.</p>
<p>The results were undeniable; they had a demo setup the the expo area that was really good at detecting a punch and kick.</p>
<p><del>The only real drawback to this solution is the data collection; they needed something on the order of 70,000 examples of punches and 7x that in negative not a punch examples before the training produced accuracies over 90-95% from the chart they had; if my memory is correct. </del><del><br />
</del></p>
<p>In training the system they had 70,000 frames worth of recorded training data.  The actual number of recorded punches used to train the system was 25 different people doing 10 punches, so around 250 punch examples.  Then they had about 7x that number in negative training examples, which might be things like waves, or other actions that SVM can use to differentiate between random movement and an intentional punch. (Thanks to Claude for clarifying this)</p>
<h3>Kinect and Kids: Pitfalls and Pleasantries &#8211; Deborah Hendersen</h3>
<p>If you had asked me to make a Kinect game for kids (ages 3-6) before seeing this presentation I likely would&#8217;ve designed something with a dumb-me as the target audience.  What I quickly realized is how wrong I would&#8217;ve been to make that assumption.  At that stage of development kids are not capable of interacting with games I&#8217;m used to playing.</p>
<p>Something as simple as a menu of options is an impossibility since they are illiterate.  How many games have you seen that you could play without knowing how to read?</p>
<p>When interacting with an onscreen character, the kids ignore social norms of waiting for the person to finish talking.  They may just jump the gun if they already know what is expected and get frustrated if they can&#8217;t do it when they want to.</p>
<p>Kids are distracted very easily and will make their own games out of game behavior.  Deborah mentioned one story where a kid stopped playing the game because he realized he could get the game to react to leaving the play area and Kinect could no longer detect him the game would do something.  So he made up his own game of jumping in and out of the play area to activate this condition; utterly boring for adults, completely entertaining for this kid.</p>
<p>You almost have to design the game like passive experience like a children&#8217;s TV show.  Where on TV because there is no feedback, the TV show host asks the kid, &#8220;Can you find _______?&#8221; and the kid at home says something, and expecting this the show simply pauses while he waits for the response.  The game has to function in essentially the same way, regardless of the kid participating in the expected fashion the game has to move forward.  If it functions like a state machine that requires proper actions to move forward the kid may become bored and simply want to move on.  If the game refuses to let them move on, they&#8217;ll just walk away.</p>
<p>I really enjoyed this presentation because it was very clear how difficult the problem space is and it was interesting to hear how they tried to solve each one.</p>
<h3>Kinect Hands: Finger Tracking and Voxel UI - Abdulwajid Mohamed and Tony Ambrus</h3>
<p>This presentation was broken into two completely different parts, the first part was on finger tracking with Kinect.  This is one area I&#8217;ve been playing around in for awhile so it was interesting to see someone else&#8217;s attempt to solve the problem.  Because the Kinect is a structured light depth camera you don&#8217;t necessarily have depth at each pixel like you would on a time of flight depth camera.  Structured light cameras build a topology of depth using the light pattern it projects into the scene, viewed from a different angle it can discern depth, but a single dot does not give you depth.  It connects groups of them when determining the depth of a surface.  This means that even though your hand can be seen by Kinect, the further you back away from the sensor, the more like a mitten your hand becomes.  The gaps between your fingers disappear until they are just clumps on your wrist.</p>
<p>Because of this limitation you can&#8217;t go past 10 feet, there simply isn&#8217;t enough data.  Ideally the user is at 6 feet or closer, past 6 feet the accuracy begins to break down.</p>
<p>The way Microsoft tackled the problem was to first capture lots of hand examples and then to train an SVM (Support Vector Machine) against a curvature analysis of the hands.  So once you know all the pixels that make up a persons hand you find the points on the hand that result in the largest changes in curvature.  On an open hand these curves are your fingers and if you&#8217;re close enough to the camera that it can see the gaps between fingers it&#8217;s a very large change in curvature.  A closed hand has more or less a uniform curvature change viewed from any angle.  By training the SVM against a set of closed hand curvature examples vs. open hand curvature examples they were able to get pretty accurate results at about the 6-8 foot range for an adult, 5-7 feet for kids.</p>
<p>Because the detector is instantaneous i.e. it can tell you in a single frame is the hand open or closed, you need some something to counteract a single/couple misinterpreted frame.  So they trained an HMM (Hidden Markov Model) on examples of a flaky transition where the system is quickly switching between 2 states because the hand is at an odd orientation confusing the SVM; I thought it was an interesting solution to the problem.  I&#8217;ve only ever tried something simple like requiring 3 contiguous frames of agreement to have a state change.</p>
<p>The second half of the presentation was on a 3D (not stereoscopic) UI for Kinect.  One of the problems with navigating a &#8216;push to click&#8217; interface is that it&#8217;s hard to correct for user drift.  When a user pushes forward they may do several things,</p>
<ul>
<li>Push toward the TV</li>
<li>Push toward the sensor</li>
<li>Push forward (wherever forward happens to be at that moment in time)</li>
</ul>
<p>Depending upon what you&#8217;re expecting them to do there&#8217;s going to be drift away from the thing on the screen they are trying to click.  To attempt to correct this Abdulwajid presented a UI where the hands are visualized as voxelized clumps of boxes in a 3D environment with 3D buttons that could be mashed.  Seeing the hand in the same space as the button appeared to make it much easier to perform the click.</p>
<p>One thing I noticed that was not called out was his use of 2 directional shadow casting lights.  By having 2 directional lights facing each other both casting shadows, the resulting effect is a focal point.  As the hand gets closer to a surface the eye perceives the two shadows heading towards each other and can see the point where they will meet.  I thought that was and additional powerful indicator of where your hand was moving in the space and made it much easier to correct drift.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nickdarnell.com/2011/09/trip-report-gamefest-2011-seattle/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Published Achievement Unlocked!</title>
		<link>http://www.nickdarnell.com/2011/09/published-achievement-unlocked/</link>
		<comments>http://www.nickdarnell.com/2011/09/published-achievement-unlocked/#comments</comments>
		<pubDate>Thu, 08 Sep 2011 07:08:57 +0000</pubDate>
		<dc:creator>NickDarnell</dc:creator>
				<category><![CDATA[Awesome]]></category>
		<category><![CDATA[Game Industry]]></category>
		<category><![CDATA[Graphics]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Rendering]]></category>
		<category><![CDATA[Culling]]></category>
		<category><![CDATA[Game Developer Magazine]]></category>
		<category><![CDATA[Hierarchical Z-Buffer]]></category>

		<guid isPermaLink="false">http://www.nickdarnell.com/?p=1654</guid>
		<description><![CDATA[The September 2011 issue of Game Developer Magazine contains an article of mine!&#160; They asked me to write an article for the “Inner Product” section summarizing the Hi-Z GPU Culling algorithm as well as the related research I started working on to automatically generate occluders for the runtime. My copy hasn’t yet arrived in the [...]]]></description>
			<content:encoded><![CDATA[<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 5px; padding-left: 0px; padding-right: 0px; display: inline; float: right; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" align="right" src="http://www.nickdarnell.com/wp-content/uploads/2011/09/image.png" width="220" height="298" />
<p>The September 2011 issue of Game Developer Magazine contains an article of mine!&#160; They asked me to write an article for the “Inner Product” section summarizing the Hi-Z GPU Culling algorithm as well as the related research I started working on to automatically generate occluders for the runtime.</p>
<p>My copy hasn’t yet arrived in the mail so I don’t know how the final version turned out, but the last draft I saw after the good folks at GD Mag spruced up the language in my article was looking really good.</p>
<p>It was a lot of work putting the article together, more than I actually thought going into it.&#160; Especially since I already had 3 blog entries to pull from.&#160; However, you find yourself second guessing everything you write because it’s not like a blog entry that you can go back and edit if there’s a mistake.</p>
<p>It also becomes a bit more of a challenge to summarize things that you simply can’t add a link to and tell the reader, go read this.&#160; Also, not being able to just insert a huge chunk of code makes explaining something simple often a lot harder to explain in words.&#160; Hopefully you’re good at making diagrams in those situations.</p>
<p>It was an interesting experience.&#160; Really glad I got the opportunity to contribute an article.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nickdarnell.com/2011/09/published-achievement-unlocked/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SWIG: Casting Revisited</title>
		<link>http://www.nickdarnell.com/2011/08/swig-casting-revisited/</link>
		<comments>http://www.nickdarnell.com/2011/08/swig-casting-revisited/#comments</comments>
		<pubDate>Wed, 10 Aug 2011 14:59:52 +0000</pubDate>
		<dc:creator>NickDarnell</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[SWIG]]></category>

		<guid isPermaLink="false">http://www.nickdarnell.com/?p=1631</guid>
		<description><![CDATA[A while back I wrote SWIG and a Miss, which is a post about several of the problems I’ve encountered with SWIG. At that time I didn’t have a solution for dealing with down casting – the process of casting from a base class to a more derived class. I ended up coming up with [...]]]></description>
			<content:encoded><![CDATA[<p>A while back I wrote <a href="http://www.nickdarnell.com/2011/05/swig-and-a-miss/" target="_blank">SWIG and a Miss</a>, which is a post about several of the problems I’ve encountered with SWIG.  At that time I didn’t have a solution for dealing with down casting – the process of casting from a base class to a more derived class.</p>
<p>I ended up coming up with a solution that I thought would be good to do a post on, since there doesn’t seem to be much out there on SWIG and these types of problems.</p>
<h3>Some Background</h3>
<p>For those unfamiliar with why it’s difficult, let me explain.  When your API returns a native pointer to be wrapped, of lets say class Foo, and your function returns Foo* but the instance it returns is actually the more derived version Bar.  Sadly SWIG has no way of knowing this, so the object it creates in C# would be a C# Foo class.  Therefore, if you tried to cast the C# Foo to the more derived C# Bar you’d be unable to because as far as .Net is concerned the instance of Foo is just a Foo and nothing more.</p>
<p>Alright now that you understand the problem, lets talk about how we can solve it.</p>
<h3>How We Can Solve It</h3>
<p>The solution to the problem can be solved in essentially 3 ways,</p>
<h4>1 // Walk Away</h4>
<p>Simply don&#8217;t do anything that would require it.  Don&#8217;t expose classes that users will ever need to downcast to for any reason.  If this option is available to you, take it.  This however means that your base class needs to support all the functionality a user will ever need, something not always possible or desirable.  But if you can, do it, because once you get to script land, down casting becomes a expensive process.</p>
<h4>2 // Manual Cast Wrapper</h4>
<p>Write or generate C++ functions for every downcast that you would like to perform and SWIG those functions.  This would allow you to take object Foo as a parameter, returns Bar, does the dynamic cast in C++ and returns the pointer to Bar.</p>
<p>This option is manpower intensive and is truly brute forcing a solution.  It also causes potential holes where nasty aliasing occurs and can become a real problem if the source object is ever deleted.  Imagine an API with a factory function that returns object Foo, but Foo is actually Bar due to the way the factory works.  You need to access a Bar specific only function on the object so you downcast Foo to Bar.</p>
<p>Now in C++ these objects are the same object, but SWIG doesn&#8217;t know this, so two completely different C# objects are created one wrapping the native pointer to Foo, and one wrapping the native pointer to Bar.  If the SWIG layer was properly authored, the factory function notes that the object returned was created with new memory and thus SWIG is responsible for deleting the object.</p>
<p>So we call our Bar specific function and we decide to hang onto Bar and we let Foo on the stack pass out of scope, because why hang onto it, it&#8217;s the same object as Bar…right?  But Foo was responsible for managing the memory for the common native object they both point to.  So the underlying native object is destroyed when the garbage collector runs next after Foo is no longer referenced and now our Bar object points to totally bogus memory.</p>
<h4>3 // Custom Solution</h4>
<p>The solution I ended up coming up with requires you to have a custom RTTI system that allows you to check if an object is a specific type by name.</p>
<p>The first step is to extend the C# wrapper for your base class with RTTI information.  If you don’t have a base RTTI object this will be a bit harder.  The reason we have a new m_castedSource member variable is to solve the aliasing problem.  After the cast we can store the source here so that we never have to worry about the garbage collector accidentally cleaning up memory we’re still using.</p>

<div class="wp_syntax_wrapper"><span class="wp_syntax_lang">C#</span><div class="wp_syntax"><div class="code"><pre class="csharp" style="color: #FFF; font-family:&quot;Consolas&quot;,monospace,&quot;Courier New&quot;"><span style="color: #CCC;">%</span>typemap<span style="color: #CCC;">&#40;</span>cscode<span style="color: #CCC;">&#41;</span> YourBaseRTTIObject
<span style="color: #CCC;">%</span><span style="color: #CCC;">&#123;</span>
    <span style="color: #3D9EDD;">internal</span> YourBaseRTTIObject m_castedSource<span style="color: #CCC;">;</span>
&nbsp;
    <span style="color: #3D9EDD;">public</span> <span style="color: #99FFFF;">bool</span> IsKindOf<span style="color: #CCC;">&lt;</span>T<span style="color: #CCC;">&gt;</span><span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#41;</span>
    <span style="color: #CCC;">&#123;</span>
        <span style="color: #999;">// Use your C++ RTTI system to test if this wrapped C# object's</span>
        <span style="color: #999;">// native object is a 'typeof(T).Name'</span>
    <span style="color: #CCC;">&#125;</span>
<span style="color: #CCC;">%</span><span style="color: #CCC;">&#125;</span></pre></div></div></div>

<p>The next step is to create a function that can create the C# method needed to factory the C# object. We could use reflection, but that method is slow and we can do a far better job by emitting IL at runtime to specifically initialize one type and just cache those created methods.</p>

<div class="wp_syntax_wrapper"><span class="wp_syntax_lang">C#</span><div class="wp_syntax"><div class="code"><pre class="csharp" style="color: #FFF; font-family:&quot;Consolas&quot;,monospace,&quot;Courier New&quot;"><span style="color: #3D9EDD;">private</span> <span style="color: #3D9EDD;">static</span> Dictionary<span style="color: #CCC;">&lt;</span>Type, Func<span style="color: #CCC;">&lt;</span>IntPtr, <span style="color: #99FFFF;">bool</span>, <span style="color: #99FFFF;">object</span><span style="color: #CCC;">&gt;&gt;</span> constructorCache <span style="color: #CCC;">=</span>
    <span style="color: #996699;">new</span> Dictionary<span style="color: #CCC;">&lt;</span>Type, Func<span style="color: #CCC;">&lt;</span>IntPtr, <span style="color: #99FFFF;">bool</span>, <span style="color: #99FFFF;">object</span><span style="color: #CCC;">&gt;&gt;</span><span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
&nbsp;
<span style="color: #3D9EDD;">private</span> <span style="color: #3D9EDD;">static</span> Func<span style="color: #CCC;">&lt;</span>IntPtr, <span style="color: #99FFFF;">bool</span>, <span style="color: #99FFFF;">object</span><span style="color: #CCC;">&gt;</span> CreateConstructorDelegate<span style="color: #CCC;">&lt;</span>T<span style="color: #CCC;">&gt;</span><span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#41;</span>
<span style="color: #CCC;">&#123;</span>
    <span style="color: #999;">// We need to first grab the reflection information for the more derrived type we're casting to.</span>
    <span style="color: #999;">// SWIG has protected constructors we'll be able to call that take 2 parameters, the native pointer</span>
    <span style="color: #999;">// to the type and whether or not SWIG owns the memory</span>
    ConstructorInfo ctor <span style="color: #CCC;">=</span> <span style="color: #996699;">typeof</span><span style="color: #CCC;">&#40;</span>T<span style="color: #CCC;">&#41;</span><span style="color: #CCC;">.</span><span style="color: #FFF;">GetConstructor</span><span style="color: #CCC;">&#40;</span>
        BindingFlags<span style="color: #CCC;">.</span><span style="color: #FFF;">Instance</span> <span style="color: #CCC;">|</span> BindingFlags<span style="color: #CCC;">.</span><span style="color: #FFF;">NonPublic</span>, <span style="color: #3D9EDD;">null</span>,
        CallingConventions<span style="color: #CCC;">.</span><span style="color: #FFF;">HasThis</span>, <span style="color: #996699;">new</span> Type<span style="color: #CCC;">&#91;</span><span style="color: #CCC;">&#93;</span> <span style="color: #CCC;">&#123;</span> <span style="color: #996699;">typeof</span><span style="color: #CCC;">&#40;</span>IntPtr<span style="color: #CCC;">&#41;</span>, <span style="color: #996699;">typeof</span><span style="color: #CCC;">&#40;</span><span style="color: #99FFFF;">bool</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#125;</span>, <span style="color: #3D9EDD;">null</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
&nbsp;
    <span style="color: #999;">// Lets emit some IL that will allow us to construct our type much</span>
    <span style="color: #999;">// faster than using reflection.</span>
    DynamicMethod dm <span style="color: #CCC;">=</span> <span style="color: #996699;">new</span> DynamicMethod<span style="color: #CCC;">&#40;</span><span style="color: #7ACC00;">&quot;Create&quot;</span>, <span style="color: #996699;">typeof</span><span style="color: #CCC;">&#40;</span><span style="color: #99FFFF;">object</span><span style="color: #CCC;">&#41;</span>,
        <span style="color: #996699;">new</span> Type<span style="color: #CCC;">&#91;</span><span style="color: #CCC;">&#93;</span> <span style="color: #CCC;">&#123;</span> <span style="color: #996699;">typeof</span><span style="color: #CCC;">&#40;</span>IntPtr<span style="color: #CCC;">&#41;</span>, <span style="color: #996699;">typeof</span><span style="color: #CCC;">&#40;</span><span style="color: #99FFFF;">bool</span><span style="color: #CCC;">&#41;</span> <span style="color: #CCC;">&#125;</span>, <span style="color: #996699;">typeof</span><span style="color: #CCC;">&#40;</span>T<span style="color: #CCC;">&#41;</span>, <span style="color: #3D9EDD;">true</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
    ILGenerator il <span style="color: #CCC;">=</span> dm<span style="color: #CCC;">.</span><span style="color: #FFF;">GetILGenerator</span><span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
    il<span style="color: #CCC;">.</span><span style="color: #FFF;">Emit</span><span style="color: #CCC;">&#40;</span>OpCodes<span style="color: #CCC;">.</span><span style="color: #FFF;">Ldarg_0</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
    il<span style="color: #CCC;">.</span><span style="color: #FFF;">Emit</span><span style="color: #CCC;">&#40;</span>OpCodes<span style="color: #CCC;">.</span><span style="color: #FFF;">Ldarg_1</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
    il<span style="color: #CCC;">.</span><span style="color: #FFF;">Emit</span><span style="color: #CCC;">&#40;</span>OpCodes<span style="color: #CCC;">.</span><span style="color: #FFF;">Newobj</span>, ctor<span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
    il<span style="color: #CCC;">.</span><span style="color: #FFF;">Emit</span><span style="color: #CCC;">&#40;</span>OpCodes<span style="color: #CCC;">.</span><span style="color: #FFF;">Ret</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
&nbsp;
    <span style="color: #999;">// Create the delegate for the dynamic method, which will further improve the calling speed.</span>
    <span style="color: #3D9EDD;">return</span> <span style="color: #CCC;">&#40;</span>Func<span style="color: #CCC;">&lt;</span>IntPtr, <span style="color: #99FFFF;">bool</span>, <span style="color: #99FFFF;">object</span><span style="color: #CCC;">&gt;</span><span style="color: #CCC;">&#41;</span>dm<span style="color: #CCC;">.</span><span style="color: #FFF;">CreateDelegate</span><span style="color: #CCC;">&#40;</span><span style="color: #996699;">typeof</span><span style="color: #CCC;">&#40;</span>Func<span style="color: #CCC;">&lt;</span>IntPtr, <span style="color: #99FFFF;">bool</span>, <span style="color: #99FFFF;">object</span><span style="color: #CCC;">&gt;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
<span style="color: #CCC;">&#125;</span></pre></div></div></div>

<p>After that we need to add a function that can perform the down cast. This is just a matter of checking if the object is actually the desired casting type. If it is we get or create the factory delegate for the type. We construct the new wrapper object and hand it the pointer for the type. (NOTE: This is only viable if the new type isn&#8217;t offset in the vtable, as would be the case with multiple inheritance).</p>

<div class="wp_syntax_wrapper"><span class="wp_syntax_lang">C#</span><div class="wp_syntax"><div class="code"><pre class="csharp" style="color: #FFF; font-family:&quot;Consolas&quot;,monospace,&quot;Courier New&quot;"><span style="color: #3D9EDD;">public</span> <span style="color: #3D9EDD;">static</span> T CastTo<span style="color: #CCC;">&lt;</span>t<span style="color: #CCC;">&gt;</span><span style="color: #CCC;">&#40;</span>YourBaseRTTIObject self<span style="color: #CCC;">&#41;</span> <span style="color: #3D9EDD;">where</span> T <span style="color: #CCC;">:</span> YourBaseRTTIObject
<span style="color: #CCC;">&#123;</span>
    <span style="color: #3D9EDD;">if</span> <span style="color: #CCC;">&#40;</span>self <span style="color: #CCC;">==</span> <span style="color: #3D9EDD;">null</span><span style="color: #CCC;">&#41;</span>
        <span style="color: #3D9EDD;">return</span> <span style="color: #3D9EDD;">null</span><span style="color: #CCC;">;</span>
&nbsp;
    <span style="color: #999;">// Check if the object is actually the type we're trying to cast to.</span>
    <span style="color: #3D9EDD;">if</span> <span style="color: #CCC;">&#40;</span>self<span style="color: #CCC;">.</span><span style="color: #FFF;">IsKindOf</span><span style="color: #CCC;">&lt;</span>t<span style="color: #CCC;">&gt;</span><span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#41;</span>
    <span style="color: #CCC;">&#123;</span>
        Type type <span style="color: #CCC;">=</span> <span style="color: #996699;">typeof</span><span style="color: #CCC;">&#40;</span>T<span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
&nbsp;
        <span style="color: #999;">// Check if we've already cached the factory function.</span>
        Func<span style="color: #CCC;">&lt;</span>IntPtr, <span style="color: #99FFFF;">bool</span>, <span style="color: #99FFFF;">object</span><span style="color: #CCC;">&gt;</span> factory<span style="color: #CCC;">;</span>
        <span style="color: #3D9EDD;">if</span> <span style="color: #CCC;">&#40;</span><span style="color: #CCC;">!</span>constructorCache<span style="color: #CCC;">.</span><span style="color: #FFF;">TryGetValue</span><span style="color: #CCC;">&#40;</span>type, <span style="color: #3D9EDD;">out</span> factory<span style="color: #CCC;">&#41;</span><span style="color: #CCC;">&#41;</span>
        <span style="color: #CCC;">&#123;</span>
            factory <span style="color: #CCC;">=</span> CreateConstructorDelegate<span style="color: #CCC;">&lt;</span>t<span style="color: #CCC;">&gt;</span><span style="color: #CCC;">&#40;</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
            constructorCache<span style="color: #CCC;">.</span><span style="color: #FFF;">Add</span><span style="color: #CCC;">&#40;</span>type, factory<span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
        <span style="color: #CCC;">&#125;</span>
&nbsp;
        <span style="color: #999;">// Call the factory function and set the casted source to the</span>
        <span style="color: #999;">// current object.</span>
        T castedObject <span style="color: #CCC;">=</span> <span style="color: #CCC;">&#40;</span>T<span style="color: #CCC;">&#41;</span>factory<span style="color: #CCC;">&#40;</span>YourBaseRTTIObject<span style="color: #CCC;">.</span><span style="color: #FFF;">getCPtr</span><span style="color: #CCC;">&#40;</span>self<span style="color: #CCC;">&#41;</span><span style="color: #CCC;">.</span><span style="color: #FFF;">Handle</span>, <span style="color: #3D9EDD;">false</span><span style="color: #CCC;">&#41;</span><span style="color: #CCC;">;</span>
        castedObject<span style="color: #CCC;">.</span><span style="color: #FFF;">m_castedSource</span> <span style="color: #CCC;">=</span> self<span style="color: #CCC;">;</span>
&nbsp;
        <span style="color: #3D9EDD;">return</span> castedObject<span style="color: #CCC;">;</span>
    <span style="color: #CCC;">&#125;</span>
    <span style="color: #3D9EDD;">return</span> <span style="color: #3D9EDD;">null</span><span style="color: #CCC;">;</span>
<span style="color: #CCC;">&#125;</span></pre></div></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.nickdarnell.com/2011/08/swig-casting-revisited/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Project Photofly Experiment</title>
		<link>http://www.nickdarnell.com/2011/07/project-photofly-experiment/</link>
		<comments>http://www.nickdarnell.com/2011/07/project-photofly-experiment/#comments</comments>
		<pubDate>Tue, 26 Jul 2011 06:33:31 +0000</pubDate>
		<dc:creator>NickDarnell</dc:creator>
				<category><![CDATA[Awesome]]></category>
		<category><![CDATA[Game Industry]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Kinect]]></category>
		<category><![CDATA[Project Photofly]]></category>

		<guid isPermaLink="false">http://www.nickdarnell.com/?p=1621</guid>
		<description><![CDATA[Last week we were sitting around the office wondering if it would be possible to place ourselves in a game world with Autodesk’s Project Photofly.  How cool would that be?  We thought we might be able to scan one of us in a T-pose and then use Mixamo’s Auto-Rigging tool to create a rigged avatar.  [...]]]></description>
			<content:encoded><![CDATA[<p>Last week we were sitting around the office wondering if it would be possible to place ourselves in a game world with <a href="http://labs.autodesk.com/utilities/photo_scene_editor/overview/" target="_blank">Autodesk’s Project Photofly</a>.  How cool would that be?  We thought we might be able to scan one of us in a T-pose and then use <a href="http://www.mixamo.com/c/auto-rigger" target="_blank">Mixamo’s Auto-Rigging</a> tool to create a rigged avatar.  Then we could be running around a level in front of our Kinect as ourselves.</p>
<p>Sadly it never went past stage one.  It’s harder than you might think to hold a T-pose for 3 minutes while someone circles you twice snapping pictures at 10 degree intervals.</p>
<p>I don’t have any pictures of the results; I came out looking like the elephant man.  We’ll probably try again at some point, but in the meantime I made another scan of a pair of static objects that was turning out pretty good until I got to the back of the monkey.</p>
<p><a href="http://www.nickdarnell.com/2011/07/project-photofly-experiment/"><em>Click here to view the embedded video.</em></a></p>
<p>All in all Autodesk’s Photofly software is pretty cool.  It’s still lacking in the area of iteration and debugging.  You can try manually tagging photo matchup points between images to give it a better idea on how the images fit together but it takes awhile for the data to be processed in the cloud.  It’s also unclear where some data comes from, or why portions of the background become part of the foreground mesh.  If it had better feedback for how that data became part of the mesh cleaning up the results would be a lot easier.</p>
<p>Also, if you own a camera with a sports video mode that captures at 60 FPS you can just slowly circle the subject and then dump all the frames using <a href="http://paul.glagla.free.fr/imagegrab_en.htm" target="_blank">ImageGrab</a>.  Which is way easier than snapping individual pictures.</p>
<p>I wonder if I could generate 3d art for a game jam&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nickdarnell.com/2011/07/project-photofly-experiment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 1.037 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2012-02-12 23:08:49 -->

