<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearch/1.1/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0' gd:etag='W/&quot;DkQCQncyeip7ImA9WhVbE00.&quot;'><id>tag:blogger.com,1999:blog-5924991233318401474</id><updated>2012-05-29T08:12:43.992-07:00</updated><category term='C#'/><category term='DirectX tutorial'/><category term='game'/><category term='DirectX'/><category term='DirectX.NET'/><category term='car'/><title>Game Inventors</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://gameinventors.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5924991233318401474/posts/default?redirect=false&amp;v=2'/><link rel='alternate' type='text/html' href='http://gameinventors.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Akshay Vats</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh4.googleusercontent.com/-RJymz9rhmqE/AAAAAAAAAAI/AAAAAAAAAI4/OmuJvHJII-c/s512-c/photo.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>3</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry gd:etag='W/&quot;CE8DRn09eip7ImA9WhVbEkQ.&quot;'><id>tag:blogger.com,1999:blog-5924991233318401474.post-6123946911212150319</id><published>2012-05-28T01:37:00.001-07:00</published><updated>2012-05-29T05:01:17.362-07:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2012-05-29T05:01:17.362-07:00</app:edited><title>Tutorial 2, DirectX using C#</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div&gt;
&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;h2 style="text-align: left;"&gt;




































&lt;u&gt;&lt;u&gt;&lt;span style="color: #660000; font-size: large;"&gt;DirectX using C# &lt;/span&gt;&lt;/u&gt;&lt;/u&gt;&lt;/h2&gt;
&lt;h2 style="text-align: left;"&gt;




































&lt;span style="color: #274e13; font-size: large; font-weight: normal;"&gt;Tutorial 2&lt;/span&gt;&lt;/h2&gt;
&lt;h3 style="text-align: left;"&gt;




































&lt;u&gt;&lt;span style="color: #0b5394; font-size: large; font-weight: normal;"&gt;Loading a model&lt;/span&gt;&lt;/u&gt;&lt;/h3&gt;
&lt;div style="text-align: left;"&gt;
&lt;span style="color: #0b5394; font-size: small; font-weight: normal;"&gt;&lt;span style="color: #134f5c;"&gt;Models are 3d objects that form part of game. We'll have separate class for managing these objects nested within cosmicX.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;h4 style="text-align: left;"&gt;









&lt;span style="color: #0b5394; font-size: large; font-weight: normal;"&gt;Contents of class &lt;b&gt;Object&lt;/b&gt;&lt;/span&gt;&lt;span style="color: #e06666;"&gt;&amp;nbsp;
&lt;/span&gt;&lt;span style="color: #0b5394; font-size: small; font-weight: normal;"&gt;&lt;span style="color: #134f5c;"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h4&gt;
&lt;/div&gt;
&lt;div style="background: none repeat scroll 0% 0% white; border-color: gray; border-style: solid; border-width: 0.1em 0.1em 0.1em 0.8em; color: black; overflow: auto; padding: 0.2em 0.6em; width: auto;"&gt;
&lt;pre style="line-height: 125%; margin: 0pt;"&gt;            &lt;span style="color: green; font-weight: bold;"&gt;private&lt;/span&gt; Mesh mesh;
            &lt;span style="color: green; font-weight: bold;"&gt;private&lt;/span&gt; Material[] materials;
            &lt;span style="color: green; font-weight: bold;"&gt;private&lt;/span&gt; Texture[] textures;
&lt;/pre&gt;
&lt;/div&gt;
These 3 fields define a 3d model&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style="background: none repeat scroll 0% 0% white; border-color: gray; border-style: solid; border-width: 0.1em 0.1em 0.1em 0.8em; color: black; overflow: auto; padding: 0.2em 0.6em; width: auto;"&gt;
&lt;pre style="line-height: 125%; margin: 0pt;"&gt;&lt;span style="color: green; font-weight: bold;"&gt;private&lt;/span&gt; &lt;span style="color: #303090; font-weight: bold;"&gt;float&lt;/span&gt; radius;
&lt;span style="color: green; font-weight: bold;"&gt;public&lt;/span&gt; Vector3 Position, centre, Orientation, LocalAxis, Scaling;
&lt;/pre&gt;
&lt;/div&gt;
&lt;ul style="text-align: left;"&gt;
&lt;li&gt;radius -&amp;gt; used for simple collision detection&lt;/li&gt;
&lt;li&gt;Orientation is actually angle(s) made by object with X, Y, Z axis&lt;/li&gt;
&lt;li&gt;LocalAxis will be used for moving object in 3d space&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
Another thing to note is that our class cosmicX is now Singleton, to provide easy reference to class Object&lt;br /&gt;
&lt;div style="background: none repeat scroll 0% 0% white; border-color: gray; border-style: solid; border-width: 0.1em 0.1em 0.1em 0.8em; color: black; overflow: auto; padding: 0.2em 0.6em; width: auto;"&gt;
&lt;pre style="line-height: 125%; margin: 0pt;"&gt;&lt;span style="color: green; font-weight: bold;"&gt;static&lt;/span&gt; cosmicX _CosmicX;
&lt;span style="color: green; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: green; font-weight: bold;"&gt;static&lt;/span&gt; cosmicX CosmicX
            {
                &lt;span style="color: green; font-weight: bold;"&gt;get&lt;/span&gt; { &lt;span style="color: green; font-weight: bold;"&gt;return&lt;/span&gt; cosmicX._CosmicX; }
                &lt;span style="color: green; font-weight: bold;"&gt;set&lt;/span&gt; { cosmicX._CosmicX = &lt;span style="color: green; font-weight: bold;"&gt;value&lt;/span&gt;; }
            }
&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h3 style="text-align: left;"&gt;





&lt;span style="color: #990000;"&gt;Using the code&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div style="background: none repeat scroll 0% 0% white; border-color: gray; border-style: solid; border-width: 0.1em 0.1em 0.1em 0.8em; color: black; overflow: auto; padding: 0.2em 0.6em; width: auto;"&gt;
&lt;pre style="line-height: 125%; margin: 0pt;"&gt;cosmicX.Object truck;
        &lt;span style="color: green; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: #0060b0; font-weight: bold;"&gt;Form1&lt;/span&gt;()
        {
            InitializeComponent();
            SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, &lt;span style="color: green; font-weight: bold;"&gt;true&lt;/span&gt;);
            X = &lt;span style="color: green; font-weight: bold;"&gt;new&lt;/span&gt; cosmicX(&lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;);
            truck = &lt;span style="color: green; font-weight: bold;"&gt;new&lt;/span&gt; cosmicX.Object(&lt;span style="background-color: #fff0f0;"&gt;"slam\\slam.x"&lt;/span&gt;, &lt;span style="color: #6000e0; font-weight: bold;"&gt;1&lt;/span&gt;);
        }
&lt;/pre&gt;
&lt;/div&gt;
&lt;span style="color: #0b5394;"&gt;See its simple !&lt;/span&gt;&lt;br /&gt;
&lt;h3 style="text-align: left;"&gt;



&lt;span style="color: #990000;"&gt;Output&lt;/span&gt;&lt;/h3&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-siQHHsa93wI/T8M5HgGIq-I/AAAAAAAAALE/YmQCuPxaCAg/s1600/3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-siQHHsa93wI/T8M5HgGIq-I/AAAAAAAAALE/YmQCuPxaCAg/s1600/3.png" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;h3 style="color: #990000; text-align: left;"&gt;



Complete Code&lt;/h3&gt;
&lt;div style="background: none repeat scroll 0% 0% white; border-color: gray; border-style: solid; border-width: 0.1em 0.1em 0.1em 0.8em; color: black; overflow: auto; padding: 0.2em 0.6em; width: auto;"&gt;
&lt;pre style="line-height: 125%; margin: 0pt;"&gt;&lt;span style="color: green; font-weight: bold;"&gt;using&lt;/span&gt; &lt;span style="color: #0e84b5; font-weight: bold;"&gt;System&lt;/span&gt;;
&lt;span style="color: green; font-weight: bold;"&gt;using&lt;/span&gt; &lt;span style="color: #0e84b5; font-weight: bold;"&gt;System.Collections.Generic&lt;/span&gt;;
&lt;span style="color: green; font-weight: bold;"&gt;using&lt;/span&gt; &lt;span style="color: #0e84b5; font-weight: bold;"&gt;System.ComponentModel&lt;/span&gt;;
&lt;span style="color: green; font-weight: bold;"&gt;using&lt;/span&gt; &lt;span style="color: #0e84b5; font-weight: bold;"&gt;System.Data&lt;/span&gt;;
&lt;span style="color: green; font-weight: bold;"&gt;using&lt;/span&gt; &lt;span style="color: #0e84b5; font-weight: bold;"&gt;System.Drawing&lt;/span&gt;;
&lt;span style="color: green; font-weight: bold;"&gt;using&lt;/span&gt; &lt;span style="color: #0e84b5; font-weight: bold;"&gt;System.Linq&lt;/span&gt;;
&lt;span style="color: green; font-weight: bold;"&gt;using&lt;/span&gt; &lt;span style="color: #0e84b5; font-weight: bold;"&gt;System.Text&lt;/span&gt;;
&lt;span style="color: green; font-weight: bold;"&gt;using&lt;/span&gt; &lt;span style="color: #0e84b5; font-weight: bold;"&gt;System.Windows.Forms&lt;/span&gt;;
&lt;span style="color: green; font-weight: bold;"&gt;using&lt;/span&gt; &lt;span style="color: #0e84b5; font-weight: bold;"&gt;Microsoft.DirectX&lt;/span&gt;;
&lt;span style="color: green; font-weight: bold;"&gt;using&lt;/span&gt; &lt;span style="color: #0e84b5; font-weight: bold;"&gt;Microsoft.DirectX.Direct3D&lt;/span&gt;;
&lt;span style="color: green; font-weight: bold;"&gt;using&lt;/span&gt; &lt;span style="color: #0e84b5; font-weight: bold;"&gt;D3D&lt;/span&gt; = Microsoft.DirectX.Direct3D;

&lt;span style="color: green; font-weight: bold;"&gt;namespace&lt;/span&gt; &lt;span style="color: #0e84b5; font-weight: bold;"&gt;XBasic&lt;/span&gt;
{
    &lt;span style="color: green; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: green; font-weight: bold;"&gt;partial&lt;/span&gt; &lt;span style="color: green; font-weight: bold;"&gt;class&lt;/span&gt; &lt;span style="color: #b00060; font-weight: bold;"&gt;Form1&lt;/span&gt; : Form
    {
        &lt;span style="color: green; font-weight: bold;"&gt;class&lt;/span&gt; &lt;span style="color: #b00060; font-weight: bold;"&gt;cosmicX&lt;/span&gt;
        {
            &lt;span style="color: green; font-weight: bold;"&gt;event&lt;/span&gt; EventHandler Render;
            &lt;span style="color: #507090;"&gt;#region -FIELDS-&lt;/span&gt;
            D3D.Device device;
            Form form;
            &lt;span style="color: #303090; font-weight: bold;"&gt;float&lt;/span&gt; aspectRatio;
            &lt;span style="color: green; font-weight: bold;"&gt;static&lt;/span&gt; cosmicX _CosmicX;
&lt;span style="color: #507090;"&gt;#endregion&lt;/span&gt;
            &lt;span style="color: #507090;"&gt;#region -Properties-&lt;/span&gt;
            &lt;span style="color: green; font-weight: bold;"&gt;public&lt;/span&gt; D3D.Device Device
            {
                &lt;span style="color: green; font-weight: bold;"&gt;get&lt;/span&gt; { &lt;span style="color: green; font-weight: bold;"&gt;return&lt;/span&gt; device; }
                &lt;span style="color: green; font-weight: bold;"&gt;set&lt;/span&gt; { device = &lt;span style="color: green; font-weight: bold;"&gt;value&lt;/span&gt;; }
            }
            &lt;span style="color: green; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: green; font-weight: bold;"&gt;static&lt;/span&gt; cosmicX CosmicX
            {
                &lt;span style="color: green; font-weight: bold;"&gt;get&lt;/span&gt; { &lt;span style="color: green; font-weight: bold;"&gt;return&lt;/span&gt; cosmicX._CosmicX; }
                &lt;span style="color: green; font-weight: bold;"&gt;set&lt;/span&gt; { cosmicX._CosmicX = &lt;span style="color: green; font-weight: bold;"&gt;value&lt;/span&gt;; }
            }
            &lt;span style="color: #507090;"&gt;#endregion&lt;/span&gt;
            &lt;span style="color: #507090;"&gt;#region -Methods-&lt;/span&gt;
            &lt;span style="color: green; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: #0060b0; font-weight: bold;"&gt;cosmicX&lt;/span&gt;(Form f)
        {
            CosmicX = &lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;;
            &lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;.form = f;
            D3D.PresentParameters presentParams = &lt;span style="color: green; font-weight: bold;"&gt;new&lt;/span&gt; D3D.PresentParameters();
            presentParams.Windowed = &lt;span style="color: green; font-weight: bold;"&gt;true&lt;/span&gt;;
            presentParams.SwapEffect = SwapEffect.Discard;
            presentParams.AutoDepthStencilFormat = DepthFormat.D16;
            presentParams.EnableAutoDepthStencil = &lt;span style="color: green; font-weight: bold;"&gt;true&lt;/span&gt;;
            &lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;.Device = &lt;span style="color: green; font-weight: bold;"&gt;new&lt;/span&gt; D3D.Device(&lt;span style="color: #6000e0; font-weight: bold;"&gt;0&lt;/span&gt;, D3D.DeviceType.Hardware, f, CreateFlags.SoftwareVertexProcessing, presentParams);
            calculateAspectRatio();
        }
        &lt;span style="color: green; font-weight: bold;"&gt;void&lt;/span&gt; &lt;span style="color: #0060b0; font-weight: bold;"&gt;calculateAspectRatio&lt;/span&gt;()
        {
            &lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;.device.RenderState.Lighting = &lt;span style="color: green; font-weight: bold;"&gt;true&lt;/span&gt;;

            &lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;.device.Lights[&lt;span style="color: #6000e0; font-weight: bold;"&gt;0&lt;/span&gt;].Type = LightType.Directional;
            &lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;.device.Lights[&lt;span style="color: #6000e0; font-weight: bold;"&gt;0&lt;/span&gt;].Diffuse = Color.White;
            &lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;.device.Lights[&lt;span style="color: #6000e0; font-weight: bold;"&gt;0&lt;/span&gt;].Direction = &lt;span style="color: green; font-weight: bold;"&gt;new&lt;/span&gt; Vector3(&lt;span style="color: #6000e0; font-weight: bold;"&gt;1&lt;/span&gt;, &lt;span style="color: #6000e0; font-weight: bold;"&gt;1&lt;/span&gt;, -&lt;span style="color: #6000e0; font-weight: bold;"&gt;1&lt;/span&gt;);
            &lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;.device.Lights[&lt;span style="color: #6000e0; font-weight: bold;"&gt;0&lt;/span&gt;].Update();
            &lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;.device.Lights[&lt;span style="color: #6000e0; font-weight: bold;"&gt;0&lt;/span&gt;].Enabled = &lt;span style="color: green; font-weight: bold;"&gt;true&lt;/span&gt;;

            &lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;.device.Lights[&lt;span style="color: #6000e0; font-weight: bold;"&gt;1&lt;/span&gt;].Type = LightType.Directional;
            &lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;.device.Lights[&lt;span style="color: #6000e0; font-weight: bold;"&gt;1&lt;/span&gt;].Diffuse = Color.White;
            &lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;.device.Lights[&lt;span style="color: #6000e0; font-weight: bold;"&gt;1&lt;/span&gt;].Direction = &lt;span style="color: green; font-weight: bold;"&gt;new&lt;/span&gt; Vector3(-&lt;span style="color: #6000e0; font-weight: bold;"&gt;1&lt;/span&gt;, -&lt;span style="color: #6000e0; font-weight: bold;"&gt;1&lt;/span&gt;, -&lt;span style="color: #6000e0; font-weight: bold;"&gt;1&lt;/span&gt;);
            &lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;.device.Lights[&lt;span style="color: #6000e0; font-weight: bold;"&gt;1&lt;/span&gt;].Update();
            &lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;.device.Lights[&lt;span style="color: #6000e0; font-weight: bold;"&gt;1&lt;/span&gt;].Enabled = &lt;span style="color: green; font-weight: bold;"&gt;true&lt;/span&gt;;
            &lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;.aspectRatio = (&lt;span style="color: #303090; font-weight: bold;"&gt;float&lt;/span&gt;)form.Width / (&lt;span style="color: #303090; font-weight: bold;"&gt;float&lt;/span&gt;)form.Height;
            &lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;.device.Transform.Projection = Matrix.PerspectiveFovLH((&lt;span style="color: #303090; font-weight: bold;"&gt;float&lt;/span&gt;)Math.PI / &lt;span style="color: #6000e0; font-weight: bold;"&gt;4&lt;/span&gt;, &lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;.aspectRatio, &lt;span style="color: #6000e0; font-weight: bold;"&gt;0.3f&lt;/span&gt;, &lt;span style="color: #6000e0; font-weight: bold;"&gt;500f&lt;/span&gt;);

        }
        &lt;span style="color: green; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: green; font-weight: bold;"&gt;void&lt;/span&gt; &lt;span style="color: #0060b0; font-weight: bold;"&gt;RenderX&lt;/span&gt;()
        {
            &lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;.device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.DarkSlateBlue, &lt;span style="color: #6000e0; font-weight: bold;"&gt;1.0f&lt;/span&gt;, &lt;span style="color: #6000e0; font-weight: bold;"&gt;0&lt;/span&gt;);
            &lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;.device.BeginScene();
            &lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;.device.RenderState.Ambient = Color.DarkGray;
            &lt;span style="color: green; font-weight: bold;"&gt;if&lt;/span&gt; (Render != &lt;span style="color: green; font-weight: bold;"&gt;null&lt;/span&gt;)
                Render(&lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;, &lt;span style="color: green; font-weight: bold;"&gt;null&lt;/span&gt;);
            &lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;.device.EndScene();
            &lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;.device.Present();
            &lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;.form.Invalidate();
        }
            &lt;span style="color: #507090;"&gt;#endregion&lt;/span&gt;
        &lt;span style="color: green; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: green; font-weight: bold;"&gt;class&lt;/span&gt; &lt;span style="color: #b00060; font-weight: bold;"&gt;Object&lt;/span&gt;
        {
            &lt;span style="color: green; font-weight: bold;"&gt;private&lt;/span&gt; Mesh mesh;
            &lt;span style="color: green; font-weight: bold;"&gt;private&lt;/span&gt; Material[] materials;
            &lt;span style="color: green; font-weight: bold;"&gt;private&lt;/span&gt; Texture[] textures;
            &lt;span style="color: #303090; font-weight: bold;"&gt;object&lt;/span&gt; _Tag;
            &lt;span style="color: green; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: #303090; font-weight: bold;"&gt;object&lt;/span&gt; Tag
            {
                &lt;span style="color: green; font-weight: bold;"&gt;get&lt;/span&gt; { &lt;span style="color: green; font-weight: bold;"&gt;return&lt;/span&gt; _Tag; }
                &lt;span style="color: green; font-weight: bold;"&gt;set&lt;/span&gt; { _Tag = &lt;span style="color: green; font-weight: bold;"&gt;value&lt;/span&gt;; }
            }
            &lt;span style="color: green; font-weight: bold;"&gt;private&lt;/span&gt; &lt;span style="color: #303090; font-weight: bold;"&gt;float&lt;/span&gt; radius;
            &lt;span style="color: green; font-weight: bold;"&gt;public&lt;/span&gt; Vector3 Position, centre, Orientation, LocalAxis, Scaling;
            &lt;span style="color: green; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: #0060b0; font-weight: bold;"&gt;Object&lt;/span&gt;(&lt;span style="color: #303090; font-weight: bold;"&gt;string&lt;/span&gt; Filename, &lt;span style="color: #303090; font-weight: bold;"&gt;float&lt;/span&gt; scaling)
                : &lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;(Filename, scaling, &lt;span style="color: green; font-weight: bold;"&gt;true&lt;/span&gt;)
            {

            }
            &lt;span style="color: green; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: #0060b0; font-weight: bold;"&gt;Object&lt;/span&gt;(&lt;span style="color: #303090; font-weight: bold;"&gt;string&lt;/span&gt; Filename, &lt;span style="color: #303090; font-weight: bold;"&gt;float&lt;/span&gt; scaling, &lt;span style="color: #303090; font-weight: bold;"&gt;bool&lt;/span&gt; renderable)
            {
                Scaling = &lt;span style="color: green; font-weight: bold;"&gt;new&lt;/span&gt; Vector3(scaling, scaling, scaling);
                LoadMesh(Filename, &lt;span style="color: green; font-weight: bold;"&gt;ref&lt;/span&gt; mesh, &lt;span style="color: green; font-weight: bold;"&gt;ref&lt;/span&gt; materials, &lt;span style="color: green; font-weight: bold;"&gt;ref&lt;/span&gt; textures, &lt;span style="color: green; font-weight: bold;"&gt;ref&lt;/span&gt; radius, scaling, &lt;span style="color: green; font-weight: bold;"&gt;out&lt;/span&gt; centre);
                Position = &lt;span style="color: green; font-weight: bold;"&gt;new&lt;/span&gt; Vector3(&lt;span style="color: #6000e0; font-weight: bold;"&gt;0&lt;/span&gt;, &lt;span style="color: #6000e0; font-weight: bold;"&gt;0&lt;/span&gt;, &lt;span style="color: #6000e0; font-weight: bold;"&gt;0&lt;/span&gt;);
                &lt;span style="color: green; font-weight: bold;"&gt;if&lt;/span&gt; (renderable)
                    CosmicX.Render += &lt;span style="color: green; font-weight: bold;"&gt;new&lt;/span&gt; EventHandler(_CosmicX_Render);
                Orientation = &lt;span style="color: green; font-weight: bold;"&gt;new&lt;/span&gt; Vector3(&lt;span style="color: #6000e0; font-weight: bold;"&gt;0&lt;/span&gt;, &lt;span style="color: #6000e0; font-weight: bold;"&gt;0&lt;/span&gt;, &lt;span style="color: #6000e0; font-weight: bold;"&gt;0&lt;/span&gt;);
                LocalAxis = &lt;span style="color: green; font-weight: bold;"&gt;new&lt;/span&gt; Vector3(&lt;span style="color: #6000e0; font-weight: bold;"&gt;0&lt;/span&gt;, &lt;span style="color: #6000e0; font-weight: bold;"&gt;0&lt;/span&gt;, &lt;span style="color: #6000e0; font-weight: bold;"&gt;1&lt;/span&gt;);
            }
            &lt;span style="color: green; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: green; font-weight: bold;"&gt;void&lt;/span&gt; &lt;span style="color: #0060b0; font-weight: bold;"&gt;LoadMesh&lt;/span&gt;(&lt;span style="color: #303090; font-weight: bold;"&gt;string&lt;/span&gt; filename, &lt;span style="color: green; font-weight: bold;"&gt;ref&lt;/span&gt; Mesh mesh, &lt;span style="color: green; font-weight: bold;"&gt;ref&lt;/span&gt; Material[] meshmaterials, &lt;span style="color: green; font-weight: bold;"&gt;ref&lt;/span&gt; Texture[] meshtextures, &lt;span style="color: green; font-weight: bold;"&gt;ref&lt;/span&gt; &lt;span style="color: #303090; font-weight: bold;"&gt;float&lt;/span&gt; meshradius, &lt;span style="color: #303090; font-weight: bold;"&gt;float&lt;/span&gt; scaling, &lt;span style="color: green; font-weight: bold;"&gt;out&lt;/span&gt; Vector3 meshcenter)
            {
                &lt;span style="color: green; font-weight: bold;"&gt;if&lt;/span&gt; (!System.IO.File.Exists(filename))
                { &lt;span style="color: green; font-weight: bold;"&gt;throw&lt;/span&gt; &lt;span style="color: green; font-weight: bold;"&gt;new&lt;/span&gt; Exception(&lt;span style="background-color: #fff0f0;"&gt;"File not found "&lt;/span&gt; + filename); }
                ExtendedMaterial[] materialarray;
                mesh = Mesh.FromFile(filename, MeshFlags.Managed, CosmicX.device, &lt;span style="color: green; font-weight: bold;"&gt;out&lt;/span&gt; materialarray);

                &lt;span style="color: green; font-weight: bold;"&gt;if&lt;/span&gt; ((materialarray != &lt;span style="color: green; font-weight: bold;"&gt;null&lt;/span&gt;) &amp;amp;&amp;amp; (materialarray.Length &amp;gt; &lt;span style="color: #6000e0; font-weight: bold;"&gt;0&lt;/span&gt;))
                {
                    meshmaterials = &lt;span style="color: green; font-weight: bold;"&gt;new&lt;/span&gt; Material[materialarray.Length];
                    meshtextures = &lt;span style="color: green; font-weight: bold;"&gt;new&lt;/span&gt; Texture[materialarray.Length];

                    &lt;span style="color: green; font-weight: bold;"&gt;for&lt;/span&gt; (&lt;span style="color: #303090; font-weight: bold;"&gt;int&lt;/span&gt; i = &lt;span style="color: #6000e0; font-weight: bold;"&gt;0&lt;/span&gt;; i &amp;lt; materialarray.Length; i++)
                    {
                        meshmaterials[i] = materialarray[i].Material3D;
                        meshmaterials[i].Ambient = meshmaterials[i].Diffuse;

                        &lt;span style="color: green; font-weight: bold;"&gt;if&lt;/span&gt; ((materialarray[i].TextureFilename != &lt;span style="color: green; font-weight: bold;"&gt;null&lt;/span&gt;) &amp;amp;&amp;amp; (materialarray[i].TextureFilename != &lt;span style="color: #303090; font-weight: bold;"&gt;string&lt;/span&gt;.Empty))
                        {
                            System.IO.FileInfo fi = &lt;span style="color: green; font-weight: bold;"&gt;new&lt;/span&gt; System.IO.FileInfo(filename);
                            &lt;span style="color: green; font-weight: bold;"&gt;if&lt;/span&gt; (System.IO.File.Exists(fi.DirectoryName + &lt;span style="background-color: #fff0f0;"&gt;"\\"&lt;/span&gt; + materialarray[i].TextureFilename))
                            {
                                meshtextures[i] = TextureLoader.FromFile(CosmicX.device, fi.DirectoryName + &lt;span style="background-color: #fff0f0;"&gt;"\\"&lt;/span&gt; + materialarray[i].TextureFilename);
                            }
                            &lt;span style="color: green; font-weight: bold;"&gt;else&lt;/span&gt; System.Diagnostics.Debug.Print(&lt;span style="background-color: #fff0f0;"&gt;"File not found: "&lt;/span&gt; + materialarray[i].TextureFilename + &lt;span style="background-color: #fff0f0;"&gt;" !"&lt;/span&gt;);
                        }
                    }
                }

                mesh = mesh.Clone(mesh.Options.Value, CustomVertex.PositionNormalTextured.Format, CosmicX.device);
                mesh.ComputeNormals();

                VertexBuffer vertices = mesh.VertexBuffer;
                GraphicsStream stream = vertices.Lock(&lt;span style="color: #6000e0; font-weight: bold;"&gt;0&lt;/span&gt;, &lt;span style="color: #6000e0; font-weight: bold;"&gt;0&lt;/span&gt;, LockFlags.None);
                meshradius = Geometry.ComputeBoundingSphere(stream, mesh.NumberVertices, mesh.VertexFormat, &lt;span style="color: green; font-weight: bold;"&gt;out&lt;/span&gt; meshcenter) * scaling;

            }
            
            &lt;span style="color: green; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: green; font-weight: bold;"&gt;void&lt;/span&gt; &lt;span style="color: #0060b0; font-weight: bold;"&gt;DrawMesh&lt;/span&gt;()
            {
                &lt;span style="color: green; font-weight: bold;"&gt;for&lt;/span&gt; (&lt;span style="color: #303090; font-weight: bold;"&gt;int&lt;/span&gt; i = &lt;span style="color: #6000e0; font-weight: bold;"&gt;0&lt;/span&gt;; i &amp;lt; materials.Length; i++)
                {
                    CosmicX.device.Material = materials[i];
                    CosmicX.device.SetTexture(&lt;span style="color: #6000e0; font-weight: bold;"&gt;0&lt;/span&gt;, textures[i]);
                    mesh.DrawSubset(i);
                }
            }
            &lt;span style="color: green; font-weight: bold;"&gt;void&lt;/span&gt; &lt;span style="color: #0060b0; font-weight: bold;"&gt;_CosmicX_Render&lt;/span&gt;(&lt;span style="color: #303090; font-weight: bold;"&gt;object&lt;/span&gt; sender, EventArgs e)
            {
                Render();
            }
            &lt;span style="color: green; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: green; font-weight: bold;"&gt;void&lt;/span&gt; &lt;span style="color: #0060b0; font-weight: bold;"&gt;Render&lt;/span&gt;()
            {
                CosmicX.device.Transform.World = Matrix.Scaling(Scaling.X, Scaling.Y, Scaling.Z) * Matrix.RotationX(Orientation.X) * Matrix.RotationZ(Orientation.Z) * Matrix.RotationY(Orientation.Y) * Matrix.Translation(Position);
                DrawMesh();
            }
            &lt;span style="color: green; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: green; font-weight: bold;"&gt;void&lt;/span&gt; &lt;span style="color: #0060b0; font-weight: bold;"&gt;Dispose&lt;/span&gt;()
            {
                CosmicX.Render -= _CosmicX_Render;
                mesh = &lt;span style="color: green; font-weight: bold;"&gt;null&lt;/span&gt;;
                materials = &lt;span style="color: green; font-weight: bold;"&gt;null&lt;/span&gt;;
                textures = &lt;span style="color: green; font-weight: bold;"&gt;null&lt;/span&gt;;
                System.GC.SuppressFinalize(&lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;);
            }

        }
        
        }
        cosmicX X;
        cosmicX.Object truck;
        &lt;span style="color: green; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: #0060b0; font-weight: bold;"&gt;Form1&lt;/span&gt;()
        {
            InitializeComponent();
            SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, &lt;span style="color: green; font-weight: bold;"&gt;true&lt;/span&gt;);
            X = &lt;span style="color: green; font-weight: bold;"&gt;new&lt;/span&gt; cosmicX(&lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;);
            truck = &lt;span style="color: green; font-weight: bold;"&gt;new&lt;/span&gt; cosmicX.Object(&lt;span style="background-color: #fff0f0;"&gt;"slam\\slam.x"&lt;/span&gt;, &lt;span style="color: #6000e0; font-weight: bold;"&gt;1&lt;/span&gt;);
        }
        &lt;span style="color: green; font-weight: bold;"&gt;protected&lt;/span&gt; &lt;span style="color: green; font-weight: bold;"&gt;override&lt;/span&gt; &lt;span style="color: green; font-weight: bold;"&gt;void&lt;/span&gt; &lt;span style="color: #0060b0; font-weight: bold;"&gt;OnPaint&lt;/span&gt;(PaintEventArgs e)
        {
            &lt;span style="color: green; font-weight: bold;"&gt;base&lt;/span&gt;.OnPaint(e);
            X.RenderX();
        }
    }
}
&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5924991233318401474-6123946911212150319?l=gameinventors.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gameinventors.blogspot.com/feeds/6123946911212150319/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://gameinventors.blogspot.com/2012/05/directx-using-c-tutorial-2-loading.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5924991233318401474/posts/default/6123946911212150319?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5924991233318401474/posts/default/6123946911212150319?v=2'/><link rel='alternate' type='text/html' href='http://gameinventors.blogspot.com/2012/05/directx-using-c-tutorial-2-loading.html' title='Tutorial 2, DirectX using C#'/><author><name>Akshay Vats</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh4.googleusercontent.com/-RJymz9rhmqE/AAAAAAAAAAI/AAAAAAAAAI4/OmuJvHJII-c/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-siQHHsa93wI/T8M5HgGIq-I/AAAAAAAAALE/YmQCuPxaCAg/s72-c/3.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;CE8CQnY8fyp7ImA9WhVbEkQ.&quot;'><id>tag:blogger.com,1999:blog-5924991233318401474.post-4271199777034707286</id><published>2012-05-28T00:36:00.000-07:00</published><updated>2012-05-29T05:01:03.877-07:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2012-05-29T05:01:03.877-07:00</app:edited><title>Tutorial 1, DirectX using C#</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div class="separator" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em; text-align: center;"&gt;
&lt;a href="http://gameinventors.blogspot.in/2012/05/directx-using-c-tutorial-2-loading.html"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-q-Lzo0bA4Is/T8M5i9p6P3I/AAAAAAAAALM/AK_RW-Ie8gY/s1600/next.png" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;h2 style="text-align: left;"&gt;
































&lt;u&gt;&lt;u&gt;&lt;span style="color: #660000; font-size: large;"&gt;DirectX using C# &lt;/span&gt;&lt;/u&gt;&lt;/u&gt;&lt;/h2&gt;
&lt;div style="text-align: right;"&gt;
&lt;/div&gt;
&lt;h2 style="text-align: left;"&gt;
































&lt;span style="color: #274e13; font-size: large; font-weight: normal;"&gt;Tutorial 1&lt;/span&gt;&lt;/h2&gt;
&lt;h3 style="text-align: left;"&gt;
































&lt;u&gt;&lt;span style="color: #0b5394; font-size: large; font-weight: normal;"&gt;The Blue Window &lt;/span&gt;&lt;/u&gt;&lt;u&gt;&lt;u&gt;&lt;span style="color: #660000; font-size: large;"&gt;&lt;/span&gt;&lt;/u&gt;&lt;/u&gt;&lt;/h3&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;ol style="text-align: left;"&gt;
&lt;li&gt;&lt;span style="color: #073763; font-size: small; font-weight: normal;"&gt;Create a new project in C#&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="color: #073763; font-size: small; font-weight: normal;"&gt;Add reference to Microsoft.DirectX&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="color: #073763; font-size: small; font-weight: normal;"&gt;Add reference to Microsoft.DirectX.Direct3D&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="color: #073763; font-size: small; font-weight: normal;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #073763; font-size: small; font-weight: normal;"&gt;Add reference to Microsoft.DirectX.Direct3DX&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;span style="color: #073763; font-size: small; font-weight: normal;"&gt;&lt;span style="color: #b45f06;"&gt;Copy paste the code provided at the end, following are highlights and explanation to a few code chunk&lt;/span&gt; &lt;/span&gt;&lt;/div&gt;
&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;span style="color: #073763; font-size: small; font-weight: normal;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: #073763; font-size: small; font-weight: normal;"&gt;Under Form1 we will have a nested class 'CosmicX' which will be our framework.&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #073763; font-size: small; font-weight: normal;"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="color: #073763; font-size: small; font-weight: normal;"&gt; &lt;/span&gt;&lt;br /&gt;
&lt;div style="background: none repeat scroll 0% 0% white; border-color: gray; border-style: solid; border-width: 0.1em 0.1em 0.1em 0.8em; color: black; overflow: auto; padding: 0.2em 0.6em; width: auto;"&gt;
&lt;pre style="line-height: 125%; margin: 0pt;"&gt;&lt;span style="color: green; font-weight: bold;"&gt;using&lt;/span&gt; &lt;span style="color: #0e84b5; font-weight: bold;"&gt;Microsoft.DirectX&lt;/span&gt;;
&lt;span style="color: green; font-weight: bold;"&gt;using&lt;/span&gt; &lt;span style="color: #0e84b5; font-weight: bold;"&gt;Microsoft.DirectX.Direct3D&lt;/span&gt;;
&lt;span style="color: green; font-weight: bold;"&gt;using&lt;/span&gt; &lt;span style="color: #0e84b5; font-weight: bold;"&gt;D3D&lt;/span&gt; = Microsoft.DirectX.Direct3D;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h4 style="text-align: left;"&gt;











1. Set form style to opaque&lt;/h4&gt;
&lt;div style="background: none repeat scroll 0% 0% white; border-color: gray; border-style: solid; border-width: 0.1em 0.1em 0.1em 0.8em; color: black; overflow: auto; padding: 0.2em 0.6em; width: auto;"&gt;
&lt;pre style="line-height: 125%; margin: 0pt;"&gt;SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, &lt;span style="color: green; font-weight: bold;"&gt;true&lt;/span&gt;);&lt;/pre&gt;
&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;span style="color: #073763;"&gt;Try skipping this line and you will come to know about its importance...&lt;/span&gt; &lt;/div&gt;
&lt;h3 style="text-align: left;"&gt;











2. Turn on lightening&lt;/h3&gt;
&lt;div style="background: none repeat scroll 0% 0% white; border-color: gray; border-style: solid; border-width: 0.1em 0.1em 0.1em 0.8em; color: black; overflow: auto; padding: 0.2em 0.6em; width: auto;"&gt;
&lt;pre style="line-height: 125%; margin: 0pt;"&gt;&lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;.device.RenderState.Lighting = &lt;span style="color: green; font-weight: bold;"&gt;true&lt;/span&gt;;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style="color: #073763;"&gt;We'll be rendering DirectX meshes (.X file). Most of them have a material on them, which can be thought of color of mesh. Lightening enables material rendering. So, its important to turn it on.&lt;/span&gt;&lt;br /&gt;
&lt;h4 style="text-align: left;"&gt;














&lt;span style="color: #073763;"&gt;&lt;u&gt;3. Our Render Call Back&lt;/u&gt;&lt;/span&gt;&lt;/h4&gt;
&lt;div style="background: none repeat scroll 0% 0% white; border-color: gray; border-style: solid; border-width: 0.1em 0.1em 0.1em 0.8em; color: black; overflow: auto; padding: 0.2em 0.6em; width: auto;"&gt;
&lt;pre style="line-height: 125%; margin: 0pt;"&gt;&lt;span style="color: green; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: green; font-weight: bold;"&gt;void&lt;/span&gt; &lt;span style="color: #0060b0; font-weight: bold;"&gt;RenderX&lt;/span&gt;()
        {
            &lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;.device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.DarkSlateBlue, &lt;span style="color: #6000e0; font-weight: bold;"&gt;1.0f&lt;/span&gt;, &lt;span style="color: #6000e0; font-weight: bold;"&gt;0&lt;/span&gt;);
            &lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;.device.BeginScene();
            &lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;.device.RenderState.Ambient = Color.DarkGray;&amp;nbsp;&lt;/pre&gt;
&lt;pre style="line-height: 125%; margin: 0pt;"&gt;//We'll render objects here&lt;/pre&gt;
&lt;pre style="line-height: 125%; margin: 0pt;"&gt;&amp;nbsp;&lt;span style="color: green; font-weight: bold;"&gt;           this&lt;/span&gt;.device.EndScene();
            &lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;.device.Present();
            &lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;.form.Invalidate();
        }&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;ol style="text-align: left;"&gt;
&lt;li&gt;Clear the screen and paint it blue&lt;/li&gt;
&lt;li&gt;Render objects&lt;/li&gt;
&lt;li&gt;Invalidate form [back to point 1.]&amp;nbsp;&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 style="text-align: left;"&gt;











&lt;span style="color: #660000;"&gt;Output&lt;/span&gt;&lt;/h3&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-Ddzn7jbHFk4/T8MxZLwuuvI/AAAAAAAAAK4/bybPhoeFcyM/s1600/2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-Ddzn7jbHFk4/T8MxZLwuuvI/AAAAAAAAAK4/bybPhoeFcyM/s1600/2.png" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;h3 style="text-align: left;"&gt;








&lt;span style="color: #660000;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/h3&gt;
&lt;h3 style="text-align: left;"&gt;








&lt;span style="color: #660000;"&gt;Complete Code&lt;/span&gt;&lt;/h3&gt;
&lt;h3 style="text-align: left;"&gt;










&amp;nbsp;
&lt;span style="color: #660000;"&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;div style="background: none repeat scroll 0% 0% white; border-color: gray; border-style: solid; border-width: 0.1em 0.1em 0.1em 0.8em; color: black; overflow: auto; padding: 0.2em 0.6em; width: auto;"&gt;
&lt;pre style="line-height: 125%; margin: 0pt;"&gt;&lt;span style="color: green; font-weight: bold;"&gt;using&lt;/span&gt; &lt;span style="color: #0e84b5; font-weight: bold;"&gt;System&lt;/span&gt;;
&lt;span style="color: green; font-weight: bold;"&gt;using&lt;/span&gt; &lt;span style="color: #0e84b5; font-weight: bold;"&gt;System.Collections.Generic&lt;/span&gt;;
&lt;span style="color: green; font-weight: bold;"&gt;using&lt;/span&gt; &lt;span style="color: #0e84b5; font-weight: bold;"&gt;System.ComponentModel&lt;/span&gt;;
&lt;span style="color: green; font-weight: bold;"&gt;using&lt;/span&gt; &lt;span style="color: #0e84b5; font-weight: bold;"&gt;System.Data&lt;/span&gt;;
&lt;span style="color: green; font-weight: bold;"&gt;using&lt;/span&gt; &lt;span style="color: #0e84b5; font-weight: bold;"&gt;System.Drawing&lt;/span&gt;;
&lt;span style="color: green; font-weight: bold;"&gt;using&lt;/span&gt; &lt;span style="color: #0e84b5; font-weight: bold;"&gt;System.Linq&lt;/span&gt;;
&lt;span style="color: green; font-weight: bold;"&gt;using&lt;/span&gt; &lt;span style="color: #0e84b5; font-weight: bold;"&gt;System.Text&lt;/span&gt;;
&lt;span style="color: green; font-weight: bold;"&gt;using&lt;/span&gt; &lt;span style="color: #0e84b5; font-weight: bold;"&gt;System.Windows.Forms&lt;/span&gt;;
&lt;span style="color: green; font-weight: bold;"&gt;using&lt;/span&gt; &lt;span style="color: #0e84b5; font-weight: bold;"&gt;Microsoft.DirectX&lt;/span&gt;;
&lt;span style="color: green; font-weight: bold;"&gt;using&lt;/span&gt; &lt;span style="color: #0e84b5; font-weight: bold;"&gt;Microsoft.DirectX.Direct3D&lt;/span&gt;;
&lt;span style="color: green; font-weight: bold;"&gt;using&lt;/span&gt; &lt;span style="color: #0e84b5; font-weight: bold;"&gt;D3D&lt;/span&gt; = Microsoft.DirectX.Direct3D;

&lt;span style="color: green; font-weight: bold;"&gt;namespace&lt;/span&gt; &lt;span style="color: #0e84b5; font-weight: bold;"&gt;XBasic&lt;/span&gt;
{
    &lt;span style="color: green; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: green; font-weight: bold;"&gt;partial&lt;/span&gt; &lt;span style="color: green; font-weight: bold;"&gt;class&lt;/span&gt; &lt;span style="color: #b00060; font-weight: bold;"&gt;Form1&lt;/span&gt; : Form
    {
        &lt;span style="color: green; font-weight: bold;"&gt;class&lt;/span&gt; &lt;span style="color: #b00060; font-weight: bold;"&gt;cosmicX&lt;/span&gt;
        {
            &lt;span style="color: #507090;"&gt;#region -FIELDS-&lt;/span&gt;
            D3D.Device device;
            Form form;
            &lt;span style="color: #303090; font-weight: bold;"&gt;float&lt;/span&gt; aspectRatio;
            &lt;span style="color: #507090;"&gt;#endregion&lt;/span&gt;
            &lt;span style="color: #507090;"&gt;#region -Properties-&lt;/span&gt;
            &lt;span style="color: green; font-weight: bold;"&gt;public&lt;/span&gt; D3D.Device Device
            {
                &lt;span style="color: green; font-weight: bold;"&gt;get&lt;/span&gt; { &lt;span style="color: green; font-weight: bold;"&gt;return&lt;/span&gt; device; }
                &lt;span style="color: green; font-weight: bold;"&gt;set&lt;/span&gt; { device = &lt;span style="color: green; font-weight: bold;"&gt;value&lt;/span&gt;; }
            }
            &lt;span style="color: #507090;"&gt;#endregion&lt;/span&gt;
            &lt;span style="color: #507090;"&gt;#region -Methods-&lt;/span&gt;
            &lt;span style="color: green; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: #0060b0; font-weight: bold;"&gt;cosmicX&lt;/span&gt;(Form f)
        {
            
            &lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;.form = f;
            D3D.PresentParameters presentParams = &lt;span style="color: green; font-weight: bold;"&gt;new&lt;/span&gt; D3D.PresentParameters();
            presentParams.Windowed = &lt;span style="color: green; font-weight: bold;"&gt;true&lt;/span&gt;;
            presentParams.SwapEffect = SwapEffect.Discard;
            presentParams.AutoDepthStencilFormat = DepthFormat.D16;
            presentParams.EnableAutoDepthStencil = &lt;span style="color: green; font-weight: bold;"&gt;true&lt;/span&gt;;
            &lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;.Device = &lt;span style="color: green; font-weight: bold;"&gt;new&lt;/span&gt; D3D.Device(&lt;span style="color: #6000e0; font-weight: bold;"&gt;0&lt;/span&gt;, D3D.DeviceType.Hardware, f, CreateFlags.SoftwareVertexProcessing, presentParams);
            calculateAspectRatio();
        }
        &lt;span style="color: green; font-weight: bold;"&gt;void&lt;/span&gt; &lt;span style="color: #0060b0; font-weight: bold;"&gt;calculateAspectRatio&lt;/span&gt;()
        {
            &lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;.device.RenderState.Lighting = &lt;span style="color: green; font-weight: bold;"&gt;true&lt;/span&gt;;

            &lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;.device.Lights[&lt;span style="color: #6000e0; font-weight: bold;"&gt;0&lt;/span&gt;].Type = LightType.Directional;
            &lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;.device.Lights[&lt;span style="color: #6000e0; font-weight: bold;"&gt;0&lt;/span&gt;].Diffuse = Color.White;
            &lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;.device.Lights[&lt;span style="color: #6000e0; font-weight: bold;"&gt;0&lt;/span&gt;].Direction = &lt;span style="color: green; font-weight: bold;"&gt;new&lt;/span&gt; Vector3(&lt;span style="color: #6000e0; font-weight: bold;"&gt;1&lt;/span&gt;, &lt;span style="color: #6000e0; font-weight: bold;"&gt;1&lt;/span&gt;, -&lt;span style="color: #6000e0; font-weight: bold;"&gt;1&lt;/span&gt;);
            &lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;.device.Lights[&lt;span style="color: #6000e0; font-weight: bold;"&gt;0&lt;/span&gt;].Update();
            &lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;.device.Lights[&lt;span style="color: #6000e0; font-weight: bold;"&gt;0&lt;/span&gt;].Enabled = &lt;span style="color: green; font-weight: bold;"&gt;true&lt;/span&gt;;

            &lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;.device.Lights[&lt;span style="color: #6000e0; font-weight: bold;"&gt;1&lt;/span&gt;].Type = LightType.Directional;
            &lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;.device.Lights[&lt;span style="color: #6000e0; font-weight: bold;"&gt;1&lt;/span&gt;].Diffuse = Color.White;
            &lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;.device.Lights[&lt;span style="color: #6000e0; font-weight: bold;"&gt;1&lt;/span&gt;].Direction = &lt;span style="color: green; font-weight: bold;"&gt;new&lt;/span&gt; Vector3(-&lt;span style="color: #6000e0; font-weight: bold;"&gt;1&lt;/span&gt;, -&lt;span style="color: #6000e0; font-weight: bold;"&gt;1&lt;/span&gt;, -&lt;span style="color: #6000e0; font-weight: bold;"&gt;1&lt;/span&gt;);
            &lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;.device.Lights[&lt;span style="color: #6000e0; font-weight: bold;"&gt;1&lt;/span&gt;].Update();
            &lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;.device.Lights[&lt;span style="color: #6000e0; font-weight: bold;"&gt;1&lt;/span&gt;].Enabled = &lt;span style="color: green; font-weight: bold;"&gt;true&lt;/span&gt;;
            &lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;.aspectRatio = (&lt;span style="color: #303090; font-weight: bold;"&gt;float&lt;/span&gt;)form.Width / (&lt;span style="color: #303090; font-weight: bold;"&gt;float&lt;/span&gt;)form.Height;
            &lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;.device.Transform.Projection = Matrix.PerspectiveFovLH((&lt;span style="color: #303090; font-weight: bold;"&gt;float&lt;/span&gt;)Math.PI / &lt;span style="color: #6000e0; font-weight: bold;"&gt;4&lt;/span&gt;, &lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;.aspectRatio, &lt;span style="color: #6000e0; font-weight: bold;"&gt;0.3f&lt;/span&gt;, &lt;span style="color: #6000e0; font-weight: bold;"&gt;500f&lt;/span&gt;);

        }
        &lt;span style="color: green; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: green; font-weight: bold;"&gt;void&lt;/span&gt; &lt;span style="color: #0060b0; font-weight: bold;"&gt;RenderX&lt;/span&gt;()
        {
            &lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;.device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.DarkSlateBlue, &lt;span style="color: #6000e0; font-weight: bold;"&gt;1.0f&lt;/span&gt;, &lt;span style="color: #6000e0; font-weight: bold;"&gt;0&lt;/span&gt;);
            &lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;.device.BeginScene();
            &lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;.device.RenderState.Ambient = Color.DarkGray;
            &lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;.device.EndScene();
            &lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;.device.Present();
            &lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;.form.Invalidate();
        }
            &lt;span style="color: #507090;"&gt;#endregion&lt;/span&gt;

        }
        cosmicX X;
        &lt;span style="color: green; font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: #0060b0; font-weight: bold;"&gt;Form1&lt;/span&gt;()
        {
            InitializeComponent();
            SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, &lt;span style="color: green; font-weight: bold;"&gt;true&lt;/span&gt;);
            X = &lt;span style="color: green; font-weight: bold;"&gt;new&lt;/span&gt; cosmicX(&lt;span style="color: green; font-weight: bold;"&gt;this&lt;/span&gt;);
        }
        &lt;span style="color: green; font-weight: bold;"&gt;protected&lt;/span&gt; &lt;span style="color: green; font-weight: bold;"&gt;override&lt;/span&gt; &lt;span style="color: green; font-weight: bold;"&gt;void&lt;/span&gt; &lt;span style="color: #0060b0; font-weight: bold;"&gt;OnPaint&lt;/span&gt;(PaintEventArgs e)
        {
            &lt;span style="color: green; font-weight: bold;"&gt;base&lt;/span&gt;.OnPaint(e);
            X.RenderX();
        }
    }
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5924991233318401474-4271199777034707286?l=gameinventors.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gameinventors.blogspot.com/feeds/4271199777034707286/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://gameinventors.blogspot.com/2012/05/directx-using-c-tutorial-1-blue-window.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5924991233318401474/posts/default/4271199777034707286?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5924991233318401474/posts/default/4271199777034707286?v=2'/><link rel='alternate' type='text/html' href='http://gameinventors.blogspot.com/2012/05/directx-using-c-tutorial-1-blue-window.html' title='Tutorial 1, DirectX using C#'/><author><name>Akshay Vats</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh4.googleusercontent.com/-RJymz9rhmqE/AAAAAAAAAAI/AAAAAAAAAI4/OmuJvHJII-c/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-q-Lzo0bA4Is/T8M5i9p6P3I/AAAAAAAAALM/AK_RW-Ie8gY/s72-c/next.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;CUYBSH47fCp7ImA9WhVbEkQ.&quot;'><id>tag:blogger.com,1999:blog-5924991233318401474.post-7987186025701822013</id><published>2012-05-27T19:00:00.000-07:00</published><updated>2012-05-29T05:05:59.004-07:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2012-05-29T05:05:59.004-07:00</app:edited><category scheme='http://www.blogger.com/atom/ns#' term='car'/><category scheme='http://www.blogger.com/atom/ns#' term='DirectX.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='DirectX tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='DirectX'/><category scheme='http://www.blogger.com/atom/ns#' term='game'/><title>DirectX using C#</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;title&gt;Game Inventors&lt;/title&gt;
&lt;br /&gt;
&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;h2 style="text-align: left;"&gt;
&lt;u&gt;&lt;span style="color: #660000; font-size: x-large;"&gt;DirectX using C#&lt;/span&gt;&lt;/u&gt;&lt;/h2&gt;
&lt;div&gt;
&lt;u&gt;&lt;span style="color: #660000; font-size: x-large;"&gt;&lt;/span&gt;&lt;/u&gt;&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #0b5394;"&gt;If you are interested in making games in shortest possible time, this is the right place to start with. This series of tutorials includes making a simple 'Car cruise' game.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-9y5yCPWCJwQ/T8MjdhAYPSI/AAAAAAAAAKk/49QBXOj2L6Q/s1600/overview.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" height="288" src="http://4.bp.blogspot.com/-9y5yCPWCJwQ/T8MjdhAYPSI/AAAAAAAAAKk/49QBXOj2L6Q/s400/overview.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style="color: #0b5394;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;u&gt;&lt;span style="color: #0b5394;"&gt;Requirements&lt;/span&gt;&lt;/u&gt;&lt;/div&gt;
&lt;div&gt;
&lt;ul style="text-align: left;"&gt;
&lt;li&gt;&lt;span style="color: #0b5394;"&gt;Visual Studio&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="color: #0b5394;"&gt;DirectX SDK August 2007 or higher&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="color: #0b5394;"&gt;A little knowledge of C# (or Java) specifically ease with classes&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;span style="color: #0b5394;"&gt;If you possess all these, then you are well eligible to start making your own games...&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style="color: #0b5394;"&gt;Let's &lt;b&gt;invent&lt;/b&gt; games&lt;/span&gt;&lt;br /&gt;
&lt;h4 style="text-align: left;"&gt;



&lt;span style="color: #0b5394;"&gt;&lt;a href="http://gameinventors.blogspot.in/2012/05/directx-using-c-tutorial-1-blue-window.html"&gt;&lt;span style="color: #cc0000;"&gt;Start Tutorial Now!!!&lt;/span&gt;&lt;/a&gt; &lt;/span&gt;&lt;/h4&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5924991233318401474-7987186025701822013?l=gameinventors.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gameinventors.blogspot.com/feeds/7987186025701822013/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://gameinventors.blogspot.com/2012/05/directx-using-c-if-you-are-interested.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5924991233318401474/posts/default/7987186025701822013?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5924991233318401474/posts/default/7987186025701822013?v=2'/><link rel='alternate' type='text/html' href='http://gameinventors.blogspot.com/2012/05/directx-using-c-if-you-are-interested.html' title='DirectX using C#'/><author><name>Akshay Vats</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh4.googleusercontent.com/-RJymz9rhmqE/AAAAAAAAAAI/AAAAAAAAAI4/OmuJvHJII-c/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/-9y5yCPWCJwQ/T8MjdhAYPSI/AAAAAAAAAKk/49QBXOj2L6Q/s72-c/overview.png' height='72' width='72'/><thr:total>0</thr:total><georss:featurename>New Delhi, Delhi, India</georss:featurename><georss:point>28.635308 77.22496</georss:point><georss:box>28.4123265 76.909103 28.858289499999998 77.54081699999999</georss:box></entry></feed>