<?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>20papercups :: Michael Marner&#039;s Website &#187; Programming</title>
	<atom:link href="http://www.20papercups.net/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.20papercups.net</link>
	<description>The (awesome) website of Michael Marner</description>
	<lastBuildDate>Mon, 24 May 2010 13:29:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Augmented Foam Sculpting for Capturing 3D Models</title>
		<link>http://www.20papercups.net/unisa/augmented-foam-sculpting/</link>
		<comments>http://www.20papercups.net/unisa/augmented-foam-sculpting/#comments</comments>
		<pubDate>Wed, 24 Mar 2010 03:43:21 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Augmented Reality]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[UniSA]]></category>
		<category><![CDATA[foam cutter]]></category>
		<category><![CDATA[industrial design]]></category>
		<category><![CDATA[sar]]></category>
		<category><![CDATA[sculpting]]></category>

		<guid isPermaLink="false">http://www.20papercups.net/?p=305</guid>
		<description><![CDATA[This weekend I presented my paper, Augmented Foam Sculpting for Capturing 3D Models, at the International symposium on 3D user interfaces. Since the conference has passed, I have added the video to youtube and the paper to my publications page. First, the video, then some discussion after the jump. Foam Sculpting The inspiration for this [...]]]></description>
			<content:encoded><![CDATA[<p>This weekend I presented my <a href="http://www.20papercups.net/wp-content/uploads/2009/09/foamcutter.pdf">paper</a>, Augmented Foam Sculpting for Capturing 3D Models, at the International symposium on 3D user interfaces. Since the conference has passed, I have added the video to youtube and the paper to my publications page. First, the video, then some discussion after the jump.</p>
<p style="text-align: center;"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="344" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/VPUT2l5JvT0&amp;hl=en&amp;fs=1" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="425" height="344" src="http://www.youtube.com/v/VPUT2l5JvT0&amp;hl=en&amp;fs=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<h3><span id="more-305"></span>Foam Sculpting</h3>
<p>The inspiration for this work came out of a project we did with some industrial design students. Their job was to create some input devices for my SAR Airbrushing system. First up, we had a  meeting where I showed them a very early stages of development version of the system, to give them an idea of what we were doing. They went away and came up with ideas for input devices, and in the next meeting had a bunch of sketches ready. We discussed the sketches; what we liked and what we didn&#8217;t like. Next, they brought us foam mockups of some of the designs. We discussed these, and then eventually they came back with full CAD models ready for 3D printing. They did a great job by the way. But it got us thinking:</p>
<p><em><strong>How can we make this process better?</strong></em></p>
<p>Augmented Foam Sculpting is the result of this work. It allows a designer/artist to simultaneously create a physical design mockup and matching virtual model. This is a Good Thing™, because it utilises the skills and tools that designers are already using.</p>
<p>The system works by tracking the position and orientation of both the hot wire foam cutter, and the piece of foam the user is sculpting. We can track the motion of the hot wire as it passes through the foam. From there, we can create geometry that matches the cut path, and perform a Boolean difference operation on the foam geometry, to replicate the cut in the virtual model (Before any of you &#8220;Booleans are evil&#8221; people get to me, I&#8217;d like to point out I&#8217;m only dealing with, and creating, triangle meshes. There are no 11 sided polygons here).</p>
<p>Using projectors, we can add extra information to the foam as the user sculpts. We implemented 2 visualisations to aid designers when creating specific models. <strong>Cut Animation</strong> displays cuts to be made as animated lines on the foam surface. Once a cut has been made, the system moves to the next one. This visualisation could be used to recreate a previous object, or to instruct novices. An algorithm could be developed to calculate the actual cuts that need to be made, reducing the amount of planning needed when making an object.</p>
<p>The second visualisation, <strong>Target</strong>, projects a target model so that it appears to be inside the foam. The foam is coloured based on how much needs to be removed to match a target model. This could be used to create variations on a previous model.</p>
<p>Finally, we can use 3D procedural textures to change the appearance of the foam. For example, we implemented a wood grain 3D texture. This works pretty well, because as you cut away the foam, the texture updates to appear as though the wood was actually cut. 3D textures are also ideal because we don&#8217;t need to generate texture coordinates after each cut.</p>
<p>For all the details, please have a read of the paper. If you have any questions/comments/feedback/abuse, please comment on this post, or send me an email.</p>
<p>Michael</p>
]]></content:encoded>
			<wfw:commentRss>http://www.20papercups.net/unisa/augmented-foam-sculpting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shameless Plug: Swiftless&#8217; Game Programming Tutorials</title>
		<link>http://www.20papercups.net/random-news/shameless-plug-swiftless-game-programming-tutorials/</link>
		<comments>http://www.20papercups.net/random-news/shameless-plug-swiftless-game-programming-tutorials/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 08:29:12 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Random News]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.20papercups.net/?p=292</guid>
		<description><![CDATA[Time for another shameless plug. This time it is for Swiftless, a guy who I work with in the Wearable Computer Lab. His website has some pretty awesome tutorials on game programming, OpenGL, Shaders, game related maths and heaps more. Check it out! http://www.swiftless.com]]></description>
			<content:encoded><![CDATA[<p>Time for another shameless plug. This time it is for Swiftless<a href="http://www.20papercups.net/wp-content/uploads/2008/12/fonzie.jpeg"><img class="alignleft size-full wp-image-12" title="fonzie" src="http://www.20papercups.net/wp-content/uploads/2008/12/fonzie.jpeg" alt="" width="120" height="120" /></a>, a guy who I work with in the Wearable Computer Lab. His website has some pretty awesome tutorials on game programming, OpenGL, Shaders, game related maths and heaps more. Check it out!</p>
<p><a href="http://www.swiftless.com/"><img class="alignnone" title="Swiftless" src="http://www.swiftless.com/swiftlessbutton.jpg" alt="Swiftless" width="88" height="31" /></a><br />
<a href="http://www.swiftless.com">http://www.swiftless.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.20papercups.net/random-news/shameless-plug-swiftless-game-programming-tutorials/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OpenSceneGraph, Dual Screens &amp; TwinView</title>
		<link>http://www.20papercups.net/programming/openscenegraph-dual-screens-twinview/</link>
		<comments>http://www.20papercups.net/programming/openscenegraph-dual-screens-twinview/#comments</comments>
		<pubDate>Sun, 14 Dec 2008 06:07:24 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[dual screen]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[opengl]]></category>
		<category><![CDATA[openscenegraph]]></category>

		<guid isPermaLink="false">http://www.20papercups.net/?p=145</guid>
		<description><![CDATA[So some of my work at uni involves programming using OpenSceneGraph. Now, anybody who has used OSG before will know that as powerful as it may be, it is seriously lacking in the documentation department. So, this article describes how to do dual screen graphics on Linux using OpenSceneGraph. First we&#8217;ll look at the X [...]]]></description>
			<content:encoded><![CDATA[<p>So some of my work at uni involves programming using <a title="OpenSceneGraph Website" href="http://www.openscenegraph.org" target="_blank">OpenSceneGraph</a>. Now, anybody who has used OSG before will know that as powerful as it may be, it is seriously lacking in the documentation department. So, this article describes how to do dual screen graphics on Linux using OpenSceneGraph. First we&#8217;ll look at the X Screens approach, which is easier but probably not the best solution. Then we&#8217;ll look at a method that works with a single X screen.<span id="more-145"></span></p>
<h3>Multiple X Screens</h3>
<p>The easiest way to do dual screen output is if you have your X server configured so each output is its own X screen. The first thing you need to do is make sure you have enough screens. Finding this out is easy enough:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">int</span> getNumScreens<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    osg<span style="color: #008080;">::</span><span style="color: #007788;">GraphicsContext</span><span style="color: #008080;">::</span><span style="color: #007788;">WindowingSystemInterface</span><span style="color: #000040;">*</span> wsi <span style="color: #000080;">=</span> osg<span style="color: #008080;">::</span><span style="color: #007788;">GraphicsContext</span><span style="color: #008080;">::</span><span style="color: #007788;">getWindowingSystemInterface</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    osg<span style="color: #008080;">::</span><span style="color: #007788;">GraphicsContext</span><span style="color: #008080;">::</span><span style="color: #007788;">ScreenIdentifier</span> si<span style="color: #008080;">;</span>
    si.<span style="color: #007788;">readDISPLAY</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">return</span> wsi<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>getNumScreens<span style="color: #008000;">&#40;</span>si<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>You should do this before attempting to create your screens to make sure the X server is configured correctly. Otherwise OSG will throw an error when you try and create a graphics context for a screen that doesn&#8217;t exist. Setting up the viewers is fairly straight forward:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">//Create main scene viewer</span>
&nbsp;
ref_ptr<span style="color: #000080;">&lt;</span>osgViewer<span style="color: #008080;">::</span><span style="color: #007788;">CompositeViewer</span><span style="color: #000080;">&gt;</span> compositeViewer <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> osgViewer<span style="color: #008080;">::</span><span style="color: #007788;">CompositeViewer</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #666666;">// create first view</span>
osgViewer<span style="color: #008080;">::</span><span style="color: #007788;">View</span><span style="color: #000040;">*</span> v0 <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> osgViewer<span style="color: #008080;">::</span><span style="color: #007788;">View</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
v0<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>setUpViewOnSingleScreen<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #666666;">// add view to the composite viewer</span>
compositeViewer<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>addView<span style="color: #008000;">&#40;</span>v0<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #666666;">// do the same with the second view</span>
osgViewer<span style="color: #008080;">::</span><span style="color: #007788;">View</span><span style="color: #000040;">*</span> v1 <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> osgViewer<span style="color: #008080;">::</span><span style="color: #007788;">View</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
v1<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>setUpViewOnSingleScreen<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
compositeViewer<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>addView<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p>And thats it. You also need to set the scene data for each of your views and a couple of things I&#8217;ve missed, but that is the basic idea. The problem with this method is it creates 2 graphics contexts, which in most cases will cause a performance hit.</p>
<h3>Single X Screen, Single Context</h3>
<p>I looked into this method because I use TwinView on my Linux desktop boxes. Of course, TwinView means that there is only 1 XScreen that spans both monitors. Therefore, the getNumScreens function above will return 1. I have also set up our projector setup to use TwinView, so I don&#8217;t need to have one lot of code for testing on the desktop and then do something completely different when using the projectors. The other benefit of this approach is you only create one graphics context.</p>
<p>First thing we do is get the dimensions of the screen, which will be the combination of both screens.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">// get the total resolution of the xscreen</span>
osg<span style="color: #008080;">::</span><span style="color: #007788;">GraphicsContext</span><span style="color: #008080;">::</span><span style="color: #007788;">WindowingSystemInterface</span><span style="color: #000040;">*</span> wsi <span style="color: #000080;">=</span> osg<span style="color: #008080;">::</span><span style="color: #007788;">GraphicsContext</span><span style="color: #008080;">::</span><span style="color: #007788;">getWindowingSystemInterface</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #0000ff;">unsigned</span> width, height<span style="color: #008080;">;</span>
wsi<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>getScreenResolution<span style="color: #008000;">&#40;</span>osg<span style="color: #008080;">::</span><span style="color: #007788;">GraphicsContext</span><span style="color: #008080;">::</span><span style="color: #007788;">ScreenIdentifier</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span>, width, height<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p>Once that is done we can create our (single) graphics context.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">// create a context that spans the entire x screen</span>
traits<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>x <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
traits<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>y <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
traits<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>width <span style="color: #000080;">=</span> width<span style="color: #008080;">;</span>
traits<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>height <span style="color: #000080;">=</span> height<span style="color: #008080;">;</span>
traits<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>windowDecoration <span style="color: #000080;">=</span> <span style="color: #0000ff;">false</span><span style="color: #008080;">;</span>
traits<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>doubleBuffer <span style="color: #000080;">=</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span>
traits<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>sharedContext <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
traits<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>overrideRedirect <span style="color: #000080;">=</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span>
osg<span style="color: #008080;">::</span><span style="color: #007788;">ref_ptr</span><span style="color: #000080;">&lt;</span>osg<span style="color: #008080;">::</span><span style="color: #007788;">GraphicsContext</span><span style="color: #000080;">&gt;</span> gc <span style="color: #000080;">=</span> osg<span style="color: #008080;">::</span><span style="color: #007788;">GraphicsContext</span><span style="color: #008080;">::</span><span style="color: #007788;">createGraphicsContext</span><span style="color: #008000;">&#40;</span>traits.<span style="color: #007788;">get</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p>The important one here is overrideRedirect. Some window managers (I&#8217;m looking at you Gnome) will redirect the position of your graphics context, so it won&#8217;t appear where you want it. The overrideRedirect option is kindof new, it does not exist in the version of OSG shipping with Ubuntu 8.10. Therefore, I am running the latest stable release (2.6) compiled from source.</p>
<p>To get the equivalent of 2 screens to draw on, we create 2 views like before. However, we have to set their viewport manually. Here we just make v0 use the left half of the screen, and v1 use the right half. Easy enough?</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">//first screen</span>
osgViewer<span style="color: #008080;">::</span><span style="color: #007788;">View</span><span style="color: #000040;">*</span> v0 <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> osgViewer<span style="color: #008080;">::</span><span style="color: #007788;">View</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
osg<span style="color: #008080;">::</span><span style="color: #007788;">ref_ptr</span><span style="color: #000080;">&lt;</span>osg<span style="color: #008080;">::</span><span style="color: #007788;">Camera</span><span style="color: #000080;">&gt;</span> cam <span style="color: #000080;">=</span> v0<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>getCamera<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
cam<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>setGraphicsContext<span style="color: #008000;">&#40;</span>gc.<span style="color: #007788;">get</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
cam<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>setViewport<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">0</span>, <span style="color: #0000dd;">0</span>, width<span style="color: #000040;">/</span><span style="color: #0000dd;">2</span>, height<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
compositeViewer<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>addView<span style="color: #008000;">&#40;</span>v<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #666666;">//second screen</span>
osgViewer<span style="color: #008080;">::</span><span style="color: #007788;">View</span><span style="color: #000040;">*</span> v1 <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> osgViewer<span style="color: #008080;">::</span><span style="color: #007788;">View</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
osg<span style="color: #008080;">::</span><span style="color: #007788;">ref_ptr</span><span style="color: #000080;">&lt;</span>osg<span style="color: #008080;">::</span><span style="color: #007788;">Camera</span><span style="color: #000080;">&gt;</span> cam2 <span style="color: #000080;">=</span> v1<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>getCamera<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
cam2<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>setGraphicsContext<span style="color: #008000;">&#40;</span>gc.<span style="color: #007788;">get</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
cam2<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>setViewport<span style="color: #008000;">&#40;</span>width<span style="color: #000040;">/</span><span style="color: #0000dd;">2</span>, <span style="color: #0000dd;">0</span>, width<span style="color: #000040;">/</span><span style="color: #0000dd;">2</span>, height<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
compositeViewer<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>addView<span style="color: #008000;">&#40;</span>v1<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p>setViewport sets the viewport of the camera. The first 2 parameters are the position in the context&#8217;s window, the next 2 are the dimensions. So, each view gets width/2 for the width, and the second screen&#8217;s position is offset by half the screen width meaning it starts on the second monitor.</p>
<h2>Conclusion</h2>
<p>And there you have it. Two methods for dual screen using OpenSceneGraph. Looking at the code, it is fairly simple. However, after browsing the doxygen docs for OSG it was not at all obvious to me. Of course, the osg-users mailing list was a big help here. In fact, <a href="http://groups.google.com/group/osg-users/browse_thread/thread/684fb727c4ab6ee2/daaa720956ae17e1" target="_blank">here</a> is the thread from the mailing list</p>
<p>Cheers<br />
Michael</p>
<p><center><script type="text/javascript"><!--
google_ad_client = "pub-9376349336558898";
google_ad_slot = "0815367707";
google_ad_width = 468;
google_ad_height = 60;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</center></p>
]]></content:encoded>
			<wfw:commentRss>http://www.20papercups.net/programming/openscenegraph-dual-screens-twinview/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
