<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: How To Make a &#8220;Falling Sand&#8221; Style Water Simulation</title>
	<atom:link href="http://w-shadow.com/blog/2009/09/29/falling-sand-style-water-simulation/feed/" rel="self" type="application/rss+xml" />
	<link>http://w-shadow.com/blog/2009/09/29/falling-sand-style-water-simulation/</link>
	<description>A blog about web development, software business, and WordPress</description>
	<lastBuildDate>Wed, 08 Feb 2012 21:10:53 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: White Shadow</title>
		<link>http://w-shadow.com/blog/2009/09/29/falling-sand-style-water-simulation/comment-page-1/#comment-171433</link>
		<dc:creator>White Shadow</dc:creator>
		<pubDate>Thu, 14 Jul 2011 08:59:59 +0000</pubDate>
		<guid isPermaLink="false">http://w-shadow.com/?p=1295#comment-171433</guid>
		<description>Ah, now I see it. 

One possible way to fix the problem would be to only allow a sand particle to move left/right if both the corresponding diagonal &lt;em&gt;and&lt;/em&gt; horizontal neighbours are empty:

&lt;pre lang=&quot;java&quot;&gt;
if ((x &gt; 0) &amp;&amp; (sand[x - 1][y + 1] == 0) &amp;&amp; (sand[x - 1][y] == 0)) {
	left = true;
}

if ((x &lt; (WIDTH - 1)) &amp;&amp; (sand[x + 1][y + 1] == 0) &amp;&amp; (sand[x + 1][y] == 0)) {
	right = true;
}
&lt;/pre&gt;

(I haven&#039;t tried this myself.)</description>
		<content:encoded><![CDATA[<p>Ah, now I see it. </p>
<p>One possible way to fix the problem would be to only allow a sand particle to move left/right if both the corresponding diagonal <em>and</em> horizontal neighbours are empty:</p>
<pre lang="java">
if ((x > 0) &#038;&#038; (sand[x - 1][y + 1] == 0) &#038;&#038; (sand[x - 1][y] == 0)) {
	left = true;
}

if ((x < (WIDTH - 1)) &#038;&#038; (sand[x + 1][y + 1] == 0) &#038;&#038; (sand[x + 1][y] == 0)) {
	right = true;
}
</pre>
<p>(I haven't tried this myself.)</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: shpen</title>
		<link>http://w-shadow.com/blog/2009/09/29/falling-sand-style-water-simulation/comment-page-1/#comment-171420</link>
		<dc:creator>shpen</dc:creator>
		<pubDate>Wed, 13 Jul 2011 18:47:38 +0000</pubDate>
		<guid isPermaLink="false">http://w-shadow.com/?p=1295#comment-171420</guid>
		<description>I&#039;m actually going from top to bottom, but bottom to top still causes the same problem.

Maybe you can take a look at my source and help me figure out what&#039;s wrong:
http://dl.dropbox.com/u/77961/GameTemplate.java

Also, here&#039;s a jar which will show you what the problem looks like:
http://dl.dropbox.com/u/77961/SandTest.jar

Thanks!</description>
		<content:encoded><![CDATA[<p>I&#8217;m actually going from top to bottom, but bottom to top still causes the same problem.</p>
<p>Maybe you can take a look at my source and help me figure out what&#8217;s wrong:<br />
<a href="http://dl.dropbox.com/u/77961/GameTemplate.java" rel="nofollow">http://dl.dropbox.com/u/77961/GameTemplate.java</a></p>
<p>Also, here&#8217;s a jar which will show you what the problem looks like:<br />
<a href="http://dl.dropbox.com/u/77961/SandTest.jar" rel="nofollow">http://dl.dropbox.com/u/77961/SandTest.jar</a></p>
<p>Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: White Shadow</title>
		<link>http://w-shadow.com/blog/2009/09/29/falling-sand-style-water-simulation/comment-page-1/#comment-171396</link>
		<dc:creator>White Shadow</dc:creator>
		<pubDate>Wed, 13 Jul 2011 06:49:05 +0000</pubDate>
		<guid isPermaLink="false">http://w-shadow.com/?p=1295#comment-171396</guid>
		<description>Hmm, I don&#039;t see how that could happen. If you&#039;re iterating left to right, bottom up, the entire lower line should fall down &quot;at once&quot;, from the perspective of the simulation.</description>
		<content:encoded><![CDATA[<p>Hmm, I don&#8217;t see how that could happen. If you&#8217;re iterating left to right, bottom up, the entire lower line should fall down &#8220;at once&#8221;, from the perspective of the simulation.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: shpen</title>
		<link>http://w-shadow.com/blog/2009/09/29/falling-sand-style-water-simulation/comment-page-1/#comment-171380</link>
		<dc:creator>shpen</dc:creator>
		<pubDate>Wed, 13 Jul 2011 01:38:06 +0000</pubDate>
		<guid isPermaLink="false">http://w-shadow.com/?p=1295#comment-171380</guid>
		<description>I&#039;m having problems with creating an even falling pattern. Because I am iterating through each sand particle one by one, from left to right, the sand tends to fall to the left, since a slot on the left is opened before one on the right. Is there any way to fix this and cause an even falling pattern?</description>
		<content:encoded><![CDATA[<p>I&#8217;m having problems with creating an even falling pattern. Because I am iterating through each sand particle one by one, from left to right, the sand tends to fall to the left, since a slot on the left is opened before one on the right. Is there any way to fix this and cause an even falling pattern?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: White Shadow</title>
		<link>http://w-shadow.com/blog/2009/09/29/falling-sand-style-water-simulation/comment-page-1/#comment-148927</link>
		<dc:creator>White Shadow</dc:creator>
		<pubDate>Tue, 21 Dec 2010 23:31:00 +0000</pubDate>
		<guid isPermaLink="false">http://w-shadow.com/?p=1295#comment-148927</guid>
		<description>True, but I suspect performance would suffer if you copied the entire world (twice!) every frame.</description>
		<content:encoded><![CDATA[<p>True, but I suspect performance would suffer if you copied the entire world (twice!) every frame.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Grant</title>
		<link>http://w-shadow.com/blog/2009/09/29/falling-sand-style-water-simulation/comment-page-1/#comment-148859</link>
		<dc:creator>Grant</dc:creator>
		<pubDate>Tue, 21 Dec 2010 21:19:38 +0000</pubDate>
		<guid isPermaLink="false">http://w-shadow.com/?p=1295#comment-148859</guid>
		<description>Whoops! Instead of &quot;...but modified the copy array...&quot;, it should read &quot;...but modifies the copy array...&quot;</description>
		<content:encoded><![CDATA[<p>Whoops! Instead of &#8220;&#8230;but modified the copy array&#8230;&#8221;, it should read &#8220;&#8230;but modifies the copy array&#8230;&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Grant</title>
		<link>http://w-shadow.com/blog/2009/09/29/falling-sand-style-water-simulation/comment-page-1/#comment-148857</link>
		<dc:creator>Grant</dc:creator>
		<pubDate>Tue, 21 Dec 2010 21:18:41 +0000</pubDate>
		<guid isPermaLink="false">http://w-shadow.com/?p=1295#comment-148857</guid>
		<description>There is a very easy fix for the &quot;teleporting&quot; problem. Before the main loop (updating every tile), copy the entire world into a &quot;copy&quot; array. Then, whenever a particle is updated, it gets its information about the world from the original array, but modified the copy array. At the end of the main loop, you copy every value from the &quot;copy&quot; array into the origininal array. The reason it works is: every particle gets its information from a non-updated array! No particle can influence another particle DURING the updating process!</description>
		<content:encoded><![CDATA[<p>There is a very easy fix for the &#8220;teleporting&#8221; problem. Before the main loop (updating every tile), copy the entire world into a &#8220;copy&#8221; array. Then, whenever a particle is updated, it gets its information about the world from the original array, but modified the copy array. At the end of the main loop, you copy every value from the &#8220;copy&#8221; array into the origininal array. The reason it works is: every particle gets its information from a non-updated array! No particle can influence another particle DURING the updating process!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Henk</title>
		<link>http://w-shadow.com/blog/2009/09/29/falling-sand-style-water-simulation/comment-page-1/#comment-81956</link>
		<dc:creator>Henk</dc:creator>
		<pubDate>Fri, 27 Aug 2010 21:22:00 +0000</pubDate>
		<guid isPermaLink="false">http://w-shadow.com/?p=1295#comment-81956</guid>
		<description>Neat tutorial, I followed it on a bored friday evening :). I implemented the teleporting thing using a simple &#039;updated&#039; boolean 2d array that sets fields to true if they&#039;ve been updated during that round, but that&#039;s mainly because I&#039;m not much of a bit twiddler.

Haven&#039;t got the water going horizontal right yet though. It&#039;d probably become either very complex, or need to be rewritten if I ever add other materials.</description>
		<content:encoded><![CDATA[<p>Neat tutorial, I followed it on a bored friday evening :). I implemented the teleporting thing using a simple &#8216;updated&#8217; boolean 2d array that sets fields to true if they&#8217;ve been updated during that round, but that&#8217;s mainly because I&#8217;m not much of a bit twiddler.</p>
<p>Haven&#8217;t got the water going horizontal right yet though. It&#8217;d probably become either very complex, or need to be rewritten if I ever add other materials.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: White Shadow</title>
		<link>http://w-shadow.com/blog/2009/09/29/falling-sand-style-water-simulation/comment-page-1/#comment-31619</link>
		<dc:creator>White Shadow</dc:creator>
		<pubDate>Wed, 30 Sep 2009 13:14:58 +0000</pubDate>
		<guid isPermaLink="false">http://w-shadow.com/?p=1295#comment-31619</guid>
		<description>You are correct, updating bottom-to-top is a good approach. I didn&#039;t mention it in the post, but that&#039;s exactly what my demo app does.

However, that alone wouldn&#039;t be enough to prevent &quot;teleportation&quot; in a more complex simulation. For example, if you added a rule like &quot;if this fluid particle has another fluid particle above it, move this one sideways&quot; (i.e. a very basic pressure factor), you&#039;d get particles teleporting left or right depending on the direction of your X loop. So tracking which particles have been updated still makes sense.</description>
		<content:encoded><![CDATA[<p>You are correct, updating bottom-to-top is a good approach. I didn&#8217;t mention it in the post, but that&#8217;s exactly what my demo app does.</p>
<p>However, that alone wouldn&#8217;t be enough to prevent &#8220;teleportation&#8221; in a more complex simulation. For example, if you added a rule like &#8220;if this fluid particle has another fluid particle above it, move this one sideways&#8221; (i.e. a very basic pressure factor), you&#8217;d get particles teleporting left or right depending on the direction of your X loop. So tracking which particles have been updated still makes sense.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ross Shannon</title>
		<link>http://w-shadow.com/blog/2009/09/29/falling-sand-style-water-simulation/comment-page-1/#comment-31618</link>
		<dc:creator>Ross Shannon</dc:creator>
		<pubDate>Wed, 30 Sep 2009 13:00:31 +0000</pubDate>
		<guid isPermaLink="false">http://w-shadow.com/?p=1295#comment-31618</guid>
		<description>Good tutorial, thanks. I don&#039;t understand the problem with particles teleporting downwards though — it seems to be that the only reasonable way to program this is to do the simulation updates bottom-to-top. Otherwise, if you update top-to-bottom, when you update the game state array, any particles that have another particle above them will be overwritten by the top particle falling into their position?</description>
		<content:encoded><![CDATA[<p>Good tutorial, thanks. I don&#8217;t understand the problem with particles teleporting downwards though — it seems to be that the only reasonable way to program this is to do the simulation updates bottom-to-top. Otherwise, if you update top-to-bottom, when you update the game state array, any particles that have another particle above them will be overwritten by the top particle falling into their position?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

