<?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>Floorplanner Tech Blog &#187; Papervision3D</title>
	<atom:link href="http://techblog.floorplanner.com/tag/papervision/feed/" rel="self" type="application/rss+xml" />
	<link>http://techblog.floorplanner.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Thu, 19 Nov 2009 04:00:57 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Unproject with useProjectionMatrix = true</title>
		<link>http://techblog.floorplanner.com/2009/04/29/unproject-with-useprojectionmatrix-true/</link>
		<comments>http://techblog.floorplanner.com/2009/04/29/unproject-with-useprojectionmatrix-true/#comments</comments>
		<pubDate>Wed, 29 Apr 2009 00:45:40 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Collaboration]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Flash+ActionScript]]></category>
		<category><![CDATA[Floorplanner]]></category>
		<category><![CDATA[OS X]]></category>
		<category><![CDATA[Papervision3D]]></category>
		<category><![CDATA[camera]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[unproject]]></category>

		<guid isPermaLink="false">http://techblog.floorplanner.com/?p=580</guid>
		<description><![CDATA[I just updated Papervision3D to allow the CameraObject3D#unproject method to work when CameraObject3D#useProjectionMatrix = true.
Papervision3D has two methods of &#8216;projecting&#8217; vectors onto the screen:

useProjectionMatrix = false, this is the default &#8216;fast&#8217; method
useProjectionMatrix = true, this is the method where projection is done by a matrix

Note that Papervision3D switches to method #2 in &#8216;ortho mode&#8217;.
So what [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2009%2F04%2F29%2Funproject-with-useprojectionmatrix-true%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2009%2F04%2F29%2Funproject-with-useprojectionmatrix-true%2F" height="61" width="51" /></a></div><p>I just updated <a href="http://blog.papervision3d.org">Papervision3D</a> to allow the CameraObject3D#unproject method to work when CameraObject3D#useProjectionMatrix = true.</p>
<p>Papervision3D has two methods of &#8216;projecting&#8217; vectors onto the screen:</p>
<ol>
<li>useProjectionMatrix = false, this is the default &#8216;fast&#8217; method</li>
<li>useProjectionMatrix = true, this is the method where projection is done by a matrix</li>
</ol>
<p>Note that Papervision3D switches to method #2 in &#8216;ortho mode&#8217;.</p>
<p>So what is the difference exactly between these two kinds of projection? First we need to define what projection is. Projection is what adds &#8216;perspective&#8217; to a scene and makes sure your scene fits to the viewport. Its the last step in the so-called &#8216;render pipeline&#8217;. </p>
<p>We can derive the &#8216;fore shortening&#8217; effect of perspective in several ways. Method #1 is simple, effective and fast. It uses the camera&#8217;s focus and zoom values. Method #2 uses a more classic way of projection : it uses a dedicated matrix. Tech buffs: very much like OpenGL&#8217;s <a href="http://www.opengl.org/sdk/docs/man/xhtml/gluPerspective.xml">gluPerspective</a>.</p>
<p><a href="http://blog.zupko.info/">Andy Zupko</a> has a great <a href="http://blog.zupko.info/?p=143">post</a> on unproject using method #1.</p>
<p>We will discuss unproject using method #2, which works slightly different.</p>
<p>The difference is that when #useProjectionMatrix is set to true, then CameraObject3D#unproject  returns a point in world-space, rather then a ray. Let me explain with some code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="actionscript3" style="font-family: Monaco,monospace;"><span style="color: #009900;">// we want to use a projection matrix</span>
camera.useProjectionMatrix = <span style="color: #0033ff; font-weight: bold;">true</span>;
&nbsp;
<span style="color: #009900;">// '0' indicates we want a point on the near plane</span>
<span style="color: #6699cc; font-weight: bold;">var</span> pointOnNearPlane <span style="color: #000000; font-weight: bold;">:</span> Number3D = camera.unproject<span style="color: #000000;">&#40;</span> screenX, screenY, <span style="color: #000000; font-weight:bold;">0</span> <span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #009900;">// '1' indicates we want a point on the far plane</span>
<span style="color: #6699cc; font-weight: bold;">var</span> pointOnFarPlane <span style="color: #000000; font-weight: bold;">:</span> Number3D = camera.unproject<span style="color: #000000;">&#40;</span> screenX, screenY, <span style="color: #000000; font-weight:bold;">1</span> <span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #009900;">// Construct the ray's direction</span>
<span style="color: #6699cc; font-weight: bold;">var</span> dir <span style="color: #000000; font-weight: bold;">:</span> Number3D = Number3D.sub<span style="color: #000000;">&#40;</span> pointOnFarPlane, pointOnNearPlane <span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #009900;">// Normalize</span>
dir.<span style="color: #004993;">normalize</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #009900;">// So, now you have a ray with its origin at 'pointOnNearPlane',</span>
<span style="color: #009900;">// and direction 'dir'</span></pre></td></tr></table></div>

<p>Optimization: could save some cycles by doing (*not* in ortho mode!, see below):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="actionscript3" style="font-family: Monaco,monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> camPosition <span style="color: #000000; font-weight: bold;">:</span> Number3D = <span style="color: #0033ff; font-weight: bold;">new</span> Number3D<span style="color: #000000;">&#40;</span> camera.<span style="color: #004993;">x</span>, camera.<span style="color: #004993;">y</span>, camera.z <span style="color: #000000;">&#41;</span>;
<span style="color: #009900;">// Construct the ray's direction</span>
<span style="color: #6699cc; font-weight: bold;">var</span> dir <span style="color: #000000; font-weight: bold;">:</span> Number3D = Number3D.sub<span style="color: #000000;">&#40;</span> pointOnFarPlane, camPosition <span style="color: #000000;">&#41;</span>;
<span style="color: #009900;">// Normalize</span>
dir.<span style="color: #004993;">normalize</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #009900;">// So, now you have a ray with its origin at the camera's position</span>
<span style="color: #009900;">// and direction 'dir'</span></pre></td></tr></table></div>

<p>Why can&#8217;t we use above optimization in ortho mode?<br />
In perspective mode all &#8216;rays&#8217; originate from the camera&#8217;s position: the &#8216;view cone&#8217; has shape of a pyramid. Hence we can assume &#8216;pointOnNearPlane&#8217; to coincide with the camera&#8217;s position.<br />
In ortho mode however the &#8216;view cone&#8217; has the shape of a cube, all rays are parallel. Hence we need to unproject *two* points to construct our ray.</p>
<p>Now simply follow <a href="http://blog.zupko.info/?p=143">Andy Zupko &#8217;s post</a> to drag objects around.<br />
Or perform &#8216;picking&#8217;, or&#8230;</p>
<p>Update:<br />
Created a little demo to visualize what I&#8217;m ranting about, check it out <a href='http://techblog.floorplanner.com/wp-content/uploads/2009/04/unprojecttest1.swf'>here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.floorplanner.com/2009/04/29/unproject-with-useprojectionmatrix-true/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Papervision3D forum</title>
		<link>http://techblog.floorplanner.com/2009/01/20/papervision3d-forum/</link>
		<comments>http://techblog.floorplanner.com/2009/01/20/papervision3d-forum/#comments</comments>
		<pubDate>Tue, 20 Jan 2009 15:45:34 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[CAD]]></category>
		<category><![CDATA[Flash+ActionScript]]></category>
		<category><![CDATA[Floorplanner]]></category>
		<category><![CDATA[Papervision3D]]></category>
		<category><![CDATA[forum]]></category>

		<guid isPermaLink="false">http://techblog.floorplanner.com/?p=415</guid>
		<description><![CDATA[On request of many: Papervision3D now has a forum : http://forum.papervision3d.org/
Read more at the Papervision3D blog.
]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2009%2F01%2F20%2Fpapervision3d-forum%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2009%2F01%2F20%2Fpapervision3d-forum%2F" height="61" width="51" /></a></div><p>On request of many: Papervision3D now has a forum : http://forum.papervision3d.org/</p>
<p>Read more at the <a href="http://blog.papervision3d.org/2009/01/19/forumpapervision3dorg/">Papervision3D blog</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.floorplanner.com/2009/01/20/papervision3d-forum/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
