<?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>Ben McChesney&#039;s Blog &#187; Interactive</title>
	<atom:link href="http://www.benmcchesney.com/blog/category/interactive/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.benmcchesney.com/blog</link>
	<description>Making stuff and sharing it.</description>
	<lastBuildDate>Mon, 19 Dec 2011 04:37:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Helios Multitouch Table Top Now Available</title>
		<link>http://www.benmcchesney.com/blog/2011/12/helios-multitouch-table-top-now-available/</link>
		<comments>http://www.benmcchesney.com/blog/2011/12/helios-multitouch-table-top-now-available/#comments</comments>
		<pubDate>Mon, 19 Dec 2011 04:04:05 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Interactive]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[creative code]]></category>
		<category><![CDATA[frameworks]]></category>
		<category><![CDATA[gesture]]></category>
		<category><![CDATA[multitouch]]></category>
		<category><![CDATA[open]]></category>
		<category><![CDATA[open frameworks]]></category>
		<category><![CDATA[openGL]]></category>

		<guid isPermaLink="false">http://www.benmcchesney.com/blog/?p=499</guid>
		<description><![CDATA[I&#8217;m very pleased to announce that today Helios Interactive is releasing it&#8217;s first Open Source project ! Since I started at Helios Interactive one of my main initiatives from the beginning was to open source as many projects as possible to give back to the community. The Table Top project open sourced was originally an informational touch ...]]></description>
			<content:encoded><![CDATA[<p><span style="color: #000000;">I&#8217;m very pleased to announce that today Helios Interactive is releasing it&#8217;s first Open Source project ! Since I started at Helios Interactive one of my main initiatives from the beginning was to open source as many projects as possible to give back to the community. The Table Top project open sourced was originally an informational touch table . It is more conservative  than a lot of openFrameworks apps but I learned a lot making it and I hope that it will prove useful to anyone learning Multitouch that wants to use openFrameworks. <a href="https://github.com/benMcChesney/Helios_TableTop">You can get the full source on github</a></span></p>

<!-- powered by Iframe plugin ver. 1.7 (wordpress.org/extend/plugins/iframe/) -->
<iframe class="iframe-class" width="100%" height="480" src="http://player.vimeo.com/video/33886433" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" allowtransparency="true"></iframe>
<p>&nbsp;</p>
<p>Currently there are only Xcode project files but I will add windows code::blocks files soon.</p>
<p>This video makes use of a small library ofxPixelHitTest that works by drawing a separate input map to an frame buffer object and comparing pixel values  to unique hexadecimal values stored inside each interactive object.</p>
<p>&nbsp;</p>
<p>Some areas covered in this code that might be useful to others includes :</p>
<ul>
<li>Scale / Rotate / Drag multitouch objects</li>
<li>Basic CMS system using XML</li>
<li>Custom Events and custom event arguments to handle interaction</li>
<li>Cross Fade class to easy handle cross fading ofImages</li>
<li>Heavy use of ofxTweenzor and sequencing animations for UI</li>
</ul>
<p>&nbsp;</p>
<pre><span style="color: #000000;">Thanks so much for the awesome OF community for providing the following addons that make this possible :</span></pre>
<pre><strong><span style="color: #000000;">OF libs: </span></strong></pre>
<pre><span style="color: #000000;"> ofxNetwork</span></pre>
<pre><span style="color: #000000;"> ofxOsc</span></pre>
<pre><span style="color: #000000;"> ofxXmlSettings</span></pre>
<p>&nbsp;</p>
<pre></pre>
<pre><strong><span>Memo's libs ( <a href="https://github.com/memo"><span style="color: #000000;">https://github.com/memo</span></a> ) </span></strong></pre>
<pre><span style="color: #000000;"> ofxMSAInteractiveObject </span></pre>
<pre><span style="color: #000000;"> ofxMultiTouch</span></pre>
<pre><span style="color: #000000;"> ofxMultiTouchObject</span></pre>
<pre><span style="color: #000000;"> ofxSimpleGuiToo </span></pre>
<p>&nbsp;</p>
<pre></pre>
<pre><strong><span style="color: #000000;">Arturo's libs ( <a href="https://github.com/arturoc/"><span style="color: #000000;">https://github.com/arturoc/</span></a> ) </span></strong></pre>
<pre><span style="color: #000000;"> ofxTuioWrapper </span></pre>
<p>&nbsp;</p>
<pre></pre>
<pre><strong><span style="color: #000000;">Nick's Libs ( <a href="https://github.com/NickHardeman/"><span style="color: #000000;">https://github.com/NickHardeman/</span></a>) </span></strong></pre>
<pre><span style="color: #000000;"> ofxTweenzor </span></pre>
<p>&nbsp;</p>
<pre></pre>
<pre><strong><span style="color: #000000;">Ben McChesney's Libs: ( <a href="https://github.com/benMcChesney/"><span style="color: #000000;">https://github.com/benMcChesney/</span></a> ) </span></strong></pre>
<pre><span style="color: #000000;"> ofxPixelHitTest </span></pre>
<p>&nbsp;</p>
<pre></pre>
<pre><strong><span style="color: #000000;">SmallFly's Libs :</span></strong></pre>
<pre><span style="color: #000000;"> ofxMultiTouchActions ( <a href="http://code.google.com/p/smallfly/downloads/list"><span style="color: #000000;">http://code.google.com/p/smallfly/downloads/list</span></a></span></pre>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.benmcchesney.com/blog/2011/12/helios-multitouch-table-top-now-available/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FFT Visuals in Open Frameworks</title>
		<link>http://www.benmcchesney.com/blog/2011/09/fft-visuals-in-open-frameworks/</link>
		<comments>http://www.benmcchesney.com/blog/2011/09/fft-visuals-in-open-frameworks/#comments</comments>
		<pubDate>Sun, 18 Sep 2011 23:42:29 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Interactive]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[creative]]></category>
		<category><![CDATA[frameworks]]></category>
		<category><![CDATA[open]]></category>
		<category><![CDATA[Sound]]></category>

		<guid isPermaLink="false">http://www.benmcchesney.com/blog/?p=470</guid>
		<description><![CDATA[I had been wanting to do some sound driven animations and visualizers for a while but had always managed to put it off for one thing or another. I had looked at some options and ended up using ofxFFT addon by Kyle McDonald. After quickly looking through his example  was able to create some of ...]]></description>
			<content:encoded><![CDATA[<p>I had been wanting to do some sound driven animations and visualizers for a while but had always managed to put it off for one thing or another. I had looked at some options and ended up using ofxFFT addon by Kyle McDonald. After quickly looking through his example  was able to create some of my own visuals and customize the visualizer settings at runtime. Below is the result of my first stable iteration :</p>
<p><a href="http://www.benmcchesney.com/blog/wp-content/uploads/2011/09/app_screenshot.png"><img class="aligncenter" title="app_screenshot" src="http://www.benmcchesney.com/blog/wp-content/uploads/2011/09/app_screenshot.png" alt="" width="720" height="475" /></a></p>
<p>The video allows you to see the animation http://vimeo.com/29234695</p>
<p><span id="more-470"></span></p>
<p>But how does it work? There are several options you can take for sound analysis. The simplest example would be the audio input example provided with openFrameworks 007 which provides you with stereo channels of audio and the scaled average.</p>
<p style="text-align: center;"><a href="http://www.benmcchesney.com/blog/wp-content/uploads/2011/09/soundInput.png"><img class="aligncenter size-full wp-image-472" title="soundInput" src="http://www.benmcchesney.com/blog/wp-content/uploads/2011/09/soundInput.png" alt="" width="661" height="291" /></a></p>
<p style="text-align: left;">But this wasn&#8217;t enough information. Sure both input channels and the average values are good starting point, but I wanted to be able to have bass control one animation, and have the higher registers control another graphic. I kept looking and came across <a title="OF ofxFFT Post" href=" http://forum.openframeworks.cc/index.php/topic,2184.msg16909.html#msg16909">this post</a> on the openFrameworks forums, which detailed the ofxFFT addon created By Kyle McDonald ( http://kylemcdonald.net/ ) available here : http://code.google.com/p/kyle/downloads/list</p>
<p style="text-align: left;">This was a solution I could use! I looked at Kyle&#8217;s example and started to play. The addon uses FFT method or the Fast Fourier Transform. This process ( which is more detailed here : http://www.dspguru.com/dsp/faqs/fft ) allows a large set of data, like waveform sound data, into a smaller set of data which we can work with. One of the first issues I ran into was that lots of music I tested did not have a high range. I needed a way to limit my visuals to only work within certain ranges. Below you can see that the ranges of each circle animation are clearly marked making it easy to setup on site, tweak settings to music,  and save them for the show.</p>
<p style="text-align: left;"><a href="http://www.benmcchesney.com/blog/wp-content/uploads/2011/09/range_detail.png"><img class="aligncenter size-full wp-image-474" title="fft_range_detail" src="http://www.benmcchesney.com/blog/wp-content/uploads/2011/09/range_detail.png" alt="FFT Range Detail" width="317" height="81" /></a></p>
<p style="text-align: left;">Through testing I found that classical music like Gustav Holst : http://grooveshark.com/s/Mars+The+Bringer+Of+War/1t79vR?src=5 or Dubstep such as Dodge +&amp; Fuski : http://grooveshark.com/s/Guettastep/3Hi4WY?src=5 worked really well for testing out sound and ranges. Rock and pop seemed to be very limited to the bottom register. This is just a first iteration but I&#8217;ll continue to work on it and improve the tool. I included project files and tested it for CodeBlocks on Windows and xCode on OSX Snow Leopard.  All the source code is available on my github at : https://github.com/benMcChesney/ofFFtPlayground</p>
<p style="text-align: center;"><a href="http://www.benmcchesney.com/blog/wp-content/uploads/2011/09/app_screenshot.png"><br />
</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.benmcchesney.com/blog/2011/09/fft-visuals-in-open-frameworks/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Attraction / Repulsion Pixels in Open Frameworks</title>
		<link>http://www.benmcchesney.com/blog/2011/07/attraction-repulsion-pixels-in-open-frameworks/</link>
		<comments>http://www.benmcchesney.com/blog/2011/07/attraction-repulsion-pixels-in-open-frameworks/#comments</comments>
		<pubDate>Mon, 04 Jul 2011 07:42:25 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Interactive]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[creative]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[frameworks]]></category>
		<category><![CDATA[open]]></category>
		<category><![CDATA[open frameworks]]></category>
		<category><![CDATA[openGL]]></category>
		<category><![CDATA[processing]]></category>

		<guid isPermaLink="false">http://www.benmcchesney.com/blog/?p=407</guid>
		<description><![CDATA[As part of learning Open Frameworks I&#8217;ve been porting over simple examples from other languages such as actionscript or processing. This example is inspired from the post the  RGB Sinks and Spring post from flashAndMath.com. The code is actually much simpler in open frameworks because of overloaded operators. Short example I made as part of ...]]></description>
			<content:encoded><![CDATA[<p>As part of learning Open Frameworks I&#8217;ve been porting over simple examples from other languages such as actionscript or processing. This example is inspired from the post the <a href="http://www.flashandmath.com/advanced/rgbsinks/"> RGB Sinks and Spring post</a> from flashAndMath.com. The code is actually much simpler in open frameworks because of overloaded operators.</p>
<p><a href="http://www.benmcchesney.com/blog/wp-content/uploads/2011/07/points_pixelForce.png"><img class="aligncenter size-full wp-image-443" title="Pixel Force with Triangles" src="http://www.benmcchesney.com/blog/wp-content/uploads/2011/07/points_pixelForce.png" alt="" width="830" height="625" /></a></p>
<p><a href="http://www.benmcchesney.com/blog/wp-content/uploads/2011/07/triangles_pixelForce.png"><img class="aligncenter size-full wp-image-444" title="Pixel Force with Triangles" src="http://www.benmcchesney.com/blog/wp-content/uploads/2011/07/triangles_pixelForce.png" alt="" width="799" height="764" /></a></p>
<p><span id="more-407"></span></p>
<p>Short example I made as part of learning open frameworks. I will post a video tutorial detailing through my process. Code is available on m github : https://github.com/benMcChesney/PixelForces</p>
<p>I&#8217;ll be using xCode OSX FAT Release 0062. I use xCode because I find it much easier to use over Visual Studio Express for importing external addons and libraries. If you are new to open frameworks development I strongly recomment visiting http://www.openframeworks.cc/setup for a detailed view on how to get setup with your IDE of choice. The Open Frameworks forums are excellent for solving almost any compiler specific problem you might be having.</p>
<p>First we&#8217;ll need to create a new example to work with. Copy the &#8220;emptyExample&#8221; inside YOUR_OF_Directory/apps/examples/emptyExample and rename it to something cooler sounding like : &#8220;PixelForces&#8221; . Next step is to find a picture to use as your the color for particles. Any picture will do, kittens, godzilla, you name it! The resolution of the picture I chose was 512 × 391. Once acquired place this file inside bin/data so that the app will be able to find it easily.</p>
<p>Create a new header file and call it Particle. To start out we will create a basic empty constructor and give it three properties.</p>
<p>1 ) OfColor color &#8211; to know what color to draw</p>
<p>2 ) ofPoint position &#8211; for where to draw it.</p>
<p>3) ofPoint velocity &#8211; the speed that each particle will move every frame.</p>
<div class="codecolorer-container cpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:650px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br /></div></td><td><div class="cpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666;">//</span><br />
<span style="color: #666666;">// Particle.h</span><br />
<span style="color: #666666;">// PixelForces</span><br />
<span style="color: #666666;">//</span><br />
<span style="color: #666666;">// A Simple Particle Class</span><br />
<span style="color: #666666;">//</span><br />
<span style="color: #339900;">#ifndef _PARTICLE</span><br />
<span style="color: #339900;">#define _PARTICLE</span><br />
<br />
<span style="color: #339900;">#include &quot;ofMain.h&quot;</span><br />
<br />
<span style="color: #0000ff;">class</span> Particle<br />
<span style="color: #008000;">&#123;</span><br />
<span style="color: #0000ff;">public</span> <span style="color: #008080;">:</span><br />
Particle<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008080;">;</span><br />
Particle<span style="color: #008000;">&#40;</span> ofPoint _position , ofColor _color <span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
position <span style="color: #000080;">=</span> _position <span style="color: #008080;">;</span><br />
color <span style="color: #000080;">=</span> _color <span style="color: #008080;">;</span><br />
<br />
<span style="color: #008000;">&#125;</span><br />
<br />
ofPoint position , velocity <span style="color: #008080;">;</span><br />
ofColor color <span style="color: #008080;">;</span><br />
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span><br />
<span style="color: #339900;">#endif</span></div></td></tr></tbody></table></div>
<p>Now navigate to the testApp.h and be sure to include Particle.h at the top of the file.</p>
<div class="codecolorer-container cpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="cpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339900;">#include &quot;Particle.h&quot;</span></div></td></tr></tbody></table></div>
<p>Then we will have to add in the variables needed for this example.</p>
<div class="codecolorer-container cpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="cpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">ofImage image <span style="color: #008080;">;</span> <span style="color: #666666;">//image to load</span><br />
<span style="color: #0000ff;">int</span> sampling <span style="color: #008080;">;</span> <span style="color: #666666;">//pixels to skip</span><br />
vector particles <span style="color: #008080;">;</span> <span style="color: #666666;">//vector to store pixels</span><br />
<span style="color: #0000ff;">int</span> numParticles <span style="color: #008080;">;</span>          <span style="color: #666666;">//Number of particles</span><br />
<br />
<span style="color: #666666;">//Spring and Sink Factors</span><br />
<span style="color: #0000ff;">bool</span> springEnabled <span style="color: #008080;">;</span>        <span style="color: #666666;">//toggle whether particles return to their origin</span><br />
<span style="color: #0000ff;">float</span> forceRadius <span style="color: #008080;">;</span>                          <span style="color: #666666;">//radius of repellent/attraction force</span><br />
<span style="color: #0000ff;">float</span> velocityDampingFactor <span style="color: #008080;">;</span>   <span style="color: #666666;">//damping factor to slow the particles down</span><br />
<span style="color: #0000ff;">float</span> springFactor <span style="color: #008080;">;</span>                  <span style="color: #666666;">//how much the particle &quot;springs&quot; back to origin</span><br />
<span style="color: #0000ff;">int</span> cursorMode <span style="color: #008080;">;</span>                            <span style="color: #666666;">//whether the cursor is attracting or repelling</span></div></td></tr></tbody></table></div>
<p>Now if we navigate to testApp::setup( ) inside testApp.cpp we can see how we load in and image and get the pixels we need. This code is from an article by Daniel Shiffman on the processing learning site http://processing.org/learning/pixels/ . Be sure to check it out and lots of other great lessons that are great examples to play with. The image is stored as an array of unsigned chars for the RGB channels of each pixel and occupies 3 indicies per pixel. If our image had transparency it would be RGBA and each pixel would take up 4 indices.</p>
<div class="codecolorer-container cpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:650px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br /></div></td><td><div class="cpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000ff;">void</span> testApp<span style="color: #008080;">::</span><span style="color: #007788;">setup</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
<span style="color: #666666;">//Set the background to black</span><br />
ofBackground<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><br />
<span style="color: #666666;">//load our image inside bin/data</span><br />
image.<span style="color: #007788;">loadImage</span> <span style="color: #008000;">&#40;</span> <span style="color: #FF0000;">&quot;grandTetons_small.jpg&quot;</span> <span style="color: #008000;">&#41;</span> <span style="color: #008080;">;</span><br />
<span style="color: #666666;">//if the app performs slowly raise this number</span><br />
sampling <span style="color: #000080;">=</span> <span style="color: #0000dd;">4</span> <span style="color: #008080;">;</span><br />
<br />
<span style="color: #666666;">//Retrieve the pixels from the loaded image</span><br />
<span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">char</span> <span style="color: #000040;">*</span> pixels <span style="color: #000080;">=</span> image.<span style="color: #007788;">getPixels</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008080;">;</span><br />
<span style="color: #666666;">//store width and height for optimization and clarity</span><br />
<span style="color: #0000ff;">int</span> w <span style="color: #000080;">=</span> image.<span style="color: #007788;">width</span> <span style="color: #008080;">;</span><br />
<span style="color: #0000ff;">int</span> h <span style="color: #000080;">=</span> image.<span style="color: #007788;">height</span> <span style="color: #008080;">;</span><br />
<br />
<span style="color: #666666;">//offsets to center the particles on screen</span><br />
<span style="color: #0000ff;">int</span> xOffset <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>ofGetWidth<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">-</span> w <span style="color: #008000;">&#41;</span> <span style="color: #000040;">/</span><span style="color: #0000dd;">2</span> <span style="color: #008080;">;</span><br />
<span style="color: #0000ff;">int</span> yOffset <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>ofGetHeight<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">-</span> h <span style="color: #008000;">&#41;</span> <span style="color: #000040;">/</span><span style="color: #0000dd;">2</span> <span style="color: #008080;">;</span><br />
<br />
<span style="color: #666666;">//Loop through all the rows</span><br />
<span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">int</span> x <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span> <span style="color: #008080;">;</span> x <span style="color: #000080;">&lt;</span> w <span style="color: #008080;">;</span> x<span style="color: #000040;">+</span><span style="color: #000080;">=</span>sampling <span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
<span style="color: #666666;">//Loop through all the columns</span><br />
<span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">int</span> y <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span> <span style="color: #008080;">;</span> y <span style="color: #000080;">&lt;</span> h <span style="color: #008080;">;</span> y<span style="color: #000040;">+</span><span style="color: #000080;">=</span>sampling <span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
<span style="color: #666666;">//Pixels are stored as unsigned char ( 0 255 ) as RGB</span><br />
<span style="color: #666666;">//If our image had transparency it would be 4 for RGBA</span><br />
<span style="color: #0000ff;">int</span> index <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span> y <span style="color: #000040;">*</span> w <span style="color: #000040;">+</span> x <span style="color: #008000;">&#41;</span> <span style="color: #000040;">*</span> <span style="color: #0000dd;">3</span> <span style="color: #008080;">;</span><br />
ofColor color <span style="color: #008080;">;</span><br />
color.<span style="color: #007788;">r</span> <span style="color: #000080;">=</span> pixels<span style="color: #008000;">&#91;</span>index<span style="color: #008000;">&#93;</span> <span style="color: #008080;">;</span> <span style="color: #666666;">//red pixel</span><br />
color.<span style="color: #007788;">g</span> <span style="color: #000080;">=</span> pixels<span style="color: #008000;">&#91;</span>index<span style="color: #000040;">+</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span> <span style="color: #008080;">;</span> <span style="color: #666666;">//blue pixel</span><br />
color.<span style="color: #007788;">b</span> <span style="color: #000080;">=</span> pixels<span style="color: #008000;">&#91;</span>index<span style="color: #000040;">+</span><span style="color: #0000dd;">2</span><span style="color: #008000;">&#93;</span> <span style="color: #008080;">;</span> <span style="color: #666666;">//green pixel</span><br />
particles.<span style="color: #007788;">push_back</span><span style="color: #008000;">&#40;</span> Particle <span style="color: #008000;">&#40;</span> ofPoint <span style="color: #008000;">&#40;</span> x <span style="color: #000040;">+</span> xOffset , y <span style="color: #000040;">+</span> yOffset <span style="color: #008000;">&#41;</span> , color <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span> <span style="color: #008080;">;</span><br />
<span style="color: #008000;">&#125;</span><br />
<span style="color: #008000;">&#125;</span><br />
ofSetFrameRate<span style="color: #008000;">&#40;</span> <span style="color: #0000dd;">30</span> <span style="color: #008000;">&#41;</span> <span style="color: #008080;">;</span><br />
<br />
numParticles <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span> image.<span style="color: #007788;">width</span> <span style="color: #000040;">*</span> image.<span style="color: #007788;">height</span> <span style="color: #008000;">&#41;</span> <span style="color: #000040;">/</span> sampling <span style="color: #008080;">;</span><br />
<span style="color: #008000;">&#125;</span></div></td></tr></tbody></table></div>
<p>Next we have to change the draw( ) function to loop through a vector of particles. In c++ vectors are stored as a linked list which is a very quick way to iterate through a list of items.</p>
<p>Coming from Actionscript it took me a while to wrap my head around pointers. You can read more about them here http://www.cplusplus.com/forum/articles/9621/ . For now just know that pointers are used to reference a location in memory similar to how an object works in OOP.</p>
<div class="codecolorer-container cpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br /></div></td><td><div class="cpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000ff;">void</span> testApp<span style="color: #008080;">::</span><span style="color: #007788;">draw</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><br />
<br />
<span style="color: #666666;">//Create an iterator to cycle through the vector</span><br />
std<span style="color: #008080;">::</span><span style="color: #007788;">vector</span><span style="color: #008080;">::</span><span style="color: #007788;">iterator</span> p <span style="color: #008080;">;</span><br />
<span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span> p <span style="color: #000080;">=</span> particles.<span style="color: #007788;">begin</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008080;">;</span> p <span style="color: #000040;">!</span><span style="color: #000080;">=</span> particles.<span style="color: #007788;">end</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008080;">;</span> p<span style="color: #000040;">++</span> <span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
<span style="color: #666666;">//access the color via the pointer p</span><br />
<span style="color: #666666;">//when using pointers you have to use &quot;-&gt;&quot; syntax instead of &quot;.&quot;</span><br />
ofColor color <span style="color: #000080;">=</span> p<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>color <span style="color: #008080;">;</span><br />
ofSetColor <span style="color: #008000;">&#40;</span> color.<span style="color: #007788;">r</span> , color.<span style="color: #007788;">g</span> , color.<span style="color: #007788;">b</span> <span style="color: #008000;">&#41;</span> <span style="color: #008080;">;</span><br />
ofCircle <span style="color: #008000;">&#40;</span> p<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>position.<span style="color: #007788;">x</span> , p<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>position.<span style="color: #007788;">y</span> , <span style="color: #0000dd;">1</span> <span style="color: #008000;">&#41;</span> <span style="color: #008080;">;</span><br />
<span style="color: #008000;">&#125;</span><br />
<span style="color: #008000;">&#125;</span></div></td></tr></tbody></table></div>
<p>&nbsp;</p>
<p>Next let&#8217;s create a simple update( ) function.</p>
<div class="codecolorer-container cpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br /></div></td><td><div class="cpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000ff;">void</span> testApp<span style="color: #008080;">::</span><span style="color: #007788;">update</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><br />
<br />
<span style="color: #666666;">//Create an iterator to cycle through the vector</span><br />
<br />
std<span style="color: #008080;">::</span><span style="color: #007788;">vector</span><span style="color: #008080;">:</span>iterator p <span style="color: #008080;">;</span><br />
<br />
<span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span> p <span style="color: #000080;">=</span> particles.<span style="color: #007788;">begin</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008080;">;</span> p <span style="color: #000040;">!</span><span style="color: #000080;">=</span> particles.<span style="color: #007788;">end</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008080;">;</span> p<span style="color: #000040;">++</span> <span style="color: #008000;">&#41;</span><br />
<br />
<span style="color: #008000;">&#123;</span><br />
<br />
p<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>position <span style="color: #000040;">+</span><span style="color: #000080;">=</span> p<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>velocity <span style="color: #008080;">;</span><br />
<br />
<span style="color: #008000;">&#125;</span><br />
<br />
<span style="color: #008000;">&#125;</span></div></td></tr></tbody></table></div>
<p>&nbsp;</p>
<p style="text-align: center;">When you run the example it should look like this !<br />
<a href="http://www.benmcchesney.com/blog/wp-content/uploads/2011/07/first_step.png"><img class="aligncenter size-large wp-image-422" title="first_step" src="http://www.benmcchesney.com/blog/wp-content/uploads/2011/07/first_step-1024x806.png" alt="" width="819" height="645" /></a></p>
<p>Now we have particles but they aren&#8217;t moving! Let&#8217;s add a variable of type ofPoint velocity to our particle class.<br />
Inside the constructor let&#8217;s set it to a random number like so</p>
<div class="codecolorer-container cpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="cpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">velocity <span style="color: #000080;">=</span> ofPoint <span style="color: #008000;">&#40;</span> ofRandom <span style="color: #008000;">&#40;</span> <span style="color: #000040;">-</span><span style="color: #0000dd;">5</span> , <span style="color: #0000dd;">5</span> <span style="color: #008000;">&#41;</span> , ofRandom <span style="color: #008000;">&#40;</span> <span style="color: #000040;">-</span><span style="color: #0000dd;">5</span> , <span style="color: #0000dd;">5</span> <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span> <span style="color: #008080;">;</span></div></td></tr></tbody></table></div>
<p>Now our particles are moving but sort of all over and it&#8217;s not very cool. But this is a starting point! Let&#8217;s add two more ofPoint variables to our Particle class</p>
<div class="codecolorer-container cpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="cpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">ofPoint acceleration <span style="color: #008080;">;</span>          <span style="color: #666666;">//smoothing applied to velocity</span><br />
<br />
ofPoint spawnPoint <span style="color: #008080;">;</span>            <span style="color: #666666;">//original location to line up the picture</span></div></td></tr></tbody></table></div>
<p>Inside the constructor set spawnPoint to the argument ofPoint _position. This will be used for the particles to seek back and realign after some time. Inside testApp::setup( ) we can now set the other variables for the forces.</p>
<p>&nbsp;</p>
<div class="codecolorer-container cpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="cpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666;">//Set spring and sink values</span><br />
<br />
cursorMode <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span> <span style="color: #008080;">;</span><br />
<br />
forceRadius <span style="color: #000080;">=</span> <span style="color: #0000dd;">45</span> <span style="color: #008080;">;</span><br />
<br />
velocityDampingFactor <span style="color: #000080;">=</span> <span style="color:#800080;">0.85</span> <span style="color: #008080;">;</span><br />
<br />
springFactor <span style="color: #000080;">=</span> <span style="color:#800080;">0.12</span> <span style="color: #008080;">;</span><br />
<br />
springEnabled <span style="color: #000080;">=</span> <span style="color: #0000ff;">true</span> <span style="color: #008080;">;</span></div></td></tr></tbody></table></div>
<p>Next we will have to make some changes to our update function. For simplicity we&#8217;ll use the mouseX and mouseY as the center point of our force. The first step is to create three variables to use for checking values within looped values.</p>
<div class="codecolorer-container cpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:650px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br /></div></td><td><div class="cpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">ofPoint diff <span style="color: #008080;">;</span> <span style="color: #666666;">//Difference between particle and mouse</span><br />
<span style="color: #0000ff;">float</span> dist <span style="color: #008080;">;</span> <span style="color: #666666;">//distance from particle to mouse ( as the crow flies )</span><br />
<span style="color: #0000ff;">float</span> ratio <span style="color: #008080;">;</span> <span style="color: #666666;">//Ratio of how strong the effect is calculated by: 1 + (-dist/maxDistance) ;</span><br />
<span style="color: #0000ff;">const</span> ofPoint mousePosition <span style="color: #000080;">=</span> ofPoint<span style="color: #008000;">&#40;</span> mouseX , mouseY <span style="color: #008000;">&#41;</span> <span style="color: #008080;">;</span> <span style="color: #666666;">//Allocate and retrieve mouse values once.</span><br />
<br />
<span style="color: #666666;">//Create an iterator to cycle through the vector</span><br />
<br />
std<span style="color: #008080;">::</span><span style="color: #007788;">vector</span><span style="color: #008080;">;::</span><span style="color: #007788;">iterator</span> p <span style="color: #008080;">;</span><br />
<br />
<span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span> p <span style="color: #000080;">=</span> particles.<span style="color: #007788;">begin</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008080;">;</span> p <span style="color: #000040;">!</span><span style="color: #000080;">=</span> particles.<span style="color: #007788;">end</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008080;">;</span> p<span style="color: #000040;">++</span> <span style="color: #008000;">&#41;</span><br />
<br />
<span style="color: #008000;">&#123;</span><br />
<br />
ratio <span style="color: #000080;">=</span> <span style="color:#800080;">1.0f</span> <span style="color: #008080;">;</span><br />
<br />
p<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>velocity <span style="color: #000040;">*</span><span style="color: #000080;">=</span> friction <span style="color: #008080;">;</span><br />
<br />
<span style="color: #666666;">//reset acceleration every frame</span><br />
<br />
p<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>acceleration <span style="color: #000080;">=</span> ofPoint<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008080;">;</span><br />
<br />
diff <span style="color: #000080;">=</span> mousePosition <span style="color: #000040;">-</span> p<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>position <span style="color: #008080;">;</span><br />
<br />
dist <span style="color: #000080;">=</span> ofDist<span style="color: #008000;">&#40;</span> <span style="color: #0000dd;">0</span> , <span style="color: #0000dd;">0</span> , diff.<span style="color: #007788;">x</span> , diff.<span style="color: #007788;">y</span> <span style="color: #008000;">&#41;</span> <span style="color: #008080;">;</span><br />
<br />
<span style="color: #666666;">//If within the zone of interaction</span><br />
<br />
<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> dist <span style="color: #000080;">&lt;</span> forceRadius <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> ratio <span style="color: #000080;">=</span> <span style="color: #0000dd;">1</span> <span style="color: #000040;">-</span> dist <span style="color: #000040;">/</span> forceRadius <span style="color: #008080;">;</span> p<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span><span style="color: #008080;">;</span>acceleration <span style="color: #000040;">-</span><span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span> diff <span style="color: #000040;">*</span> ratio<span style="color: #008000;">&#41;</span> <span style="color: #008080;">;</span><br />
<br />
<span style="color: #008000;">&#125;</span><br />
<br />
<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> springEnabled <span style="color: #008000;">&#41;</span><br />
<br />
<span style="color: #008000;">&#123;</span><br />
<br />
<span style="color: #666666;">//Move back to the original position</span><br />
<br />
p<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>acceleration.<span style="color: #007788;">x</span> <span style="color: #000040;">+</span><span style="color: #000080;">=</span> springFactor <span style="color: #000040;">*</span> <span style="color: #008000;">&#40;</span>p<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>spawnPoint.<span style="color: #007788;">x</span> <span style="color: #000040;">-</span> p<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>position.<span style="color: #007788;">x</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
<br />
p<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>acceleration.<span style="color: #007788;">y</span> <span style="color: #000040;">+</span><span style="color: #000080;">=</span> springFactor <span style="color: #000040;">*</span> <span style="color: #008000;">&#40;</span>p<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>spawnPoint.<span style="color: #007788;">y</span> <span style="color: #000040;">-</span> p<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>position.<span style="color: #007788;">y</span><span style="color: #008000;">&#41;</span> <span style="color: #008080;">;</span><br />
<br />
<span style="color: #008000;">&#125;</span><br />
<br />
p<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>velocity <span style="color: #000040;">+</span><span style="color: #000080;">=</span> p<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>acceleration <span style="color: #000040;">*</span> ratio <span style="color: #008080;">;</span><br />
<br />
p<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>position <span style="color: #000040;">+</span><span style="color: #000080;">=</span> p<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>velocity <span style="color: #008080;">;</span><br />
<br />
<span style="color: #008000;">&#125;</span></div></td></tr></tbody></table></div>
<p>Now the for loop has gone through a fairly drastic change. There&#8217;s a default ratio of 1.0f so that particles outside of the zone of influence do not get affected by the mouse. Then we are applying friction to slow down the particles&#8217; velocity for a more lifelike and settling effect. The desired velocity of moving away for each particle is calculated by subtracting the mouse&#8217;s X,Y with the particles X ,Y and getting the distance. By adding these same two vectors we gain the desired vector to steer toward the mouse. We adjust the ratio based on how far away the particle is and then if springs are enabled we add the desired velocity to the acceleration. The overall acceleration is then modified by the ratio and we offset the position.</p>
<p>&nbsp;</p>
<p>Let&#8217;s add some debugging output text to keep track of the application. Skipping down to the bottom of testApp::draw( ) ;</p>
<p>&nbsp;</p>
<div class="codecolorer-container cpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="cpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">ofSetColor <span style="color: #008000;">&#40;</span> <span style="color: #0000dd;">255</span> , <span style="color: #0000dd;">255</span> , <span style="color: #0000dd;">255</span> <span style="color: #008000;">&#41;</span> <span style="color: #008080;">;</span><br />
<br />
string output <span style="color: #000080;">=</span> <span style="color: #FF0000;">&quot;S :: Springs on/off : &quot;</span> <span style="color: #000040;">+</span> ofToString<span style="color: #008000;">&#40;</span>springEnabled<span style="color: #008000;">&#41;</span> <span style="color: #000040;">+</span><br />
<br />
<span style="color: #FF0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span> C :: CursorMode repel/attract &quot;</span> <span style="color: #000040;">+</span> ofToString<span style="color: #008000;">&#40;</span> cursorMode <span style="color: #008000;">&#41;</span> <span style="color: #000040;">+</span><br />
<br />
<span style="color: #FF0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span> # of particles : &quot;</span> <span style="color: #000040;">+</span> ofToString<span style="color: #008000;">&#40;</span> numParticles <span style="color: #008000;">&#41;</span> <span style="color: #000040;">+</span><br />
<br />
<span style="color: #FF0000;">&quot; <span style="color: #000099; font-weight: bold;">\n</span> fps:&quot;</span> <span style="color: #000040;">+</span>ofToString<span style="color: #008000;">&#40;</span> ofGetFrameRate<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span> <span style="color: #008080;">;</span><br />
<br />
ofDrawBitmapString<span style="color: #008000;">&#40;</span>output ,<span style="color: #0000dd;">20</span>,<span style="color: #0000dd;">666</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></div></td></tr></tbody></table></div>
<p>Here we are building a long string and creating newlines by using the &#8220;\n&#8221; character. Then with a simple call to ofDrawBitmapString( string , x , y ) ;</p>
<p>One more bit of code for the keyboard listeners to toggle modes and make this more fun</p>
<div class="codecolorer-container cpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br /></div></td><td><div class="cpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000ff;">switch</span> <span style="color: #008000;">&#40;</span> key <span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
<span style="color: #0000ff;">case</span> <span style="color: #FF0000;">'c'</span><span style="color: #008080;">:</span><br />
<span style="color: #0000ff;">case</span> <span style="color: #FF0000;">'C'</span><span style="color: #008080;">:</span><br />
cursorMode <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span> cursorMode <span style="color: #000040;">+</span> <span style="color: #0000dd;">1</span> <span style="color: #000080;">&gt;</span> <span style="color: #0000dd;">1</span> <span style="color: #008000;">&#41;</span> <span style="color: #008080;">?</span> <span style="color: #0000dd;">0</span> <span style="color: #008080;">:</span> <span style="color: #0000dd;">1</span> <span style="color: #008080;">;</span><br />
<span style="color: #0000ff;">break</span> <span style="color: #008080;">;</span><br />
<br />
<span style="color: #0000ff;">case</span> <span style="color: #FF0000;">'s'</span><span style="color: #008080;">:</span><br />
<span style="color: #0000ff;">case</span> <span style="color: #FF0000;">'S'</span><span style="color: #008080;">:</span><br />
springEnabled <span style="color: #000080;">=</span> <span style="color: #000040;">!</span>springEnabled <span style="color: #008080;">;</span><br />
<span style="color: #0000ff;">break</span> <span style="color: #008080;">;</span><br />
<span style="color: #008000;">&#125;</span></div></td></tr></tbody></table></div>
<p>Attraction and repulsion! The only thing that could make this better would be more pixels to play with. Looking through some examples in the <a href="github.com/ofTheo/ofxKinect">ofxKinect github</a> I saw how openGL was used to draw individual points of an image in real time. By changing the draw function I was able to increase my sampling by 2x and still had a good frame rate.</p>
<div class="codecolorer-container cpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:650px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br /></div></td><td><div class="cpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666;">//Begin the openGL Drawing Mode</span><br />
<br />
glBegin<span style="color: #008000;">&#40;</span>GL_POINTS<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
<br />
<span style="color: #666666;">//Triangles look Cool too</span><br />
<br />
<span style="color: #666666;">//glBegin(GL_TRIANGLES);</span><br />
<br />
<span style="color: #666666;">//Create an iterator to cycle through the vector</span><br />
<br />
std<span style="color: #008080;">::</span><span style="color: #007788;">vector</span><span style="color: #008080;">::</span><span style="color: #007788;">iterator</span> p <span style="color: #008080;">;</span><br />
<br />
<span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span> p <span style="color: #000080;">=</span> particles.<span style="color: #007788;">begin</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008080;">;</span> p <span style="color: #000040;">!</span><span style="color: #000080;">=</span> particles.<span style="color: #007788;">end</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008080;">;</span> p<span style="color: #000040;">++</span> <span style="color: #008000;">&#41;</span><br />
<br />
<span style="color: #008000;">&#123;</span><br />
<br />
<span style="color: #666666;">//get the color and draw a point</span><br />
<br />
glColor3ub<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">char</span><span style="color: #008000;">&#41;</span>p<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>color.<span style="color: #007788;">r</span>,<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">char</span><span style="color: #008000;">&#41;</span>p<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>color.<span style="color: #007788;">g</span>,<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">char</span><span style="color: #008000;">&#41;</span>p<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>color.<span style="color: #007788;">b</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
<br />
glVertex3f<span style="color: #008000;">&#40;</span>p<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>position.<span style="color: #007788;">x</span>, p<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>position.<span style="color: #007788;">y</span> , <span style="color: #0000dd;">0</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><br />
<br />
<span style="color: #008000;">&#125;</span><br />
<br />
glEnd<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></div></td></tr></tbody></table></div>
<p>&nbsp;</p>
<p>The code for this is on my github and <a href="https://github.com/benMcChesney/PixelForces/commit/a871266096e95583a48ade2c51d72b25d1527caf"> available here </a> The next step is to create some sliders, using Frame buffers objects and make some sound analysis.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.benmcchesney.com/blog/2011/07/attraction-repulsion-pixels-in-open-frameworks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Kinect Hacks</title>
		<link>http://www.benmcchesney.com/blog/2011/02/kinect-hacks/</link>
		<comments>http://www.benmcchesney.com/blog/2011/02/kinect-hacks/#comments</comments>
		<pubDate>Tue, 22 Feb 2011 08:24:21 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Interactive]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[creative]]></category>
		<category><![CDATA[frameworks]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[installation]]></category>
		<category><![CDATA[Kinect]]></category>
		<category><![CDATA[open]]></category>

		<guid isPermaLink="false">http://www.benmcchesney.com/blog/?p=386</guid>
		<description><![CDATA[I&#8217;ve been tinkering with the Kinect and I wanted to release what applications I had been able to create. I was inspired from other people&#8217;s examples and forum posts and wanted to contribute back what I could. All the examples are on my github to ensure that I&#8217;ll be able to easily update them in ...]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been tinkering with the Kinect and I wanted to release what applications I had been able to create. I was inspired from other people&#8217;s examples and forum posts and wanted to contribute back what I could. All the examples are on <a href="https://github.com/benMcChesney/KinectHacks">my github</a> to ensure that I&#8217;ll be able to easily update them in the future. The first set of examples were all completed using <a href="http://openframeworks.cc">open frameworks</a> a c++ creative coding framework.</p>
<p>ofxSoundDraw<br />
This example was covered more in depth in a previous blog post. Using a local TUIO server to track hands it plays a sound byte if there&#8217;s enough movement in a designated zone.</p>
<p><a href="http://www.benmcchesney.com/blog/wp-content/uploads/2011/02/DrawKinect1.png"><img class="aligncenter size-full wp-image-393" title="DrawKinect" src="http://www.benmcchesney.com/blog/wp-content/uploads/2011/02/DrawKinect1.png" alt="" width="480" height="409" /></a></p>
<p>ofxKinectBox2D</p>
<p>This is the first example I got running with box2D. The circles are simple rigid bodies and when two hands are present it spawns an attraction force at the midpoint between both hands.</p>
<p style="text-align: center;"><a href="http://www.benmcchesney.com/blog/wp-content/uploads/2011/02/box2D.png"><img class="aligncenter size-full wp-image-388" title="box2D" src="http://www.benmcchesney.com/blog/wp-content/uploads/2011/02/box2D.png" alt="" width="644" height="561" /></a></p>
<p><span id="more-386"></span></p>
<p>FireIce</p>
<p>Taking the above example a little farther. Particles have two types : fire + ice. When opposites combine both pieces are rendered inert.</p>
<p style="text-align: center;"><a href="http://www.benmcchesney.com/blog/wp-content/uploads/2011/02/fireIce.png"><img class="aligncenter size-full wp-image-394" title="Fire and Ice" src="http://www.benmcchesney.com/blog/wp-content/uploads/2011/02/fireIce.png" alt="" width="644" height="561" /></a></p>
<p>ofxBounceSound<br />
Similar to the above example, but crashing groups of particles generates a piano sound.</p>
<p style="text-align: center;"><a href="http://www.benmcchesney.com/blog/wp-content/uploads/2011/02/BounceGame.png"><img class="aligncenter size-full wp-image-387" title="BounceGame" src="http://www.benmcchesney.com/blog/wp-content/uploads/2011/02/BounceGame.png" alt="" width="644" height="561" /></a></p>
<p>ofxUserMask<br />
Using openCV and .mov renders it tracks a user and draws a point cloud field. The idea was that at a concert or other event to dynamically mask that movie to a user.</p>
<p style="text-align: center;"><a href="http://www.benmcchesney.com/blog/wp-content/uploads/2011/02/ofxUserMask.png"><img class="aligncenter size-large wp-image-392" title="ofxUserMask" src="http://www.benmcchesney.com/blog/wp-content/uploads/2011/02/ofxUserMask-1024x806.png" alt="" width="573" height="451" /></a></p>
<p>ofxKinectSequence<br />
My latest Kinect + open frameworks project. I began by looking back at my sound example and decided to expand it&#8217;s functionality. Now the app features 4 tracks and loops allowing the user to create a soundscape. The tracks and rhythms are all preset now in code but I will continue to update it to make it a more robust system.</p>
<p style="text-align: center;"><a href="http://www.benmcchesney.com/blog/wp-content/uploads/2011/02/ofxSequence1.png"><img class="aligncenter size-full wp-image-395" title="ofxSequence" src="http://www.benmcchesney.com/blog/wp-content/uploads/2011/02/ofxSequence1.png" alt="" width="644" height="561" /></a></p>
<p>OpenNI_Unity3d</p>
<p>This example uses OpenNI, a middleware layer ( between software and hardware ), for natural user interaction. A module of this system is NITE skeleton tracking which allows for some great, accurate avatar interactions.</p>
<p>The most current source of information regarding this driver is this forum post : http://forum.unity3d.com/threads/67982-Kinect-plugin/</p>
<p>BernardFrancois has graciously provided this in-depth walkthrough of how to install the drivers on page 4. Also posted below :</p>
<p>In general I found windows installation much simpler than the command line route I had to go through on OSX.</p>
<p>&#8221;<br />
Installing the kinect driver, OpenNI and NITE SDK<br />
* download the OpenNI binaries from http://www.openni.org/?q=node/2 (in this case: OpenNI 1.0 Alpha build 23 binaries for Win32)<br />
* download the NITE SDK from http://www.primesense.com/?p=515 (in this case: NITE 1.3 Beta build 17 SDK for Windows)<br />
* download SensorKinect from https://github.com/avin2/SensorKinect<br />
* install OpenNI<br />
* install NITE SDK and use the following free license key frop openni.org: 0KOIk2JeIBYClPWVnMoRKn5cdY4=<br />
* unzip the SensorKinect file<br />
* connect the Kinect device<br />
* open the device manager (Start &gt; Run&#8230; &gt; devmgmt.msc) and verify that &#8216;Xbox NUI Motor&#8217; is in the list (but with an exclamation mark)<br />
* Right-click on the device and choose &#8216;Update Driver&#8217; and make windows look for a driver in the avin2-SensorKinect-b7cd39d\Platform\Win32\Driver folder. This will install a device called &#8216;Kinect Motor&#8217;.<br />
* reboot your computer when asked<br />
* After rebooting, two new devices will be found. Repeat the same process by pointing the wizard to the driver folder. One of the two new devices will fail to install (the one for the audio), the one that will succeed will add a new device called &#8216;Kinect Camera&#8217;.<br />
* install the executable the zip file in the folder avin2-SensorKinect-b7cd39d\Bin<br />
* run C:\Program Files\OpenNI\Samples\Bin\Release\NiUserTracker.exe to test if everything works<br />
* if it fails, run C:\Program Files\OpenNI\Tools\vcredist_x86.exe<br />
installing the kinect unity example<br />
* download the official UnityWrapper from OpenNI from https://github.com/OpenNI/UnityWrapper<br />
* make sure Unity3 or Unity3 pro is installed</p>
<p>&#8221; &#8211; Quoted from user &#8216;BernardFrancois&#8217; Unity3d Forums</p>
<p><iframe src="http://player.vimeo.com/video/20233290" frameborder="0" width="640" height="480"></iframe></p>
<p><a href="http://vimeo.com/20233290">Unity3d NITE Destroy City</a> from <a href="http://vimeo.com/user1688289">Ben McChesney</a> on <a href="http://vimeo.com">Vimeo</a>.</p>
<p>Currently the NITE wrapper for unity3D only works on windows. NITE was recently ported to Mac with the help of Roxlu ( roxlu.com ) and an example is included with openFrameworks 0062, but it takes a bit of configuring to get it up and running. I included a few prefabs in my scene to make it more interesting than destroying cubes. Fire hydrants that spurts Water, Lampposts that short-circuit, and a building with destructible parts make the scene much more fun.</p>
<p>Kinect Hacking has been a fun and successful hobby. There are some real possibilities integrating it with unity3d, and I think that openNI and NITE will open up even more possibilities. I found myself wanting to detect if hands were open or closed for ui control: otherwise user input is a little limited.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.benmcchesney.com/blog/2011/02/kinect-hacks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Open Frameworks + Kinect + Sound</title>
		<link>http://www.benmcchesney.com/blog/2010/12/open-frameworks-kinect-sound/</link>
		<comments>http://www.benmcchesney.com/blog/2010/12/open-frameworks-kinect-sound/#comments</comments>
		<pubDate>Mon, 13 Dec 2010 03:39:12 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Interactive]]></category>
		<category><![CDATA[frameworks]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[Kinect]]></category>
		<category><![CDATA[open]]></category>
		<category><![CDATA[opencv]]></category>
		<category><![CDATA[Sound]]></category>

		<guid isPermaLink="false">http://www.benmcchesney.com/blog/?p=335</guid>
		<description><![CDATA[While attending FlITC San Francisco I saw Theo Watson talk about his work with the creative coding libraries known as open frameworks. While I didn&#8217;t have very much experience in c++ besides a couple of simple test apps to learn openGL, I thought it would be a good experience to learn a language completely different ...]]></description>
			<content:encoded><![CDATA[<p>While attending <a href="http://www.fitc.ca">FlITC San Francisco</a> I saw Theo Watson talk about his work with the creative coding libraries known as open frameworks. While I didn&#8217;t have very much experience in c++ besides a couple of simple test apps to learn openGL, I thought it would be a good experience to learn a language completely different from actionscript. Below is the result that I after a very productive day of tinkering:</p>
<p><iframe src="http://player.vimeo.com/video/17746568" width="400" height="335" frameborder="0"></iframe>
<p><a href="http://vimeo.com/17746568">Kinect Sound Experiment with Open Frameworks</a> from <a href="http://vimeo.com/user1688289">Ben McChesney</a> on <a href="http://vimeo.com">Vimeo</a></p>
<p><span id="more-335"></span></p>
<p>What is openframeworks?</p>
<p>I think the most accurate term I&#8217;ve heard to describe it is &#8220;processing on crack&#8221;. It shares a lot of similarities with processing including an easy and intuitive openGL wrapper, powerful video / image / sound classes , and lots of examples online. To get started visit the openframeworks main page <a href="http://www.openframeworks.cc/setup"> for whatever your OS might be. </a> I used be using xCode on Mac so I can only be helpful for the particular quirks I found working with xCode. But here is the cliffnotes version of what I went through:</p>
<p>Download + install xCode for mac</p>
<p>Download openframeworks FAT 0061 and unzip it my work folder ( though it will work anywhere )</p>
<p>Compile any example project under openframeworksFolder/apps/examples/  to make things easier for yourself and to get developing quickly. Whenever you start a new OF project put it in this folder so that it can easily find the necessary libraries.</p>
<p><a href="http://www.benmcchesney.com/blog/wp-content/uploads/2010/12/example-path.png"><img class="aligncenter size-full wp-image-339" title="example path" src="http://www.benmcchesney.com/blog/wp-content/uploads/2010/12/example-path.png" alt="" width="633" height="228" /></a></p>
<p>Time to start playing with the Kinect. The latest code is available at <a href="https://github.com/ofTheo/ofxKinect"> Theo Watson&#8217;s github </a> I then simply copied that downloaded folder into my  openframeworksFolder/apps/examples/ and double clicked the xCode project.</p>
<p>Running it looked like this  :</p>
<div id="attachment_345" class="wp-caption aligncenter" style="width: 747px"><a href="http://www.benmcchesney.com/blog/wp-content/uploads/2010/12/lookingGoodTex_breakdown.png"><img class="size-large wp-image-345  " title="Kinect program input breakdown" src="http://www.benmcchesney.com/blog/wp-content/uploads/2010/12/lookingGoodTex_breakdown-1024x806.png" alt="" width="737" height="581" /></a><p class="wp-caption-text">&quot;Looking good Tex&quot;</p></div>
<p>Neat! Let&#8217;s see what&#8217;s happening here. There&#8217;s the Depth Feed , which is the result of the infrared projector, The normal webcam feed, openCV addon which detects blobs ( hands ) and is similar to how infrared touchscreens work. The 3D DOTS is an interesting effect using the depth to create a 3d image with circles.</p>
<p>But what&#8217;s next? Well after digging around the OF forums and some googling I found a <a href="https://code.google.com/p/tuiokinect/"> TUIO Kinect example. </a></p>
<p>The TUIO library is a popular choice for touch screens because it provides lots of helper functions to track active blobs, the history of those blobs, speed , size, almost anything you could want. But with the meant specifically for Kinect I began to wonder what I could do with it.</p>
<p>While looking through the <a href="http://www.tuio.org/api/cpp/annotated.html">TUIO documentation </a> I found the calls to get the history of the path. And with this code block below started to get an effect I liked:</p>
<p><a href="http://www.benmcchesney.com/blog/wp-content/uploads/2010/12/trailCodeBlock.png"><img class="aligncenter size-full wp-image-362" title="Trail Code Block" src="http://www.benmcchesney.com/blog/wp-content/uploads/2010/12/trailCodeBlock.png" alt="" width="591" height="336" /></a></p>
<p>Feeling good about my circle trail with a little bit of gravity I looked at some of the openframeworks examples to see what I could combine together. After looking through the sound examples the choice seemed easy. The first step was creating a sound wave, and then playing a .wave file and controlling the speed to change pitch.</p>
<div id="attachment_373" class="wp-caption aligncenter" style="width: 672px"><a href="http://www.benmcchesney.com/blog/wp-content/uploads/2010/12/final_play.png"><img class="size-full wp-image-373  " title="End result playing with hands + feet" src="http://www.benmcchesney.com/blog/wp-content/uploads/2010/12/final_play.png" alt="" width="662" height="578" /></a><p class="wp-caption-text">Yes, you will look like a fool playing with a kinect. But who cares?</p></div>
<p>But what&#8217;s next? Well sound is cool but I want it to be more&#8230; fun. But after a quick look through the <a href="http://www.openframeworks.cc/addons/contributed"> contributed addons </a> Box2D looks like a good contender for some physics based awesome.</p>
<p><a href=" http://benmcchesney.com/blog/kinectSample_DRAW.zip"> Source code is available here for this project </a></p>
<p>Lastly I just wanted to give a big thanks to all the groups and people who worked on things in their free time and open-sourced it.</p>
<p>The <a href="http://openkinect.org/wiki/Main_Page"> Open Kinect </a> project and the libfreeKinect driver for everyone to use.</p>
<p><a href="http://www.theowatson.com/">Theo Watson </a> and the rest of the open frameworks community for providing increasingly faster, cooler examples using the kinect. If you haven&#8217;t join the forums and see what people are building.</p>
<p><a href="http://modin.yuri.at/">Martin Kaltenbrunner</a> for providing the TUIO Kinect examples making it possible to make touch screen functionality from 8 feet away.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.benmcchesney.com/blog/2010/12/open-frameworks-kinect-sound/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Loading a Collada file in Away3D</title>
		<link>http://www.benmcchesney.com/blog/2010/08/loading-a-collada-file-in-away3d/</link>
		<comments>http://www.benmcchesney.com/blog/2010/08/loading-a-collada-file-in-away3d/#comments</comments>
		<pubDate>Tue, 24 Aug 2010 06:05:32 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Interactive]]></category>
		<category><![CDATA[Motion]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[3d]]></category>
		<category><![CDATA[action]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[actionscript 3]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Away3D]]></category>
		<category><![CDATA[cinema4d]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.benmcchesney.com/blog/?p=302</guid>
		<description><![CDATA[Recently I had been doing a little more work in Away3D and I needed to use an object that was more complex than a preset primitive. After looking through some of the Away3D examples I  tried bringing in my own model from Cinema4D. I quickly found that setting up and exporting your file correctly is ...]]></description>
			<content:encoded><![CDATA[<p>Recently I had been doing a little more work in Away3D and I needed to use an object that was more complex than a preset primitive. After looking through some of the Away3D examples I  tried bringing in my own model from Cinema4D. I quickly found that setting up and exporting your file correctly is half the battle. In this tutorial I&#8217;ll explain how to create a primitive in cinema4D export it correctly for Away3D inside flash. Source code is available at the bottom. Use the right/left arrows to switch models and the up/down to change the texture. Below is the final product:</p>
<p><span id="more-302"></span></p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_ColladaExample_1968229661"
			class="flashmovie"
			width="800"
			height="600">
	<param name="movie" value="http://www.benmcchesney.com/blog/ColladaExample.swf" />
	<param name="play" value="false" />
	<param name="scale" value="noscale" />
	<param name="allowfullscreen" value="false" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.benmcchesney.com/blog/ColladaExample.swf"
			name="fm_ColladaExample_1968229661"
			width="800"
			height="600">
		<param name="play" value="false" />
		<param name="scale" value="noscale" />
		<param name="allowfullscreen" value="false" />
	<!--<![endif]-->
		

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>It all starts in Cinema4D. I&#8217;m using Cinema4D R11. Create a new project and start with a tube primitive.  Below are some of the parameters I used</p>
<div id="attachment_304" class="wp-caption alignnone" style="width: 353px"><a href="http://www.benmcchesney.com/blog/wp-content/uploads/2010/08/01_tut_sphereProperties.png"><img class="size-full wp-image-304" title="01_tut_sphereProperties" src="http://www.benmcchesney.com/blog/wp-content/uploads/2010/08/01_tut_sphereProperties.png" alt="" width="343" height="331" /></a><p class="wp-caption-text">Tube Properties</p></div>
<p>Then select the primtive and hit the &#8220;C&#8221; button. This will convert it to a polygon object. Your object manager should now look like this:</p>
<p><a href="http://www.benmcchesney.com/blog/wp-content/uploads/2010/08/03_tut_sphereObject.png"><img class="alignnone size-full wp-image-306" title="03_tut_sphereObject" src="http://www.benmcchesney.com/blog/wp-content/uploads/2010/08/03_tut_sphereObject.png" alt="" width="415" height="84" /></a></p>
<p>Now we will add a new material. I downloaded a metal texture off of <a href="http://cgtextures.com">CG Textures </a> and reduced it&#8217;s size to 256 x 256.  In a 3d system inside flash the two biggest things that can quickly bring your project down are the number of vertices in your model and the dimensions of your texture. Some general numbers are that a scene can support around 6,000 vertices give or take. So it&#8217;s great for simple scenes but for anything larger you might want to try another 3d environment like <a href="http://unity3d.com">unity3d.</a></p>
<p><a href="http://www.benmcchesney.com/blog/wp-content/uploads/2010/08/05_tut_textureSettings.png"><img class="alignnone size-full wp-image-308" title="05_tut_textureSettings" src="http://www.benmcchesney.com/blog/wp-content/uploads/2010/08/05_tut_textureSettings.png" alt="" width="518" height="529" /></a></p>
<p>and when you get prompted to copy a version of your texture file to the textures folder hit yes, it will save some hassle later with the file path. Also be sure to rename the texture to something recognizable like &#8220;RingMat&#8221; so that it can be identified later.</p>
<p><a href="http://www.benmcchesney.com/blog/wp-content/uploads/2010/08/04_tut_copyPath.png"><img class="alignnone size-full wp-image-307" title="04_tut_copyPath" src="http://www.benmcchesney.com/blog/wp-content/uploads/2010/08/04_tut_copyPath.png" alt="" width="500" height="236" /></a></p>
<p>Now switch over to vertices mode and hit apple + a to select all the points. Then select functions &gt; triangulate. In Cinema4D will default to drawing quads or units of 4 points. Inside Away3D it draws with triangles so we need to make this adjustment.</p>
<p><a href="http://www.benmcchesney.com/blog/wp-content/uploads/2010/08/06_tut_triangulate.png"><img class="alignnone size-full wp-image-309" title="06_tut_triangulate" src="http://www.benmcchesney.com/blog/wp-content/uploads/2010/08/06_tut_triangulate.png" alt="" width="701" height="536" /></a>Now we switch over to BodyPaint UV Edit where we can quickly adjust the UV Map so it doesn&#8217;t look quite so hideous. If you are new to UV mapping and 3d in general UV mapping allows you to customize and control how your 2d texture appears on geometry and shapes in 3d. UV Mapping is an art in itself and can take weeks to do perfectly. For this exampl and for other simple tasks the UV Editor inside Cinema4D can take a lot of the work out of it.</p>
<p><a href="http://www.benmcchesney.com/blog/wp-content/uploads/2010/08/07_tut_bpUVEdit.png"><img class="alignnone size-full wp-image-310" title="07_tut_bpUVEdit" src="http://www.benmcchesney.com/blog/wp-content/uploads/2010/08/07_tut_bpUVEdit.png" alt="" width="183" height="423" /></a></p>
<p>Now select the UV Mapping wizard.</p>
<p><a href="http://www.benmcchesney.com/blog/wp-content/uploads/2010/08/08_tut_iconWizard.png"><img class="alignnone size-full wp-image-311" title="08_tut_iconWizard" src="http://www.benmcchesney.com/blog/wp-content/uploads/2010/08/08_tut_iconWizard.png" alt="" width="660" height="107" /></a></p>
<p>Now just have to go through all the steps of the wizard.</p>
<p><a href="http://www.benmcchesney.com/blog/wp-content/uploads/2010/08/09_tut_uvwizard_object.png"><img class="alignnone size-full wp-image-312" title="09_tut_uvwizard_object" src="http://www.benmcchesney.com/blog/wp-content/uploads/2010/08/09_tut_uvwizard_object.png" alt="" width="460" height="396" /></a></p>
<p>We will be using the object option.</p>
<p><a href="http://www.benmcchesney.com/blog/wp-content/uploads/2010/08/10_tut_uvwizard_cubic.png"><img class="alignnone size-full wp-image-313" title="10_tut_uvwizard_cubic" src="http://www.benmcchesney.com/blog/wp-content/uploads/2010/08/10_tut_uvwizard_cubic.png" alt="" width="460" height="396" /></a></p>
<p>There are multiple ways you can map coordinates to a texture. Cubic Mapping will work fine in this case. Cubic maps generally make simpler uv coordinate systems. Angle mapping by default will have a collection of smaller more precise parts.</p>
<p><img class="alignnone size-full wp-image-314" title="11_tut_uvwizard_channels" src="http://www.benmcchesney.com/blog/wp-content/uploads/2010/08/11_tut_uvwizard_channels.png" alt="" width="460" height="396" /></p>
<p>Now select the color channel until it has a &#8211; through it&#8217;s check box. Otherwise the UV Wizard will overwrite the texture that we already set. If we had a more complicated texture scheme we&#8217;d want to map other channels too. But for now color will suffice. Now switch over to polygons mode. Hit cmd + a to select all the polygons. If the selected polygons are orange that means their normals are facing the correct direction.</p>
<p>For the non initiated when a 3d renderer draws all the vertices it draws them in order and this order determines which way it faces. The flat solid part drawn between them is also called a face. A 3d engine does not render faces that do not have their normals facing the camera. So they save on resources by only rendering half of what we need too.</p>
<p><a href="http://www.benmcchesney.com/blog/wp-content/uploads/2010/08/12_tut_normals.png"><img class="alignnone size-full wp-image-315" title="12_tut_normals" src="http://www.benmcchesney.com/blog/wp-content/uploads/2010/08/12_tut_normals.png" alt="" width="734" height="517" /></a></p>
<p>Now the good part: we export! In this screenshot is also a rendering of what the new UV Map looks like.</p>
<p><a href="http://www.benmcchesney.com/blog/wp-content/uploads/2010/08/13_tut_export.png"><img class="alignnone size-full wp-image-316" title="13_tut_export" src="http://www.benmcchesney.com/blog/wp-content/uploads/2010/08/13_tut_export.png" alt="" width="675" height="491" /></a></p>
<p>Export the file in into your project. You will need to also copy the /tex folder into wherever you export your .dae ( collada ) file. This is because inside the Collada file it specifies a URL to it&#8217;s default material. Open up the Collada file in your preferred text editor. TextMate or BBEdit are popular choices: I&#8217;ll be using BBEdit.</p>
<p><a href="http://www.benmcchesney.com/blog/wp-content/uploads/2010/08/14_tut_colladaFile_initFrom.png"><img class="alignnone size-full wp-image-317" title="14_tut_colladaFile_initFrom" src="http://www.benmcchesney.com/blog/wp-content/uploads/2010/08/14_tut_colladaFile_initFrom.png" alt="" width="508" height="162" /></a></p>
<p>A Collada file is basically a large XML File with specific nodes for a 3d scene including vertices, UV Coordinates, and texture parameters. Inside &lt;libraray_image&gt; there is the &lt;init_from&gt; that specifies the URL of a UV texture. If you are using Cinema4D 11.5 it will provide an absolute url but you can change it to relative like the screenshot above.</p>
<p><a href="http://www.benmcchesney.com/blog/wp-content/uploads/2010/08/15_tut_colladaLibrary.png"><img class="alignnone size-full wp-image-318" title="15_tut_colladaLibrary" src="http://www.benmcchesney.com/blog/wp-content/uploads/2010/08/15_tut_colladaLibrary.png" alt="" width="564" height="188" /></a></p>
<p>Inside the &lt;library_materials&gt; you can spot the texture we named inside Cinema4D. We will use &#8220;ID3&#8243; inside Away3D to get the material info we need.</p>
<p>Now onto the code. The code is written with a .fla and a document class but it will work as pure actionscript. There is nothing linked in the library or any other dependencies. When I use Away3D in a project I usually place all the 3d information inside a seperate class but here the document class should be fine. I always make a createAway3D function()</p>
<p><a href="http://www.benmcchesney.com/blog/wp-content/uploads/2010/08/16_tut_away3DCreate.png"><img class="alignnone size-full wp-image-319" title="16_tut_away3DCreate" src="http://www.benmcchesney.com/blog/wp-content/uploads/2010/08/16_tut_away3DCreate.png" alt="" width="870" height="348" /></a></p>
<p>In this function we create a test object to make sure our scene renders. Away3D is composed of a few basic parts. First we have the View3D: think of this as a sprite that will hold and render your 3d scene. The Camera is how the scene will be viewed: it&#8217;s the window to your 3d world. Views are also comprised of scenes which is a holder for all of your 3D Objects. The last component of a view is the renderer: this is what will actually rasterize your 3d scene into a 2d image every frame.  In Away3D when you create an 3d Object you pass in a separate object with all the properties that you want initialized. The x + y properties dictate where the center of the scene is. The view will automatically be full stage size.</p>
<p><a href="http://www.benmcchesney.com/blog/wp-content/uploads/2010/08/17_tut_loadCollada.png"><img class="alignnone size-full wp-image-320" title="17_tut_loadCollada" src="http://www.benmcchesney.com/blog/wp-content/uploads/2010/08/17_tut_loadCollada.png" alt="" width="849" height="248" /></a></p>
<p>To call the collada file you create a new Loader3D class and use the static Collada.load() method. In the document class you can see the onLoaderSuccess Method but it&#8217;s fairly straight forward. In a collada file we have to access the material through the MaterialData class. Here we plug in the ID3 that was identified in the Collada .dae file.</p>
<p>One last concept that I used in this code is Bitwise operations. Bitwise operations are quicker ways of doing simple operations. There are a whole slew of bitwise operations that can be quickly googled for. This bitwise operation will cycle through all the items in the array and when it reaches the end will return to zero.</p>
<p><a href="http://www.benmcchesney.com/blog/wp-content/uploads/2010/08/18_tut_bitwise.png"><img class="alignnone size-full wp-image-321" title="18_tut_bitwise" src="http://www.benmcchesney.com/blog/wp-content/uploads/2010/08/18_tut_bitwise.png" alt="" width="819" height="362" /></a></p>
<p>That&#8217;s it! Full Collada model support. If you are having trouble seeing your model make sure that your normals are correct and try adjust the size drastically. Sometimes my models come out with .25 , 5 , or 90 for the scale. It&#8217;s all relative. The source code is <a href="http://benmcchesney.com/blog/Collada_Tutorial.zip">available here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.benmcchesney.com/blog/2010/08/loading-a-collada-file-in-away3d/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Robots! Animating Text with Actionscript and XML</title>
		<link>http://www.benmcchesney.com/blog/2010/04/robots-animating-text-with-actionscript-and-xml/</link>
		<comments>http://www.benmcchesney.com/blog/2010/04/robots-animating-text-with-actionscript-and-xml/#comments</comments>
		<pubDate>Wed, 07 Apr 2010 00:52:37 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Interactive]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[animate]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[embed]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[flight of the conchords]]></category>
		<category><![CDATA[font]]></category>
		<category><![CDATA[free]]></category>
		<category><![CDATA[robots]]></category>
		<category><![CDATA[text]]></category>
		<category><![CDATA[textField]]></category>

		<guid isPermaLink="false">http://www.benmcchesney.com/blog/?p=277</guid>
		<description><![CDATA[source code is available HERE Recently I decided to tackle a challenge posed by Firstborn in New York on behalf of the Society of Digital Agencies to students at RIT . The challenge: was to animate type completely with Actionscript 3.0. This text had to be loaded and configured using XML, and XML only. Having ...]]></description>
			<content:encoded><![CDATA[<p>source code is available <a href="http://benmcchesney.com/blog/Robots_text_example.zip"> HERE</a></p>
<p><a href="http://benmcchesney.com/robots/"><img class="alignnone size-full wp-image-285" title="Robots!" src="http://www.benmcchesney.com/blog/wp-content/uploads/2010/04/robots.jpg" alt="" width="450" height="450" /></a></p>
<p>Recently I decided to tackle a challenge posed by <a href="http://www.firstbornmultimedia.com/"> Firstborn </a> in New York on behalf of the <a href="http://www.societyofdigitalagencies.org/">Society of Digital Agencies</a> to students at <a href="http://www.rit.edu"> RIT </a>. The challenge: was to animate type completely with Actionscript 3.0. This text had to be loaded and configured using XML, and XML only. Having previously done a text explosion effect in papervision3D I knew that I wanted to do something a little different. I finally decided on everyone&#8217;s favorite thing about New Zealand- no not Lord of the Rings. Flight of the Conchords! Being the tech geek that I am their song &#8220;Robots&#8221; seemed perfect for this assignment, plus it was only two minutes long.</p>
<p><span id="more-277"></span></p>
<p>The XML was broken apart into<br />
tags which symbolizes a single line of lyrics. Feature creep got out of control on this quickly as I quickly wanted to be able to set the font, color, start position, end position, whether the positions were relative- just to name a few.</p>
<p>a type line might look like this:</p>
<div id="_mcePaste">&lt;line continuous=&#8221;true&#8221; duration=&#8221;1.5&#8243;  font=&#8221;Silkscreen&#8221; &gt;</div>
<div id="_mcePaste">&lt;start x=&#8221;-75&#8243; z=&#8221;400&#8243;/&gt;</div>
<div id="_mcePaste">&lt;end z=&#8221;-400&#8243; y=&#8221;0&#8243; x=&#8221;0&#8243; /&gt;</div>
<div id="_mcePaste">&lt;lyric &gt;The distant future&lt;/lyric&gt;</div>
<div id="_mcePaste">&lt;/line&gt;</div>
<p>other attributes included were changing the background gradient color, and a duration offset that was used to keep two lyrics on the screen at once.</p>
<p>Toward the end of development I realized that I needed a way to embed the fonts so that they were viewable on all computers. After googling and researching several different methods I simply found many of them to be very cumbersome. I couldn&#8217;t find any solutions that allowed me to embed multiple size fonts inside a single font.swf. Imagine my frustration when I wanted to embed 12 different font sizes that were key to my animation. So: in not the *best* coding practices I simple included two dynamic text fields and grabbed their font on the fly. Long ago I learned that by placing a space character &#8221; &#8221; inside a dynamic textfield it kept all of it&#8217;s textFormat properties, this made coordinating with designers much easier on a smaller page-by-page basis.</p>
<p>This magical method allowed me to quickly embed the font by using these pre-embedded textFields and go about my day.</p>
<p><a href="http://www.benmcchesney.com/blog/wp-content/uploads/2010/04/Screen-shot-2010-04-06-at-9.14.03-PM.png"><img class="alignnone size-full wp-image-281" title="Embed Font Workaround" src="http://www.benmcchesney.com/blog/wp-content/uploads/2010/04/Screen-shot-2010-04-06-at-9.14.03-PM.png" alt="" width="561" height="480" /></a></p>
<p>I posted the source code so anyone can look through it and see exactly how I pulled the XML data and loaded fonts. Unfortunately I cannot zip up the song to go with it because the Flight of the Conchords own the intellectual property, but you can view the final result below.</p>
<p>WordPress is blocking the the .swf file from loading external files so you can <a href="http://benmcchesney.com/robots/">view this here</a></p>
<p>source code is available <a href="http://benmcchesney.com/blog/Robots_text_example.zip"> HERE </a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.benmcchesney.com/blog/2010/04/robots-animating-text-with-actionscript-and-xml/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordDNA: Twitter + Flickr + Away3D</title>
		<link>http://www.benmcchesney.com/blog/2010/03/worddna-twitter-flicker-away3d/</link>
		<comments>http://www.benmcchesney.com/blog/2010/03/worddna-twitter-flicker-away3d/#comments</comments>
		<pubDate>Mon, 15 Mar 2010 15:46:52 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Interactive]]></category>
		<category><![CDATA[Motion]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[3d]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[away]]></category>
		<category><![CDATA[Away3D]]></category>
		<category><![CDATA[camera]]></category>
		<category><![CDATA[camera movement]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[files]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[flickr]]></category>
		<category><![CDATA[free]]></category>
		<category><![CDATA[mashup]]></category>
		<category><![CDATA[photo]]></category>
		<category><![CDATA[source]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.benmcchesney.com/blog/?p=242</guid>
		<description><![CDATA[Source Code is available here Recently I had been wanting to do some more interactive 3D type of projects. I wanted to create something beyond just a pre-rendered sequence that simulated camera movement. I have previously been using papervision3D but wanted to expand my knowledge and check out the competition. Papervision X has been long ...]]></description>
			<content:encoded><![CDATA[<p>Source Code is <a href="http://benmcchesney.com/blog/wordDNA.zip"> available here </a></p>
<p>Recently I had been wanting to do some more interactive 3D type of projects. I wanted to create something beyond just a pre-rendered sequence that simulated camera movement. I have previously been using <a href="http://www.papervision3d.org"> papervision3D</a> but wanted to expand my knowledge and check out the competition. Papervision X has been long expected but with Ralph Hauwert <a href="http://www.unitZeroOne.com"> Unit Zero One</a> leaving the team I thought it was time to move on. Away3D was very highly recommended by my colleague <a href="http://www.kylebeikirch.com"> Kyle Beikirch</a> for it&#8217;s more frequent updates to SVN and ease of interactivity. Since I was exactly sure what would be interactive when I started: I gave it a shot.</p>
<p><a href="http://www.benmcchesney.com/blog/wp-content/uploads/2010/03/flitter_screenshot.png"><img class="alignnone size-full wp-image-250" title="flitter_screenshot" src="http://www.benmcchesney.com/blog/wp-content/uploads/2010/03/flitter_screenshot.png" alt="Build Animation of wordDNA" width="806" height="702" /></a></p>
<p><span id="more-242"></span></p>
<p>In what I did there wasn&#8217;t really a huge difference between the images but I did like how Away3D uses associative arrays much like <a href="http://www.greensock.com/">Greensock Tweening platform </a> instead of traditional constructors. If I didn&#8217;t want to pre-render as many assets as possible I would need an internet source to grab them from. I thought that combining the antics of twitter with somewhat related photos could yield some interesting results. At first I grabbed XML from the twitter time line, but I wanted to have more control over my results. I used the Tweetr Twitter API, and got a lot of code inspiration from Lindsey Burtner&#8217;s <a href="http://lindsayburtner.com/blog/?p=176" > Word Feeder</a>. Lindsey helped me last year when I first began mashing together the last.fm API, and proved an invaluable resource, so props to her.</p>
<p>Let&#8217;s dive into some of the key functions that make this work:</p>
<p>Once the Flickr and Twitter data has been collected we then insert it into a 2D MovieClip and prepare it for 3D.</p>
<div id="attachment_248" class="wp-caption alignnone" style="width: 895px"><a href="http://www.benmcchesney.com/blog/wp-content/uploads/2010/03/prepareBitmap.png"><img class="size-full wp-image-248" title="prepareBitmap" src="http://www.benmcchesney.com/blog/wp-content/uploads/2010/03/prepareBitmap.png" alt="Dynamic Draw of Movie Clip to Bitmap Material" width="885" height="458" /></a><p class="wp-caption-text">Dynamic Draw of Movie Clip to Bitmap Material</p></div>
<p>We prepare it for 3D by simple flattening it with transparency.</p>
<div id="attachment_246" class="wp-caption alignnone" style="width: 858px"><a href="http://www.benmcchesney.com/blog/wp-content/uploads/2010/03/makeBitmapFrom.png"><img class="size-full wp-image-246" title="makeBitmapFrom" src="http://www.benmcchesney.com/blog/wp-content/uploads/2010/03/makeBitmapFrom.png" alt="Document Class creates Bitmap Material" width="848" height="185" /></a><p class="wp-caption-text">Document Class creates Bitmap Material</p></div>
<p>I wanted to organize the planes in  a Helix and found <ahref="http://theflashblog.com/?p=306" >this post </a> from Lee Brimelow&#8217;s blog and modified it for my needs. The by rotating the scene 360 degrees we get this cool spin effect for the zoom out.</p>
<div id="attachment_247" class="wp-caption alignnone" style="width: 810px"><a href="http://www.benmcchesney.com/blog/wp-content/uploads/2010/03/makeHelix.png"><img class="size-full wp-image-247" title="makeHelix" src="http://www.benmcchesney.com/blog/wp-content/uploads/2010/03/makeHelix.png" alt="Make a Helix" width="800" height="604" /></a><p class="wp-caption-text">Make a Double Helix our of Shapes</p></div>
<p>Now we need a way to navigate between planes, at first it was very linear but that got boring quickly. So I added in a new random index each movement to make it feel more exploratory. Adding a mouse event to planes would have been the next logical step to give users some control.</p>
<div id="attachment_249" class="wp-caption alignnone" style="width: 752px"><a href="http://www.benmcchesney.com/blog/wp-content/uploads/2010/03/randomIndex.png"><img class="size-full wp-image-249" title="randomIndex" src="http://www.benmcchesney.com/blog/wp-content/uploads/2010/03/randomIndex.png" alt="Generating a Random Index from an Array" width="742" height="339" /></a><p class="wp-caption-text">Generating a Random Index from an Array</p></div>
<p>Now the fun part: the camera. First we get the distance to to the next target and tweak it so that that camera movement is smooth for all distances.</p>
<p>The Camera has two tweens:</p>
<p>1) To move away from the plane randomly around it in 3D space</p>
<p>2) To move towards the new target</p>
<p>We change the focus of the camera by tweening an empty displayObject3D this would be our &#8220;null object&#8221; in 3d or After Effects.</p>
<p>The bezier gives the tween a nice smooth and organic feel, something that is lacking with a lot of fully 3d sites.</p>
<p>The newY just calculates which direction the camera should swoop in depending if the target is above or below it.</p>
<div id="attachment_244" class="wp-caption alignnone" style="width: 770px"><a href="http://www.benmcchesney.com/blog/wp-content/uploads/2010/03/camera_1.png"><img class="size-full wp-image-244" title="camera_1" src="http://www.benmcchesney.com/blog/wp-content/uploads/2010/03/camera_1.png" alt="Camera AS3 Text" width="760" height="405" /></a><p class="wp-caption-text">Moving the Camera</p></div>
<p>We save the initial values of our current target so that we can return it to it&#8217;s rightful place the user is done looking at it. In our tweenCameraDone() function we save the coordinates of the camera in case we need to reset it.</p>
<div id="attachment_245" class="wp-caption alignnone" style="width: 890px"><a href="http://www.benmcchesney.com/blog/wp-content/uploads/2010/03/camera_2.png"><img class="size-full wp-image-245" title="camera_2" src="http://www.benmcchesney.com/blog/wp-content/uploads/2010/03/camera_2.png" alt="Moving the Camera pt 2" width="880" height="322" /></a><p class="wp-caption-text">Moving the Camera pt 2</p></div>
<p>That&#8217;s it! I had fun making it and mixing interactivity and 3d Camera. Play with it and let me know what you come up with!</p>
<p>Source Code is <a href="http://benmcchesney.com/blog/wordDNA.zip"> available here </a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.benmcchesney.com/blog/2010/03/worddna-twitter-flicker-away3d/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Some Color Matrix Fun in Actionscript 3</title>
		<link>http://www.benmcchesney.com/blog/2010/02/some-color-matrix-fun-in-actionscript-3/</link>
		<comments>http://www.benmcchesney.com/blog/2010/02/some-color-matrix-fun-in-actionscript-3/#comments</comments>
		<pubDate>Sat, 13 Feb 2010 19:51:42 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Interactive]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[bitmap]]></category>
		<category><![CDATA[blur]]></category>
		<category><![CDATA[color]]></category>
		<category><![CDATA[colorMatrix]]></category>
		<category><![CDATA[cool]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[draw]]></category>
		<category><![CDATA[effects]]></category>
		<category><![CDATA[Filter]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[matrix]]></category>

		<guid isPermaLink="false">http://www.benmcchesney.com/blog/?p=201</guid>
		<description><![CDATA[I was reading Lee Brimelow&#8217;s Blog  ( http://gotoandlearn.com/play?id=63 ) and was having some fun playing with effects. While I was trying out a few different solutions to see what the effect would be. The problem was having to continuously recompile my flash movie to see the changed effect. A few numeric steppers later I was ...]]></description>
			<content:encoded><![CDATA[<p>I was reading Lee Brimelow&#8217;s Blog  ( http://gotoandlearn.com/play?id=63 ) and was having some fun playing with effects. While I was trying out a few different solutions to see what the effect would be. The problem was having to continuously recompile my flash movie to see the changed effect. A few numeric steppers later I was able to make a this little applications that spits out the colorMatrix Filter code.</p>
<p>Infinite Puddle:<a href="http://www.benmcchesney.com/blog/wp-content/uploads/2010/02/Picture-5.png"><img class="alignnone size-full wp-image-204" title="Infinite Puddle" src="http://www.benmcchesney.com/blog/wp-content/uploads/2010/02/Picture-5.png" alt="" width="820" height="638" /></a><br />
<span id="more-201"></span><br />
Have fun and share your results!<br />

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_colorMatrixDisplay_216138643"
			class="flashmovie"
			width="600"
			height="600">
	<param name="movie" value="http://benmcchesney.com/blog/colorMatrixDisplay.swf" />
	<param name="play" value="false" />
	<param name="scale" value="noscale" />
	<param name="allowfullscreen" value="false" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://benmcchesney.com/blog/colorMatrixDisplay.swf"
			name="fm_colorMatrixDisplay_216138643"
			width="600"
			height="600">
		<param name="play" value="false" />
		<param name="scale" value="noscale" />
		<param name="allowfullscreen" value="false" />
	<!--<![endif]-->
		
<p><a href="http://adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>But first: How Does the Color Matrix Filter work? The API Doc can be read <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/filters/ColorMatrixFilter.html">here.</a> But is creates a matrix that alters each pixel&#8217;s color channel.</p>
<div class="wp-caption alignnone" style="width: 190px"><a href="http://www.adobe.com/devnet/flash/articles/matrix_transformations_04.html"><img title="Adobe Color Matrix Chart" src="http://www.adobe.com/devnet/flash/articles/matrix_transformations/fig04.gif" alt="Adobe Developer Net ColorMatrix Filter Chart" width="180" height="180" /></a><p class="wp-caption-text">This is called an &quot;identity matrix&quot; and it will result in no color change.</p></div>
<p>Each channel is multiplied by the Red, Green, Blue, and Alpha channels and then offset by the last argument in each row.</p>
<p>Now the code I used was directly based off of Lee Brimelow&#8217;s code:</p>
<div id="attachment_208" class="wp-caption alignnone" style="width: 661px"><a href="http://www.benmcchesney.com/blog/wp-content/uploads/2010/02/Picture-26.png"><img class="size-full wp-image-208" title="Variables" src="http://www.benmcchesney.com/blog/wp-content/uploads/2010/02/Picture-26.png" alt="Varibles used For Color Matrix Filter and Blur Filter" width="651" height="217" /></a><p class="wp-caption-text">Basic variables needed to create effect.</p></div>
<p>It only takes three variables to achieve this effect:</p>
<ul>
<li>A Sprite Holder of what to affect</li>
<li>Blur Filter to create spill-off effect</li>
<li>Color Matrix Filter to apply for Color</li>
</ul>
<p>And then inside an Event.ENTER_FRAME you add this code:</p>
<div id="attachment_209" class="wp-caption alignnone" style="width: 632px"><a href="http://www.benmcchesney.com/blog/wp-content/uploads/2010/02/Picture-25.png"><img class="size-full wp-image-209" title="Enter Frame Code" src="http://www.benmcchesney.com/blog/wp-content/uploads/2010/02/Picture-25.png" alt="Draw the sprite, apply blur and color filter" width="622" height="126" /></a><p class="wp-caption-text">Draw the sprite, apply blur and color filter</p></div>
<p>and voila cool trails! Don&#8217;t believe me? Here are some examples I was playing around with:</p>
<p>Lava Lamp Looping Fluid effect :</p>
<div id="attachment_206" class="wp-caption alignnone" style="width: 830px"><a href="http://www.benmcchesney.com/blog/wp-content/uploads/2010/02/Picture-6.png"><img class="size-full wp-image-206" title="Lava Lamp Ripples" src="http://www.benmcchesney.com/blog/wp-content/uploads/2010/02/Picture-6.png" alt="" width="820" height="640" /></a><p class="wp-caption-text">Effect creating Lava Lame Ripples</p></div>
<p>Day Glow Trails</p>
<p><a href="http://www.benmcchesney.com/blog/wp-content/uploads/2010/02/Picture-23.png"><img class="alignnone size-full wp-image-203" title="Day Glow Trails" src="http://www.benmcchesney.com/blog/wp-content/uploads/2010/02/Picture-23.png" alt="" width="800" height="600" /></a></p>
<p>Exploding Trails<a href="http://www.benmcchesney.com/blog/wp-content/uploads/2010/02/Picture-24.png"><img class="alignnone size-full wp-image-202" title="Exploding Fizzles" src="http://www.benmcchesney.com/blog/wp-content/uploads/2010/02/Picture-24.png" alt="" width="800" height="600" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.benmcchesney.com/blog/2010/02/some-color-matrix-fun-in-actionscript-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Oh yeah TEXT? My name is Leo Wong and I say BOOM! Papervision3D Text Explode Sample</title>
		<link>http://www.benmcchesney.com/blog/2009/12/oh-yeah-text-i-say-boom-papervision3d-text-explode-sample/</link>
		<comments>http://www.benmcchesney.com/blog/2009/12/oh-yeah-text-i-say-boom-papervision3d-text-explode-sample/#comments</comments>
		<pubDate>Fri, 18 Dec 2009 23:30:26 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Interactive]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[3]]></category>
		<category><![CDATA[3d]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[actionscript 3]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[free]]></category>
		<category><![CDATA[learn]]></category>
		<category><![CDATA[papervision3D]]></category>
		<category><![CDATA[papervistion]]></category>
		<category><![CDATA[text]]></category>
		<category><![CDATA[type]]></category>
		<category><![CDATA[typography]]></category>

		<guid isPermaLink="false">http://www.benmcchesney.com/blog/?p=180</guid>
		<description><![CDATA[Experiment in papervision3D to get the text inside a dynamic textField to explode in X,Y,Z space and then reform. Code Available]]></description>
			<content:encoded><![CDATA[<p>I was in the lab yesterday and saw my friend animating text and 3D and it did not seem very appetizing. I really regret having to do tedious time-consuming things by hand. If there is ever a procedural way to generate or simulate something I&#8217;m willing to try. So I put together this little example.</p>
<p>*UPDATE*</p>
<p>I was able to get the zDepth working by applying simple blur filters to the bitmaps of the BitmapMaterials inside papervision3D. I also added in an input text field so that users could change the text without having to recompile. I have some bigger ideas for this down the road, like sequencing camera tweens between each letter. And exploding a whole paragraph word for word. I had some trouble with making the letter interactive, but it&#8217;s always been a bit of a pain to get events working with papervision3D. But for now: I&#8217;m happy where it is. The code is extremely well documented and if you have any questions just shoot me a line at : ben.mcchesney@gmail.com</p>
<p>The update source code is located <a href="http://www.benmcchesney.com/blog/textExplode_changeText.zip"> here</a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><img title="movieclip_zsort" src="http://www.benmcchesney.com/blog/wp-content/uploads/2009/12/movieclip_zsort.png" alt="z-sort issue" width="566" height="442" /></p>
<p><span id="more-180"></span></p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_TextExplode_change_13675324"
			class="flashmovie"
			width="550"
			height="400">
	<param name="movie" value="TextExplode_change.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="TextExplode_change.swf"
			name="fm_TextExplode_change_13675324"
			width="550"
			height="400">
	<!--<![endif]-->
		

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>Click on my name to get the explode effect, and click again to revert to the whole word.</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_textJumble_1523989010"
			class="flashmovie"
			width="550"
			height="400">
	<param name="movie" value="textJumble.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="textJumble.swf"
			name="fm_textJumble_1523989010"
			width="550"
			height="400">
	<!--<![endif]-->
		

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>First I created a sample using just 2d MovieClips in Flash. Using the text of a dynamic textField on the stage it breaks down and seperates each text into it&#8217;s own textField with it&#8217;s own movieClip container. By the character&#8217;s inside a movieClip I was able to apply TweenLite&#8217;s blurFilter and fake depth of field, by checking the zDepth of the letter</p>
<p>But this solution wasn&#8217;t as appetizing. It lacked the interactivity that I was trying to emulate. I wanted to be able to explode the text and explore the wreckage. The Flash player 10 also has an issue with z-sorting. Since all of the 3d is just a raster illusion the zDepth is fake. If a child that has display index than another child with a lower z-depth the illusion is broken. So I could either write my own methods to parse through each array item and update the displayList constantly or I could go in a different direction.</p>
<p>.I was going to create a version of textExplode using an actionscript 3D api : Papervision3D (<a href="http://papervision3D.org">Papervision3D Site</a>) . In papervision you have to create a small plane for each letter and draw a bitmap of it. You then take this bitmap and apply it to the geometry of the plane.</p>
<div id="attachment_186" class="wp-caption alignnone" style="width: 798px"><img class="size-full wp-image-186 " title="BitmapCodeSample" src="http://www.benmcchesney.com/blog/wp-content/uploads/2009/12/picture-2.png" alt="By creating a bitmapData object to draw the movieClip we can cast it as a BitmapMaterial and apply it to a plane." width="788" height="356" /><p class="wp-caption-text">By creating a bitmapData object to draw the movieClip we can cast it as a BitmapMaterial and apply it to a plane.</p></div>
<p>I had been used to the old version of papervision3D which meant constructing a scene with viewports, cameras , renderers, and scenes. But in papervision 2.0 by simple extending the BasicView Class, all of these assets are extendable for your connivence. The result was a quickly developed, dynamic 3d text explode code set.</p>
<p>Another different technique I used was the use of Vectors. Vectors are a new data type in Flash Player 10 and are essentially arrays with of one and only one data type. This allows for strict data typing in for all array function increasing performance. It&#8217;s less noticeable in this example, but in a physics simulation where it&#8217;s stepping through each particle&#8217;s force application every frame. The increased limit of particles or general smoothness would be more obvious.<br />
More information can be found on Mike Chambers Blog : <a href="http://www.mikechambers.com/blog/2008/08/19/using-vectors-in-actionscript-3-and-flash-player-10/"> here </a></p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_TextExplode_1973448686"
			class="flashmovie"
			width="550"
			height="400">
	<param name="movie" value="TextExplode.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="TextExplode.swf"
			name="fm_TextExplode_1973448686"
			width="550"
			height="400">
	<!--<![endif]-->
		
<p><a href="http://adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>The next steps are to apply depth of field by checking z-depth and being able to change the textField while the swf is running. I would also like to increase the interactivity by being able to focus and zoom to certain letter and really get the exploration feel. Another change that&#8217;s on the to-do list is a second stage breakup of the letters bitmaps into tiny triangles or squares for more fodder to explode.</p>
<p>I&#8217;ll keep posting as I get farther along and make it more and more extensible.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.benmcchesney.com/blog/2009/12/oh-yeah-text-i-say-boom-papervision3d-text-explode-sample/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

