<?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; Optimization</title>
	<atom:link href="http://www.gamerendering.com/tag/optimization/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>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>Percentage Closer Filtering for Shadow Mapping</title>
		<link>http://www.gamerendering.com/2008/11/15/percentage-closer-filtering-for-shadow-mapping/</link>
		<comments>http://www.gamerendering.com/2008/11/15/percentage-closer-filtering-for-shadow-mapping/#comments</comments>
		<pubDate>Sat, 15 Nov 2008 15:08:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Shadow Mapping]]></category>
		<category><![CDATA[Bilinear Interpolation]]></category>
		<category><![CDATA[Fetch4]]></category>
		<category><![CDATA[Filtering]]></category>
		<category><![CDATA[GLSL]]></category>
		<category><![CDATA[Optimization]]></category>
		<category><![CDATA[PCF]]></category>
		<category><![CDATA[Percentage Closer Filtering]]></category>
		<category><![CDATA[Shadows]]></category>

		<guid isPermaLink="false">http://www.gamerendering.com/?p=505</guid>
		<description><![CDATA[This is a technique for making softer shadows when doing shadow mapping. It works by filtering the result of the depth comparison. So when comparing a depth, some depths around should also be compared and the result should be averaged. This will give a softer look on the shadow edges.

It can be implemented as simple as this in [...]]]></description>
			<content:encoded><![CDATA[<p>This is a technique for making softer shadows when doing shadow mapping. It works by filtering the result of the depth comparison. So when comparing a depth, some depths around should also be compared and the result should be averaged. This will give a softer look on the shadow edges.</p>
<div class="mceTemp"><a href="http://www.gamerendering.com/wp-content/uploads/pcf.jpg"><img class="size-medium wp-image-509" title="An example of the the soft shadows when using PCF Shadow Mapping" src="http://www.gamerendering.com/wp-content/uploads/pcf.jpg" alt="An example of the the soft shadows when using PCF Shadow Mapping" width="370" height="252" /></a></div>
<p>It can be implemented as simple as this in a the pixel shader:</p>

<div class="wp_codebox"><table width="100%" ><tr id="p5056"><td class="code" id="p505code6"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">float</span> result<span style="color: #339933;">;</span>
result <span style="color: #339933;">=</span> shadow2DProj<span style="color: #009900;">&#40;</span>shadowMap<span style="color: #339933;">,</span>texCoord<span style="color: #339933;">+</span>offset<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
result <span style="color: #339933;">+=</span> shadow2DProj<span style="color: #009900;">&#40;</span>shadowMap<span style="color: #339933;">,</span>texCoord<span style="color: #339933;">+</span>offset<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
result <span style="color: #339933;">+=</span> shadow2DProj<span style="color: #009900;">&#40;</span>shadowMap<span style="color: #339933;">,</span>texCoord<span style="color: #339933;">+</span>offset<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
result <span style="color: #339933;">+=</span> shadow2DProj<span style="color: #009900;">&#40;</span>shadowMap<span style="color: #339933;">,</span>texCoord<span style="color: #339933;">+</span>offset<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
result <span style="color: #339933;">/=</span> <span style="color:#800080;">4.0</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// now result will hold the average shading</span></pre></td></tr></table></div>

<p>The samples are often either taken in a grid-based square around the original sample location or randomly scattered around it.</p>
<p><strong>Optimization:</strong></p>
<p>NVIDIA has built in hardware support for doing bilinear interpolation between four samples.</p>
<p>ATI has fetch4 which will fetch four texture samples at the same time.  </p>
<p>The original paper for PCF:<br />
<a href="http://graphics.pixar.com/library/ShadowMaps/paper.pdf">http://graphics.pixar.com/library/ShadowMaps/paper.pdf</a></p>
<p>A technique that is similar (percentage-closer soft shadows)<br />
<a href="http://developer.download.nvidia.com/shaderlibrary/docs/shadow_PCSS.pdf">http://developer.download.nvidia.com/shaderlibrary/docs/shadow_PCSS.pdf</a></p>
<p>A paper including lot&#8217;s of shadow mapping information, including different ways to do PCF (the image in this article is borrowed from this presentation):<br />
<a href="http://developer.amd.com/media/gpu_assets/Isidoro-ShadowMapping.pdf">http://developer.amd.com/media/gpu_assets/Isidoro-ShadowMapping.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%252F2008%252F11%252F15%252Fpercentage-closer-filtering-for-shadow-mapping%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%252F15%252Fpercentage-closer-filtering-for-shadow-mapping%252F%26amp%3Btitle%3DPercentage%2520Closer%2520Filtering%2520for%2520Shadow%2520Mapping%26amp%3Bbodytext%3DThis%2520is%2520a%2520technique%2520for%2520making%2520softer%2520shadows%2520when%2520doing%2520shadow%2520mapping.%2520It%2520works%2520by%2520filtering%2520the%2520result%2520of%2520the%2520depth%2520comparison.%2520So%2520when%2520comparing%2520a%2520depth%252C%2520some%2520depths%2520around%2520should%2520also%2520be%2520compared%2520and%2520the%2520result%2520should%2520be%2520averaged.%2520This%2520will%2520give';" 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%252F15%252Fpercentage-closer-filtering-for-shadow-mapping%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%252F15%252Fpercentage-closer-filtering-for-shadow-mapping%252F%26amp%3Btitle%3DPercentage%2520Closer%2520Filtering%2520for%2520Shadow%2520Mapping%26amp%3Bnotes%3DThis%2520is%2520a%2520technique%2520for%2520making%2520softer%2520shadows%2520when%2520doing%2520shadow%2520mapping.%2520It%2520works%2520by%2520filtering%2520the%2520result%2520of%2520the%2520depth%2520comparison.%2520So%2520when%2520comparing%2520a%2520depth%252C%2520some%2520depths%2520around%2520should%2520also%2520be%2520compared%2520and%2520the%2520result%2520should%2520be%2520averaged.%2520This%2520will%2520give';" 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%252F15%252Fpercentage-closer-filtering-for-shadow-mapping%252F%26amp%3Bt%3DPercentage%2520Closer%2520Filtering%2520for%2520Shadow%2520Mapping';" 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%252F15%252Fpercentage-closer-filtering-for-shadow-mapping%252F%26amp%3Btitle%3DPercentage%2520Closer%2520Filtering%2520for%2520Shadow%2520Mapping';" 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%252F15%252Fpercentage-closer-filtering-for-shadow-mapping%252F%26amp%3Btitle%3DPercentage%2520Closer%2520Filtering%2520for%2520Shadow%2520Mapping%26amp%3Bannotation%3DThis%2520is%2520a%2520technique%2520for%2520making%2520softer%2520shadows%2520when%2520doing%2520shadow%2520mapping.%2520It%2520works%2520by%2520filtering%2520the%2520result%2520of%2520the%2520depth%2520comparison.%2520So%2520when%2520comparing%2520a%2520depth%252C%2520some%2520depths%2520around%2520should%2520also%2520be%2520compared%2520and%2520the%2520result%2520should%2520be%2520averaged.%2520This%2520will%2520give';" 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%252F15%252Fpercentage-closer-filtering-for-shadow-mapping%252F%26amp%3Btitle%3DPercentage%2520Closer%2520Filtering%2520for%2520Shadow%2520Mapping';" 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%252F15%252Fpercentage-closer-filtering-for-shadow-mapping%252F%26amp%3Btitle%3DPercentage%2520Closer%2520Filtering%2520for%2520Shadow%2520Mapping%26amp%3Bsource%3DGame%2BRendering%2B%26amp%3Bsummary%3DThis%2520is%2520a%2520technique%2520for%2520making%2520softer%2520shadows%2520when%2520doing%2520shadow%2520mapping.%2520It%2520works%2520by%2520filtering%2520the%2520result%2520of%2520the%2520depth%2520comparison.%2520So%2520when%2520comparing%2520a%2520depth%252C%2520some%2520depths%2520around%2520should%2520also%2520be%2520compared%2520and%2520the%2520result%2520should%2520be%2520averaged.%2520This%2520will%2520give';" 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%252F15%252Fpercentage-closer-filtering-for-shadow-mapping%252F%26amp%3Btitle%3DPercentage%2520Closer%2520Filtering%2520for%2520Shadow%2520Mapping';" 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%252F15%252Fpercentage-closer-filtering-for-shadow-mapping%252F%26amp%3Bt%3DPercentage%2520Closer%2520Filtering%2520for%2520Shadow%2520Mapping';" 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%3DPercentage%2520Closer%2520Filtering%2520for%2520Shadow%2520Mapping%26amp%3Burl%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2008%252F11%252F15%252Fpercentage-closer-filtering-for-shadow-mapping%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%252F15%252Fpercentage-closer-filtering-for-shadow-mapping%252F%26amp%3Btitle%3DPercentage%2520Closer%2520Filtering%2520for%2520Shadow%2520Mapping';" 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%3DPercentage%2520Closer%2520Filtering%2520for%2520Shadow%2520Mapping%2520-%2520http%253A%252F%252Fwww.gamerendering.com%252F2008%252F11%252F15%252Fpercentage-closer-filtering-for-shadow-mapping%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%252F15%252Fpercentage-closer-filtering-for-shadow-mapping%252F%26amp%3Btitle%3DPercentage%2520Closer%2520Filtering%2520for%2520Shadow%2520Mapping';" 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%252F15%252Fpercentage-closer-filtering-for-shadow-mapping%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%252F15%252Fpercentage-closer-filtering-for-shadow-mapping%252F%26amp%3Bt%3DPercentage%2520Closer%2520Filtering%2520for%2520Shadow%2520Mapping%26opener%3Dbm%26amp%3Bei%3DUTF-8%26amp%3Bd%3DThis%2520is%2520a%2520technique%2520for%2520making%2520softer%2520shadows%2520when%2520doing%2520shadow%2520mapping.%2520It%2520works%2520by%2520filtering%2520the%2520result%2520of%2520the%2520depth%2520comparison.%2520So%2520when%2520comparing%2520a%2520depth%252C%2520some%2520depths%2520around%2520should%2520also%2520be%2520compared%2520and%2520the%2520result%2520should%2520be%2520averaged.%2520This%2520will%2520give';" 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/15/percentage-closer-filtering-for-shadow-mapping/feed/</wfw:commentRss>
		<slash:comments>1</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>
		<item>
		<title>Quadtree</title>
		<link>http://www.gamerendering.com/2008/10/17/quadtree/</link>
		<comments>http://www.gamerendering.com/2008/10/17/quadtree/#comments</comments>
		<pubDate>Thu, 16 Oct 2008 23:05:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Spatial Data Structure]]></category>
		<category><![CDATA[Collision Detection]]></category>
		<category><![CDATA[Culling]]></category>
		<category><![CDATA[Optimization]]></category>
		<category><![CDATA[Quadtree]]></category>
		<category><![CDATA[Rendering]]></category>

		<guid isPermaLink="false">http://www.gamerendering.com/?p=362</guid>
		<description><![CDATA[Nearly the same as a Octree but instead of dividing the space in cuboids in 3D it&#8217;s rectangles in 2D space. This is useful for rendering terrain and you want to cull a lot of the terrain fast.

A visual demonstration of a quadtree used for fast collision detection:
http://lab.polygonal.de/2007/09/09/quadtree-demonstration/
Introduction to quadtrees and sample code:
http://www.gamedev.net/reference/programming/features/quadtrees/
More info about quadtrees, including source:
http://www.kyleschouviller.com/wsuxna/quadtree-source-included/



Please share:


	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	


]]></description>
			<content:encoded><![CDATA[<p>Nearly the same as a <a title="Octree" href="http://www.gamerendering.com/2008/10/14/octree/">Octree</a> but instead of dividing the space in cuboids in 3D it&#8217;s rectangles in 2D space. This is useful for rendering terrain and you want to cull a lot of the terrain fast.</p>
<div class="mceTemp"><a href="http://www.gamerendering.com/wp-content/uploads/quadtree.jpg"><img class="size-medium wp-image-363" title="Example of the creation of a quadtree" src="http://www.gamerendering.com/wp-content/uploads/quadtree.jpg" alt="Example of the creation of a quadtree" width="252" height="251" /></a></div>
<p>A visual demonstration of a quadtree used for fast collision detection:<br />
<a href="http://lab.polygonal.de/2007/09/09/quadtree-demonstration/">http://lab.polygonal.de/2007/09/09/quadtree-demonstration/</a></p>
<p>Introduction to quadtrees and sample code:<br />
<a href="http://www.gamedev.net/reference/programming/features/quadtrees/">http://www.gamedev.net/reference/programming/features/quadtrees/</a></p>
<p>More info about quadtrees, including source:<br />
<a href="http://www.kyleschouviller.com/wsuxna/quadtree-source-included/">http://www.kyleschouviller.com/wsuxna/quadtree-source-included/</a></p>

<div class="sociable">
<div class="sociable_tagline">
<strong>Please share:</strong>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow" id="print" href="javascript:window.location='http%3A%2F%2Fwww.printfriendly.com%2Fprint%3Furl%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2008%252F10%252F17%252Fquadtree%252F%26amp%3Bpartner%3Dsociable';" title="Print this article!"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/printfriendly.png" title="Print this article!" alt="Print this article!" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="digg" href="javascript:window.location='http%3A%2F%2Fdigg.com%2Fsubmit%3Fphase%3D2%26amp%3Burl%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2008%252F10%252F17%252Fquadtree%252F%26amp%3Btitle%3DQuadtree%26amp%3Bbodytext%3DNearly%2520the%2520same%2520as%2520a%2520Octree%25C2%25A0but%2520instead%2520of%2520dividing%2520the%2520space%2520in%2520cuboids%2520in%25C2%25A03D%25C2%25A0it%2527s%2520rectangles%2520in%25202D%2520space.%2520This%2520is%2520useful%2520for%2520rendering%2520terrain%2520and%2520you%2520want%2520to%2520cull%2520a%2520lot%2520of%2520the%25C2%25A0terrain%2520fast.%250D%250A%250D%250AA%2520visual%2520demonstration%2520of%2520a%2520quadtree%2520used%2520for%2520fast';" title="Digg"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="sphinn" href="javascript:window.location='http%3A%2F%2Fsphinn.com%2Findex.php%3Fc%3Dpost%26m%3Dsubmit%26link%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2008%252F10%252F17%252Fquadtree%252F';" title="Sphinn"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/sphinn.png" title="Sphinn" alt="Sphinn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="del.icio.us" href="javascript:window.location='http%3A%2F%2Fdelicious.com%2Fpost%3Furl%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2008%252F10%252F17%252Fquadtree%252F%26amp%3Btitle%3DQuadtree%26amp%3Bnotes%3DNearly%2520the%2520same%2520as%2520a%2520Octree%25C2%25A0but%2520instead%2520of%2520dividing%2520the%2520space%2520in%2520cuboids%2520in%25C2%25A03D%25C2%25A0it%2527s%2520rectangles%2520in%25202D%2520space.%2520This%2520is%2520useful%2520for%2520rendering%2520terrain%2520and%2520you%2520want%2520to%2520cull%2520a%2520lot%2520of%2520the%25C2%25A0terrain%2520fast.%250D%250A%250D%250AA%2520visual%2520demonstration%2520of%2520a%2520quadtree%2520used%2520for%2520fast';" title="del.icio.us"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="facebook" href="javascript:window.location='http%3A%2F%2Fwww.facebook.com%2Fshare.php%3Fu%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2008%252F10%252F17%252Fquadtree%252F%26amp%3Bt%3DQuadtree';" title="Facebook"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="mixx" href="javascript:window.location='http%3A%2F%2Fwww.mixx.com%2Fsubmit%3Fpage_url%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2008%252F10%252F17%252Fquadtree%252F%26amp%3Btitle%3DQuadtree';" title="Mixx"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="google" href="javascript:window.location='http%3A%2F%2Fwww.google.com%2Fbookmarks%2Fmark%3Fop%3Dedit%26amp%3Bbkmk%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2008%252F10%252F17%252Fquadtree%252F%26amp%3Btitle%3DQuadtree%26amp%3Bannotation%3DNearly%2520the%2520same%2520as%2520a%2520Octree%25C2%25A0but%2520instead%2520of%2520dividing%2520the%2520space%2520in%2520cuboids%2520in%25C2%25A03D%25C2%25A0it%2527s%2520rectangles%2520in%25202D%2520space.%2520This%2520is%2520useful%2520for%2520rendering%2520terrain%2520and%2520you%2520want%2520to%2520cull%2520a%2520lot%2520of%2520the%25C2%25A0terrain%2520fast.%250D%250A%250D%250AA%2520visual%2520demonstration%2520of%2520a%2520quadtree%2520used%2520for%2520fast';" title="Google Bookmarks"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="current" href="javascript:window.location='http%3A%2F%2Fcurrent.com%2Fclipper.htm%3Furl%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2008%252F10%252F17%252Fquadtree%252F%26amp%3Btitle%3DQuadtree';" title="Current"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/current.png" title="Current" alt="Current" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="linkedin" href="javascript:window.location='http%3A%2F%2Fwww.linkedin.com%2FshareArticle%3Fmini%3Dtrue%26amp%3Burl%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2008%252F10%252F17%252Fquadtree%252F%26amp%3Btitle%3DQuadtree%26amp%3Bsource%3DGame%2BRendering%2B%26amp%3Bsummary%3DNearly%2520the%2520same%2520as%2520a%2520Octree%25C2%25A0but%2520instead%2520of%2520dividing%2520the%2520space%2520in%2520cuboids%2520in%25C2%25A03D%25C2%25A0it%2527s%2520rectangles%2520in%25202D%2520space.%2520This%2520is%2520useful%2520for%2520rendering%2520terrain%2520and%2520you%2520want%2520to%2520cull%2520a%2520lot%2520of%2520the%25C2%25A0terrain%2520fast.%250D%250A%250D%250AA%2520visual%2520demonstration%2520of%2520a%2520quadtree%2520used%2520for%2520fast';" title="LinkedIn"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="live" href="javascript:window.location='https%3A%2F%2Ffavorites.live.com%2Fquickadd.aspx%3Fmarklet%3D1%26amp%3Burl%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2008%252F10%252F17%252Fquadtree%252F%26amp%3Btitle%3DQuadtree';" title="Live"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/live.png" title="Live" alt="Live" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="myspace" href="javascript:window.location='http%3A%2F%2Fwww.myspace.com%2FModules%2FPostTo%2FPages%2F%3Fu%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2008%252F10%252F17%252Fquadtree%252F%26amp%3Bt%3DQuadtree';" 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%3DQuadtree%26amp%3Burl%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2008%252F10%252F17%252Fquadtree%252F';" title="Netvibes"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/netvibes.png" title="Netvibes" alt="Netvibes" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="stumbleupon" href="javascript:window.location='http%3A%2F%2Fwww.stumbleupon.com%2Fsubmit%3Furl%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2008%252F10%252F17%252Fquadtree%252F%26amp%3Btitle%3DQuadtree';" 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%3DQuadtree%2520-%2520http%253A%252F%252Fwww.gamerendering.com%252F2008%252F10%252F17%252Fquadtree%252F';" title="Twitter"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="reddit" href="javascript:window.location='http%3A%2F%2Freddit.com%2Fsubmit%3Furl%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2008%252F10%252F17%252Fquadtree%252F%26amp%3Btitle%3DQuadtree';" title="Reddit"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow" id="technorati" href="javascript:window.location='http%3A%2F%2Ftechnorati.com%2Ffaves%3Fadd%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2008%252F10%252F17%252Fquadtree%252F';" title="Technorati"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow" id="yahoo! bookmarks" href="javascript:window.location='http%3A%2F%2Fbookmarks.yahoo.com%2Ftoolbar%2Fsavebm%3Fu%3Dhttp%253A%252F%252Fwww.gamerendering.com%252F2008%252F10%252F17%252Fquadtree%252F%26amp%3Bt%3DQuadtree%26opener%3Dbm%26amp%3Bei%3DUTF-8%26amp%3Bd%3DNearly%2520the%2520same%2520as%2520a%2520Octree%25C2%25A0but%2520instead%2520of%2520dividing%2520the%2520space%2520in%2520cuboids%2520in%25C2%25A03D%25C2%25A0it%2527s%2520rectangles%2520in%25202D%2520space.%2520This%2520is%2520useful%2520for%2520rendering%2520terrain%2520and%2520you%2520want%2520to%2520cull%2520a%2520lot%2520of%2520the%25C2%25A0terrain%2520fast.%250D%250A%250D%250AA%2520visual%2520demonstration%2520of%2520a%2520quadtree%2520used%2520for%2520fast';" title="Yahoo! Bookmarks"><img src="http://www.gamerendering.com/wp-content/plugins/sociable/images/yahoomyweb.png" title="Yahoo! Bookmarks" alt="Yahoo! Bookmarks" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.gamerendering.com/2008/10/17/quadtree/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
