<?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>Milan Nankov’s Blog &#187; Game Development</title>
	<atom:link href="http://blog.nankov.com/category/technology/game-development/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.nankov.com</link>
	<description>WPF, XNA, MSBuild, and other technologies blog</description>
	<lastBuildDate>Sat, 22 Oct 2011 21:00:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Unit Testing Games (Part 1) &#8211; Vectors and Transformations</title>
		<link>http://blog.nankov.com/2008/11/25/unit-testing-games-part-1-vectors-and-transformations/</link>
		<comments>http://blog.nankov.com/2008/11/25/unit-testing-games-part-1-vectors-and-transformations/#comments</comments>
		<pubDate>Tue, 25 Nov 2008 09:26:46 +0000</pubDate>
		<dc:creator>Milan</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[Software Testing]]></category>
		<category><![CDATA[XNA]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[games]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[trasformation]]></category>
		<category><![CDATA[Unit Testing]]></category>
		<category><![CDATA[vectors]]></category>

		<guid isPermaLink="false">http://blog.nankov.com/?p=116</guid>
		<description><![CDATA[Test driven development and testing in general are mandatory techniques if you are serious about the code that you create. That is especially true in game development where almost every piece of code is very complex. In this first post about testing I will give you a little insight about testing vectors and transformations. The [...]]]></description>
			<content:encoded><![CDATA[<p>Test driven development and testing in general are mandatory techniques if you are serious about the code that you create. That is especially true in game development where almost every piece of code is very complex. In this first post about testing I will give you a little insight about testing vectors and transformations.</p>
<p>The code that I am going to provide is written for the XNA framework and the Visual Studio testing framework but the concepts that are described in this post can be applied to any game development and testing platforms. <span id="more-116"></span></p>
<p>In many cases ensuring that a vector is the one we expect is not as straight forward as writing:</p>
<pre name="code" class="c#">
Assert.AreEqual(expectedVector, actualVector).
</pre>
<p>To illustrate the problem imagine that we have a vector (0, 0, -200), we perform some operations that transform the vector by rotating it around the Y axis by 90 degrees, and we want to assert that the operation is done correctly. You might be baffled to find that after the transformation the vector does not equal exactly (-200, 0, 0), but rather something like (-200, 0, 0.000008742278). This “error” has to do with floating-point numbers and round-off errors. So in order to be able to test our code we have to allow for such imprecision.</p>
<p>The Visual Studio testing framework provides a method that we can use to compare floating-point numbers with a specified tolerance. We just have to build on top of that in order to create a method that we can use for vector comparison. Let&#8217;s call the method VectorsAreEqual and inplement it in a class called MathAssert.</p>
<pre name="code" class="c#">
public static class MathAssert
{
    private static float precisionDelta = 0.00001f;

    public static void VectorsAreEqual(Vector3 expected, Vector3 actual)
    {
        Assert.AreEqual(expected.X, actual.X, precisionDelta);
        Assert.AreEqual(expected.Y, actual.Y, precisionDelta);
        Assert.AreEqual(expected.Z, actual.Z, precisionDelta);
    }
}
</pre>
<p>The method is very simple and probably the only question remaining is what a good value for the delta is? The value should be as precise a possible, but at the same time not too precise so it can eliminate the floting-point errors. In my tests I am using a value of 0.00001 which in my opinion is good enough.</p>
<p>Now that we have created our method we can easily compare the vectors (-200, 0, 0.000008742278) and (-200, 0, 0) and assert that they are equal:</p>
<pre name="code" class="c#">
Vector3 expectedVector = new Vector3(-200f, 0f, 0f);
Vector3 actualVector = new Vector3(-200f, 0f, 0.000008742278f);

MathAssert.VectorsAreEqual(expectedVector, actualVector);
</pre>
<p>Transformations are another fundamental part of game programming and being able to test them is crucial. If you are building a scene graph, for example, you probably want to make sure the when a parent node rotates all of its child nodes rotate as well. So we need a way to verify that the resulting transformations are computed as expected. As you might know transformations are composed of linearly independent vectors called basis vectors. A 2D transformation matrix has 2 basis vectors, while a 3D matrix has 3.</p>
<img class="size-full wp-image-119" title="2D Transformations" src="http://blog.nankov.com/wp-content/uploads/2008/11/2dtransformations.png" alt="2D Transformations" width="800" height="200" />
<p>The illustrations above show 3 different two-dimensional transformations and their basis vectors. First (on figure 1) we have identity transformation which does not alter vectors in any way. On the second figure we have a transformation that performs 90 degree rotation of vectors. On figure 3 we have a transformation that performs scaling along the X axis. </p>
<p>As you might know every basis vector corresponds to a single axis of the coordinate space that its transformation describes. In figure 1, for example, the first basis vector corresponds to the X axis and the second vector corresponds to the Y axis. Similarly on figure 2 the first basis vector corresponds to the X axis but the difference there is that the X axis of this transformation points up.<br />
In order to test a transformation for correctness we need to assert that the basis vectors are the ones that we expect. </p>
<p>XNA’s Matrix class can give us a lot of information and we can easily get the basis vectors. The three basis vectors are Matrix.Right, Matrix.Up, and Matrix.Forward.  So if we expect to have a transformation that would rotate a vector around the Y axis by 90 degrees we would expect to have (-1, 0, 0) for Forward, (0, 0, -1) for Right, and (0, 0, 1) for Up. </p>
<p>So in order to test a transformation we have to test the 3 basis vectors. For convenience we create a a new method called BasisIsCorrect in our MathAssert class: </p>
<pre name="code" class="c#">
public static class MathAssert
{
    private static float precisionDelta = 0.00001f;

    public static void VectorsAreEqual(Vector3 expected, Vector3 actual)
    {
        Assert.AreEqual(expected.X, actual.X, precisionDelta);
        Assert.AreEqual(expected.Y, actual.Y, precisionDelta);
        Assert.AreEqual(expected.Z, actual.Z, precisionDelta);
    } 

    public static void BasisIsCorrect(Matrix basis, Vector3 expectedForward, Vector3 expectedRight, Vector3 expectedUp)
    {
        MathAssert.VectorsAreEqual(expectedForward, basis.Forward);
        MathAssert.VectorsAreEqual(expectedRight, basis.Right);
        MathAssert.VectorsAreEqual(expectedUp, basis.Up);
    }
}
</pre>
<p>Now all we have to do to test a transformation is to use this method.</p>
<p>Happy testing.</p>
<div class="printfriendly alignleft"><a href="http://blog.nankov.com/2008/11/25/unit-testing-games-part-1-vectors-and-transformations/?pfstyle=wp" rel="nofollow" ><img src="//cdn.printfriendly.com/pf-icon-small.gif" alt="Print Friendly"/><span class="printfriendly-text">Print Friendly</span></a></div>]]></content:encoded>
			<wfw:commentRss>http://blog.nankov.com/2008/11/25/unit-testing-games-part-1-vectors-and-transformations/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Best books about game development</title>
		<link>http://blog.nankov.com/2008/10/30/best-books-about-game-development/</link>
		<comments>http://blog.nankov.com/2008/10/30/best-books-about-game-development/#comments</comments>
		<pubDate>Thu, 30 Oct 2008 21:46:08 +0000</pubDate>
		<dc:creator>Milan</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[Best]]></category>
		<category><![CDATA[Books]]></category>
		<category><![CDATA[DirectX]]></category>
		<category><![CDATA[Shaders]]></category>

		<guid isPermaLink="false">http://blog.nankov.com/?p=6</guid>
		<description><![CDATA[Since this is my first post I&#8217;ve decided to start off with a post that would help anyone that is just starting with game development and is looking for the right books that will get him going. There are primarily two problems of finding good books about game development. First there are many of them [...]]]></description>
			<content:encoded><![CDATA[<p>Since this is my first post I&#8217;ve decided to start off with a post that would help anyone that is just starting with game development and is looking for the right books that will get him going.</p>
<p>There are primarily two problems of finding good books about game development. First there are many of them our there. Probably not as many as in some other fields but still you should spend considerable time for research. The second problem is that game development tends to be a very complex and very extensive field and unfortunately not every author can present such complex material in a digestible form.</p>
<p>When I first started with game development I bought about 2 dozen books and as you might expect some of them were great while others proved to be a waste of money. In attempt to save someone some time and money I have listed several books that, in my opinion, are the best.<span id="more-6"></span></p>
<p>So here is my list of the best books about game development:</p>
<div style="left: 0px; float: left; width: 100%; position: relative; top: 0px;">
<div style="left: 0px; float: left; width: 244; position: relative; top: 0px;">
<div id="attachment_13" class="wp-caption alignleft" style="width: 254px"><a href="http://www.amazon.com/Primer-Graphics-Development-Wordware-Library/dp/1556229119/ref=pd_bbs_sr_1?ie=UTF8&amp;s=books&amp;qid=1225395683&amp;sr=8-1"><img class="size-full wp-image-13" title="3d-math-primer" src="http://blog.nankov.com/wp-content/uploads/2008/10/3d-math-primer.jpg" alt="3D Path Primer for Graphics and Game Development" width="244" height="300" /></a><p class="wp-caption-text">3D Math Primer for Graphics and Game Development</p></div>
</div>
<div>
<p>This is one of my favorite books. It is a great source for learning the mathematics behind game development. Important concepts like coordinate spaces, vectors, matrices, quaternions, transformations, etc are clearly explained. The understanding is aided by good illustrations and sample code written in C++. Moreover, the last part of the book introduces many technologies like collision tests, lighting, etc that are used in today&#8217;s games and are build upon the concepts introduces in the first part of the book.<br />
Great book.</p></div>
</div>
<div style="left: 0px; float: left; width: 100%; position: relative; top: 0px;">
<div style="left: 0px; float: left; width: 244; position: relative; top: 0px;">
<div id="attachment_16" class="wp-caption alignleft" style="width: 210px"><a href="http://www.amazon.com/Introduction-Game-Programming-Direct-9-0c/dp/1598220160/ref=pd_bbs_sr_2?ie=UTF8&amp;s=books&amp;qid=1225396789&amp;sr=8-2"><img class="size-full wp-image-16" title="intro-to-3d" src="http://blog.nankov.com/wp-content/uploads/2008/10/intro-to-3d.jpg" alt="Introduction to 3D Game Programming with DirectX 9.0c" width="200" height="300" /></a><p class="wp-caption-text">Introduction to 3D Game Programming with DirectX 9.0c a Shader Approach</p></div>
</div>
<div>
<p>Another favorite. Great introduction to the DirectX API. Most importantly the book focuses on the use of shaders and the High-level shading language. The book demonstrates how you can use shaders to create special effects like reflections, shadows, lighting, particle systems, etc.<br />
The latest iteration of this book focuses on DirectX 10. I haven&#8217;t been able to check it our so far but I&#8217;m sure that it is a must have introduction to DX 10.</p></div>
</div>
<div style="left: 0px; float: left; width: 100%; position: relative; top: 0px;">
<div style="left: 0px; float: left; width: 244; position: relative; top: 0px;">
<div id="attachment_18" class="wp-caption alignleft" style="width: 254px"><a href="http://www.amazon.com/Game-Coding-Complete-Mike-McShaffry/dp/1932111913/ref=sr_1_5?ie=UTF8&amp;s=books&amp;qid=1225397627&amp;sr=8-5"><img class="size-full wp-image-18" title="game-coding-complete" src="http://blog.nankov.com/wp-content/uploads/2008/10/game-coding-complete.jpg" alt="Game Conding Complete, Second Edition" width="244" height="315" /></a><p class="wp-caption-text">Game Coding Complete, Second Edition</p></div>
</div>
<div>
<p>One of the best books about computer technologies that I have ever read. Great writing style and most importantly great content. The book explores game development on a higher level by introducing the concept of game engines. If you want to learn about the building blocks of today&#8217;s games and how those blocks interact with one another this book is probably the best starting resource available.</p></div>
</div>
<div style="left: 0px; float: left; width: 100%; position: relative; top: 0px;">
<div style="left: 0px; float: left; width: 244; position: relative; top: 0px;">
<div id="attachment_19" class="wp-caption alignleft" style="width: 210px"><a href="http://www.amazon.com/ShaderX5-Advanced-Rendering-Techniques-Shaderx/dp/1584504994"><img class="size-full wp-image-19" title="shaderx" src="http://blog.nankov.com/wp-content/uploads/2008/10/shaderx.jpg" alt="Shader X Series" width="200" height="251" /></a><p class="wp-caption-text">Shader X Series</p></div>
</div>
<div>
<p>No doubt one of the best sources for intermediate to advanced knowledge in the field of graphics. Every edition provides a look into cutting-edge computer graphics techniques that take advantage of the latest advancements in computer hardware. Truly a remarkable resource and a must-have.</p></div>
</div>
<p>I have got a couple more good books on my shelves, but I will leave them for another time.<br />
Share your thoughts about my book selection. What are your favorite books?</p>
<div class="printfriendly alignleft"><a href="http://blog.nankov.com/2008/10/30/best-books-about-game-development/?pfstyle=wp" rel="nofollow" ><img src="//cdn.printfriendly.com/pf-icon-small.gif" alt="Print Friendly"/><span class="printfriendly-text">Print Friendly</span></a></div>]]></content:encoded>
			<wfw:commentRss>http://blog.nankov.com/2008/10/30/best-books-about-game-development/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

