<?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/"
	>

<channel>
	<title>Jason Mitchell</title>
	<atom:link href="http://www.jason-mitchell.com/index.php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jason-mitchell.com</link>
	<description>I'M A PC!</description>
	<pubDate>Tue, 23 Feb 2010 15:52:10 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Development identity</title>
		<link>http://www.jason-mitchell.com/index.php/2010/02/07/development-identity/</link>
		<comments>http://www.jason-mitchell.com/index.php/2010/02/07/development-identity/#comments</comments>
		<pubDate>Sun, 07 Feb 2010 18:15:56 +0000</pubDate>
		<dc:creator>jmitch18</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.jason-mitchell.com/index.php/2010/02/07/development-identity/</guid>
		<description><![CDATA[Since I now have plans to create and release some of my own work I&#8217;ve been needing to create an identity to do it under.  Below is my current &#8220;logo&#8221; that could be used as a splash screen for an XNA game (with a little animation added of course).

The name &#8220;Dazed About&#8221; is fairly old [...]]]></description>
			<content:encoded><![CDATA[<p>Since I now have plans to create and release some of my own work I&#8217;ve been needing to create an identity to do it under.  Below is my current &#8220;logo&#8221; that could be used as a splash screen for an <a href="http://en.wikipedia.org/wiki/Microsoft_XNA" target="_blank">XNA</a> game (with a little animation added of course).</p>
<p><a href="http://www.jason-mitchell.com/images/blog/Developmentidentity_FFB0/DALOGO.png"><img style="border-bottom: 0px; border-left: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px" title="DA-LOGO" src="http://www.jason-mitchell.com/images/blog/Developmentidentity_FFB0/DALOGO_thumb.png" border="0" alt="DA-LOGO" width="640" height="360" /></a></p>
<p>The name &#8220;Dazed About&#8221; is fairly old for me and goes back to when I did some freelance web development (however then it was &#8220;Dazed About Dot Com&#8221;).  Anyway, I&#8217;m pretty pleased with the quality of this image; mostly thanks to a friend with meticulous attention to detail!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jason-mitchell.com/index.php/2010/02/07/development-identity/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Personal projects site</title>
		<link>http://www.jason-mitchell.com/index.php/2010/02/07/personal-projects-site/</link>
		<comments>http://www.jason-mitchell.com/index.php/2010/02/07/personal-projects-site/#comments</comments>
		<pubDate>Sun, 07 Feb 2010 18:04:50 +0000</pubDate>
		<dc:creator>jmitch18</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.jason-mitchell.com/index.php/2010/02/07/personal-projects-site/</guid>
		<description><![CDATA[For quite some time, I&#8217;ve been meaning to get round to making myself a website dedicated to posting my projects on.&#160; I&#8217;ve finally done it after a lot of screwing around with the idea of a dedicated Silverlight website and then finally settling for a good old ASP.NET website; I love how quickly it can [...]]]></description>
			<content:encoded><![CDATA[<p>For quite some time, I&#8217;ve been meaning to get round to making myself a website dedicated to posting my projects on.&#160; I&#8217;ve finally done it after a lot of screwing around with the idea of a dedicated <a href="http://www.silverlight.net" target="_blank">Silverlight</a> website and then finally settling for a good old <a href="http://www.asp.net/" target="_blank">ASP.NET</a> website; I love how quickly it can be to get a site up and running with ASP.NET.</p>
<p>My projects site can be found at <a href="http://projects.jason-mitchell.com">http://projects.jason-mitchell.com</a> or by clicking the Projects link at the top of the page.&#160; Right now it just has some filler content but I will be getting this sorted ASAP.&#160; My previous approach for my really really old projects site was to stick absolutely everything on there but this time I&#8217;m going for quality, not quantity.&#160; As such, despite the amount of programming I actually do in my spare time, I can only think of three projects that I plan to post initially.</p>
<p>On a side note, I also signed up to LinkedIn.&#160; Find me <a href="http://uk.linkedin.com/in/jasonmitchell89" target="_blank">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jason-mitchell.com/index.php/2010/02/07/personal-projects-site/feed/</wfw:commentRss>
		</item>
		<item>
		<title>It&#8217;s been a while&#8230;</title>
		<link>http://www.jason-mitchell.com/index.php/2009/12/19/its-been-a-while/</link>
		<comments>http://www.jason-mitchell.com/index.php/2009/12/19/its-been-a-while/#comments</comments>
		<pubDate>Sat, 19 Dec 2009 09:49:31 +0000</pubDate>
		<dc:creator>jmitch18</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.jason-mitchell.com/?p=119</guid>
		<description><![CDATA[It&#8217;s been a while since I have updated and written anything here; I&#8217;ve been busy with work and my own Silverlight project.  I&#8217;ve also been experimenting with 3D XNA a bit more.  Hopefully I will be able to write a few tutorials based on my experience with what I&#8217;ve been doing recently.  I have a [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been a while since I have updated and written anything here; I&#8217;ve been busy with work and my own Silverlight project.  I&#8217;ve also been experimenting with 3D XNA a bit more.  Hopefully I will be able to write a few tutorials based on my experience with what I&#8217;ve been doing recently.  I have a few ideas  for topics to write about such as data binding, creating draggable user controls in Silverlight and creating a basic class to handle the details of 3D models in XNA.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jason-mitchell.com/index.php/2009/12/19/its-been-a-while/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Zune HD: XNA Accelerometer</title>
		<link>http://www.jason-mitchell.com/index.php/2009/10/24/zune-hd-accelerometer/</link>
		<comments>http://www.jason-mitchell.com/index.php/2009/10/24/zune-hd-accelerometer/#comments</comments>
		<pubDate>Sat, 24 Oct 2009 19:29:04 +0000</pubDate>
		<dc:creator>jmitch18</dc:creator>
		
		<category><![CDATA[XNA]]></category>

		<category><![CDATA[Zune HD]]></category>

		<category><![CDATA[accelerometer]]></category>

		<category><![CDATA[hd]]></category>

		<category><![CDATA[zune]]></category>

		<guid isPermaLink="false">http://www.jason-mitchell.com/index.php/2009/10/24/zune-hd-accelerometer/</guid>
		<description><![CDATA[My Zune HD arrived last week and after getting over the initial disappointment of a disgracefully empty marketplace for it, I was really itching to try out some XNA and play around with the accelerometer.  First things first, I needed to download the XNA extensions that would provide the necessary framework to use the accelerometer [...]]]></description>
			<content:encoded><![CDATA[<p>My Zune HD arrived last week and after getting over the initial disappointment of a disgracefully empty marketplace for it, I was really itching to try out some XNA and play around with the accelerometer.  First things first, I needed to download the XNA extensions that would provide the necessary framework to use the accelerometer in the Zune HD; these can be found right <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=48f7ba37-8ba7-4d16-8873-0b7f83ef77f9&amp;displaylang=en" target="_blank">here</a>.  As far as I’m aware, XNA for the older Zune won’t let you use the 3D API (I could be wrong??) and I don’t think this has been rectified by the XNA 3.1 Zune Extensions however hopefully an XNA 3.2 or 4.0 will come along in the near future and open that up.</p>
<p>UPDATE:</p>
<p>I verified that the 3D API isn&#8217;t available.  The likes of the Effect class aren&#8217;t available on the Zune.</p>
<p><span id="more-114"></span></p>
<p>In order to play with the accelerometer, I made a quick test project that allows the user to roll a ball about in a lovely blank black background. See this video:</p>
<p><object width="445" height="364" data="http://www.youtube.com/v/xOZ1a5lXBoQ&amp;hl=en&amp;fs=1&amp;color1=0x3a3a3a&amp;color2=0x999999&amp;border=1" type="application/x-shockwave-flash"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/xOZ1a5lXBoQ&amp;hl=en&amp;fs=1&amp;color1=0x3a3a3a&amp;color2=0x999999&amp;border=1" /><param name="allowfullscreen" value="true" /></object></p>
<p>Ok, so it’s not quite a ball….its a big white dot!  Who cares?</p>
<p>This was actually incredibly simple to achieve and was much easier than I had originally anticipated.  The XNA extensions provide a new class under Microsoft.Xna.Framework.Input called Accelerometer.  As with the other input devices, this class provides a GetState() method so it very much keeps in line with what XNA developers are already used to.  This method returns an object of type AccelerometerState which has a Vector3 property called Acceleration.  This property holds all the information you need for detecting tilt on the device.</p>
<p>Since the code is so simple, I don’t think I will walk through it step by step but rather I will just post my very quick code below.  Please ignore the rubbish boundary collisions – I didn’t feel like it was very important to make them perfect.  Rough and ready…just the way I like it!</p>
<div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:493cb8ce-6e13-427c-a1b6-45651b972ae1" class="wlWriterEditableSmartContent" style="width: 1032px; display: block; float: none; margin-left: auto; margin-right: auto; padding: 5px;">
<div style="border: #000080 1px solid; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Code Snippet</div>
<div style="background: #ddd; overflow: auto; padding: 0">
<ol style="background: #ffffff; margin: 0 0 0 35px; white-space: wrap">
<li><span style="color:#0000ff">using</span> System;</li>
<li style="background: #f3f3f3"><span style="color:#0000ff">using</span> Microsoft.Xna.Framework;</li>
<li><span style="color:#0000ff">using</span> Microsoft.Xna.Framework.Graphics;</li>
<li style="background: #f3f3f3"><span style="color:#0000ff">using</span> Microsoft.Xna.Framework.Input;</li>
<li style="background: #f3f3f3"><span style="color:#0000ff">namespace</span> AccelerometerTest</li>
<li>{</li>
<li style="background: #f3f3f3">    <span style="color:#0000ff">public</span> <span style="color:#0000ff">class</span> <span style="color:#2b91af">Game1</span> : Microsoft.Xna.Framework.<span style="color:#2b91af">Game</span></li>
<li>    {</li>
<li style="background: #f3f3f3">        <span style="color:#0000ff">private</span> <span style="color:#0000ff">const</span> <span style="color:#0000ff">float</span> rollSpeed = 50f;</li>
<li style="background: #f3f3f3">        <span style="color:#0000ff">private</span> <span style="color:#2b91af">GraphicsDeviceManager</span> graphics;</li>
<li>        <span style="color:#0000ff">private</span> <span style="color:#2b91af">SpriteBatch</span> spriteBatch;</li>
<li>        <span style="color:#0000ff">private</span> <span style="color:#2b91af">Rectangle</span> boundary;</li>
<li>        <span style="color:#0000ff">private</span> <span style="color:#2b91af">Texture2D</span> ballTexture;</li>
<li style="background: #f3f3f3">        <span style="color:#0000ff">private</span> <span style="color:#2b91af">Vector2</span> ballPosition;</li>
<li style="background: #f3f3f3">        <span style="color:#0000ff">public</span> Game1()</li>
<li>        {</li>
<li style="background: #f3f3f3">            graphics = <span style="color:#0000ff">new</span> <span style="color:#2b91af">GraphicsDeviceManager</span>(<span style="color:#0000ff">this</span>);</li>
<li>            Content.RootDirectory = <span style="color:#a31515">&#8220;Content&#8221;</span>;</li>
<li>            <span style="color:#008000">// Frame rate is 30 fps by default for Zune.</span></li>
<li style="background: #f3f3f3">            TargetElapsedTime = <span style="color:#2b91af">TimeSpan</span>.FromSeconds(1 / 30.0);</li>
<li>        }</li>
<li>        <span style="color:#0000ff">protected</span> <span style="color:#0000ff">override</span> <span style="color:#0000ff">void</span> Initialize()</li>
<li style="background: #f3f3f3">        {</li>
<li>            boundary = GraphicsDevice.Viewport.TitleSafeArea;</li>
<li>            <span style="color:#0000ff">base</span>.Initialize();</li>
<li style="background: #f3f3f3">        }</li>
<li style="background: #f3f3f3">        <span style="color:#0000ff">protected</span> <span style="color:#0000ff">override</span> <span style="color:#0000ff">void</span> LoadContent()</li>
<li>        {</li>
<li style="background: #f3f3f3">            spriteBatch = <span style="color:#0000ff">new</span> <span style="color:#2b91af">SpriteBatch</span>(GraphicsDevice);</li>
<li style="background: #f3f3f3">            ballTexture = Content.Load&lt;<span style="color:#2b91af">Texture2D</span>&gt;(<span style="color:#a31515">&#8220;ball&#8221;</span>);</li>
<li>            ballPosition = <span style="color:#0000ff">new</span> <span style="color:#2b91af">Vector2</span>(boundary.Width / 2, boundary.Height / 2);</li>
<li style="background: #f3f3f3">        }</li>
<li style="background: #f3f3f3">        <span style="color:#0000ff">protected</span> <span style="color:#0000ff">override</span> <span style="color:#0000ff">void</span> UnloadContent()</li>
<li>        {</li>
<li style="background: #f3f3f3">            <span style="color:#008000">// TODO: Unload any non ContentManager content here</span></li>
<li>        }</li>
<li>        <span style="color:#0000ff">protected</span> <span style="color:#0000ff">override</span> <span style="color:#0000ff">void</span> Update(<span style="color:#2b91af">GameTime</span> gameTime)</li>
<li style="background: #f3f3f3">        {</li>
<li>            <span style="color:#0000ff">if</span> (<span style="color:#2b91af">GamePad</span>.GetState(<span style="color:#2b91af">PlayerIndex</span>.One).Buttons.Back == <span style="color:#2b91af">ButtonState</span>.Pressed)</li>
<li style="background: #f3f3f3">                <span style="color:#0000ff">this</span>.Exit();</li>
<li style="background: #f3f3f3">            <span style="color:#2b91af">Vector3</span> acceleration = <span style="color:#2b91af">Accelerometer</span>.GetState().Acceleration;</li>
<li>            <span style="color:#2b91af">Vector2</span> velocity = <span style="color:#0000ff">new</span> <span style="color:#2b91af">Vector2</span>(acceleration.X, -acceleration.Y) * rollSpeed;</li>
<li>            <span style="color:#2b91af">Vector2</span> projectedPosition = ballPosition + velocity;</li>
<li style="background: #f3f3f3">            <span style="color:#2b91af">Rectangle</span> projectedRectangle = <span style="color:#0000ff">new</span> <span style="color:#2b91af">Rectangle</span>((<span style="color:#0000ff">int</span>)projectedPosition.X, (<span style="color:#0000ff">int</span>)projectedPosition.Y, ballTexture.Width, ballTexture.Height);</li>
<li style="background: #f3f3f3">            <span style="color:#0000ff">if</span> (projectedRectangle.Left &lt; boundary.Left || projectedRectangle.Right &gt; boundary.Right)</li>
<li>                velocity.X = 0;</li>
<li>            <span style="color:#0000ff">if</span> (projectedRectangle.Top &lt; boundary.Top || projectedRectangle.Bottom &gt; boundary.Bottom)</li>
<li style="background: #f3f3f3">                velocity.Y = 0;</li>
<li style="background: #f3f3f3">            ballPosition += velocity;</li>
<li style="background: #f3f3f3">            <span style="color:#0000ff">base</span>.Update(gameTime);</li>
<li>        }</li>
<li>        <span style="color:#0000ff">protected</span> <span style="color:#0000ff">override</span> <span style="color:#0000ff">void</span> Draw(<span style="color:#2b91af">GameTime</span> gameTime)</li>
<li style="background: #f3f3f3">        {</li>
<li>            GraphicsDevice.Clear(<span style="color:#2b91af">Color</span>.Black);</li>
<li>            spriteBatch.Begin(<span style="color:#2b91af">SpriteBlendMode</span>.AlphaBlend);</li>
<li style="background: #f3f3f3">            spriteBatch.Draw(ballTexture, ballPosition, <span style="color:#2b91af">Color</span>.White);</li>
<li>            spriteBatch.End();</li>
<li>            <span style="color:#0000ff">base</span>.Draw(gameTime);</li>
<li style="background: #f3f3f3">        }</li>
<li>    }</li>
<li style="background: #f3f3f3">}</li>
</ol>
</div>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.jason-mitchell.com/index.php/2009/10/24/zune-hd-accelerometer/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Wordpress Stats Plug-in Not Counting</title>
		<link>http://www.jason-mitchell.com/index.php/2009/09/27/wordpress-stats-plug-in-not-counting/</link>
		<comments>http://www.jason-mitchell.com/index.php/2009/09/27/wordpress-stats-plug-in-not-counting/#comments</comments>
		<pubDate>Sun, 27 Sep 2009 13:47:17 +0000</pubDate>
		<dc:creator>jmitch18</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[plugin.counting]]></category>

		<category><![CDATA[stats]]></category>

		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.jason-mitchell.com/index.php/2009/09/27/wordpress-stats-plug-in-not-counting/</guid>
		<description><![CDATA[I have various Wordpress plug-ins installed for my blog but my favourite has got to be the Wordpress Stats plug-in.  I like to be able to keep an eye on the amount of traffic my blog gets and in particular what the most popular articles are.  At the minute, it seems to be my article [...]]]></description>
			<content:encoded><![CDATA[<p>I have various Wordpress plug-ins installed for my blog but my favourite has got to be the Wordpress Stats plug-in.  I like to be able to keep an eye on the amount of traffic my blog gets and in particular what the most popular articles are.  At the minute, it seems to be <a href="http://www.jason-mitchell.com/index.php/2009/08/27/xna-first-person-camera/" target="_blank">my article on a first person camera</a> in <a href="http://en.wikipedia.org/wiki/Microsoft_XNA" target="_blank">XNA</a> and <a href="http://www.jason-mitchell.com/index.php/2009/04/07/iphone-application-development/" target="_blank">my article about iPhone development</a>.  However, for the past month or so the plug-in hasn&#8217;t been counting visits at all.  Which was a little annoying, I figured that I was either hugely unpopular or there was something up with the plug-in.  Not wanting to resign to the possible truth that no one cares what I have to say, I did a little bit of searching for people having similar problems.  it wasn&#8217;t difficult to turn up some results, but the answer came from the <a href="http://wordpress.org/extend/plugins/stats/faq/" target="_blank">plug-in&#8217;s FAQ page on Wordpress Extend</a> as I had hoped for.  Basically this plug-in depends on the wp_footer PHP function being called in your theme.  Turns out, my current theme didn&#8217;t call this.  All that I needed to do was add &lt;?php wp_footer(); ?&gt; just before the &lt;/body&gt; tag and the plug-in began counting stats straight away.  Easy fix!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jason-mitchell.com/index.php/2009/09/27/wordpress-stats-plug-in-not-counting/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Silverlight Portfolio Site</title>
		<link>http://www.jason-mitchell.com/index.php/2009/09/25/silverlight-portfolio-site/</link>
		<comments>http://www.jason-mitchell.com/index.php/2009/09/25/silverlight-portfolio-site/#comments</comments>
		<pubDate>Fri, 25 Sep 2009 21:39:00 +0000</pubDate>
		<dc:creator>jmitch18</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://www.jason-mitchell.com/index.php/2009/09/25/silverlight-portfolio-site/</guid>
		<description><![CDATA[It’s been a while since I posted here; I’ve been kept quite busy at work and haven’t had much interesting stuff to write about.  I’ve spent a little bit of my time in the evening working on my own portfolio site in Silverlight as a way of getting more familiar with Silverlight development and working [...]]]></description>
			<content:encoded><![CDATA[<p>It’s been a while since I posted here; I’ve been kept quite busy at work and haven’t had much interesting stuff to write about.  I’ve spent a little bit of my time in the evening working on my own portfolio site in Silverlight as a way of getting more familiar with Silverlight development and working with XAML.  You can see the site at <a href="http://projects.jason-mitchell.com">http://projects.jason-mitchell.com</a> and check out my progress.  I originally planned to use PHP server-side scripting to interact with the database, but the ASP.NET web services integrate really nicely with C#.  Using PHP would be really handy given how easy it is to access MySQL databases and my past experience with it.</p>
<p><strong>Edit:</strong></p>
<p>The projects site mentioned above is no longer a Silverlight site.  I have updated it to be a simple ASP.NET just to get it up and online.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jason-mitchell.com/index.php/2009/09/25/silverlight-portfolio-site/feed/</wfw:commentRss>
		</item>
		<item>
		<title>XNA 3D Terrain</title>
		<link>http://www.jason-mitchell.com/index.php/2009/08/30/xna-3d-terrain/</link>
		<comments>http://www.jason-mitchell.com/index.php/2009/08/30/xna-3d-terrain/#comments</comments>
		<pubDate>Sun, 30 Aug 2009 15:06:02 +0000</pubDate>
		<dc:creator>jmitch18</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[XNA]]></category>

		<guid isPermaLink="false">http://www.jason-mitchell.com/index.php/2009/08/30/xna-3d-terrain/</guid>
		<description><![CDATA[Having created my own first person camera, I moved on to creating some 3D terrain for my game.&#160; I have to admit, I cheated on this a bit and just used the custom content pipeline from the XNA Creators Club’s generated geometry sample found here.&#160; For this reason, I currently do not fully understand the [...]]]></description>
			<content:encoded><![CDATA[<p align="justify">Having created my own <a href="http://www.jason-mitchell.com/index.php/2009/08/27/xna-first-person-camera/" target="_blank">first person camera</a>, I moved on to creating some 3D terrain for my game.&#160; I have to admit, I cheated on this a bit and just used the custom content pipeline from the <a href="http://creators.xna.com" target="_blank">XNA Creators Club</a>’s generated geometry sample found <a href="http://http://creators.xna.com/en-GB/sample/generatedgeometry" target="_blank">here</a>.&#160; For this reason, I currently do not fully understand the process of creating terrain from a height map despite despite understanding the basic theory behind it.&#160; For this reason I can’t really provide a guide as to how to code it yourself at the minute but I will hopefully be able to do this in the future.</p>
</p>
<p> <span id="more-99"></span>
</p>
<p align="justify">The sample from the creators club website isn’t without it’s flaws; it’s a great way to easily get terrain in your game however it does hard code the name of the height map and it’s texture in the processor itself.&#160; This doesn’t provide much flexibility at all and isn’t an ideal solution.&#160; I will be looking into whether or not it is possible to pass in extra details to the processor (ie the height map file) which would provide a much nicer solution.&#160; I also want to remove the texturing from the processor and do this via an <a href="http://en.wikipedia.org/wiki/HLSL" target="_blank">HLSL</a> effects file and provide multi <a href="http://en.wikipedia.org/wiki/Texture_splatting" target="_blank">texture splatting</a> functionality.&#160; If anyone knows a good resource for information on this please feel free to leave a comment.</p>
<p align="justify">Despite using a ready made processor for loading my terrain, my experience with getting this working wasn’t so simple due to some <a href="http://en.wikipedia.org/wiki/Microsoft_XNA" target="_blank">XNA</a> functionality that seems relatively undocumented and doesn’t seem to come up in 3D tutorials.&#160; When setting up my terrain, I was completely unaware that my use of a SpriteBatch object to draw some debug text to the screen would modify the GraphicsDevice render states and not reset them.&#160; This resulted in the errors seen in the two following images:</p>
<p align="justify"><a href="http://www.jason-mitchell.com/images/blog/XNA3DTerrain_E030/renderError.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="renderError" border="0" alt="renderError" src="http://www.jason-mitchell.com/images/blog/XNA3DTerrain_E030/renderError_thumb.jpg" width="452" height="235" /></a> <a href="http://www.jason-mitchell.com/images/blog/XNA3DTerrain_E030/textureStretch.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="textureStretch" border="0" alt="textureStretch" src="http://www.jason-mitchell.com/images/blog/XNA3DTerrain_E030/textureStretch_thumb.jpg" width="402" height="235" /></a></p>
<p align="justify">The image on the left was caused by the SpriteBatch object disabling the depth buffer on the GraphicsDevice.&#160; This will allow parts of the scene in the background to appear to be drawn in front of larger foreground sections.&#160; The problem on the right was caused by the SpriteBatch object changing the UV coordinates for the texture sampler.&#160; To fix this, I simply added the following code just before rendering my terrain:</p>
<div class="csharpcode">
<div class="csharpcode">
<pre class="alt">GraphicsDevice.RenderState.DepthBufferEnable = <span class="kwrd">true</span>;</pre>
<pre>GraphicsDevice.SamplerStates[0].AddressU = TextureAddressMode.Wrap;</pre>
<pre class="alt">GraphicsDevice.SamplerStates[0].AddressV = TextureAddressMode.Wrap;</pre>
</p></div>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
</div>
<p><!--.csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } --></p>
<p>For more information on the effects a SpriteBatch object will have on your render states, <a href="http://blogs.msdn.com/shawnhar/archive/2006/11/13/spritebatch-and-renderstates.aspx" target="_blank">check out this article</a> by Shawn Hargreaves.</p>
<p>After figuring all that out thanks to help of the community on the XNA Creators Club website, I got my terrain working quite well and looking relatively nice:</p>
<p><a href="http://www.jason-mitchell.com/images/blog/XNA3DTerrain_E030/terrain.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="terrain" border="0" alt="terrain" src="http://www.jason-mitchell.com/images/blog/XNA3DTerrain_E030/terrain_thumb.jpg" width="695" height="400" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jason-mitchell.com/index.php/2009/08/30/xna-3d-terrain/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Silverlight 3 Rotating Video Player</title>
		<link>http://www.jason-mitchell.com/index.php/2009/08/30/silverlight-3-rotating-video-player/</link>
		<comments>http://www.jason-mitchell.com/index.php/2009/08/30/silverlight-3-rotating-video-player/#comments</comments>
		<pubDate>Sun, 30 Aug 2009 10:50:00 +0000</pubDate>
		<dc:creator>jmitch18</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://www.jason-mitchell.com/index.php/2009/08/30/silverlight-3-rotating-video-player/</guid>
		<description><![CDATA[Yesterday I wrote an article about creating a rotating video player using Silverlight 3 (see here) and I admit that there was an awful lot of text in it, so here is a list of numbered steps for you to follow with less of the rambling in between steps.



Create a new Silverlight 3 + website [...]]]></description>
			<content:encoded><![CDATA[<p align="justify">Yesterday I wrote an article about creating a rotating video player using <a href="http://www.silverlight.net" target="_blank">Silverlight</a> 3 (see <a href="http://www.jason-mitchell.com/index.php/2009/08/29/silverlight-3-fun-3d-projection-and-element-binding/" target="_blank">here</a>) and I admit that there was an awful lot of text in it, so here is a list of numbered steps for you to follow with less of the rambling in between steps.</p>
<p><span id="more-93"></span></p>
<ol>
<li>
<div>Create a new Silverlight 3 + website project (obviously) in Blend 3</div>
</li>
<li>
<div>Create 3 rows in the default grid layout</div>
</li>
<li>
<div>Add MediaElement control to top row</div>
</li>
<li>
<div>Add Slider control to middle row</div>
</li>
<li>
<div>Add two Button controls to bottom row</div>
</li>
<li>
<div>Set Slider maximum value to 360</div>
</li>
<li>
<div>Set MediaElement source to your video</div>
<ul>
<li>
<div>Embedded in project or…</div>
</li>
<li>
<div>web address</div>
</li>
</ul>
</li>
<li>
<div>Select Slider control, open Common Properties pane, right click Value textbox, select Data Binding</div>
</li>
<li>
<div>Select Element Property tab, click MediaElement control from left-hand list</div>
</li>
<li>
<div>Check “Use custom path expression” box and enter Projection.RotationY into the textbox</div>
</li>
<li>
<div>Expand Data Binding window and select TwoWay from the Binding Direction radio buttons</div>
</li>
<li>
<div>Select MediaElement, open Transform pane and make sure the X centre of rotation is 0.5 and Y is 1</div>
</li>
<li>
<div>Run application and you should be able to turn the video using the slider</div>
</li>
<li>
<div>Create a new storyboard called Down</div>
</li>
<li>
<div>Move to 1.5 seconds on timeline and set X value of Projection of the MediaElement to –90</div>
</li>
<li>
<div>Click the key frame on the time line to open the Easing pane</div>
</li>
<li>
<div>Select Bounce Out from drop down list</div>
</li>
<li>
<div>Select a Button control and open it’s event pane (small icon in the top left with a lightning bolt)</div>
</li>
<li>
<div>Enter FallDown into the Click text box and press enter</div>
</li>
<li>
<div>Type “Down.Begin();” in the new method</div>
</li>
<li>
<div>Run application and click the button to make the video fall over</div>
</li>
<li>
<div>Create a new storyboard called Up</div>
</li>
<li>
<div>Move to 1.5 second on timeline and set X value of Projection of the MediaElement to 0</div>
<ul>
<li>
<div>If this is already 0, click the Add New Key Frame button on the timeline</div>
</li>
</ul>
</li>
<li>
<div>Add a Bounce Out easing effect</div>
</li>
<li>
<div>Select the second Button control and create a click event for it and enter “Up.Begin();” into the new method</div>
</li>
</ol>
<p align="justify">And there you have it!  25 steps to create a useless and impractical video player, at least I hope its only 25!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jason-mitchell.com/index.php/2009/08/30/silverlight-3-rotating-video-player/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Silverlight 3 Fun: 3D Projection and Element Binding</title>
		<link>http://www.jason-mitchell.com/index.php/2009/08/29/silverlight-3-fun-3d-projection-and-element-binding/</link>
		<comments>http://www.jason-mitchell.com/index.php/2009/08/29/silverlight-3-fun-3d-projection-and-element-binding/#comments</comments>
		<pubDate>Sat, 29 Aug 2009 15:34:36 +0000</pubDate>
		<dc:creator>jmitch18</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://www.jason-mitchell.com/index.php/2009/08/29/silverlight-3-fun-3d-projection-and-element-binding/</guid>
		<description><![CDATA[Yesterday at work, there was a talk about Silverlight 3 about its capabilities and the improvements over Silverlight 2.  The talk featured demonstrations of existing applications and some step by step “how to&#8221; tutorials in which I saw how to rotate controls in 3D space and a cool Twitter reader which was made surprisingly quickly; albeit [...]]]></description>
			<content:encoded><![CDATA[<p align="justify">Yesterday at work, there was a talk about <a href="http://www.silverlight.net" target="_blank">Silverlight</a> 3 about its capabilities and the improvements over Silverlight 2.  The talk featured demonstrations of existing applications and some step by step “how to&#8221; tutorials in which I saw how to rotate controls in 3D space and a cool <a href="http://www.twitter.com" target="_blank">Twitter</a> reader which was made surprisingly quickly; albeit with some ready prepared code.  It had been a while since I had played with Silverlight and this talk inspired me to go home and have a play about.  In this article I am going to outline the steps taken to create this video player but check out <a href="http://www.jason-mitchell.com/index.php/2009/08/30/silverlight-3-rotating-video-player/">this article</a> for step-by-step instructions to create this video player.</p>
<p><span id="more-89"></span></p>
<p align="justify">To make this application, I used <strong>Expression Blend 3</strong> although since Silverlight is based on <a href="http://en.wikipedia.org/wiki/XAML" target="_blank">XAML</a>, it is entirely possible to do this just from Visual Studio.  Personally, I don’t really like writing XAML unless I really have to and prefer to use the automatically generated code from Expression Blend.</p>
<p align="justify">The first step in creating this application was to give the default <strong>grid layout three rows</strong>, one for the video, one for the slider and one for the up and down buttons.  For this example, this step isn’t all <a href="http://www.jason-mitchell.com/images/blog/Silverlight3Fun3DProjectionandElementBin_D20F/blendControlsDialog.jpg"><img style="border-right-width: 0px; margin: 10px 0px 0px 10px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="blendControlsDialog" src="http://www.jason-mitchell.com/images/blog/Silverlight3Fun3DProjectionandElementBin_D20F/blendControlsDialog_thumb.jpg" border="0" alt="blendControlsDialog" width="492" height="344" align="right" /></a>that important but I did it anyway! The layout for this application is very straightforward to create; we need to add a<strong> MediaElement control</strong> to the top row, a<strong> Slider control</strong> to the second row finally <strong>two Button controls</strong> to the bottom row.  If you don’t know where to find the <strong>MediaElement </strong>and <strong>Slider</strong> controls, you can search for them in the <strong>assets dialog box</strong> which is shown in the image to the right.  Once you have added the<strong> Slider</strong> to your application, you can change the <strong>minimum and maximum values in the Common Properties pane</strong>.  I set mine to go from<strong> 0 to 360 so the Slider will spin the MediaElement around fully</strong>.  You will also want to set the<strong> media source for the MediaElement</strong> control, you can embed a video in the project and reference it in the Source box, however this will create a very large XAP package that will take some time to download.  To solve this you can specify a web address to use as your video source which is what I have done.</p>
<p align="justify">Next, we want to link the value of my <strong>Slider</strong> control, to the <strong>Projection.RotationY</strong> property to rotate the video around the <strong>Y-axis</strong>.  This is really simple to do , in Blend if you select the <strong>Slider control</strong>, open the <strong>Common Properties</strong> pane,<strong> right click on Value</strong> and select <strong>Data Binding</strong> you will see a new dialog box on the screen allowing to create a new data binding.  We want to bind the<strong> Slider</strong> value to the property of another element in the application so select the <strong>Element Property</strong> tab at the top of this window.  You should now see two lists, one that displays the elements in your application and another that displays the element properties.  Select your <strong>MediaElement</strong> control from the list on the left (I called mine<strong> mediaElement</strong>).  Unfortunately we can’t select the <strong>RotationY</strong> property from the second list so we need to check the box below the lists that say<strong> “Use a custom path expression” and enter Projection.RotationY</strong>.  We need to set the <strong>binding direction</strong> option to TwoWay, so click the arrow below the custom expression box and select TwoWay then click ok.  To make the <strong>MediaElement</strong> rotate about it’s centre, we need to change it’s<strong> centre of rotation in the Transform pane</strong>; make sure that the <strong>value of X is 0.5</strong> (the range goes from 0 to 1).   Now if you build and run the application you should be able to rotate the video using the Slider.</p>
<p align="justify">Now we need to make the buttons make the<strong> MediaElement</strong> fall down and come back up again.  First step is to make another change to it’s <strong>centre of rotation</strong>, so if we open the Transform pane again and <strong>set it’s Y value to 1</strong> to indicate that we want it to rotate on the X-axis around the bottom of the element.  In order to create the animations we need to use <strong>Storyboards</strong>, you can create a new storyboard by clicking the “+” in the<strong> Objects and Timeline pane</strong>.  Name your storyboard “Down”, we will use this to to make the<strong> MediaElement</strong> rotate and make it look like it fell over.  Once you create your<strong> storyboard</strong>, the timeline should automatically open; <strong>move the yellow marker</strong> to 1.5 seconds and with the <strong>MediaElement selected</strong>, go to the <strong>Transform pane and set the value of X under Projection to –90</strong>.  Now click play on the timeline and you should see the MediaElement “fall “ down….but it doesn’t look very realistic!!  To make this animation look a bit better, we can use something called<strong> Easing</strong>, a feature new to Silverlight 3. Click on the key frame in the timeline and the<strong> Easing pane</strong> should open up (by default this appears on the right hand side of the screen).  The<strong> Easing pane</strong> contains a drop down list with all the different types of easing, you should definitely have a play about with these and see their effects.  For my example, I chose <strong>Bounce Out </strong>to make it look as if the<strong> MediaElement</strong> has actually hit something that’s stopping it falling further.  Click play on the timeline and see what happens!</p>
<p>We now need to <strong>tell our application when to play this animation</strong>.  So select the button you want to use to make the video fall and open the<strong> events pane</strong> (little icon in the top right of the window with a lightning bolt on it).  In the <strong>Click box, type MoveDown and press enter (</strong>oh look Blend 3 has a built-in code editor), this will automatically hook up the event and create the method to handle it.  In your method type in “Down.Begin();” this will tell the storyboard to begin playing.</p>
<p>Creating the <strong>Up animation</strong> is similar to the Down animation.  Create a new storyboard and call it Up, then in the timeline move the yellow marker to 1.5 seconds and this time click the Record Keyframe button.  You MediaElement should already be displayed in the up-right position so we don’t need to change any properties.  If it isn’t upright, then set the X value for Projection in the Transform pane to 0.  Follow the same steps to add an Easing effect to this animation.  I used a Bounce Out effect again and set it’s bounces to 1 and bounciness to 23.  Don’t forget to set the event to your Up button!</p>
<p>Boy that was a lot of waffling, thinking back I should have maybe just made a numbered list of steps; maybe I will do that later!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jason-mitchell.com/index.php/2009/08/29/silverlight-3-fun-3d-projection-and-element-binding/feed/</wfw:commentRss>
		</item>
		<item>
		<title>XNA First Person Camera</title>
		<link>http://www.jason-mitchell.com/index.php/2009/08/27/xna-first-person-camera/</link>
		<comments>http://www.jason-mitchell.com/index.php/2009/08/27/xna-first-person-camera/#comments</comments>
		<pubDate>Thu, 27 Aug 2009 20:01:42 +0000</pubDate>
		<dc:creator>jmitch18</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[XNA]]></category>

		<guid isPermaLink="false">http://www.jason-mitchell.com/?p=75</guid>
		<description><![CDATA[As I previously mentioned, I plan on updating this blog with my experience of learning 3D XNA and hopefully be able to help out others doing the same as well as receive a bit of feedback and advice on how to improve the work I have done.  The first section I began working on was [...]]]></description>
			<content:encoded><![CDATA[<p>As I previously mentioned, I plan on updating this blog with my experience of learning 3D XNA and hopefully be able to help out others doing the same as well as receive a bit of feedback and advice on how to improve the work I have done.  The first section I began working on was the camera for the game.  Since my game is being planned for the Xbox Live Indie Games, the tutorial below is intended to work with the Xbox 360 game pad although with a little modification it should be possible to use it on the PC.</p>
<p> </p>
<p><span id="more-75"></span></p>
<p>The current view and field of vision are defined in two matrices; the <strong>View matrix</strong> and the <strong>Projection matrix</strong>. </p>
<p>In order to define the the <strong>View matrix</strong> we need 3 Vector3 objects; one for the position of the camera, one for the target the camera is pointing at and a vector defining which way is up for the camera. We don&#8217;t need to worry about what goes on to define the <strong>View matrix</strong> as the Matrix class in XNA provides a method called<strong> CreateLookAt</strong> which accepts the position, target and up vectors as parameters and returns the view matrix.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Matrix viewMatrix <span style="color: #008000;">=</span> Matrix.<span style="color: #0000FF;">CreateLookAt</span><span style="color: #000000;">&#40;</span>position, target, upVector<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>To create the <strong>Projection matrix</strong>, we need to know the angle of the field of view in radians, the aspect ratio of the screen, the near plane distance and the far plane distance. The near and far planes dictate the planes to draw between, everything outside of these planes will not be rendered. It is worth remembering that setting a very low near plane and a very large far plane may negatively impact your games performance if there is a lot going on. As with the View matrix, we do not need to worry too much about the details about how the <strong>Projection matrix</strong> is created as XNA again provides a useful method for this:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">projectionMatrix<span style="color: #008000;">=</span> Matrix.<span style="color: #0000FF;">CreatePerspectiveFieldOfView</span><span style="color: #000000;">&#40;</span>MathHelper.<span style="color: #0000FF;">PiOver4</span>, GraphicsDevice.<span style="color: #0000FF;">Viewport</span>.<span style="color: #0000FF;">AspectRatio</span>, <span style="color: #FF0000;">1</span>, <span style="color: #FF0000;">400</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>For my game, I decided to make a base<strong> camera</strong> class which handles all this for me so I don&#8217;t need to worry about it again.  The code for this class is very straight forward and simply handles the basic camera functionality.</p>
<p>Camera.cs</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">Microsoft.Xna.Framework</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> Cameras
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> Camera <span style="color: #008000;">:</span> GameComponent
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">public</span> Vector3 position<span style="color: #008000;">;</span>
        <span style="color: #0600FF;">public</span> Vector3 target<span style="color: #008000;">;</span>
        <span style="color: #0600FF;">public</span> Vector3 upVector<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> Matrix viewMatrix<span style="color: #008000;">;</span>
        <span style="color: #0600FF;">public</span> Matrix projectionMatrix<span style="color: #008000;">;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">float</span> fieldOfView <span style="color: #008000;">=</span> MathHelper.<span style="color: #0000FF;">PiOver4</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">float</span> nearPlaneDistance <span style="color: #008000;">=</span> 1f<span style="color: #008000;">;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">float</span> farPlaneDistance <span style="color: #008000;">=</span> 500f<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> Camera<span style="color: #000000;">&#40;</span>Game game, Vector3 position, Vector3 target, Vector3 upVector<span style="color: #000000;">&#41;</span>
            <span style="color: #008000;">:</span> <span style="color: #0600FF;">base</span><span style="color: #000000;">&#40;</span>game<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">position</span> <span style="color: #008000;">=</span> position<span style="color: #008000;">;</span>
            <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">target</span> <span style="color: #008000;">=</span> target<span style="color: #008000;">;</span>
            <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">upVector</span> <span style="color: #008000;">=</span> upVector<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> Initialize<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            UpdateViewMatrix<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #FF0000;">float</span> aspectRatio <span style="color: #008000;">=</span> Game.<span style="color: #0000FF;">GraphicsDevice</span>.<span style="color: #0000FF;">Viewport</span>.<span style="color: #0000FF;">AspectRatio</span><span style="color: #008000;">;</span>
            projectionMatrix<span style="color: #008000;">=</span> Matrix.<span style="color: #0000FF;">CreatePerspectiveFieldOfView</span><span style="color: #000000;">&#40;</span>fieldOfView, aspectRatio, nearPlaneDistance, farPlaneDistance<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">Initialize</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">void</span> UpdateViewMatrix<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            viewMatrix <span style="color: #008000;">=</span> Matrix.<span style="color: #0000FF;">CreateLookAt</span><span style="color: #000000;">&#40;</span>position, target, upVector<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>For this class, I have made all it&#8217;s variables public for the purposes of this article so the code is much shorter.  I would strongly recommend encapsulating these variables if you are using it in any of your projects.</p>
<p>All this class does is allow us to point the camera in one direction and does not have any built in functionality for movement so that is our next step.  So far, I&#8217;ve always found myself wanting to be able to move around and get a better look at what I&#8217;m currently working on, so for that reason my next step was to create a <strong>first person camera</strong>.  This was a bit trickier, however with a bit of playing around I was eventually able to get it working!  Following is the code for the class and then I will explain it a bit afterwards.</p>
<p>FirstPersonCamera.cs</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">Microsoft.Xna.Framework</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> Cameras
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> FirstPersonCamera <span style="color: #008000;">:</span> Camera
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">public</span> Vector3 cameraReference<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">float</span> leftRightRot<span style="color: #008000;">;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">float</span> upDownRot<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">float</span> rotationSpeed <span style="color: #008000;">=</span> 0.05f<span style="color: #008000;">;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">float</span> translationSpeed <span style="color: #008000;">=</span> 1f<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> FirstPersonCamera<span style="color: #000000;">&#40;</span>Game game, Vector3 position, Vector3 target, Vector3 upVector<span style="color: #000000;">&#41;</span>
            <span style="color: #008000;">:</span> <span style="color: #0600FF;">base</span><span style="color: #000000;">&#40;</span>game, position, target, upVector<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            cameraReference <span style="color: #008000;">=</span> target<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> Update<span style="color: #000000;">&#40;</span>Vector3 translation, <span style="color: #FF0000;">float</span> leftRightRot, <span style="color: #FF0000;">float</span> upDownRot<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">leftRightRot</span> <span style="color: #008000;">+=</span> leftRightRot <span style="color: #008000;">*</span> rotationSpeed<span style="color: #008000;">;</span>
            <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">upDownRot</span> <span style="color: #008000;">+=</span> upDownRot <span style="color: #008000;">*</span> rotationSpeed<span style="color: #008000;">;</span>
            Matrix rotationMatrix <span style="color: #008000;">=</span> Matrix.<span style="color: #0000FF;">CreateRotationX</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">upDownRot</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">*</span> Matrix.<span style="color: #0000FF;">CreateRotationY</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">leftRightRot</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            Vector3 transformedReference <span style="color: #008000;">=</span> Vector3.<span style="color: #0000FF;">Transform</span><span style="color: #000000;">&#40;</span>cameraReference, rotationMatrix<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            position <span style="color: #008000;">+=</span> Vector3.<span style="color: #0000FF;">Transform</span><span style="color: #000000;">&#40;</span>translation, rotationMatrix<span style="color: #000000;">&#41;</span> <span style="color: #008000;">*</span> translationSpeed<span style="color: #008000;">;</span>
            target <span style="color: #008000;">=</span> transformedReference <span style="color: #008000;">+</span> position<span style="color: #008000;">;</span>
&nbsp;
            UpdateViewMatrix<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Possibly the most important part of this is the <strong>cameraReference</strong> variable.  This holds the <strong>original target vector</strong> we set up for our camera and is used for calculating our resulting camera target after rotation.  This was the part that was catching me out for a little while!  The<strong> leftRightRot</strong> and <strong>upDownRot</strong> variables keep track of how far we have moved from the <strong>original target</strong> and are also used in calculating our<strong> rotated camera target</strong>.</p>
<p>I created a new<strong> Update</strong> method that accepts the <strong>translation</strong> (ie the amout to move the camera by),<strong> left-right rotation</strong> and <strong>up-down rotation</strong> as parameters.  My next step was to add this onto my<strong> rotation variables and create the rotation matrix</strong>.  The purpose for adding the rotations to my class variables rather than just assigning them, is so that the<strong> camera rotation will persist</strong> even after, for example, the thumbstick has been released and is at it default position.  If we were to just assign the rotations to the variables, The camera would have limited movement in the desired direction and then reset to the centre once the thumbstick has been released.</p>
<p>Now that I have the <strong>rotation matrix</strong>, I can use this, along with the <strong>cameraReference</strong> the calculate the <strong>rotated camera target</strong>.  All that is left to do is to<strong> calculate the rotated translation</strong>, <strong>add it to the camera position</strong> and set the<strong> new camera target by adding our transformedReference to the camera position</strong>.  Finally we called the <strong>UpdateViewMatrix</strong> method from the Camera class to generate our new view matrix.</p>
<p>It is worth noting that if you are rotating in any possible combination of the x, y and z axis, you may encounter an issue known as <a href="http://en.wikipedia.org/wiki/Gimbal_lock" target="_blank">Gimbal Lock</a>.  I have read that this can be solved by using<strong> Quaternions</strong> for the rotations but I have yet to look into this too much.  If anyone has any useful information about how to do this please let me know!</p>
<p>Lastly we will need a way to test our camera out so here is a small class I used for my testing; I&#8217;m not going to explain it as it&#8217;s all fairly straight forward!</p>
<p>Game1.cs</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">Microsoft.Xna.Framework</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">Microsoft.Xna.Framework.Graphics</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">Microsoft.Xna.Framework.Input</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> Cameras
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> Game1 <span style="color: #008000;">:</span> Microsoft.<span style="color: #0000FF;">Xna</span>.<span style="color: #0000FF;">Framework</span>.<span style="color: #0000FF;">Game</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">private</span> GraphicsDeviceManager graphics<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF;">private</span> FirstPersonCamera camera<span style="color: #008000;">;</span>
        <span style="color: #0600FF;">private</span> VertexPositionColor<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> verts<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> Game1<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            graphics <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> GraphicsDeviceManager<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            Content.<span style="color: #0000FF;">RootDirectory</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Content&quot;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> Initialize<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            camera <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> FirstPersonCamera<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>, <span style="color: #008000;">new</span> Vector3<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span>, <span style="color: #FF0000;">0</span>, <span style="color: #FF0000;">20</span><span style="color: #000000;">&#41;</span>, Vector3.<span style="color: #0000FF;">Forward</span>, Vector3.<span style="color: #0000FF;">Up</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            Components.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>camera<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">Initialize</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> LoadContent<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            verts <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> VertexPositionColor<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">4</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
            verts<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> VertexPositionColor<span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> Vector3<span style="color: #000000;">&#40;</span><span style="color: #008000;">-</span><span style="color: #FF0000;">3</span>, <span style="color: #008000;">-</span><span style="color: #FF0000;">3</span>, <span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span>, Color.<span style="color: #0000FF;">Red</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            verts<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> VertexPositionColor<span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> Vector3<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">3</span>, <span style="color: #008000;">-</span><span style="color: #FF0000;">3</span>, <span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span>, Color.<span style="color: #0000FF;">Green</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            verts<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">2</span><span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> VertexPositionColor<span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> Vector3<span style="color: #000000;">&#40;</span><span style="color: #008000;">-</span><span style="color: #FF0000;">3</span>, <span style="color: #FF0000;">3</span>, <span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span>, Color.<span style="color: #0000FF;">Blue</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            verts<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">3</span><span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> VertexPositionColor<span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> Vector3<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">3</span>, <span style="color: #FF0000;">3</span>, <span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span>, Color.<span style="color: #0000FF;">Yellow</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> UnloadContent<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
&nbsp;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> Update<span style="color: #000000;">&#40;</span>GameTime gameTime<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            GamePadState gamepadState <span style="color: #008000;">=</span> GamePad.<span style="color: #0000FF;">GetState</span><span style="color: #000000;">&#40;</span>PlayerIndex.<span style="color: #0000FF;">One</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>gamepadState.<span style="color: #0000FF;">Buttons</span>.<span style="color: #0000FF;">Back</span> <span style="color: #008000;">==</span> ButtonState.<span style="color: #0000FF;">Pressed</span><span style="color: #000000;">&#41;</span>
                <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Exit</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            Vector3 translation <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Vector3<span style="color: #000000;">&#40;</span>gamepadState.<span style="color: #0000FF;">ThumbSticks</span>.<span style="color: #0000FF;">Left</span>.<span style="color: #0000FF;">X</span>, <span style="color: #FF0000;">0</span>, <span style="color: #008000;">-</span>gamepadState.<span style="color: #0000FF;">ThumbSticks</span>.<span style="color: #0000FF;">Left</span>.<span style="color: #0000FF;">Y</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            camera.<span style="color: #0000FF;">Update</span><span style="color: #000000;">&#40;</span>translation, <span style="color: #008000;">-</span>gamepadState.<span style="color: #0000FF;">ThumbSticks</span>.<span style="color: #0000FF;">Right</span>.<span style="color: #0000FF;">X</span>, gamepadState.<span style="color: #0000FF;">ThumbSticks</span>.<span style="color: #0000FF;">Right</span>.<span style="color: #0000FF;">Y</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">Update</span><span style="color: #000000;">&#40;</span>gameTime<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> Draw<span style="color: #000000;">&#40;</span>GameTime gameTime<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            GraphicsDevice.<span style="color: #0000FF;">Clear</span><span style="color: #000000;">&#40;</span>Color.<span style="color: #0000FF;">CornflowerBlue</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            GraphicsDevice.<span style="color: #0000FF;">RenderState</span>.<span style="color: #0000FF;">CullMode</span> <span style="color: #008000;">=</span> CullMode.<span style="color: #0000FF;">None</span><span style="color: #008000;">;</span>
&nbsp;
            GraphicsDevice.<span style="color: #0000FF;">VertexDeclaration</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> VertexDeclaration<span style="color: #000000;">&#40;</span>GraphicsDevice, VertexPositionColor.<span style="color: #0000FF;">VertexElements</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            BasicEffect effect <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> BasicEffect<span style="color: #000000;">&#40;</span>GraphicsDevice, <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            effect.<span style="color: #0000FF;">World</span> <span style="color: #008000;">=</span> Matrix.<span style="color: #0000FF;">Identity</span><span style="color: #008000;">;</span>
            effect.<span style="color: #0000FF;">View</span> <span style="color: #008000;">=</span> camera.<span style="color: #0000FF;">ViewMatrix</span><span style="color: #008000;">;</span>
            effect.<span style="color: #0000FF;">Projection</span> <span style="color: #008000;">=</span> camera.<span style="color: #0000FF;">ProjectionMatrix</span><span style="color: #008000;">;</span>
&nbsp;
            effect.<span style="color: #0000FF;">VertexColorEnabled</span> <span style="color: #008000;">=</span> true<span style="color: #008000;">;</span>
&nbsp;
            effect.<span style="color: #0000FF;">Begin</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>EffectPass pass <span style="color: #0600FF;">in</span> effect.<span style="color: #0000FF;">CurrentTechnique</span>.<span style="color: #0000FF;">Passes</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                pass.<span style="color: #0000FF;">Begin</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                GraphicsDevice.<span style="color: #0000FF;">DrawUserPrimitives</span><span style="color: #000000;">&#40;</span>PrimitiveType.<span style="color: #0000FF;">TriangleStrip</span>, verts, <span style="color: #FF0000;">0</span>, <span style="color: #FF0000;">2</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                pass.<span style="color: #0000FF;">End</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
            effect.<span style="color: #0000FF;">End</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">Draw</span><span style="color: #000000;">&#40;</span>gameTime<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.jason-mitchell.com/index.php/2009/08/27/xna-first-person-camera/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
