XNA http://blogs.ugidotnet.org/angellaa-en/category/XNA.aspx XNA en Angella Andrea Subtext Version 2.6.0.0 XNA &ndash; DirectX Capabilities Viewer http://blogs.ugidotnet.org/angellaa-en/archive/2010/05/29/xna-ndash-directx-capabilities-viewer.aspx <p> <br />If you want to know the capabilities available in your graphics card you can use a tool in the DirectX SDK\Utilities\Bin\x86.</p> <p>This tool is called “<strong>DXCapsViewer.exe</strong>”.</p> <p>Here a screenshot with the capabilities of my NVIDIA GeForce 8600M GT: <br /></p> <p><a href="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/angellaa-en/WindowsLiveWriter/XNADirectXCapabilitiesViewer_22BB/capsviewer_2.jpg" rel="lightbox"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="capsviewer" border="0" alt="capsviewer" src="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/angellaa-en/WindowsLiveWriter/XNADirectXCapabilitiesViewer_22BB/capsviewer_thumb.jpg" width="983" height="669" /></a> </p> <p> </p> <p>You can download the latest DirectX SDK at the following link:</p> <p><a title="http://msdn.microsoft.com/en-us/directx/aa937788.aspx" href="http://msdn.microsoft.com/en-us/directx/aa937788.aspx">http://msdn.microsoft.com/en-us/directx/aa937788.aspx</a></p><img src="http://blogs.ugidotnet.org/angellaa-en/aggbug/98678.aspx" width="1" height="1" /> Angella Andrea http://blogs.ugidotnet.org/angellaa-en/archive/2010/05/29/xna-ndash-directx-capabilities-viewer.aspx Sat, 29 May 2010 02:33:09 GMT http://blogs.ugidotnet.org/angellaa-en/archive/2010/05/29/xna-ndash-directx-capabilities-viewer.aspx#feedback 1 http://blogs.ugidotnet.org/angellaa-en/comments/commentRss/98678.aspx http://blogs.ugidotnet.org/angellaa-en/services/trackbacks/98678.aspx XNA &ndash; Multisampling http://blogs.ugidotnet.org/angellaa-en/archive/2010/05/29/xna-ndash-multisampling.aspx <p><strong>Multisampling</strong> is an <strong>antialiasing</strong> technique directly supported by DirectX and obviously by XNA. The problem of aliasing occurs when you draw a line on a monitor with low resolution. In that cases you see a stair step when approximating a line by a matrix of pixels. Multisampling use neighbouring pixels (called <strong>samples</strong>) to calculate the final color of a pixel.</p> <p>You can enable multisampling in XNA in this simple way:</p> <pre class="code"><span style="color: rgb(1, 0, 1);">graphics</span>.<span style="color: rgb(1, 0, 1);">PreferMultiSampling </span>= <span style="color: blue;">true</span>;</pre> <a href="http://11011.net/software/vspaste"></a> <p> <br /> Then you should also specify two options. </p> <p>The <strong>type</strong> is an enumerator (<strong>MultiSampleType</strong>) that represent the number of samples to use in multisampling. The <strong>quality</strong> is an integer that represent the quality level. This value is always set to zero. Before to set the type of multisampling you should always check if the graphic adapter support it using the method <strong><span style="color: rgb(1, 0, 1);">adapter</span>.<span style="color: rgb(1, 0, 1);">CheckDeviceMultiSampleType()</span></strong></p> <pre class="code"><span style="color: rgb(1, 0, 1);">graphics</span>.<span style="color: rgb(1, 0, 1);">PreparingDeviceSettings </span>+= <span style="color: blue;">new </span><span style="color: rgb(43, 145, 175);">EventHandler</span>&lt;<span style="color: rgb(43, 145, 175);">PreparingDeviceSettingsEventArgs</span>&gt;((<span style="color: rgb(1, 0, 1);">sender</span>, <span style="color: rgb(1, 0, 1);">e</span>) =&gt; <br />{<br /> <span style="color: rgb(43, 145, 175);">PresentationParameters </span><span style="color: rgb(1, 0, 1);">parameters </span>= <span style="color: rgb(1, 0, 1);">e</span>.<span style="color: rgb(1, 0, 1);">GraphicsDeviceInformation</span>.<span style="color: rgb(1, 0, 1);">PresentationParameters</span>;<br /> <span style="color: rgb(1, 0, 1);">parameters</span>.<span style="color: rgb(1, 0, 1);">MultiSampleQuality </span>= 0;<br /><br /> <span style="color: blue;">#if </span>XBOX<br /> <span style="color: gray;">pp.MultiSampleType = MultiSampleType.FourSamples;<br /> return;<br /> </span><span style="color: blue;">#else<br /><br /> int </span><span style="color: rgb(1, 0, 1);">quality</span>;<br /> <span style="color: rgb(43, 145, 175);">GraphicsAdapter </span><span style="color: rgb(1, 0, 1);">adapter </span>= <span style="color: rgb(1, 0, 1);">e</span>.<span style="color: rgb(1, 0, 1);">GraphicsDeviceInformation</span>.<span style="color: rgb(1, 0, 1);">Adapter</span>;<br /> <span style="color: rgb(43, 145, 175);">SurfaceFormat </span><span style="color: rgb(1, 0, 1);">format </span>= <span style="color: rgb(1, 0, 1);">adapter</span>.<span style="color: rgb(1, 0, 1);">CurrentDisplayMode</span>.<span style="color: rgb(1, 0, 1);">Format</span>;<br /><br /> <span style="color: blue;">if </span>(<span style="color: rgb(1, 0, 1);">adapter</span>.<span style="color: rgb(1, 0, 1);">CheckDeviceMultiSampleType</span>(<span style="color: rgb(43, 145, 175);">DeviceType</span>.<span style="color: rgb(1, 0, 1);">Hardware</span>, <span style="color: rgb(1, 0, 1);">format</span>, <span style="color: blue;">false</span>, <span style="color: rgb(43, 145, 175);">MultiSampleType</span>.<span style="color: rgb(1, 0, 1);">FourSamples</span>, <span style="color: blue;">out </span><span style="color: rgb(1, 0, 1);">quality</span>))<br /> {<br /> <span style="color: rgb(1, 0, 1);">parameters</span>.<span style="color: rgb(1, 0, 1);">MultiSampleType </span>= <span style="color: rgb(43, 145, 175);">MultiSampleType</span>.<span style="color: rgb(1, 0, 1);">FourSamples</span>;<br /> }<br /> <span style="color: blue;">else if </span>(<span style="color: rgb(1, 0, 1);">adapter</span>.<span style="color: rgb(1, 0, 1);">CheckDeviceMultiSampleType</span>(<span style="color: rgb(43, 145, 175);">DeviceType</span>.<span style="color: rgb(1, 0, 1);">Hardware</span>, <span style="color: rgb(1, 0, 1);">format</span>, <span style="color: blue;">false</span>, <span style="color: rgb(43, 145, 175);">MultiSampleType</span>.<span style="color: rgb(1, 0, 1);">TwoSamples</span>, <span style="color: blue;">out </span><span style="color: rgb(1, 0, 1);">quality</span>))<br /> {<br /> <span style="color: rgb(1, 0, 1);">parameters</span>.<span style="color: rgb(1, 0, 1);">MultiSampleType </span>= <span style="color: rgb(43, 145, 175);">MultiSampleType</span>.<span style="color: rgb(1, 0, 1);">TwoSamples</span>;<br /> } <br />});</pre> <a href="http://11011.net/software/vspaste"></a><a href="http://11011.net/software/vspaste"></a> <p> </p> <p>For more information:</p> <p><a href="http://en.wikipedia.org/wiki/Multisample_anti-aliasing" title="http://en.wikipedia.org/wiki/Multisample_anti-aliasing">http://en.wikipedia.org/wiki/Multisample_anti-aliasing</a></p> <p><a href="http://msdn.microsoft.com/en-us/library/bb975403.aspx" title="http://msdn.microsoft.com/en-us/library/bb975403.aspx">http://msdn.microsoft.com/en-us/library/bb975403.aspx</a></p><img src="http://blogs.ugidotnet.org/angellaa-en/aggbug/98677.aspx" width="1" height="1" /> Angella Andrea http://blogs.ugidotnet.org/angellaa-en/archive/2010/05/29/xna-ndash-multisampling.aspx Sat, 29 May 2010 02:00:01 GMT http://blogs.ugidotnet.org/angellaa-en/archive/2010/05/29/xna-ndash-multisampling.aspx#feedback 2 http://blogs.ugidotnet.org/angellaa-en/comments/commentRss/98677.aspx http://blogs.ugidotnet.org/angellaa-en/services/trackbacks/98677.aspx XNA &ndash; Nuclex Framework http://blogs.ugidotnet.org/angellaa-en/archive/2010/05/29/xna-ndash-nuclex-framework.aspx <p>I would like to inform you that an interesting stable project is available on codeplex. This is the Nuclex Framework.</p> <p>This is the main page of the project:</p> <p><a href="http://nuclexframework.codeplex.com/" title="http://nuclexframework.codeplex.com/">http://nuclexframework.codeplex.com/</a></p> <p>The more interesting features for me are the following:</p> <ul> <li><a href="http://nuclexframework.codeplex.com/wikipage?title=Vector%20Fonts&amp;referringTitle=Documentation">3D Text Rendering</a></li> <li><a href="http://nuclexframework.codeplex.com/wikipage?title=LzmaContentManager&amp;referringTitle=Documentation">LZMA Content Compression</a> (that's 7-Zip's compression)</li> <li><a href="http://nuclexframework.codeplex.com/wikipage?title=Nuclex.UserInterface&amp;referringTitle=Documentation">Themeable Graphical User Interfaces</a></li> <li><a href="http://nuclexframework.codeplex.com/wikipage?title=Game%20State%20Management&amp;referringTitle=Documentation">Game State Management</a></li> <li><a href="http://nuclexframework.codeplex.com/wikipage?title=DebugDrawer&amp;referringTitle=Documentation">Debugging Overlays</a></li> </ul><img src="http://blogs.ugidotnet.org/angellaa-en/aggbug/98676.aspx" width="1" height="1" /> Angella Andrea http://blogs.ugidotnet.org/angellaa-en/archive/2010/05/29/xna-ndash-nuclex-framework.aspx Sat, 29 May 2010 00:55:20 GMT http://blogs.ugidotnet.org/angellaa-en/archive/2010/05/29/xna-ndash-nuclex-framework.aspx#feedback http://blogs.ugidotnet.org/angellaa-en/comments/commentRss/98676.aspx http://blogs.ugidotnet.org/angellaa-en/services/trackbacks/98676.aspx XNA &ndash; Analytical Geometry http://blogs.ugidotnet.org/angellaa-en/archive/2010/05/28/xna-ndash-analytical-geometry.aspx <p>Mathematics plays a fundamental role in video game development. I strongly recommend to study the basics of linear algebra to have a better control of what you create. However, in XNA there is a lot of support for analytical geometry. There are some complex algorithms already implemented so it’s extremely important to know what it is available.</p> <p>You can manage positions, speeds and directions using the classes: <strong>Point</strong>, <strong>Vector2</strong>, <strong>Vector3 </strong>and <strong>Vector4</strong>. </p> <pre class="code"><span style="color: rgb(43, 145, 175);">Vector3 </span><span style="color: rgb(1, 0, 1);">a </span>= <span style="color: blue;">new </span><span style="color: rgb(43, 145, 175);">Vector3</span>(0, 0, 10);<br /><span style="color: rgb(1, 0, 1);">a</span>.<span style="color: rgb(1, 0, 1);">Normalize</span>();<br /><span style="color: blue;">float </span><span style="color: rgb(1, 0, 1);">x </span>= <span style="color: rgb(1, 0, 1);">a</span>.<span style="color: rgb(1, 0, 1);">X</span>;<br /><span style="color: blue;">float </span><span style="color: rgb(1, 0, 1);">y </span>= <span style="color: rgb(1, 0, 1);">a</span>.<span style="color: rgb(1, 0, 1);">Y</span>;<br /><span style="color: blue;">float </span><span style="color: rgb(1, 0, 1);">z </span>= <span style="color: rgb(1, 0, 1);">a</span>.<span style="color: rgb(1, 0, 1);">Z</span>;<br /><span style="color: blue;">float </span><span style="color: rgb(1, 0, 1);">length </span>= <span style="color: rgb(1, 0, 1);">a</span>.<span style="color: rgb(1, 0, 1);">Length</span>();<br /><span style="color: rgb(43, 145, 175);">Vector3 </span><span style="color: rgb(1, 0, 1);">b </span>= <span style="color: rgb(43, 145, 175);">Vector3</span>.<span style="color: rgb(1, 0, 1);">Right</span>;<br /><span style="color: rgb(43, 145, 175);">Vector3 </span><span style="color: rgb(1, 0, 1);">c </span>= <span style="color: rgb(1, 0, 1);">a </span>+ <span style="color: rgb(1, 0, 1);">b</span>;<br /><span style="color: blue;">float </span><span style="color: rgb(1, 0, 1);">distance </span>= <span style="color: rgb(43, 145, 175);">Vector3</span>.<span style="color: rgb(1, 0, 1);">Distance</span>(<span style="color: rgb(1, 0, 1);">a</span>, <span style="color: rgb(1, 0, 1);">b</span>);<br /><span style="color: blue;">float </span><span style="color: rgb(1, 0, 1);">dotProduct </span>= <span style="color: rgb(43, 145, 175);">Vector3</span>.<span style="color: rgb(1, 0, 1);">Dot</span>(<span style="color: rgb(1, 0, 1);">a</span>, <span style="color: rgb(1, 0, 1);">b</span>);<br /><span style="color: rgb(43, 145, 175);">Vector3 </span><span style="color: rgb(1, 0, 1);">crossProduct </span>= <span style="color: rgb(43, 145, 175);">Vector3</span>.<span style="color: rgb(1, 0, 1);">Cross</span>(<span style="color: rgb(1, 0, 1);">a</span>, <span style="color: rgb(1, 0, 1);">b</span>);<br /><span style="color: rgb(43, 145, 175);">Vector3 </span><span style="color: rgb(1, 0, 1);">trasform </span>= <span style="color: rgb(43, 145, 175);">Vector3</span>.<span style="color: rgb(1, 0, 1);">Transform</span>(<span style="color: rgb(1, 0, 1);">a</span>, <span style="color: rgb(43, 145, 175);">Matrix</span>.<span style="color: rgb(1, 0, 1);">CreateScale</span>(5));</pre> <a href="http://11011.net/software/vspaste"></a> <p> <br /> The most important class in XNA is the <strong>Matrix</strong> class:</p> <pre class="code"><span style="color: rgb(43, 145, 175);">Matrix </span><span style="color: rgb(1, 0, 1);">identity </span>= <span style="color: rgb(43, 145, 175);">Matrix</span>.<span style="color: rgb(1, 0, 1);">Identity</span>;<br /><br /><span style="color: rgb(43, 145, 175);">Vector3 </span><span style="color: rgb(1, 0, 1);">cameraPosition </span>= <span style="color: blue;">new </span><span style="color: rgb(43, 145, 175);">Vector3</span>(0, 0, 10);<br /><span style="color: rgb(43, 145, 175);">Vector3 </span><span style="color: rgb(1, 0, 1);">cameraTarget </span>= <span style="color: rgb(43, 145, 175);">Vector3</span>.<span style="color: rgb(1, 0, 1);">Zero</span>;<br /><span style="color: rgb(43, 145, 175);">Vector3 </span><span style="color: rgb(1, 0, 1);">cameraUp </span>= <span style="color: rgb(43, 145, 175);">Vector3</span>.<span style="color: rgb(1, 0, 1);">Forward</span>;<br /><span style="color: blue;">var </span><span style="color: rgb(1, 0, 1);">viewMatrix </span>= <span style="color: rgb(43, 145, 175);">Matrix</span>.<span style="color: rgb(1, 0, 1);">CreateLookAt</span>(<span style="color: rgb(1, 0, 1);">cameraPosition</span>, <span style="color: rgb(1, 0, 1);">cameraTarget</span>, <span style="color: rgb(1, 0, 1);">cameraUp</span>);<br /><br /><span style="color: rgb(43, 145, 175);">Matrix </span><span style="color: rgb(1, 0, 1);">projectionMatrix </span>= <span style="color: rgb(43, 145, 175);">Matrix</span>.<span style="color: rgb(1, 0, 1);">CreatePerspectiveFieldOfView</span>(<br /> <span style="color: rgb(43, 145, 175);">MathHelper</span>.<span style="color: rgb(1, 0, 1);">PiOver4</span>, <br /> <span style="color: rgb(1, 0, 1);">GraphicsDevice</span>.<span style="color: rgb(1, 0, 1);">Viewport</span>.<span style="color: rgb(1, 0, 1);">Width </span>/ <span style="color: rgb(1, 0, 1);">GraphicsDevice</span>.<span style="color: rgb(1, 0, 1);">Viewport</span>.<span style="color: rgb(1, 0, 1);">Height</span>, <br /> 1, 100);<br /><br /><span style="color: rgb(43, 145, 175);">Matrix </span><span style="color: rgb(1, 0, 1);">viewProjectionMatrix </span>= <span style="color: rgb(1, 0, 1);">viewMatrix </span>* <span style="color: rgb(1, 0, 1);">projectionMatrix</span>;<br /><br /><span style="color: blue;">var </span><span style="color: rgb(1, 0, 1);">scale </span>= <span style="color: rgb(43, 145, 175);">Matrix</span>.<span style="color: rgb(1, 0, 1);">CreateScale</span>(5);<br /><span style="color: blue;">var </span><span style="color: rgb(1, 0, 1);">translation </span>= <span style="color: rgb(43, 145, 175);">Matrix</span>.<span style="color: rgb(1, 0, 1);">CreateTranslation</span>(10, 20, 30);<br /><span style="color: blue;">var </span><span style="color: rgb(1, 0, 1);">rotationX </span>= <span style="color: rgb(43, 145, 175);">Matrix</span>.<span style="color: rgb(1, 0, 1);">CreateRotationX</span>(<span style="color: rgb(43, 145, 175);">MathHelper</span>.<span style="color: rgb(1, 0, 1);">PiOver4</span>);<br /><span style="color: blue;">var </span><span style="color: rgb(1, 0, 1);">rotationY </span>= <span style="color: rgb(43, 145, 175);">Matrix</span>.<span style="color: rgb(1, 0, 1);">CreateRotationY</span>(<span style="color: rgb(43, 145, 175);">MathHelper</span>.<span style="color: rgb(1, 0, 1);">PiOver4</span>);<br /><span style="color: blue;">var </span><span style="color: rgb(1, 0, 1);">rotationZ </span>= <span style="color: rgb(43, 145, 175);">Matrix</span>.<span style="color: rgb(1, 0, 1);">CreateRotationZ</span>(<span style="color: rgb(43, 145, 175);">MathHelper</span>.<span style="color: rgb(1, 0, 1);">PiOver4</span>);<br /><span style="color: blue;">var </span><span style="color: rgb(1, 0, 1);">rotation </span>= <span style="color: rgb(43, 145, 175);">Matrix</span>.<span style="color: rgb(1, 0, 1);">CreateFromAxisAngle</span>(<span style="color: blue;">new </span><span style="color: rgb(43, 145, 175);">Vector3</span>(1, 2, 3), <span style="color: rgb(43, 145, 175);">MathHelper</span>.<span style="color: rgb(1, 0, 1);">PiOver4</span>);</pre> <a href="http://11011.net/software/vspaste"></a> <p> <br /> The <strong>Ray</strong> class represent a straight line. The <strong>Plane</strong> class represent a plane in the 3d world. Then there other important classes like <strong>Rectangle</strong>, <strong>BoundingBox</strong>, <strong>BoundingFrustum </strong>and <strong>BoundingSphere. </strong></p> <pre class="code"><span style="color: rgb(43, 145, 175);">Rectangle </span><span style="color: rgb(1, 0, 1);">rectangle1 </span>= <span style="color: blue;">new </span><span style="color: rgb(43, 145, 175);">Rectangle</span>(0, 0, 10, 10);<br /><span style="color: rgb(43, 145, 175);">Rectangle </span><span style="color: rgb(1, 0, 1);">rectangle2 </span>= <span style="color: blue;">new </span><span style="color: rgb(43, 145, 175);">Rectangle</span>(5, 5, 10, 10);<br /><span style="color: blue;">bool </span><span style="color: rgb(1, 0, 1);">intersect </span>= <span style="color: rgb(1, 0, 1);">rectangle1</span>.<span style="color: rgb(1, 0, 1);">Intersects</span>(<span style="color: rgb(1, 0, 1);">rectangle2</span>);<br /><span style="color: blue;">bool </span><span style="color: rgb(1, 0, 1);">contains </span>= <span style="color: rgb(1, 0, 1);">rectangle1</span>.<span style="color: rgb(1, 0, 1);">Contains</span>(<span style="color: blue;">new </span><span style="color: rgb(43, 145, 175);">Point</span>(10, 20));<br /><br /><span style="color: rgb(43, 145, 175);">Ray </span><span style="color: rgb(1, 0, 1);">ray </span>= <span style="color: blue;">new </span><span style="color: rgb(43, 145, 175);">Ray</span>(<span style="color: rgb(43, 145, 175);">Vector3</span>.<span style="color: rgb(1, 0, 1);">Zero</span>, <span style="color: rgb(43, 145, 175);">Vector3</span>.<span style="color: rgb(1, 0, 1);">Forward</span>);<br /><span style="color: rgb(43, 145, 175);">Plane </span><span style="color: rgb(1, 0, 1);">plane </span>= <span style="color: blue;">new </span><span style="color: rgb(43, 145, 175);">Plane</span>(<span style="color: rgb(43, 145, 175);">Vector3</span>.<span style="color: rgb(1, 0, 1);">Up</span>, 10);<br /><span style="color: rgb(43, 145, 175);">BoundingSphere </span><span style="color: rgb(1, 0, 1);">sphere </span>= <span style="color: blue;">new </span><span style="color: rgb(43, 145, 175);">BoundingSphere</span>(<span style="color: rgb(43, 145, 175);">Vector3</span>.<span style="color: rgb(1, 0, 1);">One</span>, 5);<br /><span style="color: rgb(43, 145, 175);">BoundingBox </span><span style="color: rgb(1, 0, 1);">box </span>= <span style="color: blue;">new </span><span style="color: rgb(43, 145, 175);">BoundingBox</span>(<span style="color: rgb(43, 145, 175);">Vector3</span>.<span style="color: rgb(1, 0, 1);">Zero</span>, <span style="color: rgb(43, 145, 175);">Vector3</span>.<span style="color: rgb(1, 0, 1);">One</span>);<br /><br /><span style="color: blue;">float</span>? <span style="color: rgb(1, 0, 1);">distance </span>= <span style="color: rgb(1, 0, 1);">ray</span>.<span style="color: rgb(1, 0, 1);">Intersects</span>(<span style="color: rgb(1, 0, 1);">plane</span>);<br /><span style="color: rgb(43, 145, 175);">PlaneIntersectionType </span><span style="color: rgb(1, 0, 1);">pit </span>= <span style="color: rgb(1, 0, 1);">plane</span>.<span style="color: rgb(1, 0, 1);">Intersects</span>(<span style="color: rgb(1, 0, 1);">sphere</span>);<br /><span style="color: rgb(43, 145, 175);">ContainmentType </span><span style="color: rgb(1, 0, 1);">ct </span>= <span style="color: rgb(1, 0, 1);">box</span>.<span style="color: rgb(1, 0, 1);">Contains</span>(<span style="color: rgb(1, 0, 1);">sphere</span>);<br /> <br /><span style="color: rgb(43, 145, 175);">BoundingFrustum </span><span style="color: rgb(1, 0, 1);">frustum </span>= <span style="color: blue;">new </span><span style="color: rgb(43, 145, 175);">BoundingFrustum</span>(<span style="color: rgb(1, 0, 1);">ViewMatrix </span>* <span style="color: rgb(1, 0, 1);">ProjectionMatrix</span>);<br /><span style="color: rgb(43, 145, 175);">Vector3</span>[] <span style="color: rgb(1, 0, 1);">corners </span>= <span style="color: rgb(1, 0, 1);">frustum</span>.<span style="color: rgb(1, 0, 1);">GetCorners</span>();<br /><span style="color: rgb(43, 145, 175);">Plane </span><span style="color: rgb(1, 0, 1);">nearPlane </span>= <span style="color: rgb(1, 0, 1);">frustum</span>.<span style="color: rgb(1, 0, 1);">Near</span>;<br /><span style="color: rgb(43, 145, 175);">Plane </span><span style="color: rgb(1, 0, 1);">farPlane </span>= <span style="color: rgb(1, 0, 1);">frustum</span>.<span style="color: rgb(1, 0, 1);">Far</span>;</pre> <a href="http://11011.net/software/vspaste"></a> <p> <br /> With the class <strong>Curve</strong> is then possible to handle curves. </p> <p>Finally, it is important to remember the class <strong>MathHelper</strong> that contains some useful methods</p> <pre class="code"><span style="color: blue;">float </span><span style="color: rgb(1, 0, 1);">max </span>= <span style="color: rgb(43, 145, 175);">MathHelper</span>.<span style="color: rgb(1, 0, 1);">Max</span>(5, 10);<br /><span style="color: blue;">float </span><span style="color: rgb(1, 0, 1);">min </span>= <span style="color: rgb(43, 145, 175);">MathHelper</span>.<span style="color: rgb(1, 0, 1);">Min</span>(5, 10);<br /><span style="color: blue;">float </span><span style="color: rgb(1, 0, 1);">piOver2 </span>= <span style="color: rgb(43, 145, 175);">MathHelper</span>.<span style="color: rgb(1, 0, 1);">PiOver2</span>;<br /><span style="color: blue;">float </span><span style="color: rgb(1, 0, 1);">degrees </span>= <span style="color: rgb(43, 145, 175);">MathHelper</span>.<span style="color: rgb(1, 0, 1);">ToDegrees</span>(<span style="color: rgb(1, 0, 1);">piOver2</span>);<br /><span style="color: blue;">float </span><span style="color: rgb(1, 0, 1);">radians </span>= <span style="color: rgb(43, 145, 175);">MathHelper</span>.<span style="color: rgb(1, 0, 1);">ToRadians</span>(90);</pre> <a href="http://11011.net/software/vspaste"></a><img src="http://blogs.ugidotnet.org/angellaa-en/aggbug/98675.aspx" width="1" height="1" /> Angella Andrea http://blogs.ugidotnet.org/angellaa-en/archive/2010/05/28/xna-ndash-analytical-geometry.aspx Fri, 28 May 2010 23:21:58 GMT http://blogs.ugidotnet.org/angellaa-en/archive/2010/05/28/xna-ndash-analytical-geometry.aspx#feedback 1 http://blogs.ugidotnet.org/angellaa-en/comments/commentRss/98675.aspx http://blogs.ugidotnet.org/angellaa-en/services/trackbacks/98675.aspx XNA &ndash; Console Component http://blogs.ugidotnet.org/angellaa-en/archive/2010/05/26/xna-ndash-console-component.aspx <p><br /> XNA is a fantastic technology and I want to learn it well.</p> <p>If you don’t know nothing about 2D and 3D game development, I strongly recommend to buy the book “<a href="http://www.amazon.com/Learning-XNA-3-0-Game-Development/dp/0596521952/ref=sr_1_1?ie=UTF8&amp;s=books&amp;qid=1274910186&amp;sr=8-1"><strong>Learning XNA 3.0</strong></a>”. This is really easy to understand and it introduce to many concepts in a simple step by step approach. I read other three books about XNA but this is definitely the best as a starting point.</p> <p><a href="http://www.amazon.com/Learning-XNA-3-0-Game-Development/dp/0596521952/ref=sr_1_1?ie=UTF8&amp;s=books&amp;qid=1274910186&amp;sr=8-1"><img width="240" height="240" border="0" src="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/angellaa-en/WindowsLiveWriter/XNAConsoleComponent_13F56/learning%20xna_3.jpg" alt="learning xna" title="learning xna" style="border-width: 0px; display: inline;" /></a> </p> <p><br /> I would like to share with you my demo programs, without the purpose to be exhaustive but just to share interesting stuffs that I can find during my learning process.</p> <p>It is quite useful to have a way to print text on the screen for debugging help. For this reason I created the ConsoleComponent class.</p> <p>Firstly, I’ll show you how to use the console class in the game: </p> <a href="http://11011.net/software/vspaste"></a> <pre class="code"><span style="color: blue;">public class </span><span style="color: rgb(43, 145, 175);">MyGame </span>: <span style="color: rgb(43, 145, 175);">Game<br /></span>{<br /> <span style="color: rgb(43, 145, 175);">GraphicsDeviceManager </span><span style="color: rgb(1, 0, 1);">graphics</span>;<br /> <strong><font size="3"> <span style="color: rgb(43, 145, 175);">ConsoleComponent </span><span style="color: rgb(1, 0, 1);">console</span>;</font></strong> <span style="color: blue;">public </span><span style="color: rgb(1, 0, 1);">MyGame</span>()<br /> {<br /> <span style="color: rgb(1, 0, 1);">graphics </span>= <span style="color: blue;">new </span><span style="color: rgb(43, 145, 175);">GraphicsDeviceManager</span>(<span style="color: blue;">this</span>);<br /> <span style="color: rgb(1, 0, 1);">Content</span>.<span style="color: rgb(1, 0, 1);">RootDirectory </span>= <span style="color: rgb(163, 21, 21);">"Content"</span>;<br /> }<br /><br /> <span style="color: blue;">protected override void </span><span style="color: rgb(1, 0, 1);">Initialize</span>()<br /> {<br /> <strong><font size="3"><span style="color: rgb(1, 0, 1);">console </span>= <span style="color: blue;">new </span><span style="color: rgb(43, 145, 175);">ConsoleComponent</span>(<span style="color: blue;">this</span>, 17, <span style="color: rgb(43, 145, 175);">Color</span>.<span style="color: rgb(1, 0, 1);">Yellow</span>);<br /> <span style="color: rgb(1, 0, 1);">Components</span>.<span style="color: rgb(1, 0, 1);">Add</span>(<span style="color: rgb(1, 0, 1);">console</span>);</font></strong> } <span style="color: blue;">protected override void </span><span style="color: rgb(1, 0, 1);">Update</span>(<span style="color: rgb(43, 145, 175);">GameTime </span><span style="color: rgb(1, 0, 1);">gameTime</span>)<br /> {<br /> <font size="3"><strong><span style="color: rgb(1, 0, 1);">console</span>.<span style="color: rgb(1, 0, 1);">Clear</span>();</strong> </font> <span style="color: rgb(1, 0, 1);">console</span>.<span style="color: rgb(1, 0, 1);">WriteLine</span>(<span style="color: rgb(163, 21, 21);">"GraphicsDeviceManager.DefaultBackBufferHeight = " </span>+ <span style="color: rgb(43, 145, 175);">GraphicsDeviceManager</span>.<span style="color: rgb(1, 0, 1);">DefaultBackBufferHeight</span>);<br /> <span style="color: rgb(1, 0, 1);">console</span>.<span style="color: rgb(1, 0, 1);">WriteLine</span>(<span style="color: rgb(163, 21, 21);">"GraphicsDeviceManager.DefaultBackBufferWidth = " </span>+ <span style="color: rgb(43, 145, 175);">GraphicsDeviceManager</span>.<span style="color: rgb(1, 0, 1);">DefaultBackBufferWidth</span>);<br /><br /> <strong><font size="3"><span style="color: rgb(1, 0, 1);">console</span>.<span style="color: rgb(1, 0, 1);">WriteLine</span>();</font> <font size="3"><span style="color: rgb(1, 0, 1);">console</span>.<span style="color: rgb(1, 0, 1);">WriteLine</span>(<span style="color: rgb(163, 21, 21);">"ValidAdapterFormats: "</span>);</font></strong> <span style="color: blue;">foreach </span>(<span style="color: rgb(43, 145, 175);">SurfaceFormat </span><span style="color: rgb(1, 0, 1);">surfaceFormat </span><span style="color: blue;">in </span><span style="color: rgb(43, 145, 175);">GraphicsDeviceManager</span>.<span style="color: rgb(1, 0, 1);">ValidAdapterFormats</span>)<br /> {<br /> <span style="color: rgb(1, 0, 1);">console</span>.<span style="color: rgb(1, 0, 1);">WriteLine</span>(<span style="color: rgb(163, 21, 21);">" - " </span>+ <span style="color: rgb(1, 0, 1);">surfaceFormat</span>);<br /> }<br /><br /> <span style="color: rgb(1, 0, 1);">console</span>.<span style="color: rgb(1, 0, 1);">WriteLine</span>();<br /> <span style="color: rgb(1, 0, 1);">console</span>.<span style="color: rgb(1, 0, 1);">WriteLine</span>(<span style="color: rgb(163, 21, 21);">"ValidBackBufferFormats: "</span>);<br /> <span style="color: blue;">foreach </span>(<span style="color: rgb(43, 145, 175);">SurfaceFormat </span><span style="color: rgb(1, 0, 1);">surfaceFormat </span><span style="color: blue;">in </span><span style="color: rgb(43, 145, 175);">GraphicsDeviceManager</span>.<span style="color: rgb(1, 0, 1);">ValidBackBufferFormats</span>)<br /> {<br /> <span style="color: rgb(1, 0, 1);">console</span>.<span style="color: rgb(1, 0, 1);">WriteLine</span>(<span style="color: rgb(163, 21, 21);">" - " </span>+ <span style="color: rgb(1, 0, 1);">surfaceFormat</span>);<br /> }<br /><br /> <span style="color: rgb(1, 0, 1);">console</span>.<span style="color: rgb(1, 0, 1);">WriteLine</span>();<br /> <span style="color: rgb(1, 0, 1);">console</span>.<span style="color: rgb(1, 0, 1);">WriteLine</span>(<span style="color: rgb(163, 21, 21);">"ValidDeviceTypes: "</span>);<br /> <span style="color: blue;">foreach </span>(<span style="color: rgb(43, 145, 175);">DeviceType </span><span style="color: rgb(1, 0, 1);">deviceType </span><span style="color: blue;">in </span><span style="color: rgb(43, 145, 175);">GraphicsDeviceManager</span>.<span style="color: rgb(1, 0, 1);">ValidDeviceTypes</span>)<br /> {<br /> <span style="color: rgb(1, 0, 1);">console</span>.<span style="color: rgb(1, 0, 1);">WriteLine</span>(<span style="color: rgb(163, 21, 21);">" - " </span>+ <span style="color: rgb(1, 0, 1);">deviceType</span>);<br /> }<br /><br /> <span style="color: blue;">base</span>.<span style="color: rgb(1, 0, 1);">Update</span>(<span style="color: rgb(1, 0, 1);">gameTime</span>);<br /> }<br /><br /> <span style="color: blue;">protected override void </span><span style="color: rgb(1, 0, 1);">Draw</span>(<span style="color: rgb(43, 145, 175);">GameTime </span><span style="color: rgb(1, 0, 1);">gameTime</span>)<br /> {<br /> <span style="color: rgb(1, 0, 1);">GraphicsDevice</span>.<span style="color: rgb(1, 0, 1);">Clear</span>(<span style="color: rgb(43, 145, 175);">Color</span>.<span style="color: rgb(1, 0, 1);">Black</span>);<br /><br /> <span style="color: blue;">base</span>.<span style="color: rgb(1, 0, 1);">Draw</span>(<span style="color: rgb(1, 0, 1);">gameTime</span>);<br /> }<br />}</pre> <a href="http://11011.net/software/vspaste"></a> <pre class="code"><font size="2"><font size="1"><br /></font></font></pre> <p><font size="2">It is extremely simple to use. You create an instance of the ConsoleComponent class passing a reference to the game object, the interline and the text color. Then you can use the WriteLine() method to draw a text while with the Clear() method you can clear all the text.</font></p> <p><font size="2">This is the code of the component:</font></p> <pre class="code"><font size="2"> </font></pre> <font size="2"><a href="http://11011.net/software/vspaste"></a></font> <pre class="code"><span style="color: blue;"><font size="2">public class </font></span><span style="color: rgb(43, 145, 175);"><font size="2">ConsoleComponent </font></span><font size="2">: <span style="color: rgb(43, 145, 175);">DrawableGameComponent<br /></span>{<br /> <span style="color: blue;">private </span><span style="color: rgb(43, 145, 175);">SpriteBatch </span><span style="color: rgb(1, 0, 1);">spriteBatch</span>;<br /> <span style="color: blue;">private </span><span style="color: rgb(43, 145, 175);">SpriteFont </span><span style="color: rgb(1, 0, 1);">consoleFont</span>;<br /><br /> <span style="color: blue;">private float </span><span style="color: rgb(1, 0, 1);">interline</span>;<br /> <span style="color: blue;">private </span><span style="color: rgb(43, 145, 175);">Color </span><span style="color: rgb(1, 0, 1);">textColor</span>;<br /><br /> <span style="color: blue;">private </span><span style="color: rgb(43, 145, 175);">List</span>&lt;<span style="color: blue;">string</span>&gt; <span style="color: rgb(1, 0, 1);">messages</span>;<br /> <br /> <span style="color: blue;">public </span><span style="color: rgb(1, 0, 1);">ConsoleComponent</span>(<span style="color: rgb(43, 145, 175);">MyGame </span><span style="color: rgb(1, 0, 1);">game</span>, <span style="color: blue;">float </span><span style="color: rgb(1, 0, 1);">interline</span>, <span style="color: rgb(43, 145, 175);">Color </span><span style="color: rgb(1, 0, 1);">defaultTextColor</span>) : <span style="color: blue;">base</span>(<span style="color: rgb(1, 0, 1);">game</span>)<br /> {<br /> <span style="color: blue;">this</span>.<span style="color: rgb(1, 0, 1);">interline </span>= <span style="color: rgb(1, 0, 1);">interline</span>;<br /> <span style="color: blue;">this</span>.<span style="color: rgb(1, 0, 1);">textColor </span>= <span style="color: rgb(1, 0, 1);">defaultTextColor</span>;<br /><br /> <span style="color: blue;">this</span>.<span style="color: rgb(1, 0, 1);">messages </span>= <span style="color: blue;">new </span><span style="color: rgb(43, 145, 175);">List</span>&lt;<span style="color: blue;">string</span>&gt;();<br /><br /> <span style="color: rgb(1, 0, 1);">spriteBatch </span>= <span style="color: blue;">new </span><span style="color: rgb(43, 145, 175);">SpriteBatch</span>(<span style="color: rgb(1, 0, 1);">game</span>.<span style="color: rgb(1, 0, 1);">GraphicsDevice</span>);<br /> <span style="color: rgb(1, 0, 1);">consoleFont </span>= <span style="color: rgb(1, 0, 1);">game</span>.<span style="color: rgb(1, 0, 1);">Content</span>.<span style="color: rgb(1, 0, 1);">Load</span>&lt;<span style="color: rgb(43, 145, 175);">SpriteFont</span>&gt;(<span style="color: rgb(163, 21, 21);">"consoleFont"</span>);<br /> }<br /><br /> <span style="color: blue;">public void </span><span style="color: rgb(1, 0, 1);">Clear</span>()<br /> {<br /> <span style="color: rgb(1, 0, 1);">messages</span>.<span style="color: rgb(1, 0, 1);">Clear</span>();<br /> }<br /><br /> <span style="color: blue;">public void </span><span style="color: rgb(1, 0, 1);">WriteLine</span>()<br /> {<br /> <span style="color: rgb(1, 0, 1);">messages</span>.<span style="color: rgb(1, 0, 1);">Add</span>(<span style="color: rgb(163, 21, 21);">""</span>);<br /> }<br /><br /> <span style="color: blue;">public void </span><span style="color: rgb(1, 0, 1);">WriteLine</span>(<span style="color: blue;">string </span><span style="color: rgb(1, 0, 1);">text</span>)<br /> {<br /> <span style="color: rgb(1, 0, 1);">messages</span>.<span style="color: rgb(1, 0, 1);">Add</span>(<span style="color: rgb(1, 0, 1);">text</span>);<br /> }<br /><br /> <span style="color: blue;">public override void </span><span style="color: rgb(1, 0, 1);">Draw</span>(<span style="color: rgb(43, 145, 175);">GameTime </span><span style="color: rgb(1, 0, 1);">gameTime</span>)<br /> {<br /> <span style="color: blue;">base</span>.<span style="color: rgb(1, 0, 1);">Draw</span>(<span style="color: rgb(1, 0, 1);">gameTime</span>);<br /><br /> <span style="color: rgb(1, 0, 1);">spriteBatch</span>.<span style="color: rgb(1, 0, 1);">Begin</span>();<br /><br /> <span style="color: blue;">float </span><span style="color: rgb(1, 0, 1);">y </span>= <span style="color: rgb(1, 0, 1);">interline</span>;<br /> <span style="color: blue;">foreach </span>(<span style="color: blue;">string </span><span style="color: rgb(1, 0, 1);">text </span><span style="color: blue;">in </span><span style="color: rgb(1, 0, 1);">messages</span>)<br /> {<br /> <span style="color: rgb(1, 0, 1);">spriteBatch</span>.<span style="color: rgb(1, 0, 1);">DrawString</span>(<span style="color: rgb(1, 0, 1);">consoleFont</span>, <span style="color: rgb(1, 0, 1);">text</span>, <span style="color: blue;">new </span><span style="color: rgb(43, 145, 175);">Vector2</span>(<span style="color: rgb(1, 0, 1);">interline</span>, <span style="color: rgb(1, 0, 1);">y</span>), <span style="color: rgb(1, 0, 1);">textColor</span>);<br /> <span style="color: rgb(1, 0, 1);">y </span>+= <span style="color: rgb(1, 0, 1);">interline</span>;<br /> }<br /><br /> <span style="color: rgb(1, 0, 1);">spriteBatch</span>.<span style="color: rgb(1, 0, 1);">End</span>();<br /> }<br />}</font></pre> <font size="2"><a href="http://11011.net/software/vspaste"></a> </font> <p><font size="2"><br /> In this simple example you can see how it is easier to draw 2D strings using XNA.</font></p> <p><font size="2">This is a screenshot of the application: <br /> </font></p> <p><font size="2"><a target="_blank" href="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/angellaa-en/WindowsLiveWriter/XNAConsoleComponent_13F56/consolecomponent_2.jpg"><img width="663" height="517" border="0" src="http://blogs.ugidotnet.org/images/blogs_ugidotnet_org/angellaa-en/WindowsLiveWriter/XNAConsoleComponent_13F56/consolecomponent_thumb.jpg" alt="consolecomponent" title="consolecomponent" style="border: 0px none; display: inline;" /></a> </font></p> <p><font size="2"><br /> The complete Visual Studio 2008 project is available to the following link:</font></p> <p><font size="2"><a href="http://cid-1dcae6b548e3761c.skydrive.live.com/self.aspx/.Public/XNA/ConsoleComponent.zip" title="http://cid-1dcae6b548e3761c.skydrive.live.com/self.aspx/.Public/XNA/ConsoleComponent.zip">http://cid-1dcae6b548e3761c.skydrive.live.com/self.aspx/.Public/XNA/ConsoleComponent.zip</a><a href="http://11011.net/software/vspaste"></a></font></p><img src="http://blogs.ugidotnet.org/angellaa-en/aggbug/98663.aspx" width="1" height="1" /> Angella Andrea http://blogs.ugidotnet.org/angellaa-en/archive/2010/05/26/xna-ndash-console-component.aspx Wed, 26 May 2010 23:30:40 GMT http://blogs.ugidotnet.org/angellaa-en/archive/2010/05/26/xna-ndash-console-component.aspx#feedback 2 http://blogs.ugidotnet.org/angellaa-en/comments/commentRss/98663.aspx http://blogs.ugidotnet.org/angellaa-en/services/trackbacks/98663.aspx