<?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; Optimizations</title>
	<atom:link href="http://www.gamerendering.com/category/optimizations/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>Texture Atlas</title>
		<link>http://www.gamerendering.com/2009/12/08/texture-atlas/</link>
		<comments>http://www.gamerendering.com/2009/12/08/texture-atlas/#comments</comments>
		<pubDate>Tue, 08 Dec 2009 11:07:21 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Optimizations]]></category>
		<category><![CDATA[batching]]></category>
		<category><![CDATA[mipmaps]]></category>
		<category><![CDATA[Nvidia]]></category>
		<category><![CDATA[Shaders]]></category>
		<category><![CDATA[Texture Atlas]]></category>
		<category><![CDATA[Texturing]]></category>
		<category><![CDATA[tiling]]></category>

		<guid isPermaLink="false">http://www.gamerendering.com/?p=742</guid>
		<description><![CDATA[Texture atlas [1][2] is a technique to group smaller textures into a larger texture. This decreases the number of state switches [3] a renderer needs to do and therefore often increases performance. Texture atlases have been used for a long time in the video game industry for sprite animations. When using texture atlases, the uv-coordinates of [...]]]></description>
			<content:encoded><![CDATA[<p style="MARGIN-BOTTOM: 0cm; FONT-WEIGHT: normal">Texture atlas [1][2] is a technique to group smaller textures into a larger texture. This decreases the number of state switches [3] a renderer needs to do and therefore often increases performance. Texture atlases have been used for a long time in the video game industry for sprite animations. When using texture atlases, the uv-coordinates of the models have to be changed so the original 0..1 map to the textures tile in the atlas. Grouping of textures can be done manually by texture artists or with tools. The texture coordinate system can be changed to map the new texture in a tool, or in the shader at run-time.</p>
<div class="mceTemp">
<dl id="attachment_743" class="wp-caption " style="width: 290px;">
<dt class="wp-caption-dt"><a href="http://www.gamerendering.com/wp-content/uploads/textureatlas.jpg"><img class="size-full wp-image-743" title="An example texture atlas" src="http://www.gamerendering.com/wp-content/uploads/textureatlas.jpg" alt="An example texture atlas" width="280" height="280" /></a></dt>
</dl>
</div>
<div class="mceTemp"><em>Image from article </em><a href="http://www.gamasutra.com/features/20060126/ivanov_01.shtml"><em>[2]</em></a></div>
<p style="MARGIN-BOTTOM: 0cm; FONT-WEIGHT: normal">There are some limitations with using texture atlases compared to normal textures. First of all, all texture coordinates must initially be within 0..1 range. So for example, no “free” tiling can be used. The other problem is bleeding between tiles in the atlas when doing filtering, for example when using mipmaps.</p>
<p style="MARGIN-BOTTOM: 0cm; FONT-WEIGHT: normal">Some additional information from Ivan-Assen Ivanov, author of article [2].</p>
<blockquote>
<p style="MARGIN-BOTTOM: 0cm; FONT-WEIGHT: normal"><em>&#8221; &#8211; separate textures hurts not only batching (in facts, it hurts batching less than years ago), but also memory – as there is a certain per-texture overhead. This is especially painful on consoles – on PCs, the overhead is still there, I guess, but the driver hides it from you. The exact numbers are under NDA, of course, but on an old, unreleased project, we saved about 9 MB by atlas-sing a category of textures we didn’t atlas before.</em></p>
<p><em>- vertex interpolators are expensive! make sure you measure the remapping from 0..1 to the actual UVs in the atlas both in the vertex and in the pixel shader. Sounds counterintuitive, but on modern GPUs and with dense geometry, pixel shader is actually faster.&#8221;</em> </p></blockquote>
<p style="MARGIN-BOTTOM: 0cm; FONT-WEIGHT: normal">[1] “Improve Batching Using Texture Atlases” <a href="http://http.download.nvidia.com/developer/NVTextureSuite/Atlas_Tools/Texture_Atlas_Whitepaper.pdf">http://http.download.nvidia.com/developer/NVTextureSuite/Atlas_Tools/Texture_Atlas_Whitepaper.pdf</a></p>
<p style="MARGIN-BOTTOM: 0cm; FONT-WEIGHT: normal">[2] &#8220;Practical Texture Atlases&#8221; (borrowed image from this page)<br />
<a href="http://www.gamasutra.com/features/20060126/ivanov_01.shtml">http://www.gamasutra.com/features/20060126/ivanov_01.shtml</a></p>
<p style="MARGIN-BOTTOM: 0cm; FONT-WEIGHT: normal">[3] &#8220;Batch, Batch, Batch: What Does It Really Mean?&#8221;<br />
<a href="http://developer.nvidia.com/docs/io/8230/batchbatchbatch.pdf">http://developer.nvidia.com/docs/io/8230/batchbatchbatch.pdf</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%252F08%252Ftexture-atlas%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%252F08%252Ftexture-atlas%252F%26amp%3Btitle%3DTexture%2520Atlas%26amp%3Bbodytext%3DTexture%2520atlas%2520%255B1%255D%255B2%255D%2520is%2520a%2520technique%2520to%2520group%2520smaller%2520textures%2520into%2520a%2520larger%2520texture.%2520This%2520decreases%2520the%2520number%2520of%2520state%2520switches%2520%255B3%255D%25C2%25A0a%2520renderer%2520needs%2520to%2520do%2520and%2520therefore%2520often%2520increases%2520performance.%2520Texture%2520atlases%2520have%2520been%2520used%2520for%2520a%2520long%2520time%2520in%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%252F2009%252F12%252F08%252Ftexture-atlas%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%252F08%252Ftexture-atlas%252F%26amp%3Btitle%3DTexture%2520Atlas%26amp%3Bnotes%3DTexture%2520atlas%2520%255B1%255D%255B2%255D%2520is%2520a%2520technique%2520to%2520group%2520smaller%2520textures%2520into%2520a%2520larger%2520texture.%2520This%2520decreases%2520the%2520number%2520of%2520state%2520switches%2520%255B3%255D%25C2%25A0a%2520renderer%2520needs%2520to%2520do%2520and%2520therefore%2520often%2520increases%2520performance.%2520Texture%2520atlases%2520have%2520been%2520used%2520for%2520a%2520long%2520time%2520in%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%252F2009%252F12%252F08%252Ftexture-atlas%252F%26amp%3Bt%3DTexture%2520Atlas';" 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%252F08%252Ftexture-atlas%252F%26amp%3Btitle%3DTexture%2520Atlas';" 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%252F08%252Ftexture-atlas%252F%26amp%3Btitle%3DTexture%2520Atlas%26amp%3Bannotation%3DTexture%2520atlas%2520%255B1%255D%255B2%255D%2520is%2520a%2520technique%2520to%2520group%2520smaller%2520textures%2520into%2520a%2520larger%2520texture.%2520This%2520decreases%2520the%2520number%2520of%2520state%2520switches%2520%255B3%255D%25C2%25A0a%2520renderer%2520needs%2520to%2520do%2520and%2520therefore%2520often%2520increases%2520performance.%2520Texture%2520atlases%2520have%2520been%2520used%2520for%2520a%2520long%2520time%2520in%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%252F2009%252F12%252F08%252Ftexture-atlas%252F%26amp%3Btitle%3DTexture%2520Atlas';" 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%252F08%252Ftexture-atlas%252F%26amp%3Btitle%3DTexture%2520Atlas%26amp%3Bsource%3DGame%2BRendering%2B%26amp%3Bsummary%3DTexture%2520atlas%2520%255B1%255D%255B2%255D%2520is%2520a%2520technique%2520to%2520group%2520smaller%2520textures%2520into%2520a%2520larger%2520texture.%2520This%2520decreases%2520the%2520number%2520of%2520state%2520switches%2520%255B3%255D%25C2%25A0a%2520renderer%2520needs%2520to%2520do%2520and%2520therefore%2520often%2520increases%2520performance.%2520Texture%2520atlases%2520have%2520been%2520used%2520for%2520a%2520long%2520time%2520in%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%252F2009%252F12%252F08%252Ftexture-atlas%252F%26amp%3Btitle%3DTexture%2520Atlas';" 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%252F08%252Ftexture-atlas%252F%26amp%3Bt%3DTexture%2520Atlas';" 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%3DTexture%2520Atlas%26amp%3Burl%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2009%252F12%252F08%252Ftexture-atlas%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%252F08%252Ftexture-atlas%252F%26amp%3Btitle%3DTexture%2520Atlas';" 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%3DTexture%2520Atlas%2520-%2520http%253A%252F%252Fwww.gamerendering.com%252F2009%252F12%252F08%252Ftexture-atlas%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%252F08%252Ftexture-atlas%252F%26amp%3Btitle%3DTexture%2520Atlas';" 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%252F08%252Ftexture-atlas%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%252F08%252Ftexture-atlas%252F%26amp%3Bt%3DTexture%2520Atlas%26opener%3Dbm%26amp%3Bei%3DUTF-8%26amp%3Bd%3DTexture%2520atlas%2520%255B1%255D%255B2%255D%2520is%2520a%2520technique%2520to%2520group%2520smaller%2520textures%2520into%2520a%2520larger%2520texture.%2520This%2520decreases%2520the%2520number%2520of%2520state%2520switches%2520%255B3%255D%25C2%25A0a%2520renderer%2520needs%2520to%2520do%2520and%2520therefore%2520often%2520increases%2520performance.%2520Texture%2520atlases%2520have%2520been%2520used%2520for%2520a%2520long%2520time%2520in%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/2009/12/08/texture-atlas/feed/</wfw:commentRss>
		<slash:comments>5</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="p6453"><td class="code" id="p645code3"><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="p6454"><td class="code" id="p645code4"><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>Cull Levels</title>
		<link>http://www.gamerendering.com/2008/11/17/cull-levels/</link>
		<comments>http://www.gamerendering.com/2008/11/17/cull-levels/#comments</comments>
		<pubDate>Mon, 17 Nov 2008 20:07:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Culling]]></category>
		<category><![CDATA[Batch]]></category>
		<category><![CDATA[Bounding Box]]></category>
		<category><![CDATA[Cull]]></category>
		<category><![CDATA[Object]]></category>
		<category><![CDATA[Triangle]]></category>
		<category><![CDATA[Triangle Count]]></category>
		<category><![CDATA[View Frustum Culling]]></category>

		<guid isPermaLink="false">http://www.gamerendering.com/?p=523</guid>
		<description><![CDATA[These are the different levels culling algorithms can work on.
Triangle Level
Description: Determine for each triangle if it should be culled or not.
Primary goal: Minimize triangle count.
Culling technique example: BSP 
Usage: Not used anymore, cost to much CPU.
Object Level
Description: Check each object (a group of triangles in one buffer) if they should be culled or not.
Primary goal: Minimize [...]]]></description>
			<content:encoded><![CDATA[<p>These are the different levels culling algorithms can work on.</p>
<p><strong>Triangle Level</strong></p>
<p>Description: Determine for each triangle if it should be culled or not.<br />
Primary goal: Minimize triangle count.<br />
Culling technique example: BSP <br />
Usage: Not used anymore, cost to much CPU.</p>
<p><strong>Object Level</strong></p>
<p>Description: Check each object (a group of triangles in one buffer) if they should be culled or not.<br />
Primary goal: Minimize triangle count and keep state changes low.<br />
Culling technique example: View Frustum Culling of Bounding Box Hierarchies<br />
Usage: Often used.</p>
<p><strong>Batch Level</strong></p>
<p>Description: Will check whole batches (a group of objects in one buffer)  if they should be culled or not.<br />
Primary goal: Minimize draw calls and triangle count.<br />
Culling technique example:  Uniform Grid Culling<br />
Usage: Often used.</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%252F11%252F17%252Fcull-levels%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%252F11%252F17%252Fcull-levels%252F%26amp%3Btitle%3DCull%2520Levels%26amp%3Bbodytext%3DThese%2520are%2520the%2520different%2520levels%2520culling%2520algorithms%2520can%2520work%2520on.%250D%250A%250D%250ATriangle%2520Level%250D%250A%250D%250ADescription%253A%2520Determine%2520for%2520each%2520triangle%2520if%2520it%2520should%2520be%2520culled%2520or%2520not.%250D%250APrimary%2520goal%253A%2520Minimize%2520triangle%2520count.%250D%250ACulling%2520technique%2520example%253A%2520BSP%25C2%25A0%250D%250AUsage%253A%2520Not%2520used%2520any';" 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%252F11%252F17%252Fcull-levels%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%252F11%252F17%252Fcull-levels%252F%26amp%3Btitle%3DCull%2520Levels%26amp%3Bnotes%3DThese%2520are%2520the%2520different%2520levels%2520culling%2520algorithms%2520can%2520work%2520on.%250D%250A%250D%250ATriangle%2520Level%250D%250A%250D%250ADescription%253A%2520Determine%2520for%2520each%2520triangle%2520if%2520it%2520should%2520be%2520culled%2520or%2520not.%250D%250APrimary%2520goal%253A%2520Minimize%2520triangle%2520count.%250D%250ACulling%2520technique%2520example%253A%2520BSP%25C2%25A0%250D%250AUsage%253A%2520Not%2520used%2520any';" 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%252F11%252F17%252Fcull-levels%252F%26amp%3Bt%3DCull%2520Levels';" 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%252F11%252F17%252Fcull-levels%252F%26amp%3Btitle%3DCull%2520Levels';" 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%252F11%252F17%252Fcull-levels%252F%26amp%3Btitle%3DCull%2520Levels%26amp%3Bannotation%3DThese%2520are%2520the%2520different%2520levels%2520culling%2520algorithms%2520can%2520work%2520on.%250D%250A%250D%250ATriangle%2520Level%250D%250A%250D%250ADescription%253A%2520Determine%2520for%2520each%2520triangle%2520if%2520it%2520should%2520be%2520culled%2520or%2520not.%250D%250APrimary%2520goal%253A%2520Minimize%2520triangle%2520count.%250D%250ACulling%2520technique%2520example%253A%2520BSP%25C2%25A0%250D%250AUsage%253A%2520Not%2520used%2520any';" 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%252F11%252F17%252Fcull-levels%252F%26amp%3Btitle%3DCull%2520Levels';" 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%252F11%252F17%252Fcull-levels%252F%26amp%3Btitle%3DCull%2520Levels%26amp%3Bsource%3DGame%2BRendering%2B%26amp%3Bsummary%3DThese%2520are%2520the%2520different%2520levels%2520culling%2520algorithms%2520can%2520work%2520on.%250D%250A%250D%250ATriangle%2520Level%250D%250A%250D%250ADescription%253A%2520Determine%2520for%2520each%2520triangle%2520if%2520it%2520should%2520be%2520culled%2520or%2520not.%250D%250APrimary%2520goal%253A%2520Minimize%2520triangle%2520count.%250D%250ACulling%2520technique%2520example%253A%2520BSP%25C2%25A0%250D%250AUsage%253A%2520Not%2520used%2520any';" 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%252F11%252F17%252Fcull-levels%252F%26amp%3Btitle%3DCull%2520Levels';" 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%252F11%252F17%252Fcull-levels%252F%26amp%3Bt%3DCull%2520Levels';" 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%3DCull%2520Levels%26amp%3Burl%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2008%252F11%252F17%252Fcull-levels%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%252F11%252F17%252Fcull-levels%252F%26amp%3Btitle%3DCull%2520Levels';" 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%3DCull%2520Levels%2520-%2520http%253A%252F%252Fwww.gamerendering.com%252F2008%252F11%252F17%252Fcull-levels%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%252F11%252F17%252Fcull-levels%252F%26amp%3Btitle%3DCull%2520Levels';" 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%252F11%252F17%252Fcull-levels%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%252F11%252F17%252Fcull-levels%252F%26amp%3Bt%3DCull%2520Levels%26opener%3Dbm%26amp%3Bei%3DUTF-8%26amp%3Bd%3DThese%2520are%2520the%2520different%2520levels%2520culling%2520algorithms%2520can%2520work%2520on.%250D%250A%250D%250ATriangle%2520Level%250D%250A%250D%250ADescription%253A%2520Determine%2520for%2520each%2520triangle%2520if%2520it%2520should%2520be%2520culled%2520or%2520not.%250D%250APrimary%2520goal%253A%2520Minimize%2520triangle%2520count.%250D%250ACulling%2520technique%2520example%253A%2520BSP%25C2%25A0%250D%250AUsage%253A%2520Not%2520used%2520any';" 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/11/17/cull-levels/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Basic Culling Techniques</title>
		<link>http://www.gamerendering.com/2008/11/02/basic-culling-techniques/</link>
		<comments>http://www.gamerendering.com/2008/11/02/basic-culling-techniques/#comments</comments>
		<pubDate>Sun, 02 Nov 2008 00:46:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Culling]]></category>
		<category><![CDATA[Back Face Culling]]></category>
		<category><![CDATA[Bounding Volume]]></category>
		<category><![CDATA[BSP]]></category>
		<category><![CDATA[Occlusion Culling]]></category>
		<category><![CDATA[Octree]]></category>
		<category><![CDATA[Optimization]]></category>
		<category><![CDATA[Optimizations]]></category>
		<category><![CDATA[Portal Culling]]></category>
		<category><![CDATA[Spatial Structure]]></category>
		<category><![CDATA[View Frustum Culling]]></category>

		<guid isPermaLink="false">http://www.gamerendering.com/?p=447</guid>
		<description><![CDATA[The best optimization when rendering is to not render anything unnecessary. And that is what culling is about, to find out what can be skipped when rendering because it cannot be visible anyway.  Below are the basic culling techniques which most renderers&#8217; implements. The image is from a course slide.

Back Face Culling
Faces that faces away from the camera can [...]]]></description>
			<content:encoded><![CDATA[<p>The best optimization when rendering is to not render anything unnecessary. And that is what culling is about, to find out what can be skipped when rendering because it cannot be visible anyway.  Below are the basic culling techniques which most renderers&#8217; implements. The image is from a course slide.</p>
<div class="mceTemp"><a href="http://www.gamerendering.com/wp-content/uploads/culling.jpg"><img class="size-medium wp-image-448" title="Culling Techniques" src="http://www.gamerendering.com/wp-content/uploads/culling-400x233.jpg" alt="Culling Techniques" width="400" height="233" /></a></div>
<p><strong>Back Face Culling</strong></p>
<p>Faces that faces away from the camera can not be visible on the screen so they don&#8217;t need to be drawn. This is so often used that it&#8217;s implemented by the hardware. It roughly cuts the amount of faces drawn in half. Just remember to turn it on!</p>
<p><strong>View frustum Culling</strong></p>
<p>The faces that is outside the view frustum can not be visible on the screen (we don&#8217;t bother about reflections now) so they can be culled. This check is done by checking if the geometries bounding volume is outside the view frustum volume or not. So the check will not be done on every face, as that would cost to much. Sometimes, the view frustum culling can cost more than what is gain ( for example when doing instancing). One way to speed up view frustum culling is to use a suitable spatial structure for the scene (octree, BSP or so).</p>
<p>All kind of bounding volume test that you can imagine can be found on this page:<br />
<a href="http://www.realtimerendering.com/intersections.html">http://www.realtimerendering.com/intersections.html</a></p>
<p>Info about frustum culling:<br />
<a href="http://www.flipcode.com/archives/Frustum_Culling.shtml">http://www.flipcode.com/archives/Frustum_Culling.shtml</a></p>
<p><strong>Portal Culling</strong></p>
<p>A technique that divides the scene into cells with portals between. When rendering, the camera will be in one of the rooms and that room will be rendered normally. But for each portal that is visible in the room a view frustum is set up for the size of the portal and then the room behind it is rendered. This will work recursively. The result will be that a lot of geometry can be culled by view frustum culling when rendering the other rooms. A very useful technique for indoor scenes.</p>
<p><strong>Detail Culling</strong></p>
<p>When a geometry is so far away that it&#8217;s not visible then there is no need to draw it at all so it can safely be culled. A more advanced scheme of detail culling that decreases the amount of details with the distance is LOD (level of detail).</p>
<p><strong>Occlusion Culling</strong></p>
<p>The hardest culling technique to implement. Geometry that is occluded by other geometry does not need to be rendered. One solution is to use the Z-buffer and sort the geometry in a front to back order. But this does not always work and all pixels needs to be checked against the Z-buffer so it will be costly for big scenes. Better occlusion culling techniques culls the geometry before it&#8217;s even sent to the GPU.</p>
<p>A good link to a couple of occlusion culling techniques<br />
<a href="http://www.gamasutra.com/features/19991109/moller_haines_01.htm">http://www.gamasutra.com/features/19991109/moller_haines_01.htm</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%252F11%252F02%252Fbasic-culling-techniques%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%252F11%252F02%252Fbasic-culling-techniques%252F%26amp%3Btitle%3DBasic%2520Culling%2520Techniques%26amp%3Bbodytext%3DThe%2520best%2520optimization%2520when%2520rendering%2520is%2520to%2520not%2520render%2520anything%2520unnecessary.%2520And%2520that%2520is%2520what%2520culling%2520is%2520about%252C%2520to%2520find%2520out%2520what%25C2%25A0can%2520be%2520skipped%2520when%2520rendering%2520because%2520it%2520cannot%2520be%2520visible%2520anyway.%25C2%25A0%25C2%25A0Below%2520are%2520the%2520basic%2520culling%2520techniques%2520which%2520most%2520r';" 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%252F11%252F02%252Fbasic-culling-techniques%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%252F11%252F02%252Fbasic-culling-techniques%252F%26amp%3Btitle%3DBasic%2520Culling%2520Techniques%26amp%3Bnotes%3DThe%2520best%2520optimization%2520when%2520rendering%2520is%2520to%2520not%2520render%2520anything%2520unnecessary.%2520And%2520that%2520is%2520what%2520culling%2520is%2520about%252C%2520to%2520find%2520out%2520what%25C2%25A0can%2520be%2520skipped%2520when%2520rendering%2520because%2520it%2520cannot%2520be%2520visible%2520anyway.%25C2%25A0%25C2%25A0Below%2520are%2520the%2520basic%2520culling%2520techniques%2520which%2520most%2520r';" 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%252F11%252F02%252Fbasic-culling-techniques%252F%26amp%3Bt%3DBasic%2520Culling%2520Techniques';" 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%252F11%252F02%252Fbasic-culling-techniques%252F%26amp%3Btitle%3DBasic%2520Culling%2520Techniques';" 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%252F11%252F02%252Fbasic-culling-techniques%252F%26amp%3Btitle%3DBasic%2520Culling%2520Techniques%26amp%3Bannotation%3DThe%2520best%2520optimization%2520when%2520rendering%2520is%2520to%2520not%2520render%2520anything%2520unnecessary.%2520And%2520that%2520is%2520what%2520culling%2520is%2520about%252C%2520to%2520find%2520out%2520what%25C2%25A0can%2520be%2520skipped%2520when%2520rendering%2520because%2520it%2520cannot%2520be%2520visible%2520anyway.%25C2%25A0%25C2%25A0Below%2520are%2520the%2520basic%2520culling%2520techniques%2520which%2520most%2520r';" 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%252F11%252F02%252Fbasic-culling-techniques%252F%26amp%3Btitle%3DBasic%2520Culling%2520Techniques';" 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%252F11%252F02%252Fbasic-culling-techniques%252F%26amp%3Btitle%3DBasic%2520Culling%2520Techniques%26amp%3Bsource%3DGame%2BRendering%2B%26amp%3Bsummary%3DThe%2520best%2520optimization%2520when%2520rendering%2520is%2520to%2520not%2520render%2520anything%2520unnecessary.%2520And%2520that%2520is%2520what%2520culling%2520is%2520about%252C%2520to%2520find%2520out%2520what%25C2%25A0can%2520be%2520skipped%2520when%2520rendering%2520because%2520it%2520cannot%2520be%2520visible%2520anyway.%25C2%25A0%25C2%25A0Below%2520are%2520the%2520basic%2520culling%2520techniques%2520which%2520most%2520r';" 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%252F11%252F02%252Fbasic-culling-techniques%252F%26amp%3Btitle%3DBasic%2520Culling%2520Techniques';" 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%252F11%252F02%252Fbasic-culling-techniques%252F%26amp%3Bt%3DBasic%2520Culling%2520Techniques';" 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%3DBasic%2520Culling%2520Techniques%26amp%3Burl%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2008%252F11%252F02%252Fbasic-culling-techniques%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%252F11%252F02%252Fbasic-culling-techniques%252F%26amp%3Btitle%3DBasic%2520Culling%2520Techniques';" 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%3DBasic%2520Culling%2520Techniques%2520-%2520http%253A%252F%252Fwww.gamerendering.com%252F2008%252F11%252F02%252Fbasic-culling-techniques%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%252F11%252F02%252Fbasic-culling-techniques%252F%26amp%3Btitle%3DBasic%2520Culling%2520Techniques';" 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%252F11%252F02%252Fbasic-culling-techniques%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%252F11%252F02%252Fbasic-culling-techniques%252F%26amp%3Bt%3DBasic%2520Culling%2520Techniques%26opener%3Dbm%26amp%3Bei%3DUTF-8%26amp%3Bd%3DThe%2520best%2520optimization%2520when%2520rendering%2520is%2520to%2520not%2520render%2520anything%2520unnecessary.%2520And%2520that%2520is%2520what%2520culling%2520is%2520about%252C%2520to%2520find%2520out%2520what%25C2%25A0can%2520be%2520skipped%2520when%2520rendering%2520because%2520it%2520cannot%2520be%2520visible%2520anyway.%25C2%25A0%25C2%25A0Below%2520are%2520the%2520basic%2520culling%2520techniques%2520which%2520most%2520r';" 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/11/02/basic-culling-techniques/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
