<?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>voyce &#187; Graphics</title>
	<atom:link href="http://www.voyce.com/index.php/category/graphics/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.voyce.com</link>
	<description>Programming and debugging tidbits</description>
	<lastBuildDate>Sun, 15 Jan 2012 13:10:46 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>30 years ago at CES&#8230;</title>
		<link>http://www.voyce.com/index.php/2012/01/15/30-years-ago-at-ces/</link>
		<comments>http://www.voyce.com/index.php/2012/01/15/30-years-ago-at-ces/#comments</comments>
		<pubDate>Sun, 15 Jan 2012 13:10:46 +0000</pubDate>
		<dc:creator>ian</dc:creator>
				<category><![CDATA[Gaming]]></category>
		<category><![CDATA[Graphics]]></category>
		<category><![CDATA[retro]]></category>

		<guid isPermaLink="false">http://www.voyce.com/?p=1455</guid>
		<description><![CDATA[How different did things look at CES 30 years ago? Very.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.voyce.com/wp-content/uploads/2012/01/candvg_logo.png"><img src="http://www.voyce.com/wp-content/uploads/2012/01/candvg_logo.png" alt="candvg_logo" title="candvg_logo" width="200" height="167" class="alignleft size-full wp-image-1456" /></a>The other day while I was looking through some of my ancient copies of Computer and Video Games magazine (&#8221;the first fun computer magazine!&#8221;) I discovered some coverage of the 1982 Consumer Electronics Show. It&#8217;s such a contrast to today&#8217;s shiny, immaculately produced, PR-fest that I couldn&#8217;t help but scan it in for everyone to see.<br />
<span id="more-1455"></span><br />
To get things into context, this is 1982: The state of the art in home computing is ZX81s sold in kit form, Vic20s, PET 8K, Tandy TRS-80. But as the magazine says, home computing&#8217;s not where it&#8217;s at in the US:</p>
<blockquote><p>
&#8220;The 25th Consumer Electronics Show&#8230; showed very clearly that one thing continues to dominate the media and electronics business in the USA. This is not the personal computer &#8211; which seems to be causing far more interest in Europe than in America &#8211; but the video game.&#8221;
</p></blockquote>
<p>So while in the UK we were busy typing in listings from games magazines, in the US Atari, Mattel were creating ready-to-play cartridge based games.</p>
<p><a href="http://www.voyce.com/wp-content/uploads/2012/01/frogger_small.png"><img src="http://www.voyce.com/wp-content/uploads/2012/01/frogger_small.png" alt="frogger_small" title="frogger_small" width="195" height="250" class="alignright size-full wp-image-1459" /></a>Getting compelling press coverage was made difficult by the fact that it was impossible to get decent screen shots. Think how much of the pages in modern games mags are covered with glossy, full-colour, high-resolution screen shots. Without these, you&#8217;re left with nothing but words to describe these visual wonders. Luckily, you didn&#8217;t need much of a vocabulary to describe the games of the time; they were either based on existing analogue games, or they were derived from the small pool of original video game ideas:</p>
<blockquote><p>
&#8220;Munchie, which is similar to PacMan&#8221; &#8230; &#8220;Cosmic Raiders is a fast-action Defender style games&#8221; &#8230; &#8220;Solar Conqueror is an Asteroids game.&#8221;
</p></blockquote>
<p>Of course, some of this &#8220;re-purposing&#8221; was pukka; Coleco made table-top versions of things like PacMan, Donkey Kong, and Frogger (image above). You can imagine how faithful these arcade conversions actually were&#8230;</p>
<p>We&#8217;ve made quite some progress in the last 30 years, both in terms of game mechanics and graphics. It&#8217;s best summed up by 2 images, I&#8217;m sure you can guess which is from 1982, and which from 2012?<br />
<a href="http://www.voyce.com/wp-content/uploads/2012/01/frogbog.png"><img src="http://www.voyce.com/wp-content/uploads/2012/01/frogbog.png" alt="frogbog" title="frogbog" width="269" height="200" class="alignnone size-full wp-image-1463" /></a><a href="http://www.voyce.com/wp-content/uploads/2012/01/zeldahd.png"><img src="http://www.voyce.com/wp-content/uploads/2012/01/zeldahd.png" alt="zeldahd" title="zeldahd" width="356" height="200" class="alignnone size-full wp-image-1464" /></a></p>
<p>Click through these images for the full scans on flickr.</p>
<table>
<tr>
<td>
<a href="http://www.flickr.com/photos/ianvoyce/6700584931/" title="C&amp;VG March 1982 cover by ianvoyce, on Flickr"><img src="http://farm8.staticflickr.com/7003/6700584931_2d8a0a4c60_t.jpg" width="71" height="100" alt="C&amp;VG March 1982 cover"></a></td>
<td>
<a href="http://www.flickr.com/photos/ianvoyce/6700587409/" title="C&amp;VG CES 1982 coverage 1 by ianvoyce, on Flickr"><img src="http://farm8.staticflickr.com/7174/6700587409_65b6a1a129_t.jpg" width="71" height="100" alt="C&amp;VG CES 1982 coverage 1"></a></td>
<td>
<a href="http://www.flickr.com/photos/ianvoyce/6700589945/" title="C&amp;VG CES 1982 coverage 2 by ianvoyce, on Flickr"><img src="http://farm8.staticflickr.com/7011/6700589945_4bc78d3843_t.jpg" width="71" height="100" alt="C&amp;VG CES 1982 coverage 2"></a></td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.voyce.com/index.php/2012/01/15/30-years-ago-at-ces/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating a physics-based OpenGL iOS app</title>
		<link>http://www.voyce.com/index.php/2011/11/18/creating-a-physics-based-opengl-ios-app/</link>
		<comments>http://www.voyce.com/index.php/2011/11/18/creating-a-physics-based-opengl-ios-app/#comments</comments>
		<pubDate>Fri, 18 Nov 2011 22:40:50 +0000</pubDate>
		<dc:creator>ian</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Graphics]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Bullet]]></category>
		<category><![CDATA[iPad]]></category>
		<category><![CDATA[OpenGL]]></category>
		<category><![CDATA[physics]]></category>

		<guid isPermaLink="false">http://www.voyce.com/?p=1013</guid>
		<description><![CDATA[If you know a bit of OpenGL you can integrate the powerful Bullet physics API into your iPad or iPhone app.]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.voyce.com/wp-content/uploads/2010/09/puppet_grab.png" alt="puppet_grab" title="puppet_grab" width="128" height="128" class="alignleft size-full wp-image-1030" />With the success of iOS games like Angry Birds and its flocks of imitators, there are lots of people looking at creating physics-based games, so I decided to try and create a simple demo using OpenGL ES and the Bullet physics engine.<br />
<span id="more-1013"></span></p>
<h2>OpenGL</h2>
<p>The 3D work I&#8217;d done previously on iOS was using OpenGL ES 1.1, so as part of doing this, I also needed to get up to speed with the changes in version 2.0. The move involves replacing the fixed function pipeline approach with the use of shaders crafted in &#8220;shader language&#8221;, specifically <a href="http://www.opengl.org/documentation/glsl/">GLSL</a>. This approach is more flexible, but it means you take full responsibility for combining all the relevant matrices (model, projection etc), rather than letting OpenGL do it for you.</p>
<p>There are 2 distinct types of shader programs that operate on either vertices (vertex shaders) or pixels (fragment shaders). The steps required to create shader programs mirror the process of creating &#8220;normal&#8221; programs: they&#8217;re loaded, compiled and linked. Once you&#8217;ve got a program loaded, you can initialise it by setting variables of various kinds: attribute, uniform or varying. These are used for vertex and colour data, constants and passing data between vertex and fragment shaders respectively. If you&#8217;re interested in learning more, I suggest you check out some of the plethora of internet and dead-tree material on OpenGL. I&#8217;ll only be doing pretty basic stuff here.   </p>
<h2>Bullet</h2>
<p>I decided to try using <a href="http://bulletphysics.org/wordpress/">Bullet</a> as the physics engine. It looks very powerful and is widely used in various games and <a href="http://bulletphysics.org/wordpress/?p=241">movies</a>; the only bad thing I can say about it is that decent documentation is a bit lacking. I found the best way to get help was googling for API names on the Bullet forum; not a very efficient way of doing things. Maybe I&#8217;ve just been spoilt by the copious Apple and MS docs (yeah, yeah). </p>
<h3>Building it</h3>
<p>Luckily Bullet comes with an Xcode project &#8220;in the box&#8221;, so with a bit of <code>autoconf</code> magic, it was soon up and building the demo apps. Although there are loads of files in there, the core library itself isn&#8217;t too large or complex. As such, I decided to create a separate static library project targeting the iOS simulator (i386) and devices (armv6/7).</p>
<h3>API basics</h3>
<p>My intention is to use only a small subset of the Bullet API, encompassing rigid bodies and a couple of simple constraint types. For the purposes of the demo, I&#8217;m going to create the pretty standard set-up of a large static ground-box, along with a collection of more dynamic objects.  </p>
<p>The key part of joining up Bullet with your existing API is the <a href="http://www.bulletphysics.com/Bullet/BulletFull/classbtMotionState.html">btMotionState</a> class. It enables the API to callback into your code with updated positions at each &#8216;tick&#8217; of the physics engine, and you can then alter your geometry appropriately. I created a simple class that derives from <code>btMotionState</code>, implements the required pure virtual methods and contains a reference to my world object. Bullet calls the subclassed methods and we pass the transformations on to the object.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">class</span> QuadMotionState <span style="color: #008080;">:</span> <span style="color: #0000ff;">public</span> btMotionState <span style="color: #008000;">&#123;</span>
    Quad <span style="color: #000040;">*</span>_object<span style="color: #008080;">;</span>
    btTransform _transform<span style="color: #008080;">;</span>
<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
    QuadMotionState<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> btTransform <span style="color: #000040;">&amp;</span>initialpos, Quad <span style="color: #000040;">*</span>node<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        _object <span style="color: #000080;">=</span> node<span style="color: #008080;">;</span>
        _transform <span style="color: #000080;">=</span> initialpos<span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0000ff;">virtual</span> ~QuadMotionState<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0000ff;">void</span> setNode<span style="color: #008000;">&#40;</span>Quad <span style="color: #000040;">*</span>node<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        _object <span style="color: #000080;">=</span> node<span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0000ff;">virtual</span> <span style="color: #0000ff;">void</span> getWorldTransform<span style="color: #008000;">&#40;</span>btTransform <span style="color: #000040;">&amp;</span>worldTrans<span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span> <span style="color: #008000;">&#123;</span>
        worldTrans <span style="color: #000080;">=</span> _transform<span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0000ff;">virtual</span> <span style="color: #0000ff;">void</span> setWorldTransform<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> btTransform <span style="color: #000040;">&amp;</span>worldTrans<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        <span style="color: #666666;">// Pass the worldTrans to _object</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span></pre></div></div>

<h3>Debugging</h3>
<p>Now, obviously <em>you</em> will write the perfect code first time, and will have no need for any kind of diagnostics. But I am not that perfect; I need to see the difference between what I&#8217;ve told the API to do, and what it&#8217;s actually doing. You can do this by creating an object implementing <code>btIDebugDraw</code> and passing it to the (slightly oddly named) setDebugDrawer function on your world:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">btIDebugDraw <span style="color: #000040;">*</span>debug <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> DebugDrawHelper<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
m_dynamicsWorld<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>setDebugDrawer<span style="color: #008000;">&#40;</span>debug<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p>The most important function on <code>btIDebugDraw</code> is <code>drawLine</code>. It will be called repeatedly to draw axes and bounding boxes in a variety of colours to indicate the object&#8217;s state. We can use the <code>Shader</code> we created earlier to give us an easy way of generating these debug visuals. All we need is a very simple shader, so can declare it inline:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">program.<span style="color: #007788;">loadShaders</span><span style="color: #008000;">&#40;</span>
		<span style="color: #FF0000;">&quot;attribute vec4 position;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
		<span style="color: #FF0000;">&quot;uniform mat4 projection;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
		<span style="color: #FF0000;">&quot;void main () {<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
		<span style="color: #FF0000;">&quot;gl_Position = position * projection;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
		<span style="color: #FF0000;">&quot;}<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>, 
&nbsp;
		<span style="color: #FF0000;">&quot;uniform highp vec3 color;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
		<span style="color: #FF0000;">&quot;void main () {<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
		<span style="color: #FF0000;">&quot;gl_FragColor = vec4(color.r, color.g, color.b, 0.0);<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
		<span style="color: #FF0000;">&quot;}&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p>Of course, anything more complex than this and you&#8217;ll want to put it into a separate file, but this program allows us to pass in the start and end vertex and its colour to draw the line in our implementation of <code>DrawLine</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">virtual</span> <span style="color: #0000ff;">void</span> drawLine<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> btVector3<span style="color: #000040;">&amp;</span> from,<span style="color: #0000ff;">const</span> btVector3<span style="color: #000040;">&amp;</span> to,<span style="color: #0000ff;">const</span> btVector3<span style="color: #000040;">&amp;</span> color<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        glUseProgram<span style="color: #008000;">&#40;</span>program.<span style="color: #007788;">getProgram</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
        <span style="color: #666666;">// Set the projection matrix</span>
        GLint pu <span style="color: #000080;">=</span> glGetUniformLocation<span style="color: #008000;">&#40;</span>program.<span style="color: #007788;">getProgram</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, <span style="color: #FF0000;">&quot;projection&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        glUniformMatrix4fv<span style="color: #008000;">&#40;</span>pu, <span style="color: #0000dd;">1</span>, <span style="color: #0000dd;">0</span>, _projection.<span style="color: #007788;">Pointer</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
        <span style="color: #666666;">// Set the colour of the line</span>
        GLint puc <span style="color: #000080;">=</span> glGetUniformLocation<span style="color: #008000;">&#40;</span>program.<span style="color: #007788;">getProgram</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, <span style="color: #FF0000;">&quot;color&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        vec3 v <span style="color: #000080;">=</span> vec3<span style="color: #008000;">&#40;</span>color.<span style="color: #007788;">getX</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, color.<span style="color: #007788;">getY</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, color.<span style="color: #007788;">getZ</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        glUniform3fv<span style="color: #008000;">&#40;</span>puc, <span style="color: #0000dd;">1</span>, v.<span style="color: #007788;">Pointer</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
        <span style="color: #666666;">// Set the line vertices</span>
        <span style="color: #0000ff;">float</span> tmp<span style="color: #008000;">&#91;</span> <span style="color: #0000dd;">6</span> <span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #008000;">&#123;</span> from.<span style="color: #007788;">getX</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, from.<span style="color: #007788;">getY</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, from.<span style="color: #007788;">getZ</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>,
            to.<span style="color: #007788;">getX</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, to.<span style="color: #007788;">getY</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, to.<span style="color: #007788;">getZ</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
        glVertexAttribPointer<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">0</span>, <span style="color: #0000dd;">3</span>, GL_FLOAT, <span style="color: #0000ff;">false</span>, <span style="color: #0000dd;">0</span>, <span style="color: #000040;">&amp;</span>tmp<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        glEnableVertexAttribArray<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        glDrawArrays<span style="color: #008000;">&#40;</span> GL_LINES, <span style="color: #0000dd;">0</span>, <span style="color: #0000dd;">2</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p><div id="attachment_1327" class="wp-caption alignright" style="width: 236px"><a href="http://www.voyce.com/wp-content/uploads/2010/09/physics_debug_screenshot.png"><img src="http://www.voyce.com/wp-content/uploads/2010/09/physics_debug_screenshot-226x300.png" alt="Bullet debug output" title="physics_debug_screenshot" width="226" height="300" class="size-medium wp-image-1327" /></a><p class="wp-caption-text">Bullet debug output</p></div> You&#8217;ll end up with a display showing your quads, along with their orientation and state (whether they&#8217;re &#8220;active&#8221; in the simulation). It looks something like this:<br />
<br clear="all"/></p>
<h3>Populating the world</h3>
<p>So in order to have something nice to look at, we&#8217;re gonna need to put some &#8216;things&#8217; into our world. And in order to make it act like the real world we&#8217;ll need to give those things some physical properties.</p>
<p>I created a simple class to render a textured box. This OpenGL object then needs to be represented in the physics worlds by a rigid body object, which in turn contains a collision detection object that closely matches the dimensions of the original object. In fact, in the case of a box, the collision detection object matches exactly, otherwise you&#8217;ll need to create an approximation using the more advanced classes. We use a <code>btBoxShape</code> to initialise our <code>btRigidBody</code> instance, along with setting its mass, inertia, and making a link to the state object that I mentioned above.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">btRigidBody <span style="color: #000040;">*</span>addShape<span style="color: #008000;">&#40;</span>Quad <span style="color: #000040;">*</span>shape, btScalar mass <span style="color: #000080;">=</span> <span style="color:#800080;">1.0f</span>, <span style="color: #0000ff;">float</span> restitution <span style="color: #000080;">=</span> <span style="color:#800080;">0.2f</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	<span style="color: #666666;">// Set the initial transform based on the current location of the object</span>
        btTransform transform<span style="color: #008080;">;</span>
	transform.<span style="color: #007788;">setIdentity</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	transform.<span style="color: #007788;">setOrigin</span><span style="color: #008000;">&#40;</span>btVector3<span style="color: #008000;">&#40;</span>shape<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>getX<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, shape<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>getY<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, <span style="color:#800080;">0.</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
	btCollisionShape<span style="color: #000040;">*</span> cshape <span style="color: #000080;">=</span> 
            <span style="color: #0000dd;">new</span> btBoxShape<span style="color: #008000;">&#40;</span>btVector3<span style="color: #008000;">&#40;</span>btScalar<span style="color: #008000;">&#40;</span>shape<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>getWidth<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #000040;">/</span><span style="color: #0000dd;">2</span><span style="color: #008000;">&#41;</span>,
                                     btScalar<span style="color: #008000;">&#40;</span>shape<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>getHeight<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #000040;">/</span><span style="color: #0000dd;">2</span><span style="color: #008000;">&#41;</span>,
                                     btScalar<span style="color: #008000;">&#40;</span>shape<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>getDepth<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #000040;">/</span><span style="color: #0000dd;">2</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        btVector3 localInertia<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">0</span>,<span style="color: #0000dd;">0</span>,<span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>mass <span style="color: #000040;">!</span><span style="color: #000080;">=</span> <span style="color:#800080;">0.0f</span><span style="color: #008000;">&#41;</span>
            cshape<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>calculateLocalInertia<span style="color: #008000;">&#40;</span>mass,localInertia<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
        QuadMotionState <span style="color: #000040;">*</span>state <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> QuadMotionState<span style="color: #008000;">&#40;</span>transform, shape<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	btRigidBody<span style="color: #008080;">::</span><span style="color: #007788;">btRigidBodyConstructionInfo</span> rbInfo<span style="color: #008000;">&#40;</span>mass, state, cshape, localInertia<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	btRigidBody<span style="color: #000040;">*</span> body <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> btRigidBody<span style="color: #008000;">&#40;</span>rbInfo<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
	body<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>setDamping<span style="color: #008000;">&#40;</span><span style="color:#800080;">0.85</span>, <span style="color:#800080;">0.85</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	body<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>setRestitution<span style="color: #008000;">&#40;</span>restitution<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
        <span style="color: #666666;">// Add the rigid body to the Bullet physics world</span>
	m_dynamicsWorld<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>addRigidBody<span style="color: #008000;">&#40;</span>body<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
        <span style="color: #666666;">// Establish the link between our object and the physics object</span>
	shape<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>setPhysicsObject<span style="color: #008000;">&#40;</span>body<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">return</span> body<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>To make things look a bit more polished I added some textures to the quads, along with very simple normal mapping to get some lighting effects. I also added the ability to rotate the view and zoom in and out by using <code>UIGestureRecognizer</code>s and changing the camera transform appropriately. The &#8220;finishing&#8221; touch (yeah, right), is the ability to tap to add a new quad.</p>
<h3>The results</h3>
<p>Here&#8217;s how the final thing looks. It&#8217;s very basic, I&#8217;ve hardly touched the surface of the Bullet API &#8211; there are no constraints in play, for instance &#8211; but it&#8217;s still kind of fun to play with. It&#8217;s running fairly slowly here, what with it being in the simulator, and being recorded. On a physical iPad it&#8217;s much snappier.<object width="420" height="315"><param name="movie" value="http://www.youtube.com/v/vbQ_EC_YlFY?version=3&amp;hl=en_US&amp;rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/vbQ_EC_YlFY?version=3&amp;hl=en_US&amp;rel=0" type="application/x-shockwave-flash" width="420" height="315" allowscriptaccess="always" allowfullscreen="true"></embed></object><br />
Let me know if you&#8217;d be interested to see some more coverage of some of Bullet&#8217;s constraints and hinges features. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.voyce.com/index.php/2011/11/18/creating-a-physics-based-opengl-ios-app/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Kinect SDK with F#</title>
		<link>http://www.voyce.com/index.php/2011/09/05/kinect-sdk-with-f/</link>
		<comments>http://www.voyce.com/index.php/2011/09/05/kinect-sdk-with-f/#comments</comments>
		<pubDate>Mon, 05 Sep 2011 14:34:47 +0000</pubDate>
		<dc:creator>ian</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[F#]]></category>
		<category><![CDATA[Graphics]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[kinect]]></category>
		<category><![CDATA[wpf]]></category>

		<guid isPermaLink="false">http://www.voyce.com/?p=1273</guid>
		<description><![CDATA[My first quick look at using the Kinect SDK with F#.]]></description>
			<content:encoded><![CDATA[<p><div id="attachment_1283" class="wp-caption alignleft" style="width: 210px"><a href="http://www.voyce.com/wp-content/uploads/2011/09/kinect.png"><img src="http://www.voyce.com/wp-content/uploads/2011/09/kinect.png" alt="Just what do you think you&#039;re doing, Dave?" title="kinect" width="200" height="200" class="size-full wp-image-1283" /></a><p class="wp-caption-text">Just what do you think you're doing, Dave?</p></div>I finally got around to taking a look at the <a href="http://research.microsoft.com/en-us/um/redmond/projects/kinectsdk/">Kinect SDK</a> the other day, partly because I was interested to see how the API looked from F#. Unfortunately getting it going turned out to be more of a pain than I was expecting.</p>
<p>The first bit was easy: I&#8217;m &#8220;lucky&#8221; enough to have one of the older Xboxes, which meant I&#8217;d had to get a Kinect with separate power, which is the one required by the SDK. Now all I needed was a Windows machine to develop on.<br />
<span id="more-1273"></span><br />
For all my Visual Studio stuff at home I use a virtual machine, and unfortunately I missed the point in the <a href="http://research.microsoft.com/en-us/um/redmond/projects/kinectsdk/docs/readme.htm">readme</a> about &#8220;Kinect for Windows applications cannot run in a virtual machine&#8221;. Doh. That would explain why, try as I might I couldn&#8217;t get <a href="http://www.virtualbox.org/">VirtualBox</a> to detect the device when I plugged it into the host. Whatever I did I ended up with a &#8216;resource is busy&#8217; error. </p>
<p>I even tried another VM, this time from VMWare. It got further, with the guest seeing the devices, but whenever I tried to run the sample apps the API initialisation call failed. Unfortunately the samples make a bit of a rookie mistake and don&#8217;t display the error code associated with the failure; the only way to get the underlying HRESULT is to debug the app. As it turned out the error was the catch-all <code>80080014</code>, which is attributed to various USB issues.</p>
<p>So, I finally relented and decided to once again set-up Bootcamp, which I&#8217;d stopped using a while back: why bother when VMs had done everything I needed? Again I was snookered, this time by the incompatibility of the <a href="http://en.wikipedia.org/wiki/Unified_Extensible_Firmware_Interface">EFI</a> firmware in my ageing MacBook with the Win7 x64 install disc (which I&#8217;d had to actually burn onto optical media &#8211; can&#8217;t remember the last time I burnt a real physical disk)!</p>
<p>Eventually, I got Win7 x86, Visual Studio and the Kinect SDK installed on the metal, plugged in the sensor and &#8211; whoa &#8211; the devices were recognised and the drivers installed and&#8230; the samples ran!</p>
<p>From this point doing some hacking was pretty straightforward. I set about creating a project that used the skeletal tracking ability from the SDK. The project needs to reference the <code>Microsoft.Research.Kinect</code> assembly, then we can open some namespaces and initialise the API:</p>

<div class="wp_syntax"><div class="code"><pre class="fsharp" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">open</span> System
<span style="color: #06c; font-weight: bold;">open</span> Microsoft<span style="color: #000080;">.</span><span style="color: #505090;">Research</span><span style="color: #000080;">.</span><span style="color: #505090;">Kinect</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">let</span> nui <span style="color: #000080;">=</span> Nui<span style="color: #000080;">.</span><span style="color: #505090;">Runtime</span><span style="color: #000080;">&#40;</span><span style="color: #000080;">&#41;</span>
nui<span style="color: #000080;">.</span><span style="color: #505090;">Initialize</span><span style="color: #000080;">&#40;</span>Nui<span style="color: #000080;">.</span><span style="color: #505090;">RuntimeOptions</span><span style="color: #000080;">.</span><span style="color: #505090;">UseSkeletalTracking</span><span style="color: #000080;">&#41;</span></pre></div></div>

<p>The API uses .NET events to communicate back to the application that some form of data is available. Depending on the options that you specify at init time, any of the skeletal, depth frame or colour data will be returned in the event arguments. This seems like a good place to use F# Async&#8217;s event integration: Async.AwaitEvent. We can quite easily write some code that will create an Async task that will repeatedly listen for events:</p>

<div class="wp_syntax"><div class="code"><pre class="fsharp" style="font-family:monospace;">    <span style="color: #06c; font-weight: bold;">let</span> skeleton <span style="color: #000080;">&#40;</span>nui <span style="color: #000080;">:</span> Nui<span style="color: #000080;">.</span><span style="color: #505090;">Runtime</span><span style="color: #000080;">&#41;</span> <span style="color: #000080;">=</span>
        <span style="color: #06c; font-weight: bold;">let</span> <span style="color: #06c; font-weight: bold;">rec</span> loop <span style="color: #000080;">&#40;</span><span style="color: #000080;">&#41;</span> <span style="color: #000080;">=</span>
            async <span style="color: #000080;">&#123;</span> 
                <span style="color: #06c; font-weight: bold;">let</span><span style="color: #000080;">!</span> args <span style="color: #000080;">=</span> Async<span style="color: #000080;">.</span><span style="color: #505090;">AwaitEvent</span> nui<span style="color: #000080;">.</span><span style="color: #505090;">SkeletonFrameReady</span>
                <span style="color: #060; font-style: italic;">// Do something with the args</span>
                <span style="color: #06c; font-weight: bold;">return</span><span style="color: #000080;">!</span> loop <span style="color: #000080;">&#40;</span><span style="color: #000080;">&#41;</span> 
            <span style="color: #000080;">&#125;</span>
        loop <span style="color: #000080;">&#40;</span><span style="color: #000080;">&#41;</span>
    <span style="color: #060; font-style: italic;">// Start the process of listening for events...</span>
    skeleton nui <span style="color: #000080;">|&gt;</span> Async<span style="color: #000080;">.</span><span style="color: #505090;">Start</span></pre></div></div>

<p>This seems to work nicely, although I&#8217;m not sure of the overhead involved, perhaps a solution involving Rx would be more appropriate. Anyway, let&#8217;s do something with the data we get in the event, like getting all the skeletons that are being tracked, and passing them to a <code>draw</code> function:</p>

<div class="wp_syntax"><div class="code"><pre class="fsharp" style="font-family:monospace;">                args<span style="color: #000080;">.</span><span style="color: #505090;">SkeletonFrame</span><span style="color: #000080;">.</span><span style="color: #505090;">Skeletons</span> 
                <span style="color: #000080;">|&gt;</span> Seq<span style="color: #000080;">.</span><span style="color: #505090;">filter</span> <span style="color: #000080;">&#40;</span><span style="color: #06c; font-weight: bold;">fun</span> s <span style="color: #000080;">-&gt;</span> s<span style="color: #000080;">.</span><span style="color: #505090;">TrackingState</span> <span style="color: #000080;">=</span> Nui<span style="color: #000080;">.</span><span style="color: #505090;">SkeletonTrackingState</span><span style="color: #000080;">.</span><span style="color: #505090;">Tracked</span><span style="color: #000080;">&#41;</span>
                <span style="color: #000080;">|&gt;</span> Seq<span style="color: #000080;">.</span><span style="color: #505090;">iter</span> draw</pre></div></div>

<p>All that&#8217;s left is doing something cool in <code>draw</code>! Oh, and setting up all the GUI stuff necessary to actually get some pixels on the screen. I went for the WPF approach (as the managed samples do), which involves creating a simple object tree to display a rectangle in a canvas in a grid in a window, and doing a bit of marshalling back from the thread pool (where our Async code runs) to the main GUI thread.</p>
<p>Here&#8217;s all the code for possibly the most tedious thing you could do with a Kinect! But hey, it&#8217;s a starting point, right? I&#8217;m sure at some point I&#8217;ll get around to doing something cooler than a couple of small red rectangles with it&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="fsharp" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">open</span> System
<span style="color: #06c; font-weight: bold;">open</span> System<span style="color: #000080;">.</span><span style="color: #505090;">Windows</span>
<span style="color: #06c; font-weight: bold;">open</span> Microsoft<span style="color: #000080;">.</span><span style="color: #505090;">Research</span><span style="color: #000080;">.</span><span style="color: #505090;">Kinect</span>
&nbsp;
<span style="color: #000080;">&#91;</span><span style="color: #000080;">&lt;</span>STAThread<span style="color: #000080;">&gt;</span><span style="color: #000080;">&#93;</span>
<span style="color: #06c; font-weight: bold;">do</span>
    <span style="color: #06c; font-weight: bold;">let</span> nui <span style="color: #000080;">=</span> Nui<span style="color: #000080;">.</span><span style="color: #505090;">Runtime</span><span style="color: #000080;">&#40;</span><span style="color: #000080;">&#41;</span>
    nui<span style="color: #000080;">.</span><span style="color: #505090;">Initialize</span><span style="color: #000080;">&#40;</span>Nui<span style="color: #000080;">.</span><span style="color: #505090;">RuntimeOptions</span><span style="color: #000080;">.</span><span style="color: #505090;">UseSkeletalTracking</span><span style="color: #000080;">&#41;</span>
&nbsp;
    <span style="color: #060; font-style: italic;">// lifted straight from the sample code</span>
    <span style="color: #06c; font-weight: bold;">let</span> getDisplayPosition w h <span style="color: #000080;">&#40;</span>joint <span style="color: #000080;">:</span> Nui<span style="color: #000080;">.</span><span style="color: #505090;">Joint</span><span style="color: #000080;">&#41;</span> <span style="color: #000080;">=</span>
            <span style="color: #06c; font-weight: bold;">let</span> <span style="color: #06c; font-weight: bold;">mutable</span> depthX <span style="color: #000080;">=</span> 0<span style="color: #000080;">.</span>0f
            <span style="color: #06c; font-weight: bold;">let</span> <span style="color: #06c; font-weight: bold;">mutable</span> depthY <span style="color: #000080;">=</span> 0<span style="color: #000080;">.</span>0f
            nui<span style="color: #000080;">.</span><span style="color: #505090;">SkeletonEngine</span><span style="color: #000080;">.</span><span style="color: #505090;">SkeletonToDepthImage</span><span style="color: #000080;">&#40;</span>joint<span style="color: #000080;">.</span><span style="color: #505090;">Position</span>, <span style="color: #000080;">&amp;</span>depthX, <span style="color: #000080;">&amp;</span>depthY<span style="color: #000080;">&#41;</span>
            <span style="color: #06c; font-weight: bold;">let</span> depthX <span style="color: #000080;">=</span> depthX <span style="color: #000080;">*</span> 320<span style="color: #000080;">.</span>0f<span style="color: #000080;">;</span> <span style="color: #060; font-style: italic;">//convert to 320, 240 space</span>
            <span style="color: #06c; font-weight: bold;">let</span> depthY <span style="color: #000080;">=</span> depthY <span style="color: #000080;">*</span> 240<span style="color: #000080;">.</span>0f<span style="color: #000080;">;</span> <span style="color: #060; font-style: italic;">//convert to 320, 240 space</span>
            <span style="color: #06c; font-weight: bold;">let</span> <span style="color: #06c; font-weight: bold;">mutable</span> colorX <span style="color: #000080;">=</span> <span style="color: #c6c;">0</span>
            <span style="color: #06c; font-weight: bold;">let</span> <span style="color: #06c; font-weight: bold;">mutable</span> colorY <span style="color: #000080;">=</span> <span style="color: #c6c;">0</span>
            <span style="color: #06c; font-weight: bold;">let</span> iv <span style="color: #000080;">=</span> <span style="color: #06c; font-weight: bold;">new</span> Nui<span style="color: #000080;">.</span><span style="color: #505090;">ImageViewArea</span><span style="color: #000080;">&#40;</span><span style="color: #000080;">&#41;</span>
            <span style="color: #060; font-style: italic;">// only ImageResolution.Resolution640x480 is supported at this point</span>
            nui<span style="color: #000080;">.</span><span style="color: #505090;">NuiCamera</span><span style="color: #000080;">.</span><span style="color: #505090;">GetColorPixelCoordinatesFromDepthPixel</span><span style="color: #000080;">&#40;</span>Nui<span style="color: #000080;">.</span><span style="color: #505090;">ImageResolution</span><span style="color: #000080;">.</span><span style="color: #505090;">Resolution640x480</span>, iv, 
                <span style="color: #000080;">&#40;</span>int<span style="color: #000080;">&#41;</span>depthX, <span style="color: #000080;">&#40;</span>int<span style="color: #000080;">&#41;</span>depthY, 0s, <span style="color: #000080;">&amp;</span>colorX, <span style="color: #000080;">&amp;</span>colorY<span style="color: #000080;">&#41;</span>
&nbsp;
            <span style="color: #060; font-style: italic;">// map back to visible area</span>
            <span style="color: #06c; font-weight: bold;">new</span> Point<span style="color: #000080;">&#40;</span><span style="color: #000080;">&#40;</span>w <span style="color: #000080;">*</span> <span style="color: #000080;">&#40;</span>float<span style="color: #000080;">&#41;</span>colorX <span style="color: #000080;">/</span> 640<span style="color: #000080;">.</span><span style="color: #000080;">&#41;</span>, <span style="color: #000080;">&#40;</span>h <span style="color: #000080;">*</span> <span style="color: #000080;">&#40;</span>float<span style="color: #000080;">&#41;</span>colorY <span style="color: #000080;">/</span> 480<span style="color: #000080;">.</span><span style="color: #000080;">&#41;</span><span style="color: #000080;">&#41;</span>
&nbsp;
    <span style="color: #060; font-style: italic;">// Set-up the WPF window and its contents</span>
    <span style="color: #06c; font-weight: bold;">let</span> width <span style="color: #000080;">=</span> 1024<span style="color: #000080;">.</span>
    <span style="color: #06c; font-weight: bold;">let</span> height <span style="color: #000080;">=</span> 768<span style="color: #000080;">.</span>
    <span style="color: #06c; font-weight: bold;">let</span> w <span style="color: #000080;">=</span> Window<span style="color: #000080;">&#40;</span>Width<span style="color: #000080;">=</span>width, Height<span style="color: #000080;">=</span>height<span style="color: #000080;">&#41;</span>
    <span style="color: #06c; font-weight: bold;">let</span> g <span style="color: #000080;">=</span> Controls<span style="color: #000080;">.</span><span style="color: #505090;">Grid</span><span style="color: #000080;">&#40;</span><span style="color: #000080;">&#41;</span>
    <span style="color: #06c; font-weight: bold;">let</span> c <span style="color: #000080;">=</span> Controls<span style="color: #000080;">.</span><span style="color: #505090;">Canvas</span><span style="color: #000080;">&#40;</span><span style="color: #000080;">&#41;</span>
    <span style="color: #06c; font-weight: bold;">let</span> hd <span style="color: #000080;">=</span> Shapes<span style="color: #000080;">.</span><span style="color: #505090;">Rectangle</span><span style="color: #000080;">&#40;</span>Fill<span style="color: #000080;">=</span>Media<span style="color: #000080;">.</span><span style="color: #505090;">Brushes</span><span style="color: #000080;">.</span><span style="color: #505090;">Red</span>, Width<span style="color: #000080;">=</span>10<span style="color: #000080;">.</span>, Height<span style="color: #000080;">=</span>10<span style="color: #000080;">.</span><span style="color: #000080;">&#41;</span>
    ignore <span style="color: #000080;">&lt;|</span> c<span style="color: #000080;">.</span><span style="color: #505090;">Children</span><span style="color: #000080;">.</span><span style="color: #505090;">Add</span> hd
    ignore <span style="color: #000080;">&lt;|</span> g<span style="color: #000080;">.</span><span style="color: #505090;">Children</span><span style="color: #000080;">.</span><span style="color: #505090;">Add</span> c
    w<span style="color: #000080;">.</span><span style="color: #505090;">Content</span> <span style="color: #000080;">&lt;-</span> g
&nbsp;
    <span style="color: #060; font-style: italic;">// We simple move the rectangle to where the head is</span>
    <span style="color: #06c; font-weight: bold;">let</span> draw <span style="color: #000080;">&#40;</span>s <span style="color: #000080;">:</span> Nui<span style="color: #000080;">.</span><span style="color: #505090;">SkeletonData</span><span style="color: #000080;">&#41;</span> <span style="color: #000080;">=</span>
        <span style="color: #06c; font-weight: bold;">let</span> point <span style="color: #000080;">=</span> getDisplayPosition width height s<span style="color: #000080;">.</span><span style="color: #505090;">Joints</span><span style="color: #000080;">.</span><span style="color: #000080;">&#91;</span>Nui<span style="color: #000080;">.</span><span style="color: #505090;">JointID</span><span style="color: #000080;">.</span><span style="color: #505090;">Head</span><span style="color: #000080;">&#93;</span>
        ignore <span style="color: #000080;">&lt;|</span> w<span style="color: #000080;">.</span><span style="color: #505090;">Dispatcher</span><span style="color: #000080;">.</span><span style="color: #505090;">BeginInvoke</span><span style="color: #000080;">&#40;</span>Threading<span style="color: #000080;">.</span><span style="color: #505090;">DispatcherPriority</span><span style="color: #000080;">.</span><span style="color: #505090;">Normal</span>, Action<span style="color: #000080;">&#40;</span><span style="color: #06c; font-weight: bold;">fun</span> <span style="color: #000080;">&#40;</span><span style="color: #000080;">&#41;</span> <span style="color: #000080;">-&gt;</span>    
            hd<span style="color: #000080;">.</span><span style="color: #505090;">SetValue</span><span style="color: #000080;">&#40;</span>Controls<span style="color: #000080;">.</span><span style="color: #505090;">Canvas</span><span style="color: #000080;">.</span><span style="color: #505090;">TopProperty</span>, point<span style="color: #000080;">.</span><span style="color: #505090;">Y</span><span style="color: #000080;">&#41;</span>
            hd<span style="color: #000080;">.</span><span style="color: #505090;">SetValue</span><span style="color: #000080;">&#40;</span>Controls<span style="color: #000080;">.</span><span style="color: #505090;">Canvas</span><span style="color: #000080;">.</span><span style="color: #505090;">LeftProperty</span>, point<span style="color: #000080;">.</span><span style="color: #505090;">X</span><span style="color: #000080;">&#41;</span><span style="color: #000080;">&#41;</span><span style="color: #000080;">&#41;</span>
&nbsp;
    <span style="color: #06c; font-weight: bold;">let</span> skeleton <span style="color: #000080;">&#40;</span>nui <span style="color: #000080;">:</span> Nui<span style="color: #000080;">.</span><span style="color: #505090;">Runtime</span><span style="color: #000080;">&#41;</span> <span style="color: #000080;">=</span>
        <span style="color: #06c; font-weight: bold;">let</span> <span style="color: #06c; font-weight: bold;">rec</span> loop <span style="color: #000080;">&#40;</span><span style="color: #000080;">&#41;</span> <span style="color: #000080;">=</span>
            async <span style="color: #000080;">&#123;</span> 
                <span style="color: #06c; font-weight: bold;">let</span><span style="color: #000080;">!</span> args <span style="color: #000080;">=</span> Async<span style="color: #000080;">.</span><span style="color: #505090;">AwaitEvent</span> nui<span style="color: #000080;">.</span><span style="color: #505090;">SkeletonFrameReady</span>
                args<span style="color: #000080;">.</span><span style="color: #505090;">SkeletonFrame</span><span style="color: #000080;">.</span><span style="color: #505090;">Skeletons</span> 
                <span style="color: #000080;">|&gt;</span> Seq<span style="color: #000080;">.</span><span style="color: #505090;">filter</span> <span style="color: #000080;">&#40;</span><span style="color: #06c; font-weight: bold;">fun</span> s <span style="color: #000080;">-&gt;</span> s<span style="color: #000080;">.</span><span style="color: #505090;">TrackingState</span> <span style="color: #000080;">=</span> Nui<span style="color: #000080;">.</span><span style="color: #505090;">SkeletonTrackingState</span><span style="color: #000080;">.</span><span style="color: #505090;">Tracked</span><span style="color: #000080;">&#41;</span>
                <span style="color: #000080;">|&gt;</span> Seq<span style="color: #000080;">.</span><span style="color: #505090;">iter</span> draw
                <span style="color: #06c; font-weight: bold;">return</span><span style="color: #000080;">!</span> loop <span style="color: #000080;">&#40;</span><span style="color: #000080;">&#41;</span> 
            <span style="color: #000080;">&#125;</span>
        loop <span style="color: #000080;">&#40;</span><span style="color: #000080;">&#41;</span>
&nbsp;
    skeleton nui <span style="color: #000080;">|&gt;</span> Async<span style="color: #000080;">.</span><span style="color: #505090;">Start</span>
&nbsp;
    <span style="color: #06c; font-weight: bold;">let</span> a <span style="color: #000080;">=</span> System<span style="color: #000080;">.</span><span style="color: #505090;">Windows</span><span style="color: #000080;">.</span><span style="color: #505090;">Application</span><span style="color: #000080;">&#40;</span><span style="color: #000080;">&#41;</span>
    ignore <span style="color: #000080;">&lt;|</span> a<span style="color: #000080;">.</span><span style="color: #505090;">Run</span><span style="color: #000080;">&#40;</span>w<span style="color: #000080;">&#41;</span>
&nbsp;
    nui<span style="color: #000080;">.</span><span style="color: #505090;">Uninitialize</span><span style="color: #000080;">&#40;</span><span style="color: #000080;">&#41;</span></pre></div></div>

<p>The moral of the story? Don&#8217;t be like me, and make sure you actually read the FAQing readme, then maybe you&#8217;ll spend more time doing a decent demo and less time plugging and unplugging your Kinect!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.voyce.com/index.php/2011/09/05/kinect-sdk-with-f/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>onedotzero &#8211; Sprites &#8211; doing it for the kids</title>
		<link>http://www.voyce.com/index.php/2010/11/16/onedotzero-sprites-doing-it-for-the-kids/</link>
		<comments>http://www.voyce.com/index.php/2010/11/16/onedotzero-sprites-doing-it-for-the-kids/#comments</comments>
		<pubDate>Tue, 16 Nov 2010 23:13:26 +0000</pubDate>
		<dc:creator>ian</dc:creator>
				<category><![CDATA[Graphics]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[onedotzero]]></category>

		<guid isPermaLink="false">http://www.voyce.com/?p=1109</guid>
		<description><![CDATA[This year the onedotzero film festival included for the first time a screening for families. Here's what I thought of it.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.voyce.com/wp-content/uploads/2010/11/pleix1.png"><img src="http://www.voyce.com/wp-content/uploads/2010/11/pleix1.png" alt="pleix" title="pleix" width="250" height="250" class="alignright size-full wp-image-1115" /></a>I&#8217;ve been a fan of <a href="http://www.onedotzero.com">onedotzero</a> &#8211; the forward-looking moving-image festival &#8211; for many years. I always try and make it to at least one of the screenings, normally wow+flutter, but with a couple of kids it&#8217;s been getting a bit difficult to find the time recently. The content could be pretty &#8220;dark&#8221;, so it&#8217;s definitely not a good idea to bring them along, in fact you have to be 16 years old to get into the screenings. </p>
<p>But this year, much to my surprise and delight, they introduced a special, Sunday-afternoon screening especially for kids, called &#8220;Sprites&#8221;; excellent! Now I had an excuse to bring the whole family along too! Was it a co-incidence that Shane Walter, curator of the festival, and his lady wife have had a baby this year&#8230;? Maybe&#8230;<br />
<span id="more-1109"></span><br />
To be honest, I was a bit worried; my daughters are not the most, err, robust cinema-goers. The youngest spent a good deal of the latter part of Toy Story 3 screaming in terror. Still, I was determined (and intrigued) to see what had been programmed, and thought that if it came to it I&#8217;d just have to shuffle embarrassingly out of the cinema with a tearful child.</p>
<p><a href="http://www.voyce.com/wp-content/uploads/2010/11/gluko.png"><img src="http://www.voyce.com/wp-content/uploads/2010/11/gluko.png" alt="gluko" title="gluko" width="250" height="250" class="alignleft size-full wp-image-1117" /></a>It was brilliant. I can safely say that all 4 of us (me, my wife and a 3 and 5 year old) really enjoyed the show. It was programmed really well, with a mix of 10+ minute long animated shorts, and shorter, sharper sequences. It kept everyone&#8217;s attention very effectively. The longest film was one originally intended as a pilot for a series, an unlikely sounding Argentinian creation called Gluko and Lennon, a quirky, contemporary combination of plucky pink and purple protagonists and a depressed superhero. The amorphous pink Lennon (or was it Gluko) was the youngest one&#8217;s favourite character of the show.</p>
<p>Like some of the other films, it had quite an edgy feel, but I think kids nowadays are quite used to it; they&#8217;ve been bought up on the Yo Gabba Gabba slightly knowing, ironic style. </p>
<p>There was some very high-quality (I hesitate to say it, but, Pixar-quality) animation on display; and by that I mean both beautifully animated and also very well observed and amusing, even for adults. Lucas Martell&#8217;s <a href="http://www.pigeonimpossible.com/">Pigeon: Impossible</a> was laugh-out-loud funny, and Hi-Sim&#8217;s Jun and the Hidden Skies was charming and polished. </p>
<p>There was also more traditional animation on display, which can often feel more disturbing somehow, but which were very unthreatening in this setting. The South Korean Cherry on the Cake was in this style, and featured an interesting angle on family life which was especially relevant to &#8220;little people&#8221;, though maybe a bit bigger than 2cm.</p>
<p><a href="http://vimeo.com/11159426"><img src="http://www.voyce.com/wp-content/uploads/2010/11/looklistenfeel.png" alt="looklistenfeel" title="looklistenfeel" width="250" height="250" class="alignright size-full wp-image-1120" /></a>The psychedelic style was also well represented, from the lullaby style of <a href="http://vimeo.com/12966239">Chico Jofilsan&#8217;s My Little Angel</a> to LookListenFeel, which invoked feelings of a long, lazy summers afternoon. <a href="http://andymartin.info">Andy Martin</a> was on hand to introduce his weird and wonderfully-scored <a href="http://vimeo.com/11661167">Dry Fish</a> in person.</p>
<p>The last short was a minute&#8217;s worth of scat kitten. Believe it or not this my 5 year old&#8217;s favourite. Ah well, there&#8217;s no accounting for taste&#8230;</p>
<p>So, it was a huge success. I got to see some fantastic animation on the big screen, the kids got to see things they found funny and fascinating, and we all thoroughly enjoyed ourselves. If you&#8217;ve got any interest in animation or film, and a child or two to accompany you, head down down here next year and enjoy it too.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.voyce.com/index.php/2010/11/16/onedotzero-sprites-doing-it-for-the-kids/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sneaky peek: Physics on iOS</title>
		<link>http://www.voyce.com/index.php/2010/10/15/sneaky-peek-physics-on-ios/</link>
		<comments>http://www.voyce.com/index.php/2010/10/15/sneaky-peek-physics-on-ios/#comments</comments>
		<pubDate>Fri, 15 Oct 2010 08:00:19 +0000</pubDate>
		<dc:creator>ian</dc:creator>
				<category><![CDATA[Graphics]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[3d]]></category>
		<category><![CDATA[iPad]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[OpenGL]]></category>
		<category><![CDATA[physics]]></category>

		<guid isPermaLink="false">http://www.voyce.com/?p=1057</guid>
		<description><![CDATA[A quick look at the physics demo I've been writing using Bullet on iOS.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve recently been experimenting with the <a href="http://bulletphysics.org/wordpress/">Bullet</a> physics library on iOS. It&#8217;s a great way of adding 3d collision detection and realistic looking movement to your OpenGL apps and games. I&#8217;m working on a full blog post with all the details, but in the meantime, here&#8217;s a quick look at what I&#8217;ve been doing: a simple 2.5d ragdoll character running on the iPad simulator.<br />
<span id="more-1057"></span><br />
<iframe title="YouTube video player" class="youtube-player" type="text/html" width="560" height="345" src="http://www.youtube.com/embed/yWD6b_SvPzQ?rel=0" frameborder="0"></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://www.voyce.com/index.php/2010/10/15/sneaky-peek-physics-on-ios/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Minilight renderer in F#</title>
		<link>http://www.voyce.com/index.php/2010/06/30/minilight-renderer-in-fsharp/</link>
		<comments>http://www.voyce.com/index.php/2010/06/30/minilight-renderer-in-fsharp/#comments</comments>
		<pubDate>Wed, 30 Jun 2010 17:19:43 +0000</pubDate>
		<dc:creator>ian</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[F#]]></category>
		<category><![CDATA[Graphics]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[monte carlo]]></category>

		<guid isPermaLink="false">http://www.voyce.com/?p=938</guid>
		<description><![CDATA[Porting the Minilight global illumination renderer to F#.]]></description>
			<content:encoded><![CDATA[<p><div id="attachment_961" class="wp-caption alignleft" style="width: 150px"><a href="http://www.voyce.com/wp-content/uploads/2010/06/cornellbox-e.png"><img src="http://www.voyce.com/wp-content/uploads/2010/06/cornellbox-e.png" alt="Cornell Box in the evening" title="cornellbox-e" width="140" height="140" class="size-full wp-image-961" /></a><p class="wp-caption-text">Cornell Box in the evening</p></div>I&#8217;m a sucker for eye-candy, and the other day I came across the beautifully lit renders produced by <a href="http://www.hxa.name/minilight/">Minilight</a>. It&#8217;s a nice, minimal implementation of a global illumination renderer that&#8217;s been ported to a wide variety of different languages from C to ActionScript. So of course, I couldn&#8217;t resist trying to implement it in F#.<br />
<span id="more-938"></span></p>
<h3>What is a &#8220;global illumination renderer&#8221;?</h3>
<p>In short; a global illumination renderer attempts to simulate the way that light behaves in the real world. It bounces rays of light around the scene, noting which surfaces are hit, and how each of them affects the ray. Of course real light travels fast &#8211; at about the speed of light, in fact &#8211; and our simulated rays can&#8217;t match that, so although the resulting effect looks natural, it&#8217;s not a very efficient way of getting there. Graphics systems that need to be near real-time (i.e. games), use a variety of short-cuts to try and get the same effect without requiring the same amount of number crunching.</p>
<p>Even this implementation is forced to use a couple of techniques to improve performance, I won&#8217;t go into them here, as they&#8217;re explained pretty thoroughly on the Minilight site. </p>
<p>Interestingly the algorithm uses a Monte Carlo technique to simulate the random path of the ray through the scene and the same technique is used in finance to model how the price of an asset will change through time. </p>
<h3>Translating to F#</h3>
<p><div id="attachment_970" class="wp-caption alignright" style="width: 160px"><a href="http://www.voyce.com/wp-content/uploads/2010/06/roomfront.sun.ml.png"><img src="http://www.voyce.com/wp-content/uploads/2010/06/roomfront.sun.ml-150x150.png" alt="Room with sun and light, 800 paths per pixel" title="roomfront.sun.ml" width="150" height="150" class="size-thumbnail wp-image-970" /></a><p class="wp-caption-text">Room with sun and light, 800 paths per pixel</p></div>Luckily, the existing OCaml version is considered one of the reference implementations, and as ML is the spiritual predecessor of F# I didn&#8217;t expect it to be too difficult to port. It wasn&#8217;t. I&#8217;m no ML expert, so some of the language features were a bit of a surprise; things like the use of a dot on all of the operators, but these are pretty minimal syntactic differences.</p>
<p>Some of the ML constructs caused warnings from the F# compiler as I didn&#8217;t use the explicit ML compatibility mode. For instance, the use of the <code>^</code> operator to concatenate strings:<br />
<code><br />
warning FS0062: This construct is for ML compatibility. Consider using the '+' operator instead. This may require a type annotation to indicate it acts on strings.<br />
</code><br />
Some other changes included:</p>
<ul>
<li>Using dot rather than # notation to access class members</li>
<li>Using square bracket for array element access (<code>array.[n]</code> rather than <code>array.(n)</code>)</li>
<li>Removing <code>let...and</code> for non-recursive bindings</li>
</ul>
<p>There was also the opportunity to make use of some of the .NET framework classes, things like <code>System.Drawing.Bitmap</code> to write pixels directly into a bitmap and then save it into a .PNG file. Much easier than trying to find something to read the .PPM file that the original version emits.    </p>
<h3>Potential improvements</h3>
<p>One of the most obvious improvements that could be made is to make use of the parallelism support in F# and .NET. The algorithm itself is easily (if not embarrassingly) parallelisable, given that it iterates over the pixels in the output image, and performs independent operations on each of them. Unfortunately I haven&#8217;t had a chance to look at this yet &#8211; and the Windows VM I&#8217;m using only has a single processor anyway, so on a purely selfish note, I wouldn&#8217;t see any immediate performance improvements.  It should be as simple as changing the pixel loop to use <code>Parallel.For</code>, or creating an <code>async</code> computation expression.</p>
<p>Something else to note: I err&#8217;d on the side of caution when it comes to saving intermediate images, so every iteration it creates and writes the file. This will be doing lots of allocation and strictly unnecessary work, especially for simple scenes.</p>
<p>Given this approach is so completely compute bound it would be interesting to see how moving some of the calculations to a GPU would affect it. It might even be possible to use quotations for some of the inner loops and then generate Nvidia intermediate language (PTX) from them &#8211; that&#8217;s something I&#8217;ve been wanting to do for a while. </p>
<p>I did run the code through the Visual Studio 2010 profiler to get a rough idea of where the time was being spent; it looked like the majority was in the leaf of the calculations where numerical operations where being performed on the vectors, which is consistent with what we&#8217;d expect.</p>
<h3>Use the source</h3>
<p>So, here&#8217;s the source. No warranties implied, use at your own risk, your mileage may vary, all errors are mine etc, etc.<br />
<a href='http://www.voyce.com/wp-content/uploads/2010/06/minilight_fsharp.zip'>minilight_fsharp</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.voyce.com/index.php/2010/06/30/minilight-renderer-in-fsharp/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Creating an iPad flip-clock with Core Animation</title>
		<link>http://www.voyce.com/index.php/2010/04/10/creating-an-ipad-flip-clock-with-core-animation/</link>
		<comments>http://www.voyce.com/index.php/2010/04/10/creating-an-ipad-flip-clock-with-core-animation/#comments</comments>
		<pubDate>Sat, 10 Apr 2010 17:48:04 +0000</pubDate>
		<dc:creator>ian</dc:creator>
				<category><![CDATA[Graphics]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[iPad]]></category>

		<guid isPermaLink="false">http://www.voyce.com/?p=791</guid>
		<description><![CDATA[Using Core Animation to create flip-card number animations on the iPad and iPhone]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.voyce.com/wp-content/uploads/2010/04/flipclock_one.png"><img src="http://www.voyce.com/wp-content/uploads/2010/04/flipclock_one.png" alt="flipclock_one" title="flipclock_one" width="69" height="127" class="alignleft size-full wp-image-793" /></a>As part of the sliding puzzle game I&#8217;m developing for the iPhone and iPad (well, I can&#8217;t survive on the profits from <a href="http://voyce.com/BattleFingers/">BattleFingers</a> forever), I looked for a way to represent a numeric score and time display in an interesting way. One of the nicer visual effects you could use for this is the &#8220;flip-card clock&#8221; style, where each number consists of a top and bottom part, and the top part flips down to reveal the next number. It&#8217;s been used in a few other places including the home screen in the HTC Diamond device, and its physical, realistic style fits well with the iPad, so I set about creating a version for the iPhone and iPad using the built-in Core Animation library. Read on for more details.<br />
<span id="more-791"></span><br />
I started by thinking about the motions that would be required for the animation. We can break it down as three elements, the top, the bottom and the flipping part. Each of these parts can be represented as a Core Animation Layer (a <code>CALayer</code>). We create them using the class method on CALayer, there&#8217;s no additional <code>retain</code> here, as the <code>_toplayer</code> property is retained.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">_toplayer <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CALayer layer<span style="color: #002200;">&#93;</span>;</pre></div></div>

<h2>Splitting images</h2>
<p>Now we&#8217;ve got the layers, we need something to but into them. I didn&#8217;t want to create lots of pre-processed images for the top and bottom sections of each number, so instead I wrote a routine to split the images in code, drawing each half into an image context and grabbing a <code>UIImage</code> from it. This is then stored in an array for later use. We can get any of the elements from the array and set it as the <code>content</code> of the layer as required.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">// The size of each part is half the height of the whole image</span>
CGSize size <span style="color: #002200;">=</span> CGSizeMake<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>img size<span style="color: #002200;">&#93;</span>.width, <span style="color: #002200;">&#91;</span>img size<span style="color: #002200;">&#93;</span>.height<span style="color: #002200;">/</span><span style="color: #2400d9;">2</span><span style="color: #002200;">&#41;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">// Create image-based graphics context for top half</span>
UIGraphicsBeginImageContext<span style="color: #002200;">&#40;</span>size<span style="color: #002200;">&#41;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">// Draw into context, bottom half is cropped off</span>
<span style="color: #002200;">&#91;</span>img drawAtPoint<span style="color: #002200;">:</span>CGPointMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0.0</span>,<span style="color: #2400d9;">0.0</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #11740a; font-style: italic;">// Grab the current contents of the context as a UIImage </span>
<span style="color: #11740a; font-style: italic;">// and add it to our array</span>
UIImage <span style="color: #002200;">*</span>top <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIGraphicsGetImageFromCurrentImageContext<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span> retain<span style="color: #002200;">&#93;</span>;			
<span style="color: #002200;">&#91;</span>_imagesTop addObject<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>top<span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">// Now draw the image starting half way down, to get the bottom half</span>
<span style="color: #002200;">&#91;</span>img drawAtPoint<span style="color: #002200;">:</span>CGPointMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0.0</span>,<span style="color: #002200;">-</span><span style="color: #002200;">&#91;</span>img size<span style="color: #002200;">&#93;</span>.height<span style="color: #002200;">/</span><span style="color: #2400d9;">2</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #11740a; font-style: italic;">// And store that image in the array too</span>
UIImage <span style="color: #002200;">*</span>bottom <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIGraphicsGetImageFromCurrentImageContext<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span> retain<span style="color: #002200;">&#93;</span>;			
<span style="color: #002200;">&#91;</span>_imagesBottom addObject<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>bottom<span style="color: #002200;">&#93;</span>;
&nbsp;
UIGraphicsEndImageContext<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>;</pre></div></div>

<p>Now our <code>_imagesTop</code> and <code>_imagesBottom</code> arrays contains all the images we need, let&#8217;s get &#8216;em moving.</p>
<h2>Applying animation</h2>
<p><div id="attachment_808" class="wp-caption alignright" style="width: 212px"><a href="http://www.voyce.com/wp-content/uploads/2010/04/flipclock_axes1.png"><img src="http://www.voyce.com/wp-content/uploads/2010/04/flipclock_axes1-202x300.png" alt="The axes and anchor point of a CALayer" title="flipclock_axes" width="202" height="300" class="size-medium wp-image-808" /></a><p class="wp-caption-text">The axes and anchor point of a CALayer</p></div>The animation we need to apply to the &#8216;flipping&#8217; part is a rotation around the bottom of the layer, at the join between the two halves. The default location of the anchor point is the middle of the layer, which would mean the piece would rotate around the middle, but we can easily change it to instead be at the middle in the bottom (for our purposes it could be anywhere on the bottom, as we&#8217;re only interested in x-axis rotation):</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">_fliplayer.anchorPoint <span style="color: #002200;">=</span> CGPointMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0.5</span>, <span style="color: #2400d9;">1.0</span><span style="color: #002200;">&#41;</span>;</pre></div></div>

<p>I use the <code>CATransform3DMakeRotation</code> function to create a transform around the X axis using the vector [1,0,0]. For the first part of the motion, we go from 0 radians to pi/2 radians (0 to 90 degrees), using an explicit <code>CABasicAnimation</code> object:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">CABasicAnimation <span style="color: #002200;">*</span>topAnim <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CABasicAnimation animationWithKeyPath<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;transform&quot;</span><span style="color: #002200;">&#93;</span>;
topAnim.duration<span style="color: #002200;">=</span><span style="color: #2400d9;">0.25</span>;
topAnim.repeatCount<span style="color: #002200;">=</span><span style="color: #2400d9;">1</span>;
topAnim.fromValue<span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSValue</span> valueWithCATransform3D<span style="color: #002200;">:</span>CATransform3DMakeRotation<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0.0</span>, <span style="color: #2400d9;">1</span>, <span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #a61390;">float</span> f <span style="color: #002200;">=</span> <span style="color: #002200;">-</span>M_PI<span style="color: #002200;">/</span><span style="color: #2400d9;">2</span>;
topAnim.toValue<span style="color: #002200;">=</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSValue</span> valueWithCATransform3D<span style="color: #002200;">:</span>CATransform3DMakeRotation<span style="color: #002200;">&#40;</span>f, <span style="color: #2400d9;">1</span>, <span style="color: #2400d9;">0</span>, <span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
topAnim.delegate <span style="color: #002200;">=</span> self;
topAnim.removedOnCompletion <span style="color: #002200;">=</span> FALSE;
<span style="color: #002200;">&#91;</span>_fliplayer addAnimation<span style="color: #002200;">:</span>topAnim forKey<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithUTF8String<span style="color: #002200;">:</span>k_TopAnimKey<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<h2>Drawing layer content</h2>
<p>Unfortunately a CALayer doesn&#8217;t have a &#8220;back&#8221;, so creating the flip layer is not as easy as it could be. We need to add a step in the process to change the image displayed by the flip layer half way through its fall. We can do this in a variety of ways, I&#8217;ve chosen to set a delegate object to perform the drawing of the layer contents:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">&#91;</span>_fliplayer setDelegate<span style="color: #002200;">:</span>_layerHelper<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>This means our delegate object (<code>_layerHelper</code>) has its <code>drawLayer</code> method called whenever the layer needs to display its contents. Be wary though, this may not be as often as you think! Core graphics aggressively caches the contents of the layer, and will only call your delegate when absolutely necessary. You can force it to happen by calling <code>setNeedsDisplay</code>, which invalidates the contents of the layer:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">&#91;</span>_fliplayer setNeedsDisplay<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>I encapsulated this in the helper object itself, by providing a custom implementation of the <code>isTop</code> property setter that calls <code>setNeedsDisplay</code>. At least that way callers don&#8217;t have to be aware of this requirement.</p>
<p>The <code>drawLayer</code> method itself simply draws one of two images into the context, depending on whether it&#8217;s in &#8216;top&#8217; mode. A slight further complication is that when drawing the bottom part, the image needs to be inverted to display upside down. This is achieved by applying a translation and scale to the context before drawing the image:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">CGContextSaveGState<span style="color: #002200;">&#40;</span>context<span style="color: #002200;">&#41;</span>;
CGContextTranslateCTM<span style="color: #002200;">&#40;</span>context, 0.0f, r.size.height<span style="color: #002200;">&#41;</span>;
CGContextScaleCTM<span style="color: #002200;">&#40;</span>context, 1.0f, <span style="color: #002200;">-</span>1.0f<span style="color: #002200;">&#41;</span>;
&nbsp;
CGContextDrawImage<span style="color: #002200;">&#40;</span>context, r, <span style="color: #002200;">&#91;</span>_imgTop CGImage<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>;
&nbsp;
CGContextRestoreGState<span style="color: #002200;">&#40;</span>context<span style="color: #002200;">&#41;</span>;</pre></div></div>

<h2>Avoiding implicit animation</h2>
<p>I&#8217;ve tried to avoid using implicit animation here, instead using explicit construction of <code>CABasicAnimation</code> objects, because we need some control of when things happen, and the order in which they happen. Normally, it would be easier to just set some property of the view and let the OS manage animating it. Many properties have default transition that are applied whenever they&#8217;re changed, so it takes some additional effort to make them change immediately.</p>
<p>In our example we change the contents of the top half and show the flip layer, but we need that to happen immediately so we disable actions within an explicit transaction that we then commit. This gives us the control we need, and avoids the default behaviour of the transition occurring when the message loop next runs.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">&#91;</span>CATransaction begin<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>CATransaction setValue<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>kCFBooleanTrue
				forKey<span style="color: #002200;">:</span>kCATransactionDisableActions<span style="color: #002200;">&#93;</span>;
_toplayer.contents <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>_imagesTop objectAtIndex<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>self getNextIndex<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span> CGImage<span style="color: #002200;">&#93;</span>;
_fliplayer.hidden <span style="color: #002200;">=</span> <span style="color: #a61390;">NO</span>;
<span style="color: #002200;">&#91;</span>CATransaction commit<span style="color: #002200;">&#93;</span>;</pre></div></div>

<h2>Getting some perspective</h2>
<p>Although the images I&#8217;ve used to illustrate this post are isometric, what we really want is a front-on perspective view, so that the falling piece seems to stick out. For this we have to set a <code>sublayerTransform</code> on the view&#8217;s inherent layer, by setting an individual element on a transform:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">CATransform3D aTransform <span style="color: #002200;">=</span> CATransform3DIdentity;
<span style="color: #a61390;">float</span> zDistance <span style="color: #002200;">=</span> <span style="color: #2400d9;">1000</span>;
aTransform.m34 <span style="color: #002200;">=</span> <span style="color: #2400d9;">1.0</span> <span style="color: #002200;">/</span> <span style="color: #002200;">-</span>zDistance;	
<span style="color: #002200;">&#91;</span>self layer<span style="color: #002200;">&#93;</span>.sublayerTransform <span style="color: #002200;">=</span> aTransform;</pre></div></div>

<p>This gives us a much more realistic look.</p>
<h2>Putting it together</h2>
<p>Wow, so now we&#8217;ve got some appropriately sliced images, some layers and some animations. Let&#8217;s put them together to get the final effect.<br />
<div id="attachment_812" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.voyce.com/wp-content/uploads/2010/04/flipclock.png"><img src="http://www.voyce.com/wp-content/uploads/2010/04/flipclock-300x96.png" alt="The animation states (last is same as first)" title="flipclock" width="300" height="96" class="size-medium wp-image-812" /></a><p class="wp-caption-text">The animation states (last is same as first)</p></div><br />
I&#8217;ve used a very simple state machine that moves through 3 states; TopToMiddle, MiddleToBottom, ResetForNext. We can use the <code>animationDidStop</code> delegate as the state transition point. We don&#8217;t have to bother determining exactly which animation finished, because we do the same thing (change state) regardless.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>animationDidStop<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CAAnimation <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>oldAnimation finished<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>flag
<span style="color: #002200;">&#123;</span>
	<span style="color: #002200;">&#91;</span>self changeState<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<ul>
<li><strong>TopToMiddle</strong>: show flip layer, and start rotation through 90 degrees</li>
<li><strong>MiddleToBottom</strong>: change image on flip layer, start rotation through further 90 degrees</li>
<li><strong>ResetForNext</strong>: change displayed top and bottom layer contents and hide flip layer</li>
</ul>
<p>Let&#8217;s see how it looks in action:<br />
<object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/RbPmAl_AeSU&#038;hl=en_US&#038;fs=1&#038;rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/RbPmAl_AeSU&#038;hl=en_US&#038;fs=1&#038;rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://www.voyce.com/index.php/2010/04/10/creating-an-ipad-flip-clock-with-core-animation/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>iPad &#8211; The rise of the naturalistic user interface</title>
		<link>http://www.voyce.com/index.php/2010/03/11/ipad-the-rise-of-the-naturalistic-user-interface/</link>
		<comments>http://www.voyce.com/index.php/2010/03/11/ipad-the-rise-of-the-naturalistic-user-interface/#comments</comments>
		<pubDate>Thu, 11 Mar 2010 01:05:53 +0000</pubDate>
		<dc:creator>ian</dc:creator>
				<category><![CDATA[Graphics]]></category>
		<category><![CDATA[Usability]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[iPad]]></category>

		<guid isPermaLink="false">http://www.voyce.com/?p=679</guid>
		<description><![CDATA[Apple's iPad applications make use of real-world objects in their user interfaces: books, newspapers, address books. What is it about the iPad that makes it a good platform for this kind of UI?]]></description>
			<content:encoded><![CDATA[<p>It was fascinating to see Apple unveiling its new iPad hardware recently, and one of the things that caught my eye were the interfaces of the various apps that were demonstrated. They look different from apps on other platforms, and even from the equivalent apps on the iPhone. It seems to me as if there&#8217;s been a change to a more naturalistic style of user interfaces. Why is this, and what is it about the iPad that makes it suited to this kind of UI?<br />
<span id="more-679"></span></p>
<h2>Form factor</h2>
<p>The most obvious reason that this kind of interface works on the iPad is the form factor of the device itself. Think about it: an iPhone is a small (well, smallish) object which has no physical, real-world equivalent. It&#8217;s not supposed to &#8220;be&#8221; anything other than a phone. The iPad, on the other hand, is intended to mimic an actual object, or rather, a variety of objects: a book, a newspaper or an address book for example. The interface for each of these uses reflects this directly: the address book looks like a &#8220;little black book&#8221;, complete with tabs. </p>
<p>The iPhone uses some of the same metaphors &#8211; like the address book for contacts &#8211; but the representation is abstract, whereas the iPad UI is literal, using an actual image of a book. The abstraction is necessary on the iPhone in order for it to remain usable with a smaller screen. Compare the iPad and iPhone Contacts interfaces:</p>
<table>
<tr>
<td><div id="attachment_682" class="wp-caption alignnone" style="width: 310px"><a href="http://www.voyce.com/wp-content/uploads/2010/02/contacts_ipad_fullpage_small.png"><img src="http://www.voyce.com/wp-content/uploads/2010/02/contacts_ipad_fullpage_small-300x230.png" alt="The realistic looking address book application on the iPad" title="contacts_ipad_fullpage_small" width="300" height="230" class="size-medium wp-image-682" /></a><p class="wp-caption-text">The realistic looking address book application on the iPad</p></div>
</td>
<td><div id="attachment_684" class="wp-caption alignnone" style="width: 130px"><a href="http://www.voyce.com/wp-content/uploads/2010/02/contacts_iphone_small.png"><img src="http://www.voyce.com/wp-content/uploads/2010/02/contacts_iphone_small-156x300.png" alt="iPhone contacts interface" title="contacts_iphone_small" width="120" height="230" class="size-medium wp-image-684" /></a><p class="wp-caption-text">iPhone contacts interface</p></div></td>
</tr>
</table>
<p>The abstract to realistic continuum has been explored extensively in the world of icons (explained brilliantly <a href="http://ignorethecode.net/blog/2010/01/21/realism_in_ui_design/">here</a>), but less so in the interface as a whole. Obviously some apps don&#8217;t have any form of real world equivalent (think System Preferences.app), so they&#8217;re likely to stay in a more abstract form. </p>
<h2>Display fidelity</h2>
<p>Of course, it&#8217;s always been possible to <i>represent</i> real objects on the screen, but without a display capable of a decent resolution it probably won&#8217;t look real. So another enabler for naturalistic UI is display technology: the more pixels and colour depth the better when it comes to rendering physical things. Realism often relies on subtle lighting and rich textures to achieve the desired effect. Anyone who&#8217;s ever attempted to render wood grain using 8-bit colour will appreciate how much easier it is with a 32-bit 1024&#215;768 display. </p>
<p>The need for display quality goes hand-in-hand with a need for more processing power to push the pixels. If the processing &#8220;oomph&#8221; required to render your interface with sufficient quality means that it&#8217;s not responsive enough, then you&#8217;ve failed by any measure. The iPad seems to have reached a sweet spot where display capabilities, raw power and form-factor meet to make naturalistic UIs a feasible approach.   </p>
<h2>Direct manipulation</h2>
<p><a href="http://www.voyce.com/wp-content/uploads/2010/03/Apple_Mouse_no.png"><img src="http://www.voyce.com/wp-content/uploads/2010/03/Apple_Mouse_no.png" alt="Apple_Mouse_no" title="Apple_Mouse_no" width="160" height="160" class="alignleft size-full wp-image-722" /></a>Up until the relatively recent introduction of direct manipulation technologies like touch-senstive displays, there&#8217;s a been a forced physical separation between users and their computer in the form of a mouse and keyboard. A drag operation using a mouse involves disconnected, abstract operations like pointing and clicking, which bear no relation to the object being acted upon. As such, there&#8217;s little use in having an extremely realistic representation of something to interact with, because the suspension-of-disbelief has already been broken. </p>
<p>But in the world of touch-based devices, our interactions are much closer to the physical actions we&#8217;d make, so having a closer visual representation to go along with it is beneficial. For instance, turning a page in an eBook and actually seeing the page flick over seems consistent when using a natural gesture like flicking a finger across the screen. Otherwise if you had to click a corner of the page and drag it across in a poor imitation of the physical action the visual aspects can quickly start to feel superfluous.   </p>
<p>Perhaps given the iPad&#8217;s larger interaction surface we can expect to see a wider and more expressive range of gestures supported?  </p>
<h2>History</h2>
<p>Of course, naturalistic UI isn&#8217;t really a new thing. It&#8217;s in use in quite a few applications already, albeit mostly in desktop apps, where capable hardware is more readily available. In fact, there was much a-twittering (not <i>all</i> of it from Will Shipley) about the similarity between the demo&#8217;d iPad apps and the interface of the fantastic Mac application <a href="http://delicious-monster.com/">Delicious Library</a>. I&#8217;m sure of course &#8211; how do they say it in the movie credits &#8211; the similarity is entirely coincidental&#8230;</p>
<table>
<tr>
<td valign="top"><div id="attachment_733" class="wp-caption alignnone" style="width: 303px"><img src="http://www.voyce.com/wp-content/uploads/2010/03/delicious_library_shrunk.png" alt="Delicious Library UI" title="delicious_library_shrunk" width="293" height="196" class="size-full wp-image-733" /><p class="wp-caption-text">Delicious Library UI</p></div></td>
<td><div id="attachment_734" class="wp-caption alignnone" style="width: 160px"><img src="http://www.voyce.com/wp-content/uploads/2010/03/ibooks_shrunk.png" alt="iBooks UI" title="ibooks_shrunk" width="150" height="199" class="size-full wp-image-734" /><p class="wp-caption-text">iBooks UI</p></div></td>
</tr>
</table>
<p><a href="http://www.voyce.com/wp-content/uploads/2010/03/rebirth_knobs_crop.png"><img src="http://www.voyce.com/wp-content/uploads/2010/03/rebirth_knobs_crop.png" alt="rebirth_knobs_crop" title="rebirth_knobs_crop" width="250" height="110" class="alignleft size-full wp-image-717" /></a>One of the first widespread uses of naturalistic UI elements was in software synths. Guys like <a href="http://www.propellerheads.se/">Propellerheads</a> and <a href="http://www.native-instruments.com/">Native Instruments</a> set about creating exact software duplicates of well-known and well-loved bits of <a href="http://en.wikipedia.org/wiki/Roland_TB-303">mid-80&#8217;s audio hardware</a>. The UIs included virtual versions of a huge number of physical elements that had never been used before: including things like sliders, LEDs, toggle buttons, rotary knobs and rocker switches. These interface elements were probably first seen in software-based mixing desks, but the techniques used to make them feel real have gone on to be used in many different ways. Even the lowly push button in both Windows and MacOS got an upgrade by application of some of the 3D effects that they originated. </p>
<h2>Where Now?</h2>
<p>It will be interesting to see what other types of app are given the iPad realism makeover. It certainly looks like all of the standard Apple apps are being changed, including Notes, iCal, iBooks and Contacts, which were shown in the launch presentation, but how will 3rd-party developers manage? It undoubtedly takes extra effort to make something look convincing when it can be compared to the physical object itself. </p>
<p>Apple has previously managed to get a good level of consistency in its abstract UIs by providing the various interface elements ready-made, but will that approach scale to this kind of UI? No doubt the developers who take great pride in the interfaces now will continue to strive to create apps that sit comfortably alongside Apple&#8217;s own, but perhaps there&#8217;ll just be a more obvious visual distinction between those guys and the less polished application user interfaces than there has been in the past.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.voyce.com/index.php/2010/03/11/ipad-the-rise-of-the-naturalistic-user-interface/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Highlights from onedotzero &#8211; wow+flutter</title>
		<link>http://www.voyce.com/index.php/2009/09/17/highlights-from-onedotzero-wowflutter/</link>
		<comments>http://www.voyce.com/index.php/2009/09/17/highlights-from-onedotzero-wowflutter/#comments</comments>
		<pubDate>Thu, 17 Sep 2009 21:11:05 +0000</pubDate>
		<dc:creator>ian</dc:creator>
				<category><![CDATA[Graphics]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[digital]]></category>
		<category><![CDATA[film]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://www.voyce.com/?p=371</guid>
		<description><![CDATA[Some highlights from the onedotzero wow+flutter digital short film festival.]]></description>
			<content:encoded><![CDATA[<p>I took a trip down to London&#8217;s Southbank on Sunday evening to see wow+flutter, a showcase of short, digitally-themed animations that are part of <a href="http://www.onedotzero.com">onedotzero</a>, an annual festival and tour celebrating &#8220;adventures in moving image&#8221;. I&#8217;ve been several times before when it was based at the <a href="http://www.ica.org.uk/">ICA</a> (it&#8217;s now moved to the <a href="http://www.bfi.org.uk/whatson/bfi_southbank">BFI National Film Theatre</a>), and I always find it really inspiring. Normally, I can never remember the details of the films I&#8217;ve seen &#8211; it&#8217;s pretty intense; with over an hour of back-to-back shorts each lasting only 1-3 minutes &#8211; but this year they provided a list of the films details, so I can report on some of my highlights and provide links to some of the films.</p>
<p> <span id="more-371"></span></p>
<p>The wow+flutter programme concentrates on &#8220;progressive motion graphics&#8221;, which can include pretty much anything, while other parts of the festival are more specific: wavelength for music videos, j-star for japanese shorts etc. You can check out the entire list of w+f films are <a href="http://www.onedotzero.com/programme.php?id=373&#038;event=31216">here</a>, but these are my favourites:</p>
<p><b>Ubik: voxel</b><br />
I&#8217;m a fan of the augmented reality style when it&#8217;s done well; and it certainly is here. Striking abstract graphics combine with a haunting location.<br />
<object width="400" height="230"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=4649345&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=4649345&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="230"></embed></object></p>
<p><b>Impactist: Parallelostory</b><br />
A beautifully subtle animation style with a 50&#8217;s influenced colour and texture palette.<br />
<a href="http://www.impactist.com/projectpages/parallelostory/IMP_storyqt.html"><img src="http://www.voyce.com/wp-content/uploads/2009/09/IMPACTIST_para_still06-300x127.jpg" alt="IMPACTIST_para_still06" title="IMPACTIST_para_still06" width="300" height="127" class="alignleft size-medium wp-image-376" /></a><br />
<br clear="all"/></p>
<p><b>Bruno Dicolla: Return as an Animal</b><br />
This featured a striking high-contrast rotoscoped style that looked great on the big screen. Unfortunately the shimmering starfield effect is a little lost in the on-line version. I could almost hear art directors reaching for their iPhones to jot down &#8220;must copy this at next available opportunity&#8221;.<br />
<object width="400" height="225"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=2022032&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=2022032&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="225"></embed></object></p>
<p><b>Christian Schlaeffer: Agent Orange Ready</b><br />
A dark, disturbing animation in a comic style.<br />
<object width="853" height="505"><param name="movie" value="http://www.youtube.com/v/XbW486naKvk&#038;hl=en&#038;fs=1&#038;rel=0&#038;hd=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/XbW486naKvk&#038;hl=en&#038;fs=1&#038;rel=0&#038;hd=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="853" height="505"></embed></object></p>
<h3>The Lows</h3>
<p>Ironically I found the most obviously &#8220;digital&#8221; films the most disappointing. There was a little too much in the Chris Cunningham inspired glitchy, razor-cut, super-shiny organic/mechanic vernacular. And there was also one film &#8211; which I won&#8217;t name &#8211; that looked shockingly like a Tia Maria commercial. Still, in general the signal to noise ratio was very good.</p>
<h3>The Laughs</h3>
<p>Some of the most memorable films are those with a punchline; the short film format is a great way of getting a laugh with a simple, funny idea. There&#8217;s no risk of stretching it too thin.</p>
<p><b>Mato Atom: Docking</b><br />
A laugh-out-loud concept executed nicely and succintly, and it even goes out with an anti-war punchline.<br />
<object width="853" height="505"><param name="movie" value="http://www.youtube.com/v/KqZnFiKE7aw&#038;hl=en&#038;fs=1&#038;rel=0&#038;hd=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/KqZnFiKE7aw&#038;hl=en&#038;fs=1&#038;rel=0&#038;hd=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="853" height="505"></embed></object></p>
<p>So there you are; just 5 of the 30+ shorts that were shown. If you&#8217;re into animation or cutting-edge digital film-making, I&#8217;d recommend catching a onedotzero screening wherever you can, either in London or on one of the tour locations.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.voyce.com/index.php/2009/09/17/highlights-from-onedotzero-wowflutter/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

