<?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>Game Rendering &#187; Math</title>
	<atom:link href="http://www.gamerendering.com/category/math/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.gamerendering.com</link>
	<description></description>
	<lastBuildDate>Thu, 21 Jan 2010 01:32:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Position Reconstruction</title>
		<link>http://www.gamerendering.com/2009/12/07/position-reconstruction/</link>
		<comments>http://www.gamerendering.com/2009/12/07/position-reconstruction/#comments</comments>
		<pubDate>Mon, 07 Dec 2009 15:34:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Cameras]]></category>
		<category><![CDATA[Math]]></category>
		<category><![CDATA[Deferred Rendering]]></category>
		<category><![CDATA[Deferred Shading]]></category>
		<category><![CDATA[HLSL]]></category>
		<category><![CDATA[Position]]></category>
		<category><![CDATA[Position Reconstruction]]></category>
		<category><![CDATA[Screen Space]]></category>
		<category><![CDATA[View Space]]></category>

		<guid isPermaLink="false">http://www.gamerendering.com/?p=751</guid>
		<description><![CDATA[There are many occasions when the fragment position in world space needs to be reconstructed from a texture holding the scene depth (depth texture). One example of use is in deferred rendering when trying to decrease memory usage by not saving the position but instead only the depth. This will result in one channel of [...]]]></description>
			<content:encoded><![CDATA[<p style="MARGIN-BOTTOM: 0cm">There are many occasions when the fragment position in world space needs to be reconstructed from a texture holding the scene depth (depth texture). One example of use is in deferred rendering when trying to decrease memory usage by not saving the position but instead only the depth. This will result in one channel of data, instead of three channels needed when saving the whole position.</p>
<p style="MARGIN-BOTTOM: 0cm"> </p>
<div class="mceTemp"><a href="http://www.gamerendering.com/wp-content/uploads/scenedepth.jpg"><img class="size-medium wp-image-755" title="Viewspace scene depth texture" src="http://www.gamerendering.com/wp-content/uploads/scenedepth-400x300.jpg" alt="Viewspace scene depth" width="400" height="300" /></a></div>
<p style="MARGIN-BOTTOM: 0cm">There are different ways to save the depth. The most popular are view space depth and screen space depth. Saving depth in view space instead of screen space gives two advantages. It&#8217;s faster, and it gives better precision because it&#8217;s linear in view space.</p>
<p style="MARGIN-BOTTOM: 0cm">This is how <strong>screen space depth</strong> can be rendered in HLSL:</p>

<div class="wp_codebox"><table width="100%" ><tr id="p7513"><td class="code" id="p751code3"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">struct</span> VS_OUTPUT
<span style="color: #009900;">&#123;</span>
   float4 Pos<span style="color: #339933;">:</span> POSITION<span style="color: #339933;">;</span>
   float4 posInProjectedSpace<span style="color: #339933;">:</span> TEXCOORD0<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// vertex shader</span>
VS_OUTPUT vs_main<span style="color: #009900;">&#40;</span> float4 Pos<span style="color: #339933;">:</span> POSITION <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
   VS_OUTPUT Out <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>VS_OUTPUT<span style="color: #009900;">&#41;</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
   Out.<span style="color: #202020;">Pos</span> <span style="color: #339933;">=</span> mul<span style="color: #009900;">&#40;</span>Pos<span style="color: #339933;">,</span>matWorldViewProjection<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   Out.<span style="color: #202020;">posInProjectedSpace</span> <span style="color: #339933;">=</span> Out.<span style="color: #202020;">Pos</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">return</span> Out<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// pixel shader</span>
float4 ps_main<span style="color: #009900;">&#40;</span> VS_OUTPUT Input <span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> COLOR
<span style="color: #009900;">&#123;</span>
   <span style="color: #993333;">float</span> depth <span style="color: #339933;">=</span> Input.<span style="color: #202020;">posInProjectedSpace</span>.<span style="color: #202020;">z</span> <span style="color: #339933;">/</span> Input.<span style="color: #202020;">posInProjectedSpace</span>.<span style="color: #202020;">w</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">return</span> depth<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>The HLSL pixel shader below shows how the position can be reconstructed from the depth map stored with the code above. Although this is one of the slowest ways of doing position reconstruction since it requires a matrix multiplication.</p>

<div class="wp_codebox"><table width="100%" ><tr id="p7514"><td class="code" id="p751code4"><pre class="c" style="font-family:monospace;">float4 ps_main<span style="color: #009900;">&#40;</span>float2 vPos <span style="color: #339933;">:</span> VPOS<span style="color: #339933;">;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> COLOR0
<span style="color: #009900;">&#123;</span>
   <span style="color: #993333;">float</span> depth <span style="color: #339933;">=</span> tex2D<span style="color: #009900;">&#40;</span>depthTexture<span style="color: #339933;">,</span>vPos<span style="color: #339933;">*</span>fInverseViewportDimensions <span style="color: #339933;">+</span> fInverseViewportDimensions<span style="color: #339933;">*</span><span style="color:#800080;">0.5</span><span style="color: #009900;">&#41;</span>.<span style="color: #202020;">r</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #666666; font-style: italic;">// scale it to -1..1 (screen coordinates)</span>
   float2 projectedXY <span style="color: #339933;">=</span> vPos<span style="color: #339933;">*</span>fInverseViewportDimensions<span style="color: #339933;">*</span><span style="color: #0000dd;">2</span><span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
   projectedXY.<span style="color: #202020;">y</span> <span style="color: #339933;">=</span> <span style="color: #339933;">-</span>projectedXY.<span style="color: #202020;">y</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #666666; font-style: italic;">// create the position in screen space</span>
   float4 pos <span style="color: #339933;">=</span> float4<span style="color: #009900;">&#40;</span>projectedXY<span style="color: #339933;">,</span>depth<span style="color: #339933;">,</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #666666; font-style: italic;">// transform position into world space by multiplication with the inverse view projection matrix</span>
   pos <span style="color: #339933;">=</span> mul<span style="color: #009900;">&#40;</span>pos<span style="color: #339933;">,</span>matViewProjectionInverse<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
   <span style="color: #666666; font-style: italic;">// make it homogeneous</span>
   pos <span style="color: #339933;">/=</span> pos.<span style="color: #202020;">w</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// result will be (x,y,z,1) in world space</span>
&nbsp;
   <span style="color: #b1b100;">return</span> pos<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// for now, just render it out</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p style="MARGIN-BOTTOM: 0cm">To reconstruct<strong> depth from view space</strong>, a ray from the camera position to the frustum far plane is needed. For a full screen quad, this ray can be precalculated for the four corners and passed to the shader. This is how the computer game Crysis did it [1] . But for arbitrary geometry, as needed in deferred rendering, the ray must be calculated in the shaders [2] .</p>
<p style="MARGIN-BOTTOM: 0cm">[1] &#8220;Finding next gen: CryEngine 2&#8243;<br />
<a href="http://ati.amd.com/developer/gdc/2007/mittring-finding_nextgen_cryengine2(siggraph07).pdf">http://ati.amd.com/developer/gdc/2007/mittring-finding_nextgen_cryengine2(siggraph07).pdf</a></p>
<p style="MARGIN-BOTTOM: 0cm">[2] “Reconstructing Position From Depth, Continued”<br />
<a href="http://mynameismjp.wordpress.com/2009/05/05/reconstructing-position-from-depth-continued/">http://mynameismjp.wordpress.com/2009/05/05/reconstructing-position-from-depth-continued/</a></p>

<div class="sociable">
<div class="sociable_tagline">
<strong>Please share:</strong>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow" id="print" href="javascript:window.location='http%3A%2F%2Fwww.printfriendly.com%2Fprint%3Furl%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2009%252F12%252F07%252Fposition-reconstruction%252F%26amp%3Bpartner%3Dsociable';" title="Print this article!"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/printfriendly.png" title="Print this article!" alt="Print this article!" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="digg" href="javascript:window.location='http%3A%2F%2Fdigg.com%2Fsubmit%3Fphase%3D2%26amp%3Burl%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2009%252F12%252F07%252Fposition-reconstruction%252F%26amp%3Btitle%3DPosition%2520Reconstruction%26amp%3Bbodytext%3DThere%2520are%2520many%2520occasions%2520when%2520the%2520fragment%2520position%2520in%2520world%2520space%2520needs%2520to%2520be%2520reconstructed%2520from%2520a%2520texture%2520holding%2520the%2520scene%2520depth%2520%2528depth%2520texture%2529.%2520One%2520example%2520of%2520use%2520is%2520in%2520deferred%2520rendering%2520when%2520trying%2520to%2520decrease%2520memory%2520usage%2520by%2520not%2520saving%2520the%2520po';" title="Digg"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="sphinn" href="javascript:window.location='http%3A%2F%2Fsphinn.com%2Findex.php%3Fc%3Dpost%26m%3Dsubmit%26link%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2009%252F12%252F07%252Fposition-reconstruction%252F';" title="Sphinn"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/sphinn.png" title="Sphinn" alt="Sphinn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="del.icio.us" href="javascript:window.location='http%3A%2F%2Fdelicious.com%2Fpost%3Furl%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2009%252F12%252F07%252Fposition-reconstruction%252F%26amp%3Btitle%3DPosition%2520Reconstruction%26amp%3Bnotes%3DThere%2520are%2520many%2520occasions%2520when%2520the%2520fragment%2520position%2520in%2520world%2520space%2520needs%2520to%2520be%2520reconstructed%2520from%2520a%2520texture%2520holding%2520the%2520scene%2520depth%2520%2528depth%2520texture%2529.%2520One%2520example%2520of%2520use%2520is%2520in%2520deferred%2520rendering%2520when%2520trying%2520to%2520decrease%2520memory%2520usage%2520by%2520not%2520saving%2520the%2520po';" title="del.icio.us"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="facebook" href="javascript:window.location='http%3A%2F%2Fwww.facebook.com%2Fshare.php%3Fu%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2009%252F12%252F07%252Fposition-reconstruction%252F%26amp%3Bt%3DPosition%2520Reconstruction';" title="Facebook"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="mixx" href="javascript:window.location='http%3A%2F%2Fwww.mixx.com%2Fsubmit%3Fpage_url%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2009%252F12%252F07%252Fposition-reconstruction%252F%26amp%3Btitle%3DPosition%2520Reconstruction';" title="Mixx"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="google" href="javascript:window.location='http%3A%2F%2Fwww.google.com%2Fbookmarks%2Fmark%3Fop%3Dedit%26amp%3Bbkmk%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2009%252F12%252F07%252Fposition-reconstruction%252F%26amp%3Btitle%3DPosition%2520Reconstruction%26amp%3Bannotation%3DThere%2520are%2520many%2520occasions%2520when%2520the%2520fragment%2520position%2520in%2520world%2520space%2520needs%2520to%2520be%2520reconstructed%2520from%2520a%2520texture%2520holding%2520the%2520scene%2520depth%2520%2528depth%2520texture%2529.%2520One%2520example%2520of%2520use%2520is%2520in%2520deferred%2520rendering%2520when%2520trying%2520to%2520decrease%2520memory%2520usage%2520by%2520not%2520saving%2520the%2520po';" title="Google Bookmarks"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="current" href="javascript:window.location='http%3A%2F%2Fcurrent.com%2Fclipper.htm%3Furl%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2009%252F12%252F07%252Fposition-reconstruction%252F%26amp%3Btitle%3DPosition%2520Reconstruction';" title="Current"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/current.png" title="Current" alt="Current" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="linkedin" href="javascript:window.location='http%3A%2F%2Fwww.linkedin.com%2FshareArticle%3Fmini%3Dtrue%26amp%3Burl%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2009%252F12%252F07%252Fposition-reconstruction%252F%26amp%3Btitle%3DPosition%2520Reconstruction%26amp%3Bsource%3DGame%2BRendering%2B%26amp%3Bsummary%3DThere%2520are%2520many%2520occasions%2520when%2520the%2520fragment%2520position%2520in%2520world%2520space%2520needs%2520to%2520be%2520reconstructed%2520from%2520a%2520texture%2520holding%2520the%2520scene%2520depth%2520%2528depth%2520texture%2529.%2520One%2520example%2520of%2520use%2520is%2520in%2520deferred%2520rendering%2520when%2520trying%2520to%2520decrease%2520memory%2520usage%2520by%2520not%2520saving%2520the%2520po';" title="LinkedIn"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="live" href="javascript:window.location='https%3A%2F%2Ffavorites.live.com%2Fquickadd.aspx%3Fmarklet%3D1%26amp%3Burl%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2009%252F12%252F07%252Fposition-reconstruction%252F%26amp%3Btitle%3DPosition%2520Reconstruction';" title="Live"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/live.png" title="Live" alt="Live" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="myspace" href="javascript:window.location='http%3A%2F%2Fwww.myspace.com%2FModules%2FPostTo%2FPages%2F%3Fu%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2009%252F12%252F07%252Fposition-reconstruction%252F%26amp%3Bt%3DPosition%2520Reconstruction';" title="MySpace"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/myspace.png" title="MySpace" alt="MySpace" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="netvibes" href="javascript:window.location='http%3A%2F%2Fwww.netvibes.com%2Fshare%3Ftitle%3DPosition%2520Reconstruction%26amp%3Burl%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2009%252F12%252F07%252Fposition-reconstruction%252F';" title="Netvibes"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/netvibes.png" title="Netvibes" alt="Netvibes" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="stumbleupon" href="javascript:window.location='http%3A%2F%2Fwww.stumbleupon.com%2Fsubmit%3Furl%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2009%252F12%252F07%252Fposition-reconstruction%252F%26amp%3Btitle%3DPosition%2520Reconstruction';" title="StumbleUpon"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="twitter" href="javascript:window.location='http%3A%2F%2Ftwitter.com%2Fhome%3Fstatus%3DPosition%2520Reconstruction%2520-%2520http%253A%252F%252Fwww.gamerendering.com%252F2009%252F12%252F07%252Fposition-reconstruction%252F';" title="Twitter"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="reddit" href="javascript:window.location='http%3A%2F%2Freddit.com%2Fsubmit%3Furl%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2009%252F12%252F07%252Fposition-reconstruction%252F%26amp%3Btitle%3DPosition%2520Reconstruction';" title="Reddit"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="technorati" href="javascript:window.location='http%3A%2F%2Ftechnorati.com%2Ffaves%3Fadd%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2009%252F12%252F07%252Fposition-reconstruction%252F';" title="Technorati"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow" id="yahoo! bookmarks" href="javascript:window.location='http%3A%2F%2Fbookmarks.yahoo.com%2Ftoolbar%2Fsavebm%3Fu%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2009%252F12%252F07%252Fposition-reconstruction%252F%26amp%3Bt%3DPosition%2520Reconstruction%26opener%3Dbm%26amp%3Bei%3DUTF-8%26amp%3Bd%3DThere%2520are%2520many%2520occasions%2520when%2520the%2520fragment%2520position%2520in%2520world%2520space%2520needs%2520to%2520be%2520reconstructed%2520from%2520a%2520texture%2520holding%2520the%2520scene%2520depth%2520%2528depth%2520texture%2529.%2520One%2520example%2520of%2520use%2520is%2520in%2520deferred%2520rendering%2520when%2520trying%2520to%2520decrease%2520memory%2520usage%2520by%2520not%2520saving%2520the%2520po';" title="Yahoo! Bookmarks"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/yahoomyweb.png" title="Yahoo! Bookmarks" alt="Yahoo! Bookmarks" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.gamerendering.com/2009/12/07/position-reconstruction/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Grid Traversal</title>
		<link>http://www.gamerendering.com/2009/07/20/grid-traversal/</link>
		<comments>http://www.gamerendering.com/2009/07/20/grid-traversal/#comments</comments>
		<pubDate>Mon, 20 Jul 2009 20:03:26 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Math]]></category>
		<category><![CDATA[Optimizations]]></category>
		<category><![CDATA[Algorithm]]></category>
		<category><![CDATA[Applet]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Demo]]></category>
		<category><![CDATA[Grid Traversal]]></category>
		<category><![CDATA[Optimization]]></category>
		<category><![CDATA[Source]]></category>

		<guid isPermaLink="false">http://www.gamerendering.com/?p=645</guid>
		<description><![CDATA[Probably the best and most famous grid traversal algorithm uses a simple loop that for each iteration takes one more step in the grid. It works in both 2D and 3D.
Java code:

   public boolean isFreePath&#40;float startX, float startZ, float endX, float endZ&#41;
   &#123;
      // calculate the direction [...]]]></description>
			<content:encoded><![CDATA[<p>Probably the best and most famous grid traversal algorithm uses a simple loop that for each iteration takes one more step in the grid. It works in both 2D and 3D.</p>
<p><strong>Java code:</strong></p>

<div class="wp_codebox"><table width="100%" ><tr id="p6457"><td class="code" id="p645code7"><pre class="c" style="font-family:monospace;">   public boolean isFreePath<span style="color: #009900;">&#40;</span><span style="color: #993333;">float</span> startX<span style="color: #339933;">,</span> <span style="color: #993333;">float</span> startZ<span style="color: #339933;">,</span> <span style="color: #993333;">float</span> endX<span style="color: #339933;">,</span> <span style="color: #993333;">float</span> endZ<span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">// calculate the direction of the ray (linear algebra)</span>
      dirX <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>endX <span style="color: #339933;">-</span> startX<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      dirY <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>endZ <span style="color: #339933;">-</span> startZ<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #993333;">float</span> length <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">float</span><span style="color: #009900;">&#41;</span> Math.<span style="color: #202020;">sqrt</span><span style="color: #009900;">&#40;</span>dirX <span style="color: #339933;">*</span> dirX <span style="color: #339933;">+</span> dirY <span style="color: #339933;">*</span> dirY<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      dirX <span style="color: #339933;">/=</span> length<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// normalize the direction vector</span>
      dirY <span style="color: #339933;">/=</span> length<span style="color: #339933;">;</span>
&nbsp;
      tDeltaX <span style="color: #339933;">=</span> MAP_RESOLUTION <span style="color: #339933;">/</span> Math.<span style="color: #202020;">abs</span><span style="color: #009900;">&#40;</span>dirX<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// how far we must move in the ray direction before we encounter a new voxel in x-direction</span>
      tDeltaY <span style="color: #339933;">=</span> MAP_RESOLUTION <span style="color: #339933;">/</span> Math.<span style="color: #202020;">abs</span><span style="color: #009900;">&#40;</span>dirY<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// same but y-direction</span>
&nbsp;
      <span style="color: #666666; font-style: italic;">// start voxel coordinates</span>
      x <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span>worldCoordToMapCoord<span style="color: #009900;">&#40;</span>startX<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// use your transformer function here</span>
      y <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span>worldCoordToMapCoord<span style="color: #009900;">&#40;</span>startZ<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #666666; font-style: italic;">// end voxel coordinates</span>
      endX1 <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span>worldCoordToMapCoord<span style="color: #009900;">&#40;</span>endX<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      endY1 <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span>worldCoordToMapCoord<span style="color: #009900;">&#40;</span>endZ<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #666666; font-style: italic;">// decide which direction to start walking in</span>
      stepX <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span> Math.<span style="color: #202020;">signum</span><span style="color: #009900;">&#40;</span>dirX<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      stepY <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span> Math.<span style="color: #202020;">signum</span><span style="color: #009900;">&#40;</span>dirY<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #993333;">float</span> tMaxX<span style="color: #339933;">,</span> tMaxY<span style="color: #339933;">;</span>
      <span style="color: #666666; font-style: italic;">// calculate distance to first intersection in the voxel we start from</span>
      <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>dirX <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#123;</span>
         tMaxX <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>mapToWorld<span style="color: #009900;">&#40;</span>x<span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span>startX<span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> dirX<span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span>
      <span style="color: #009900;">&#123;</span>
         tMaxX <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>mapToWorld<span style="color: #009900;">&#40;</span>x<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span>startX<span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> dirX<span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
&nbsp;
      <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>dirY <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#123;</span>
         tMaxY <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>mapToWorld<span style="color: #009900;">&#40;</span>y<span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span>startY<span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> dirY<span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span>
      <span style="color: #009900;">&#123;</span>
         tMaxY <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>mapToWorld<span style="color: #009900;">&#40;</span>y<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span>startY<span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> dirY<span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
&nbsp;
      <span style="color: #666666; font-style: italic;">// check if first is occupied</span>
      <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>isMapPositionOccupied<span style="color: #009900;">&#40;</span>x<span style="color: #339933;">,</span> y<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// use your function here</span>
         <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
      boolean reachedX <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #339933;">,</span> reachedY <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#123;</span>
         <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>tMaxX <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> tMaxY<span style="color: #009900;">&#41;</span>
         <span style="color: #009900;">&#123;</span>
            tMaxX <span style="color: #339933;">+=</span> tDeltaX<span style="color: #339933;">;</span>
            x <span style="color: #339933;">+=</span> stepX<span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span>
         <span style="color: #009900;">&#123;</span>
            tMaxY <span style="color: #339933;">+=</span> tDeltaY<span style="color: #339933;">;</span>
            y <span style="color: #339933;">+=</span> stepY<span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span>
&nbsp;
         <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>stepX <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color:#800080;">0.0f</span><span style="color: #009900;">&#41;</span>
         <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>x <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;=</span> endX1<span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
               reachedX <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">true</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
         <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>x <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;=</span> endX1<span style="color: #009900;">&#41;</span>
         <span style="color: #009900;">&#123;</span>
            reachedX <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">true</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span>
&nbsp;
         <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>stepY <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color:#800080;">0.0f</span><span style="color: #009900;">&#41;</span>
         <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>y <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;=</span> endY1<span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
               reachedY <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">true</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
         <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>y <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;=</span> endY1<span style="color: #009900;">&#41;</span>
         <span style="color: #009900;">&#123;</span>
            reachedY <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">true</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span>
&nbsp;
         <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>isMapPositionOccupied<span style="color: #009900;">&#40;</span>x<span style="color: #339933;">,</span> y<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
         <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span>
&nbsp;
         <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>reachedX <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> reachedY<span style="color: #009900;">&#41;</span>
         <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span>
&nbsp;
      <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">true</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><strong>Here&#8217;s an applet showing it in action.</strong><br />
The white tiles are free, the gray tiles are blocking. The ray starts at the green dot and ends at the red dot. The gray spheres are the visited grid sections. Use leftclick to position the green dot and the right button to position the red dot.<br />
 <br />
<APPLET CODE="GTApplet.class" archive="http://www.gamerendering.com/applets/GridTraversal.jar" WIDTH=420 HEIGHT=600><br />
<PARAM NAME=TEXT VALUE="Hi There"><br />
<P>Hi There<P><br />
</APPLET></p>
<p>Link to paper:<br />
<a href="http://www.flipcode.com/archives/A%20faster%20voxel%20traversal%20algorithm%20for%20ray%20tracing.pdf">http://www.flipcode.com/archives/A%20faster%20voxel%20traversal%20algorithm%20for%20ray%20tracing.pdf</a></p>
<p>Some discussion on GameDev:<br />
<a href="http://www.gamedev.net/community/forums/topic.asp?topic_id=385303">http://www.gamedev.net/community/forums/topic.asp?topic_id=385303</a></p>
<p>Implementations:<br />
<a href="http://www.clockworkcoders.com/oglsl/rt/gpurt3.htm">http://www.clockworkcoders.com/oglsl/rt/gpurt3.htm</a><br />
<a href="http://www.devmaster.net/articles/raytracing_series/part4.php">http://www.devmaster.net/articles/raytracing_series/part4.php</a></p>
<p>Full source of the applet:</p>

<div class="wp_codebox"><table width="100%" ><tr id="p6458"><td class="code" id="p645code8"><pre class="c" style="font-family:monospace;">import java.<span style="color: #202020;">awt</span>.<span style="color: #339933;">*;</span>
import java.<span style="color: #202020;">awt</span>.<span style="color: #202020;">event</span>.<span style="color: #202020;">MouseEvent</span><span style="color: #339933;">;</span>
import java.<span style="color: #202020;">awt</span>.<span style="color: #202020;">event</span>.<span style="color: #202020;">MouseListener</span><span style="color: #339933;">;</span>
import java.<span style="color: #202020;">awt</span>.<span style="color: #202020;">event</span>.<span style="color: #202020;">MouseMotionListener</span><span style="color: #339933;">;</span>
import java.<span style="color: #202020;">applet</span>.<span style="color: #339933;">*;</span>
&nbsp;
public class GTApplet extends Applet implements MouseListener<span style="color: #339933;">,</span>
		MouseMotionListener
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">enum</span> mapNotations
	<span style="color: #009900;">&#123;</span>
		FREE<span style="color: #339933;">,</span> OCCUPIED<span style="color: #339933;">,</span> BOOKED<span style="color: #339933;">,</span> RESERVED
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
	private <span style="color: #993333;">static</span> final <span style="color: #993333;">int</span> GRID_PAINT_SIZE <span style="color: #339933;">=</span> <span style="color: #0000dd;">50</span><span style="color: #339933;">;</span>
&nbsp;
	private <span style="color: #993333;">static</span> final <span style="color: #993333;">int</span> MAP_RESOLUTION <span style="color: #339933;">=</span> GRID_PAINT_SIZE<span style="color: #339933;">;</span>
&nbsp;
	private <span style="color: #993333;">static</span> final <span style="color: #993333;">int</span> MAP_SIZE <span style="color: #339933;">=</span> <span style="color: #0000dd;">4</span> <span style="color: #339933;">*</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">;</span>
&nbsp;
	private final mapNotations<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> map <span style="color: #339933;">=</span> new mapNotations<span style="color: #009900;">&#91;</span>MAP_SIZE<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>MAP_SIZE<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
	private final <span style="color: #993333;">int</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> markedMap <span style="color: #339933;">=</span> new <span style="color: #993333;">int</span><span style="color: #009900;">&#91;</span>MAP_SIZE<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>MAP_SIZE<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Specify variables that will be needed everywhere, anytime here</span>
	<span style="color: #666666; font-style: italic;">// The font variable</span>
	Font bigFont<span style="color: #339933;">,</span> smallFont<span style="color: #339933;">,</span> smallestFont<span style="color: #339933;">;</span>
&nbsp;
	Color bgColor<span style="color: #339933;">;</span>
	Color gridLineColor<span style="color: #339933;">;</span>
	Color gridOccupiedColor<span style="color: #339933;">;</span>
	Color startColor<span style="color: #339933;">;</span>
	Color endColor<span style="color: #339933;">;</span>
	Color helperLineColor<span style="color: #339933;">;</span>
	Color markerColor<span style="color: #339933;">;</span>
	Color textColor<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #993333;">int</span> startX <span style="color: #339933;">=</span> <span style="color: #0000dd;">50</span><span style="color: #339933;">,</span> startY <span style="color: #339933;">=</span> <span style="color: #0000dd;">50</span><span style="color: #339933;">,</span> endX <span style="color: #339933;">=</span> <span style="color: #0000dd;">50</span><span style="color: #339933;">,</span> endY <span style="color: #339933;">=</span> <span style="color: #0000dd;">50</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #993333;">int</span> markerDiameter <span style="color: #339933;">=</span> <span style="color: #0000dd;">6</span><span style="color: #339933;">;</span>
	<span style="color: #993333;">int</span> mapMarkerDiameter <span style="color: #339933;">=</span> <span style="color: #0000dd;">26</span><span style="color: #339933;">;</span>
&nbsp;
	boolean isFreePath <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
	public <span style="color: #993333;">void</span> init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// init the map</span>
		<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> x <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> x <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> MAP_SIZE<span style="color: #339933;">;</span> x<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> y <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> y <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> MAP_SIZE<span style="color: #339933;">;</span> y<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> 			<span style="color: #009900;">&#123;</span> 				<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>Math.<span style="color: #202020;">random</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color:#800080;">0.2f</span><span style="color: #009900;">&#41;</span>
				<span style="color: #009900;">&#123;</span>
					map<span style="color: #009900;">&#91;</span>x<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>y<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> mapNotations.<span style="color: #202020;">FREE</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span>
				<span style="color: #009900;">&#123;</span>
					map<span style="color: #009900;">&#91;</span>x<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>y<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> mapNotations.<span style="color: #202020;">OCCUPIED</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		bigFont <span style="color: #339933;">=</span> new Font<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Arial&quot;</span><span style="color: #339933;">,</span> Font.<span style="color: #202020;">BOLD</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">16</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		bigFont <span style="color: #339933;">=</span> new Font<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Arial&quot;</span><span style="color: #339933;">,</span> Font.<span style="color: #202020;">BOLD</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">12</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		smallestFont <span style="color: #339933;">=</span> new Font<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Calibri&quot;</span><span style="color: #339933;">,</span> Font.<span style="color: #202020;">PLAIN</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		gridLineColor <span style="color: #339933;">=</span> Color.<span style="color: #202020;">DARK_GRAY</span><span style="color: #339933;">;</span>
		gridOccupiedColor <span style="color: #339933;">=</span> Color.<span style="color: #202020;">LIGHT_GRAY</span><span style="color: #339933;">;</span>
		startColor <span style="color: #339933;">=</span> Color.<span style="color: #202020;">green</span><span style="color: #339933;">;</span>
		endColor <span style="color: #339933;">=</span> Color.<span style="color: #202020;">red</span><span style="color: #339933;">;</span>
		helperLineColor <span style="color: #339933;">=</span> Color.<span style="color: #202020;">black</span><span style="color: #339933;">;</span>
		markerColor <span style="color: #339933;">=</span> Color.<span style="color: #202020;">gray</span><span style="color: #339933;">;</span>
		textColor <span style="color: #339933;">=</span> Color.<span style="color: #202020;">DARK_GRAY</span><span style="color: #339933;">;</span>
&nbsp;
		bgColor <span style="color: #339933;">=</span> new Color<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">230</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">231</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">232</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		setBackground<span style="color: #009900;">&#40;</span>bgColor<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		addMouseListener<span style="color: #009900;">&#40;</span>this<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		addMouseMotionListener<span style="color: #009900;">&#40;</span>this<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
	public <span style="color: #993333;">void</span> mouseEntered<span style="color: #009900;">&#40;</span>MouseEvent e<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// called when the pointer enters the applet's rectangular area</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	public <span style="color: #993333;">void</span> mouseExited<span style="color: #009900;">&#40;</span>MouseEvent e<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// called when the pointer leaves the applet's rectangular area</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	public <span style="color: #993333;">void</span> mouseClicked<span style="color: #009900;">&#40;</span>MouseEvent e<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// called after a press and release of a mouse button</span>
		<span style="color: #666666; font-style: italic;">// with no motion in between</span>
		<span style="color: #666666; font-style: italic;">// (If the user presses, drags, and then releases, there will be</span>
		<span style="color: #666666; font-style: italic;">// no click event generated.)</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	public <span style="color: #993333;">void</span> mousePressed<span style="color: #009900;">&#40;</span>MouseEvent e<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// called after a button is pressed down</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #202020;">getButton</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> MouseEvent.<span style="color: #202020;">BUTTON1</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			startX <span style="color: #339933;">=</span> e.<span style="color: #202020;">getX</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			startY <span style="color: #339933;">=</span> e.<span style="color: #202020;">getY</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span>
		<span style="color: #009900;">&#123;</span>
			endX <span style="color: #339933;">=</span> e.<span style="color: #202020;">getX</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			endY <span style="color: #339933;">=</span> e.<span style="color: #202020;">getY</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		resetMarkedMap<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		isFreePath <span style="color: #339933;">=</span> isFreePath<span style="color: #009900;">&#40;</span>startX<span style="color: #339933;">,</span> startY<span style="color: #339933;">,</span> endX<span style="color: #339933;">,</span> endY<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		repaint<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">// &quot;Consume&quot; the event so it won't be processed in the</span>
		<span style="color: #666666; font-style: italic;">// default manner by the source which generated it.</span>
		e.<span style="color: #202020;">consume</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	public <span style="color: #993333;">void</span> mouseReleased<span style="color: #009900;">&#40;</span>MouseEvent e<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// called after a button is released</span>
	<span style="color: #666666; font-style: italic;">//        repaint();</span>
		e.<span style="color: #202020;">consume</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	public <span style="color: #993333;">void</span> mouseMoved<span style="color: #009900;">&#40;</span>MouseEvent e<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// called during motion when no buttons are down</span>
	<span style="color: #666666; font-style: italic;">//        repaint();</span>
		e.<span style="color: #202020;">consume</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	public <span style="color: #993333;">void</span> mouseDragged<span style="color: #009900;">&#40;</span>MouseEvent e<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// called during motion with buttons down</span>
	<span style="color: #666666; font-style: italic;">//        repaint();</span>
		e.<span style="color: #202020;">consume</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	public <span style="color: #993333;">void</span> stop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// just some simple and rude drawing</span>
	public <span style="color: #993333;">void</span> paint<span style="color: #009900;">&#40;</span>Graphics g<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		g.<span style="color: #202020;">setColor</span><span style="color: #009900;">&#40;</span>gridLineColor<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> x <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> x <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> MAP_SIZE <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span> x<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
			g.<span style="color: #202020;">drawLine</span><span style="color: #009900;">&#40;</span>x <span style="color: #339933;">*</span> GRID_PAINT_SIZE<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> x <span style="color: #339933;">*</span> GRID_PAINT_SIZE<span style="color: #339933;">,</span> MAP_SIZE
					<span style="color: #339933;">*</span> GRID_PAINT_SIZE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> y <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> y <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> MAP_SIZE <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span> y<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
			g.<span style="color: #202020;">drawLine</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> y <span style="color: #339933;">*</span> GRID_PAINT_SIZE<span style="color: #339933;">,</span> MAP_SIZE <span style="color: #339933;">*</span> GRID_PAINT_SIZE<span style="color: #339933;">,</span> y
					<span style="color: #339933;">*</span> GRID_PAINT_SIZE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		g.<span style="color: #202020;">setColor</span><span style="color: #009900;">&#40;</span>gridOccupiedColor<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> x <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> x <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> MAP_SIZE<span style="color: #339933;">;</span> x<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> y <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> y <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> MAP_SIZE<span style="color: #339933;">;</span> y<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>map<span style="color: #009900;">&#91;</span>x<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>y<span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> mapNotations.<span style="color: #202020;">OCCUPIED</span><span style="color: #009900;">&#41;</span>
				<span style="color: #009900;">&#123;</span>
					g.<span style="color: #202020;">fillRect</span><span style="color: #009900;">&#40;</span>x <span style="color: #339933;">*</span> GRID_PAINT_SIZE <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">,</span>
							y <span style="color: #339933;">*</span> GRID_PAINT_SIZE <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> GRID_PAINT_SIZE <span style="color: #339933;">-</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">,</span>
							GRID_PAINT_SIZE <span style="color: #339933;">-</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		g.<span style="color: #202020;">setColor</span><span style="color: #009900;">&#40;</span>textColor<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		g.<span style="color: #202020;">setFont</span><span style="color: #009900;">&#40;</span>smallestFont<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> x <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> x <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> MAP_SIZE<span style="color: #339933;">;</span> x<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> y <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> y <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> MAP_SIZE<span style="color: #339933;">;</span> y<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				g.<span style="color: #202020;">drawString</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;(&quot;</span> <span style="color: #339933;">+</span> x <span style="color: #339933;">+</span> <span style="color: #ff0000;">&quot;,&quot;</span> <span style="color: #339933;">+</span> y <span style="color: #339933;">+</span> <span style="color: #ff0000;">&quot;)&quot;</span><span style="color: #339933;">,</span> x <span style="color: #339933;">*</span> GRID_PAINT_SIZE <span style="color: #339933;">+</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">,</span>
						y <span style="color: #339933;">*</span> GRID_PAINT_SIZE <span style="color: #339933;">+</span> <span style="color: #0000dd;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		g.<span style="color: #202020;">setFont</span><span style="color: #009900;">&#40;</span>bigFont<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		g.<span style="color: #202020;">drawString</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Start: (&quot;</span> <span style="color: #339933;">+</span> startX <span style="color: #339933;">+</span> <span style="color: #ff0000;">&quot;,&quot;</span> <span style="color: #339933;">+</span> startY <span style="color: #339933;">+</span> <span style="color: #ff0000;">&quot;)&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">16</span><span style="color: #339933;">,</span> MAP_SIZE
				<span style="color: #339933;">*</span> GRID_PAINT_SIZE <span style="color: #339933;">+</span> <span style="color: #0000dd;">30</span> <span style="color: #339933;">+</span> <span style="color: #0000dd;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		g.<span style="color: #202020;">drawString</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;End: (&quot;</span> <span style="color: #339933;">+</span> endX <span style="color: #339933;">+</span> <span style="color: #ff0000;">&quot;,&quot;</span> <span style="color: #339933;">+</span> endY <span style="color: #339933;">+</span> <span style="color: #ff0000;">&quot;)&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">16</span><span style="color: #339933;">,</span> MAP_SIZE
				<span style="color: #339933;">*</span> GRID_PAINT_SIZE <span style="color: #339933;">+</span> <span style="color: #0000dd;">48</span> <span style="color: #339933;">+</span> <span style="color: #0000dd;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		g.<span style="color: #202020;">drawString</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Is free path: &quot;</span> <span style="color: #339933;">+</span> isFreePath<span style="color: #339933;">,</span> <span style="color: #0000dd;">16</span><span style="color: #339933;">,</span> MAP_SIZE
				<span style="color: #339933;">*</span> GRID_PAINT_SIZE <span style="color: #339933;">+</span> <span style="color: #0000dd;">48</span> <span style="color: #339933;">+</span> <span style="color: #0000dd;">18</span> <span style="color: #339933;">+</span> <span style="color: #0000dd;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		g.<span style="color: #202020;">setFont</span><span style="color: #009900;">&#40;</span>smallFont<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		g.<span style="color: #202020;">drawString</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Start (map coords): (&quot;</span> <span style="color: #339933;">+</span> sx <span style="color: #339933;">+</span> <span style="color: #ff0000;">&quot;,&quot;</span> <span style="color: #339933;">+</span> sy <span style="color: #339933;">+</span> <span style="color: #ff0000;">&quot;)&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">16</span><span style="color: #339933;">,</span>
				MAP_SIZE <span style="color: #339933;">*</span> GRID_PAINT_SIZE <span style="color: #339933;">+</span> <span style="color: #0000dd;">10</span> <span style="color: #339933;">+</span> <span style="color: #0000dd;">48</span> <span style="color: #339933;">+</span> <span style="color: #0000dd;">18</span> <span style="color: #339933;">+</span> <span style="color: #0000dd;">18</span> <span style="color: #339933;">+</span> <span style="color: #0000dd;">0</span> <span style="color: #339933;">*</span> <span style="color: #0000dd;">14</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		g.<span style="color: #202020;">drawString</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;End (map coords): (&quot;</span> <span style="color: #339933;">+</span> endX1 <span style="color: #339933;">+</span> <span style="color: #ff0000;">&quot;,&quot;</span> <span style="color: #339933;">+</span> endY1 <span style="color: #339933;">+</span> <span style="color: #ff0000;">&quot;)&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">16</span><span style="color: #339933;">,</span>
				MAP_SIZE <span style="color: #339933;">*</span> GRID_PAINT_SIZE <span style="color: #339933;">+</span> <span style="color: #0000dd;">10</span> <span style="color: #339933;">+</span> <span style="color: #0000dd;">48</span> <span style="color: #339933;">+</span> <span style="color: #0000dd;">18</span> <span style="color: #339933;">+</span> <span style="color: #0000dd;">18</span> <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span> <span style="color: #339933;">*</span> <span style="color: #0000dd;">14</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		g.<span style="color: #202020;">drawString</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Step (map coords): (&quot;</span> <span style="color: #339933;">+</span> stepX <span style="color: #339933;">+</span> <span style="color: #ff0000;">&quot;,&quot;</span> <span style="color: #339933;">+</span> stepY <span style="color: #339933;">+</span> <span style="color: #ff0000;">&quot;)&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">16</span><span style="color: #339933;">,</span>
				MAP_SIZE <span style="color: #339933;">*</span> GRID_PAINT_SIZE <span style="color: #339933;">+</span> <span style="color: #0000dd;">10</span> <span style="color: #339933;">+</span> <span style="color: #0000dd;">48</span> <span style="color: #339933;">+</span> <span style="color: #0000dd;">18</span> <span style="color: #339933;">+</span> <span style="color: #0000dd;">18</span> <span style="color: #339933;">+</span> <span style="color: #0000dd;">2</span> <span style="color: #339933;">*</span> <span style="color: #0000dd;">14</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		g.<span style="color: #202020;">drawString</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Dir: (&quot;</span> <span style="color: #339933;">+</span> dirX <span style="color: #339933;">+</span> <span style="color: #ff0000;">&quot;,&quot;</span> <span style="color: #339933;">+</span> dirY <span style="color: #339933;">+</span> <span style="color: #ff0000;">&quot;)&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">16</span><span style="color: #339933;">,</span> MAP_SIZE
				<span style="color: #339933;">*</span> GRID_PAINT_SIZE <span style="color: #339933;">+</span> <span style="color: #0000dd;">10</span> <span style="color: #339933;">+</span> <span style="color: #0000dd;">48</span> <span style="color: #339933;">+</span> <span style="color: #0000dd;">18</span> <span style="color: #339933;">+</span> <span style="color: #0000dd;">18</span> <span style="color: #339933;">+</span> <span style="color: #0000dd;">3</span> <span style="color: #339933;">*</span> <span style="color: #0000dd;">14</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		g.<span style="color: #202020;">drawString</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;tDelta: (&quot;</span> <span style="color: #339933;">+</span> tDeltaX <span style="color: #339933;">+</span> <span style="color: #ff0000;">&quot;,&quot;</span> <span style="color: #339933;">+</span> tDeltaY <span style="color: #339933;">+</span> <span style="color: #ff0000;">&quot;)&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">16</span><span style="color: #339933;">,</span> MAP_SIZE
				<span style="color: #339933;">*</span> GRID_PAINT_SIZE <span style="color: #339933;">+</span> <span style="color: #0000dd;">10</span> <span style="color: #339933;">+</span> <span style="color: #0000dd;">48</span> <span style="color: #339933;">+</span> <span style="color: #0000dd;">18</span> <span style="color: #339933;">+</span> <span style="color: #0000dd;">18</span> <span style="color: #339933;">+</span> <span style="color: #0000dd;">4</span> <span style="color: #339933;">*</span> <span style="color: #0000dd;">14</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		g.<span style="color: #202020;">drawString</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;sTMax: (&quot;</span> <span style="color: #339933;">+</span> sTMaxX <span style="color: #339933;">+</span> <span style="color: #ff0000;">&quot;,&quot;</span> <span style="color: #339933;">+</span> sTMaxY <span style="color: #339933;">+</span> <span style="color: #ff0000;">&quot;)&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">16</span><span style="color: #339933;">,</span> MAP_SIZE
				<span style="color: #339933;">*</span> GRID_PAINT_SIZE <span style="color: #339933;">+</span> <span style="color: #0000dd;">10</span> <span style="color: #339933;">+</span> <span style="color: #0000dd;">48</span> <span style="color: #339933;">+</span> <span style="color: #0000dd;">18</span> <span style="color: #339933;">+</span> <span style="color: #0000dd;">18</span> <span style="color: #339933;">+</span> <span style="color: #0000dd;">5</span> <span style="color: #339933;">*</span> <span style="color: #0000dd;">14</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		g.<span style="color: #202020;">setColor</span><span style="color: #009900;">&#40;</span>markerColor<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> x <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> x <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> MAP_SIZE<span style="color: #339933;">;</span> x<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> y <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> y <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> MAP_SIZE<span style="color: #339933;">;</span> y<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>markedMap<span style="color: #009900;">&#91;</span>x<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>y<span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span>
				<span style="color: #009900;">&#123;</span>
					g.<span style="color: #202020;">fillOval</span><span style="color: #009900;">&#40;</span>x <span style="color: #339933;">*</span> GRID_PAINT_SIZE <span style="color: #339933;">-</span> mapMarkerDiameter <span style="color: #339933;">/</span> <span style="color: #0000dd;">2</span>
							<span style="color: #339933;">+</span> GRID_PAINT_SIZE <span style="color: #339933;">/</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">,</span> y <span style="color: #339933;">*</span> GRID_PAINT_SIZE
							<span style="color: #339933;">-</span> mapMarkerDiameter <span style="color: #339933;">/</span> <span style="color: #0000dd;">2</span> <span style="color: #339933;">+</span> GRID_PAINT_SIZE <span style="color: #339933;">/</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">,</span>
							mapMarkerDiameter<span style="color: #339933;">,</span> mapMarkerDiameter<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		g.<span style="color: #202020;">setColor</span><span style="color: #009900;">&#40;</span>startColor<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">// draw start and end markers</span>
		g.<span style="color: #202020;">drawOval</span><span style="color: #009900;">&#40;</span>startX <span style="color: #339933;">-</span> markerDiameter <span style="color: #339933;">/</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">,</span> startY <span style="color: #339933;">-</span> markerDiameter <span style="color: #339933;">/</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">,</span>
				markerDiameter<span style="color: #339933;">,</span> markerDiameter<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		g.<span style="color: #202020;">setColor</span><span style="color: #009900;">&#40;</span>endColor<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">// draw start and end markers</span>
		g.<span style="color: #202020;">drawOval</span><span style="color: #009900;">&#40;</span>endX <span style="color: #339933;">-</span> markerDiameter <span style="color: #339933;">/</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">,</span> endY <span style="color: #339933;">-</span> markerDiameter <span style="color: #339933;">/</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">,</span>
				markerDiameter<span style="color: #339933;">,</span> markerDiameter<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		g.<span style="color: #202020;">setColor</span><span style="color: #009900;">&#40;</span>helperLineColor<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		g.<span style="color: #202020;">drawLine</span><span style="color: #009900;">&#40;</span>startX<span style="color: #339933;">,</span> startY<span style="color: #339933;">,</span> endX<span style="color: #339933;">,</span> endY<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	public <span style="color: #993333;">void</span> resetMarkedMap<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> x <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> x <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> MAP_SIZE<span style="color: #339933;">;</span> x<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> y <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> y <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> MAP_SIZE<span style="color: #339933;">;</span> y<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				markedMap<span style="color: #009900;">&#91;</span>x<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>y<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #993333;">int</span> sx<span style="color: #339933;">,</span> sy<span style="color: #339933;">,</span> x<span style="color: #339933;">,</span> y<span style="color: #339933;">,</span> endX1<span style="color: #339933;">,</span> endY1<span style="color: #339933;">,</span> stepX<span style="color: #339933;">,</span> stepY<span style="color: #339933;">;</span>
	<span style="color: #993333;">float</span> tDeltaX<span style="color: #339933;">,</span> tDeltaY<span style="color: #339933;">;</span>
	<span style="color: #993333;">float</span> dirX<span style="color: #339933;">,</span> dirY<span style="color: #339933;">;</span>
	<span style="color: #993333;">float</span> sTMaxX<span style="color: #339933;">,</span> sTMaxY<span style="color: #339933;">;</span>
&nbsp;
	public boolean isFreePath<span style="color: #009900;">&#40;</span><span style="color: #993333;">float</span> startX<span style="color: #339933;">,</span> <span style="color: #993333;">float</span> startZ<span style="color: #339933;">,</span> <span style="color: #993333;">float</span> endX<span style="color: #339933;">,</span> <span style="color: #993333;">float</span> endZ<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// calculate the direction of the ray (linear algebra)</span>
		dirX <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>endX <span style="color: #339933;">-</span> startX<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		dirY <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>endZ <span style="color: #339933;">-</span> startZ<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #993333;">float</span> length <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">float</span><span style="color: #009900;">&#41;</span> Math.<span style="color: #202020;">sqrt</span><span style="color: #009900;">&#40;</span>dirX <span style="color: #339933;">*</span> dirX <span style="color: #339933;">+</span> dirY <span style="color: #339933;">*</span> dirY<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		dirX <span style="color: #339933;">/=</span> length<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// normalize the direction vector</span>
		dirY <span style="color: #339933;">/=</span> length<span style="color: #339933;">;</span>
&nbsp;
		tDeltaX <span style="color: #339933;">=</span> MAP_RESOLUTION <span style="color: #339933;">/</span> Math.<span style="color: #202020;">abs</span><span style="color: #009900;">&#40;</span>dirX<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// how far we must move in the ray direction before we encounter a new voxel in x-direction</span>
		tDeltaY <span style="color: #339933;">=</span> MAP_RESOLUTION <span style="color: #339933;">/</span> Math.<span style="color: #202020;">abs</span><span style="color: #009900;">&#40;</span>dirY<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// same but y-direction</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// start voxel coordinates</span>
		sx <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span>worldCoordToMapCoord<span style="color: #009900;">&#40;</span>startX<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// use your transformer function here</span>
		sy <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span>worldCoordToMapCoord<span style="color: #009900;">&#40;</span>startZ<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// end voxel coordinates</span>
		endX1 <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span>worldCoordToMapCoord<span style="color: #009900;">&#40;</span>endX<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		endY1 <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span>worldCoordToMapCoord<span style="color: #009900;">&#40;</span>endZ<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		x <span style="color: #339933;">=</span> sx<span style="color: #339933;">;</span>
		y <span style="color: #339933;">=</span> sy<span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// decide which direction to start walking in</span>
		stepX <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span> Math.<span style="color: #202020;">signum</span><span style="color: #009900;">&#40;</span>dirX<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		stepY <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span> Math.<span style="color: #202020;">signum</span><span style="color: #009900;">&#40;</span>dirY<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #993333;">float</span> tMaxX<span style="color: #339933;">,</span> tMaxY<span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">// calculate distance to first intersection in the voxel we start from</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>dirX <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			tMaxX <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>mapToWorld<span style="color: #009900;">&#40;</span>x<span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span>startX<span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> dirX<span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span>
		<span style="color: #009900;">&#123;</span>
			tMaxX <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>mapToWorld<span style="color: #009900;">&#40;</span>x<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span>startX<span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> dirX<span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>dirY <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			tMaxY <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>mapToWorld<span style="color: #009900;">&#40;</span>y<span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span>startY<span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> dirY<span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span>
		<span style="color: #009900;">&#123;</span>
			tMaxY <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>mapToWorld<span style="color: #009900;">&#40;</span>y<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span>startY<span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> dirY<span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		sTMaxX <span style="color: #339933;">=</span> tMaxX<span style="color: #339933;">;</span>
		sTMaxY <span style="color: #339933;">=</span> tMaxY<span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// check if first is occupied</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>isMapPositionOccupied<span style="color: #009900;">&#40;</span>x<span style="color: #339933;">,</span> y<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// use your function here</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
		boolean reachedX <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #339933;">,</span> reachedY <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>tMaxX <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> tMaxY<span style="color: #009900;">&#41;</span> 			<span style="color: #009900;">&#123;</span> 				tMaxX <span style="color: #339933;">+=</span> tDeltaX<span style="color: #339933;">;</span> 				x <span style="color: #339933;">+=</span> stepX<span style="color: #339933;">;</span> 			<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> 			<span style="color: #009900;">&#123;</span> 				tMaxY <span style="color: #339933;">+=</span> tDeltaY<span style="color: #339933;">;</span> 				y <span style="color: #339933;">+=</span> stepY<span style="color: #339933;">;</span> 			<span style="color: #009900;">&#125;</span> 			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>stepX <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color:#800080;">0.0f</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>x <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;=</span> endX1<span style="color: #009900;">&#41;</span>
				<span style="color: #009900;">&#123;</span>
					reachedX <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">true</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>x <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;=</span> endX1<span style="color: #009900;">&#41;</span> 			<span style="color: #009900;">&#123;</span> 				reachedX <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">true</span><span style="color: #339933;">;</span> 			<span style="color: #009900;">&#125;</span> 			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>stepY <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color:#800080;">0.0f</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>y <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;=</span> endY1<span style="color: #009900;">&#41;</span>
				<span style="color: #009900;">&#123;</span>
					reachedY <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">true</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>y <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;=</span> endY1<span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				reachedY <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">true</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>isMapPositionOccupied<span style="color: #009900;">&#40;</span>x<span style="color: #339933;">,</span> y<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>reachedX <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> reachedY<span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">true</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	private <span style="color: #993333;">float</span> mapToWorld<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> coord<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> coord<span style="color: #339933;">*</span>MAP_RESOLUTION<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	private <span style="color: #993333;">float</span> worldCoordToMapCoord<span style="color: #009900;">&#40;</span><span style="color: #993333;">float</span> coord<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> coord <span style="color: #339933;">/</span> MAP_RESOLUTION<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	private boolean isMapPositionOccupied<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> x<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> y<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>x <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> <span style="color: #0000dd;">0</span> <span style="color: #339933;">||</span> y <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">true</span><span style="color: #339933;">;</span> 
&nbsp;
		<span style="color: #666666; font-style: italic;">// save this for debug use</span>
		markedMap<span style="color: #009900;">&#91;</span>x<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>y<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">return</span> map<span style="color: #009900;">&#91;</span>x<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>y<span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> mapNotations.<span style="color: #202020;">OCCUPIED</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>


<div class="sociable">
<div class="sociable_tagline">
<strong>Please share:</strong>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow" id="print" href="javascript:window.location='http%3A%2F%2Fwww.printfriendly.com%2Fprint%3Furl%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2009%252F07%252F20%252Fgrid-traversal%252F%26amp%3Bpartner%3Dsociable';" title="Print this article!"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/printfriendly.png" title="Print this article!" alt="Print this article!" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="digg" href="javascript:window.location='http%3A%2F%2Fdigg.com%2Fsubmit%3Fphase%3D2%26amp%3Burl%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2009%252F07%252F20%252Fgrid-traversal%252F%26amp%3Btitle%3DGrid%2520Traversal%26amp%3Bbodytext%3DProbably%2520the%25C2%25A0best%2520and%2520most%2520famous%2520grid%2520traversal%2520algorithm%2520uses%2520a%2520simple%2520loop%2520that%2520for%2520each%2520iteration%2520takes%2520one%2520more%2520step%2520in%2520the%2520grid.%2520It%2520works%2520in%2520both%25202D%2520and%25203D.%250D%250A%250D%250AJava%2520code%253A%250D%250A%2520%2520%2520public%2520boolean%2520isFreePath%2528float%2520startX%252C%2520float%2520startZ%252C%2520float%2520endX%252C%2520fl';" title="Digg"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="sphinn" href="javascript:window.location='http%3A%2F%2Fsphinn.com%2Findex.php%3Fc%3Dpost%26m%3Dsubmit%26link%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2009%252F07%252F20%252Fgrid-traversal%252F';" title="Sphinn"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/sphinn.png" title="Sphinn" alt="Sphinn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="del.icio.us" href="javascript:window.location='http%3A%2F%2Fdelicious.com%2Fpost%3Furl%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2009%252F07%252F20%252Fgrid-traversal%252F%26amp%3Btitle%3DGrid%2520Traversal%26amp%3Bnotes%3DProbably%2520the%25C2%25A0best%2520and%2520most%2520famous%2520grid%2520traversal%2520algorithm%2520uses%2520a%2520simple%2520loop%2520that%2520for%2520each%2520iteration%2520takes%2520one%2520more%2520step%2520in%2520the%2520grid.%2520It%2520works%2520in%2520both%25202D%2520and%25203D.%250D%250A%250D%250AJava%2520code%253A%250D%250A%2520%2520%2520public%2520boolean%2520isFreePath%2528float%2520startX%252C%2520float%2520startZ%252C%2520float%2520endX%252C%2520fl';" title="del.icio.us"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="facebook" href="javascript:window.location='http%3A%2F%2Fwww.facebook.com%2Fshare.php%3Fu%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2009%252F07%252F20%252Fgrid-traversal%252F%26amp%3Bt%3DGrid%2520Traversal';" title="Facebook"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="mixx" href="javascript:window.location='http%3A%2F%2Fwww.mixx.com%2Fsubmit%3Fpage_url%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2009%252F07%252F20%252Fgrid-traversal%252F%26amp%3Btitle%3DGrid%2520Traversal';" title="Mixx"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="google" href="javascript:window.location='http%3A%2F%2Fwww.google.com%2Fbookmarks%2Fmark%3Fop%3Dedit%26amp%3Bbkmk%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2009%252F07%252F20%252Fgrid-traversal%252F%26amp%3Btitle%3DGrid%2520Traversal%26amp%3Bannotation%3DProbably%2520the%25C2%25A0best%2520and%2520most%2520famous%2520grid%2520traversal%2520algorithm%2520uses%2520a%2520simple%2520loop%2520that%2520for%2520each%2520iteration%2520takes%2520one%2520more%2520step%2520in%2520the%2520grid.%2520It%2520works%2520in%2520both%25202D%2520and%25203D.%250D%250A%250D%250AJava%2520code%253A%250D%250A%2520%2520%2520public%2520boolean%2520isFreePath%2528float%2520startX%252C%2520float%2520startZ%252C%2520float%2520endX%252C%2520fl';" title="Google Bookmarks"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="current" href="javascript:window.location='http%3A%2F%2Fcurrent.com%2Fclipper.htm%3Furl%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2009%252F07%252F20%252Fgrid-traversal%252F%26amp%3Btitle%3DGrid%2520Traversal';" title="Current"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/current.png" title="Current" alt="Current" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="linkedin" href="javascript:window.location='http%3A%2F%2Fwww.linkedin.com%2FshareArticle%3Fmini%3Dtrue%26amp%3Burl%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2009%252F07%252F20%252Fgrid-traversal%252F%26amp%3Btitle%3DGrid%2520Traversal%26amp%3Bsource%3DGame%2BRendering%2B%26amp%3Bsummary%3DProbably%2520the%25C2%25A0best%2520and%2520most%2520famous%2520grid%2520traversal%2520algorithm%2520uses%2520a%2520simple%2520loop%2520that%2520for%2520each%2520iteration%2520takes%2520one%2520more%2520step%2520in%2520the%2520grid.%2520It%2520works%2520in%2520both%25202D%2520and%25203D.%250D%250A%250D%250AJava%2520code%253A%250D%250A%2520%2520%2520public%2520boolean%2520isFreePath%2528float%2520startX%252C%2520float%2520startZ%252C%2520float%2520endX%252C%2520fl';" title="LinkedIn"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="live" href="javascript:window.location='https%3A%2F%2Ffavorites.live.com%2Fquickadd.aspx%3Fmarklet%3D1%26amp%3Burl%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2009%252F07%252F20%252Fgrid-traversal%252F%26amp%3Btitle%3DGrid%2520Traversal';" title="Live"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/live.png" title="Live" alt="Live" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="myspace" href="javascript:window.location='http%3A%2F%2Fwww.myspace.com%2FModules%2FPostTo%2FPages%2F%3Fu%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2009%252F07%252F20%252Fgrid-traversal%252F%26amp%3Bt%3DGrid%2520Traversal';" title="MySpace"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/myspace.png" title="MySpace" alt="MySpace" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="netvibes" href="javascript:window.location='http%3A%2F%2Fwww.netvibes.com%2Fshare%3Ftitle%3DGrid%2520Traversal%26amp%3Burl%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2009%252F07%252F20%252Fgrid-traversal%252F';" title="Netvibes"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/netvibes.png" title="Netvibes" alt="Netvibes" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="stumbleupon" href="javascript:window.location='http%3A%2F%2Fwww.stumbleupon.com%2Fsubmit%3Furl%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2009%252F07%252F20%252Fgrid-traversal%252F%26amp%3Btitle%3DGrid%2520Traversal';" title="StumbleUpon"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="twitter" href="javascript:window.location='http%3A%2F%2Ftwitter.com%2Fhome%3Fstatus%3DGrid%2520Traversal%2520-%2520http%253A%252F%252Fwww.gamerendering.com%252F2009%252F07%252F20%252Fgrid-traversal%252F';" title="Twitter"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="reddit" href="javascript:window.location='http%3A%2F%2Freddit.com%2Fsubmit%3Furl%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2009%252F07%252F20%252Fgrid-traversal%252F%26amp%3Btitle%3DGrid%2520Traversal';" title="Reddit"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="technorati" href="javascript:window.location='http%3A%2F%2Ftechnorati.com%2Ffaves%3Fadd%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2009%252F07%252F20%252Fgrid-traversal%252F';" title="Technorati"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow" id="yahoo! bookmarks" href="javascript:window.location='http%3A%2F%2Fbookmarks.yahoo.com%2Ftoolbar%2Fsavebm%3Fu%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2009%252F07%252F20%252Fgrid-traversal%252F%26amp%3Bt%3DGrid%2520Traversal%26opener%3Dbm%26amp%3Bei%3DUTF-8%26amp%3Bd%3DProbably%2520the%25C2%25A0best%2520and%2520most%2520famous%2520grid%2520traversal%2520algorithm%2520uses%2520a%2520simple%2520loop%2520that%2520for%2520each%2520iteration%2520takes%2520one%2520more%2520step%2520in%2520the%2520grid.%2520It%2520works%2520in%2520both%25202D%2520and%25203D.%250D%250A%250D%250AJava%2520code%253A%250D%250A%2520%2520%2520public%2520boolean%2520isFreePath%2528float%2520startX%252C%2520float%2520startZ%252C%2520float%2520endX%252C%2520fl';" title="Yahoo! Bookmarks"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/yahoomyweb.png" title="Yahoo! Bookmarks" alt="Yahoo! Bookmarks" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.gamerendering.com/2009/07/20/grid-traversal/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Random point in circle</title>
		<link>http://www.gamerendering.com/2009/03/26/random-point-in-circle/</link>
		<comments>http://www.gamerendering.com/2009/03/26/random-point-in-circle/#comments</comments>
		<pubDate>Wed, 25 Mar 2009 23:52:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Math]]></category>
		<category><![CDATA[Algorithm]]></category>
		<category><![CDATA[Circle]]></category>
		<category><![CDATA[Point]]></category>
		<category><![CDATA[Randomization]]></category>

		<guid isPermaLink="false">http://www.gamerendering.com/?p=603</guid>
		<description><![CDATA[The best algorithm to generate a point in a circle is to generate a point in a square with the same width as the circle diameter and then rerun the algorithm until this random point is inside the circle. This algorithm might need to run a couple of times before finding a suitable point but [...]]]></description>
			<content:encoded><![CDATA[<p>The best algorithm to generate a point in a circle is to generate a point in a square with the same width as the circle diameter and then rerun the algorithm until this random point is inside the circle. This algorithm might need to run a couple of times before finding a suitable point but will be faster than a more algorithmic solutions.</p>
<p>Pseudo code:</p>
<ol>
<li>Randomize a point in the square</li>
<li>If this point is outside the circle then jump to 1</li>
<li>Done</li>
</ol>

<div class="sociable">
<div class="sociable_tagline">
<strong>Please share:</strong>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow" id="print" href="javascript:window.location='http%3A%2F%2Fwww.printfriendly.com%2Fprint%3Furl%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2009%252F03%252F26%252Frandom-point-in-circle%252F%26amp%3Bpartner%3Dsociable';" title="Print this article!"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/printfriendly.png" title="Print this article!" alt="Print this article!" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="digg" href="javascript:window.location='http%3A%2F%2Fdigg.com%2Fsubmit%3Fphase%3D2%26amp%3Burl%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2009%252F03%252F26%252Frandom-point-in-circle%252F%26amp%3Btitle%3DRandom%2520point%2520in%2520circle%26amp%3Bbodytext%3DThe%2520best%2520algorithm%2520to%2520generate%2520a%2520point%2520in%2520a%2520circle%2520is%2520to%2520generate%2520a%2520point%2520in%2520a%2520square%2520with%2520the%2520same%2520width%2520as%2520the%2520circle%2520diameter%2520and%2520then%2520rerun%2520the%2520algorithm%2520until%2520this%2520random%2520point%2520is%2520inside%2520the%2520circle.%2520This%2520algorithm%2520might%2520need%2520to%2520run%2520a%2520couple%2520of%2520t';" title="Digg"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="sphinn" href="javascript:window.location='http%3A%2F%2Fsphinn.com%2Findex.php%3Fc%3Dpost%26m%3Dsubmit%26link%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2009%252F03%252F26%252Frandom-point-in-circle%252F';" title="Sphinn"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/sphinn.png" title="Sphinn" alt="Sphinn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="del.icio.us" href="javascript:window.location='http%3A%2F%2Fdelicious.com%2Fpost%3Furl%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2009%252F03%252F26%252Frandom-point-in-circle%252F%26amp%3Btitle%3DRandom%2520point%2520in%2520circle%26amp%3Bnotes%3DThe%2520best%2520algorithm%2520to%2520generate%2520a%2520point%2520in%2520a%2520circle%2520is%2520to%2520generate%2520a%2520point%2520in%2520a%2520square%2520with%2520the%2520same%2520width%2520as%2520the%2520circle%2520diameter%2520and%2520then%2520rerun%2520the%2520algorithm%2520until%2520this%2520random%2520point%2520is%2520inside%2520the%2520circle.%2520This%2520algorithm%2520might%2520need%2520to%2520run%2520a%2520couple%2520of%2520t';" title="del.icio.us"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="facebook" href="javascript:window.location='http%3A%2F%2Fwww.facebook.com%2Fshare.php%3Fu%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2009%252F03%252F26%252Frandom-point-in-circle%252F%26amp%3Bt%3DRandom%2520point%2520in%2520circle';" title="Facebook"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="mixx" href="javascript:window.location='http%3A%2F%2Fwww.mixx.com%2Fsubmit%3Fpage_url%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2009%252F03%252F26%252Frandom-point-in-circle%252F%26amp%3Btitle%3DRandom%2520point%2520in%2520circle';" title="Mixx"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="google" href="javascript:window.location='http%3A%2F%2Fwww.google.com%2Fbookmarks%2Fmark%3Fop%3Dedit%26amp%3Bbkmk%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2009%252F03%252F26%252Frandom-point-in-circle%252F%26amp%3Btitle%3DRandom%2520point%2520in%2520circle%26amp%3Bannotation%3DThe%2520best%2520algorithm%2520to%2520generate%2520a%2520point%2520in%2520a%2520circle%2520is%2520to%2520generate%2520a%2520point%2520in%2520a%2520square%2520with%2520the%2520same%2520width%2520as%2520the%2520circle%2520diameter%2520and%2520then%2520rerun%2520the%2520algorithm%2520until%2520this%2520random%2520point%2520is%2520inside%2520the%2520circle.%2520This%2520algorithm%2520might%2520need%2520to%2520run%2520a%2520couple%2520of%2520t';" title="Google Bookmarks"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="current" href="javascript:window.location='http%3A%2F%2Fcurrent.com%2Fclipper.htm%3Furl%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2009%252F03%252F26%252Frandom-point-in-circle%252F%26amp%3Btitle%3DRandom%2520point%2520in%2520circle';" title="Current"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/current.png" title="Current" alt="Current" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="linkedin" href="javascript:window.location='http%3A%2F%2Fwww.linkedin.com%2FshareArticle%3Fmini%3Dtrue%26amp%3Burl%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2009%252F03%252F26%252Frandom-point-in-circle%252F%26amp%3Btitle%3DRandom%2520point%2520in%2520circle%26amp%3Bsource%3DGame%2BRendering%2B%26amp%3Bsummary%3DThe%2520best%2520algorithm%2520to%2520generate%2520a%2520point%2520in%2520a%2520circle%2520is%2520to%2520generate%2520a%2520point%2520in%2520a%2520square%2520with%2520the%2520same%2520width%2520as%2520the%2520circle%2520diameter%2520and%2520then%2520rerun%2520the%2520algorithm%2520until%2520this%2520random%2520point%2520is%2520inside%2520the%2520circle.%2520This%2520algorithm%2520might%2520need%2520to%2520run%2520a%2520couple%2520of%2520t';" title="LinkedIn"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="live" href="javascript:window.location='https%3A%2F%2Ffavorites.live.com%2Fquickadd.aspx%3Fmarklet%3D1%26amp%3Burl%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2009%252F03%252F26%252Frandom-point-in-circle%252F%26amp%3Btitle%3DRandom%2520point%2520in%2520circle';" title="Live"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/live.png" title="Live" alt="Live" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="myspace" href="javascript:window.location='http%3A%2F%2Fwww.myspace.com%2FModules%2FPostTo%2FPages%2F%3Fu%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2009%252F03%252F26%252Frandom-point-in-circle%252F%26amp%3Bt%3DRandom%2520point%2520in%2520circle';" title="MySpace"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/myspace.png" title="MySpace" alt="MySpace" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="netvibes" href="javascript:window.location='http%3A%2F%2Fwww.netvibes.com%2Fshare%3Ftitle%3DRandom%2520point%2520in%2520circle%26amp%3Burl%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2009%252F03%252F26%252Frandom-point-in-circle%252F';" title="Netvibes"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/netvibes.png" title="Netvibes" alt="Netvibes" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="stumbleupon" href="javascript:window.location='http%3A%2F%2Fwww.stumbleupon.com%2Fsubmit%3Furl%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2009%252F03%252F26%252Frandom-point-in-circle%252F%26amp%3Btitle%3DRandom%2520point%2520in%2520circle';" title="StumbleUpon"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="twitter" href="javascript:window.location='http%3A%2F%2Ftwitter.com%2Fhome%3Fstatus%3DRandom%2520point%2520in%2520circle%2520-%2520http%253A%252F%252Fwww.gamerendering.com%252F2009%252F03%252F26%252Frandom-point-in-circle%252F';" title="Twitter"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="reddit" href="javascript:window.location='http%3A%2F%2Freddit.com%2Fsubmit%3Furl%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2009%252F03%252F26%252Frandom-point-in-circle%252F%26amp%3Btitle%3DRandom%2520point%2520in%2520circle';" title="Reddit"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="technorati" href="javascript:window.location='http%3A%2F%2Ftechnorati.com%2Ffaves%3Fadd%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2009%252F03%252F26%252Frandom-point-in-circle%252F';" title="Technorati"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow" id="yahoo! bookmarks" href="javascript:window.location='http%3A%2F%2Fbookmarks.yahoo.com%2Ftoolbar%2Fsavebm%3Fu%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2009%252F03%252F26%252Frandom-point-in-circle%252F%26amp%3Bt%3DRandom%2520point%2520in%2520circle%26opener%3Dbm%26amp%3Bei%3DUTF-8%26amp%3Bd%3DThe%2520best%2520algorithm%2520to%2520generate%2520a%2520point%2520in%2520a%2520circle%2520is%2520to%2520generate%2520a%2520point%2520in%2520a%2520square%2520with%2520the%2520same%2520width%2520as%2520the%2520circle%2520diameter%2520and%2520then%2520rerun%2520the%2520algorithm%2520until%2520this%2520random%2520point%2520is%2520inside%2520the%2520circle.%2520This%2520algorithm%2520might%2520need%2520to%2520run%2520a%2520couple%2520of%2520t';" title="Yahoo! Bookmarks"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/yahoomyweb.png" title="Yahoo! Bookmarks" alt="Yahoo! Bookmarks" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.gamerendering.com/2009/03/26/random-point-in-circle/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Tangent Space</title>
		<link>http://www.gamerendering.com/2008/10/17/tangent-space/</link>
		<comments>http://www.gamerendering.com/2008/10/17/tangent-space/#comments</comments>
		<pubDate>Fri, 17 Oct 2008 00:12:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Math]]></category>
		<category><![CDATA[Normal Mapping]]></category>
		<category><![CDATA[OpenGL]]></category>
		<category><![CDATA[Tangent space]]></category>
		<category><![CDATA[Textures]]></category>
		<category><![CDATA[Vertex]]></category>

		<guid isPermaLink="false">http://www.gamerendering.com/?p=374</guid>
		<description><![CDATA[Tangent space is (when speaking of rendering) the space built up by the vertex normal and the vertex texture coordinates often called  (u,v). This space is useful when dealing with textures with information in tangent space, for example a normal map.
The tangent space matrix can be separated in three vectors:
- The normal vector
- The tangent vector
- The bitangent vector
A detailed [...]]]></description>
			<content:encoded><![CDATA[<p>Tangent space is (when speaking of rendering) the space built up by the vertex normal and the vertex texture coordinates often called  (u,v). This space is useful when dealing with textures with information in tangent space, for example a normal map.</p>
<p>The tangent space matrix can be separated in three vectors:</p>
<p>- The normal vector</p>
<p>- The tangent vector</p>
<p>- The bitangent vector</p>
<p>A detailed description of how to create the tangent vector from the u,v coordinates. (including source code)<br />
<a href="http://www.terathon.com/code/tangent.html">http://www.terathon.com/code/tangent.html</a></p>
<p>More information about tangent Space (and an OpenGL implementation):<br />
<a href="http://jerome.jouvie.free.fr/OpenGl/Lessons/Lesson8.php">http://jerome.jouvie.free.fr/OpenGl/Lessons/Lesson8.php</a></p>

<div class="sociable">
<div class="sociable_tagline">
<strong>Please share:</strong>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow" id="print" href="javascript:window.location='http%3A%2F%2Fwww.printfriendly.com%2Fprint%3Furl%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2008%252F10%252F17%252Ftangent-space%252F%26amp%3Bpartner%3Dsociable';" title="Print this article!"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/printfriendly.png" title="Print this article!" alt="Print this article!" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="digg" href="javascript:window.location='http%3A%2F%2Fdigg.com%2Fsubmit%3Fphase%3D2%26amp%3Burl%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2008%252F10%252F17%252Ftangent-space%252F%26amp%3Btitle%3DTangent%2520Space%26amp%3Bbodytext%3DTangent%2520space%25C2%25A0is%2520%2528when%2520speaking%2520of%2520rendering%2529%25C2%25A0the%2520space%2520built%2520up%2520by%2520the%25C2%25A0vertex%2520normal%2520and%2520the%2520vertex%2520texture%2520coordinates%2520often%2520called%2520%25C2%25A0%2528u%252Cv%2529.%2520This%2520space%2520is%2520useful%2520when%2520dealing%2520with%2520textures%2520with%2520information%2520in%2520tangent%2520space%252C%2520for%2520example%2520a%2520normal%2520';" title="Digg"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="sphinn" href="javascript:window.location='http%3A%2F%2Fsphinn.com%2Findex.php%3Fc%3Dpost%26m%3Dsubmit%26link%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2008%252F10%252F17%252Ftangent-space%252F';" title="Sphinn"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/sphinn.png" title="Sphinn" alt="Sphinn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="del.icio.us" href="javascript:window.location='http%3A%2F%2Fdelicious.com%2Fpost%3Furl%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2008%252F10%252F17%252Ftangent-space%252F%26amp%3Btitle%3DTangent%2520Space%26amp%3Bnotes%3DTangent%2520space%25C2%25A0is%2520%2528when%2520speaking%2520of%2520rendering%2529%25C2%25A0the%2520space%2520built%2520up%2520by%2520the%25C2%25A0vertex%2520normal%2520and%2520the%2520vertex%2520texture%2520coordinates%2520often%2520called%2520%25C2%25A0%2528u%252Cv%2529.%2520This%2520space%2520is%2520useful%2520when%2520dealing%2520with%2520textures%2520with%2520information%2520in%2520tangent%2520space%252C%2520for%2520example%2520a%2520normal%2520';" title="del.icio.us"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="facebook" href="javascript:window.location='http%3A%2F%2Fwww.facebook.com%2Fshare.php%3Fu%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2008%252F10%252F17%252Ftangent-space%252F%26amp%3Bt%3DTangent%2520Space';" title="Facebook"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="mixx" href="javascript:window.location='http%3A%2F%2Fwww.mixx.com%2Fsubmit%3Fpage_url%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2008%252F10%252F17%252Ftangent-space%252F%26amp%3Btitle%3DTangent%2520Space';" title="Mixx"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="google" href="javascript:window.location='http%3A%2F%2Fwww.google.com%2Fbookmarks%2Fmark%3Fop%3Dedit%26amp%3Bbkmk%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2008%252F10%252F17%252Ftangent-space%252F%26amp%3Btitle%3DTangent%2520Space%26amp%3Bannotation%3DTangent%2520space%25C2%25A0is%2520%2528when%2520speaking%2520of%2520rendering%2529%25C2%25A0the%2520space%2520built%2520up%2520by%2520the%25C2%25A0vertex%2520normal%2520and%2520the%2520vertex%2520texture%2520coordinates%2520often%2520called%2520%25C2%25A0%2528u%252Cv%2529.%2520This%2520space%2520is%2520useful%2520when%2520dealing%2520with%2520textures%2520with%2520information%2520in%2520tangent%2520space%252C%2520for%2520example%2520a%2520normal%2520';" title="Google Bookmarks"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="current" href="javascript:window.location='http%3A%2F%2Fcurrent.com%2Fclipper.htm%3Furl%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2008%252F10%252F17%252Ftangent-space%252F%26amp%3Btitle%3DTangent%2520Space';" title="Current"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/current.png" title="Current" alt="Current" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="linkedin" href="javascript:window.location='http%3A%2F%2Fwww.linkedin.com%2FshareArticle%3Fmini%3Dtrue%26amp%3Burl%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2008%252F10%252F17%252Ftangent-space%252F%26amp%3Btitle%3DTangent%2520Space%26amp%3Bsource%3DGame%2BRendering%2B%26amp%3Bsummary%3DTangent%2520space%25C2%25A0is%2520%2528when%2520speaking%2520of%2520rendering%2529%25C2%25A0the%2520space%2520built%2520up%2520by%2520the%25C2%25A0vertex%2520normal%2520and%2520the%2520vertex%2520texture%2520coordinates%2520often%2520called%2520%25C2%25A0%2528u%252Cv%2529.%2520This%2520space%2520is%2520useful%2520when%2520dealing%2520with%2520textures%2520with%2520information%2520in%2520tangent%2520space%252C%2520for%2520example%2520a%2520normal%2520';" title="LinkedIn"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="live" href="javascript:window.location='https%3A%2F%2Ffavorites.live.com%2Fquickadd.aspx%3Fmarklet%3D1%26amp%3Burl%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2008%252F10%252F17%252Ftangent-space%252F%26amp%3Btitle%3DTangent%2520Space';" title="Live"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/live.png" title="Live" alt="Live" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="myspace" href="javascript:window.location='http%3A%2F%2Fwww.myspace.com%2FModules%2FPostTo%2FPages%2F%3Fu%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2008%252F10%252F17%252Ftangent-space%252F%26amp%3Bt%3DTangent%2520Space';" title="MySpace"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/myspace.png" title="MySpace" alt="MySpace" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="netvibes" href="javascript:window.location='http%3A%2F%2Fwww.netvibes.com%2Fshare%3Ftitle%3DTangent%2520Space%26amp%3Burl%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2008%252F10%252F17%252Ftangent-space%252F';" title="Netvibes"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/netvibes.png" title="Netvibes" alt="Netvibes" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="stumbleupon" href="javascript:window.location='http%3A%2F%2Fwww.stumbleupon.com%2Fsubmit%3Furl%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2008%252F10%252F17%252Ftangent-space%252F%26amp%3Btitle%3DTangent%2520Space';" title="StumbleUpon"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="twitter" href="javascript:window.location='http%3A%2F%2Ftwitter.com%2Fhome%3Fstatus%3DTangent%2520Space%2520-%2520http%253A%252F%252Fwww.gamerendering.com%252F2008%252F10%252F17%252Ftangent-space%252F';" title="Twitter"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="reddit" href="javascript:window.location='http%3A%2F%2Freddit.com%2Fsubmit%3Furl%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2008%252F10%252F17%252Ftangent-space%252F%26amp%3Btitle%3DTangent%2520Space';" title="Reddit"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="technorati" href="javascript:window.location='http%3A%2F%2Ftechnorati.com%2Ffaves%3Fadd%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2008%252F10%252F17%252Ftangent-space%252F';" title="Technorati"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow" id="yahoo! bookmarks" href="javascript:window.location='http%3A%2F%2Fbookmarks.yahoo.com%2Ftoolbar%2Fsavebm%3Fu%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2008%252F10%252F17%252Ftangent-space%252F%26amp%3Bt%3DTangent%2520Space%26opener%3Dbm%26amp%3Bei%3DUTF-8%26amp%3Bd%3DTangent%2520space%25C2%25A0is%2520%2528when%2520speaking%2520of%2520rendering%2529%25C2%25A0the%2520space%2520built%2520up%2520by%2520the%25C2%25A0vertex%2520normal%2520and%2520the%2520vertex%2520texture%2520coordinates%2520often%2520called%2520%25C2%25A0%2528u%252Cv%2529.%2520This%2520space%2520is%2520useful%2520when%2520dealing%2520with%2520textures%2520with%2520information%2520in%2520tangent%2520space%252C%2520for%2520example%2520a%2520normal%2520';" title="Yahoo! Bookmarks"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/yahoomyweb.png" title="Yahoo! Bookmarks" alt="Yahoo! Bookmarks" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.gamerendering.com/2008/10/17/tangent-space/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
