<?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>Jacob Repp &#187; csharp</title>
	<atom:link href="http://jrepp.com/category/csharp/feed/" rel="self" type="application/rss+xml" />
	<link>http://jrepp.com</link>
	<description>Game programming, music and life</description>
	<lastBuildDate>Fri, 16 Dec 2011 06:03:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>XNA Random Terrain Generation Sample Code</title>
		<link>http://jrepp.com/2007/07/19/xna-random-terrain-generation-sample-code/</link>
		<comments>http://jrepp.com/2007/07/19/xna-random-terrain-generation-sample-code/#comments</comments>
		<pubDate>Thu, 19 Jul 2007 00:58:27 +0000</pubDate>
		<dc:creator>proj</dc:creator>
				<category><![CDATA[csharp]]></category>
		<category><![CDATA[game programming]]></category>
		<category><![CDATA[sample code]]></category>
		<category><![CDATA[shmup]]></category>
		<category><![CDATA[xna]]></category>

		<guid isPermaLink="false">http://jrepp.com/2007/07/19/xna-random-terrain-generation-sample-code/</guid>
		<description><![CDATA[I recently received a comment asking for details on the terrain generation algorithm I used in my XNA shoot &#8216;em up proof of concept. Here&#8217;s my edited reply and sample code for anyone interested. It&#8217;s not very complex and it &#8230; <a href="http://jrepp.com/2007/07/19/xna-random-terrain-generation-sample-code/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I recently received a comment asking for details on the terrain generation algorithm I used in my XNA shoot &#8216;em up proof of concept. Here&#8217;s my edited reply and sample code for anyone interested.</p>

<p><img src="http://photos1.blogger.com/photoInclude/blogger2/3211/2667/1600/xna_shmup.jpg"/></p>

<p>It&#8217;s not very complex and it doesn&#8217;t do any culling currently because I didn&#8217;t find that to be a problem given the ammount of terrain samples that I&#8217;m rendering. I generally spend most of my time on the game play first before tweaking the graphics engine.</p>

<p>Here is the code used for generating and rendering the terrain in the screenshots:</p>

<p><a href="http://jrepp.com/code/Terrain.cs" onclick="return top.js.OpenExtLink(window,event,this)" target="_blank">http://jrepp.com/code/Terrain<wbr></wbr>.cs</a></p>

<p>The method used is as follows:</p>

<p>Given a grid of height samples
<ol>
    <li>For some number N</li>
    <li>Choose a random X,Y sample in the grid</li>
    <li>Write a random value into the sample</li>
    <li>Blend that sample with all adjacent samples recursively</li>
</ol>
The blending adds some jitter so you get some variation in the blends but as a rule you can only blend between two samples by so much. I built some tolerances into the blending so that it will never generate height differences that are greater than the [horizontal] distance between two samples.</p>

<p>The verts are colored to get the basic effect of having land and sea.</p>

<p>Overall it&#8217;s a pretty simple algorithm that produces fairly decent looking results.</p>

<p>Please let me know if you have any questions, I&#8217;ll be happy to answer them.</p>
]]></content:encoded>
			<wfw:commentRss>http://jrepp.com/2007/07/19/xna-random-terrain-generation-sample-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

