<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-US"><title type="html">David Rousset - sharing about HTML5, Windows 8 &amp;amp; Gaming</title><subtitle type="html">sharing about HTML5, Windows 8 &amp;amp; Gaming</subtitle><id>http://blogs.msdn.com/b/davrous/atom.aspx</id><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/davrous/" /><link rel="self" type="application/atom+xml" href="http://blogs.msdn.com/b/davrous/atom.aspx" /><generator uri="http://telligent.com" version="5.6.50428.7875">Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><updated>2012-12-19T15:25:08Z</updated><entry><title>Tutorial part 3: learning how to write a 3D soft engine in C#, TS or JS – loading meshes exported from Blender</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/davrous/archive/2013/06/17/tutorial-part-3-learning-how-to-write-a-3d-soft-engine-in-c-ts-or-js-loading-meshes-exported-from-blender.aspx" /><id>http://blogs.msdn.com/b/davrous/archive/2013/06/17/tutorial-part-3-learning-how-to-write-a-3d-soft-engine-in-c-ts-or-js-loading-meshes-exported-from-blender.aspx</id><published>2013-06-17T15:55:29Z</published><updated>2013-06-17T15:55:29Z</updated><content type="html">&lt;link rel="stylesheet" href="http://david.blob.core.windows.net/softengine3d/tabs.css" /&gt;&lt;script src="http://david.blob.core.windows.net/softengine3d/dw_tabs.js"&gt;&lt;/script&gt;&lt;script type="text/javascript"&gt;

                                                                                                                                                                                   DYN_WEB.Tabs.setup({
                                                                                                                                                                                       id: 'tabset1', // if of tabset
                                                                                                                                                                                       css: 'css/tabs.css', // optional if you don't care about accessibility 
                                                                                                                                                                                       useCookies: true // optional
                                                                                                                                                                                   }, { id: 'tabset2', useCookies: true });

    &lt;/script&gt;  &lt;p&gt;In the previous tutorial &lt;a title="Tutorial part 2- learning how to write a 3D soft engine from scratch in C#, TS or JS – drawing l" href="http://blogs.msdn.com/b/davrous/archive/2013/06/14/tutorial-part-2-learning-how-to-write-a-3d-soft-engine-from-scratch-in-c-ts-or-js-drawing-lines-amp-triangles.aspx"&gt;learning how to write a 3D soft engine from scratch in C#, TS or JS – drawing lines &amp;amp; triangles&lt;/a&gt;, we’ve learned how to draw lines &amp;amp; triangles and we really started to see the 3D side our meshes thanks to this wireframe rendering. But we’ve only displayed a cube… And even a simple cube already has 12 faces! Are we going to be forced to handle ourselves all the faces for more complex objects this way? Hopefully not. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;3D modelers help the collaboration between 3D designers and developers&lt;/strong&gt;. The designer can use its favorite tools to build his scenes or meshes (3D Studio Max, Maya, Blender, etc.). Then he will export his work into a file that will be loaded by the developers. The developers will finally push the meshes into his real time 3D engine. There are several file formats available on the market to serialize the job done by the artists. In our case, we’re going to use JSON. Indeed, &lt;a href="http://blogs.msdn.com/eternalcoding"&gt;David Catuhe&lt;/a&gt; has done an export library for Blender that output a &lt;strong&gt;.babylon file using JSON&lt;/strong&gt;. We’re then going to see how to parse that file and display the meshes in our lovely soft engine. &lt;/p&gt;  &lt;p&gt;Blender is a free 3D modeler you can download here: &lt;a title="http://www.blender.org/download/get-blender/" href="http://www.blender.org/download/get-blender/"&gt;http://www.blender.org/download/get-blender/&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;You can write plug-ins in Python. That’s what we’ve done for the exporter.&amp;#160; &lt;/p&gt;  &lt;p&gt;By following this tutorial, you will be able to have such a result:&lt;/p&gt; &lt;iframe style="border-top: rgb(200,200,200) 1px solid; border-right: rgb(200,200,200) 1px solid; border-bottom: rgb(200,200,200) 1px solid; border-left: rgb(200,200,200) 1px solid" height="260" src="http://david.blob.core.windows.net/softengine3d/part3/index.html" width="340" scrolling="no"&gt;&lt;/iframe&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;And you’ll see that you’ve already done most of the job in the 2 previous tutorials to do that.&amp;#160; &lt;/p&gt;  &lt;h2&gt;Install the Babylon exporter and generate your own scene with Blender&lt;/h2&gt;  &lt;p&gt;Once you’ll have installed Blender, please download our Babylon exporter from here: &lt;a href="http://david.blob.core.windows.net/softengine3d/io_export_babylon.py"&gt;io_export_babylon.py&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Copy this file into the &lt;strong&gt;&lt;em&gt;\script\addons&lt;/em&gt;&lt;/strong&gt; directory where you’ve installed Blender (for instance “&lt;em&gt;C:\Program Files\Blender Foundation\Blender\2.67\scripts\addons&lt;/em&gt;” in my specific case).&lt;/p&gt;  &lt;p&gt;You need to active our plug-in in the user preferences. Go to “&lt;strong&gt;&lt;em&gt;File&lt;/em&gt;&lt;/strong&gt;” –&amp;gt; “&lt;strong&gt;&lt;em&gt;User Preferences&lt;/em&gt;&lt;/strong&gt;” and the “&lt;strong&gt;&lt;em&gt;Addons&lt;/em&gt;&lt;/strong&gt;” tab. Search for “&lt;strong&gt;&lt;em&gt;babylon&lt;/em&gt;&lt;/strong&gt;” and activate it by checking the case. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/2671.image_5F00_01DE239B.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/7827.image_5F00_thumb_5F00_6E50C3F9.png" width="640" height="112" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Do whatever you want with Blender. If you’re like me, really bad at building 3D meshes, here is a cool option that will impress your friends during geeks parties: “&lt;strong&gt;&lt;em&gt;Add&lt;/em&gt;&lt;/strong&gt;” –&amp;gt; “&lt;strong&gt;&lt;em&gt;Mesh&lt;/em&gt;&lt;/strong&gt;” –&amp;gt; “&lt;strong&gt;&lt;em&gt;Monkey&lt;/em&gt;&lt;/strong&gt;”:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0435.image_5F00_65ECEEA2.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/3124.image_5F00_thumb_5F00_7FE0AEC4.png" width="640" height="421" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;You should then obtain a screen like that:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0880.image_5F00_561D33D1.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4722.image_5F00_thumb_5F00_2BED85E9.png" width="640" height="406" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Last step is to &lt;strong&gt;export it into the .babylon file format&lt;/strong&gt; (our JSON file). “&lt;strong&gt;File&lt;/strong&gt;” –&amp;gt; “&lt;strong&gt;Export&lt;/strong&gt;” –&amp;gt; “&lt;strong&gt;Babylon.js&lt;/strong&gt;”&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/7444.image_5F00_21D8E4BE.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0068.image_5F00_thumb_5F00_578E2A18.png" width="431" height="480" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Name the file “&lt;strong&gt;&lt;em&gt;monkey.babylon&lt;/em&gt;&lt;/strong&gt;”.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Note:&lt;/u&gt;&lt;/strong&gt; this monkey is named Suzanne and is very well-known in the 3D/gaming community. By knowing her, you’re now a proud member of this cool community! Welcome onboard! ;)&lt;/p&gt;  &lt;h2&gt;Loading the exported JSON file and displaying its meshes&lt;/h2&gt;  &lt;p&gt;As I was telling you at the beginning of this article, we’ve already built all the needed logic to display more complex meshes like Suzanne. We’ve got our Face, Mesh &amp;amp; Vertex logic. This is all we need for now. &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;In the JSON format, the Babylon exporter is adding more details than we currently need. For instance, it also adds potential details about the textures, the lights, etc. That’s why, we’re going to parse the file and jump directly to areas we’re only interesting in: the vertices and the faces’ indices to build our wireframe rendering. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Note:&lt;/u&gt;&lt;/strong&gt; for &lt;strong&gt;C#&lt;/strong&gt; developers, you need to install &lt;strong&gt;Json.NET&lt;/strong&gt; from Newtonsoft via nuGet like we’ve done in the first tutorial to add SharpDX. Indeed, JSON parsing is not natively supported in .NET like inside a browser using JavaScript. &lt;/p&gt;  &lt;p&gt;Let’s start by adding the loading logic inside the &lt;strong&gt;Device&lt;/strong&gt; object:&lt;/p&gt;  &lt;div id="tabset1" class="tabset"&gt;   &lt;ul class="tabnavs"&gt;     &lt;li&gt;&lt;a class="activeTab" href="#loadjsoncsharp"&gt;C#&lt;/a&gt; &lt;/li&gt;      &lt;li&gt;&lt;a href="#loadjsonts"&gt;TypeScript&lt;/a&gt; &lt;/li&gt;      &lt;li&gt;&lt;a href="#loadjsonjs"&gt;JavaScript&lt;/a&gt; &lt;/li&gt;   &lt;/ul&gt;    &lt;div id="loadjsoncsharp" class="tabpane activePane"&gt;     &lt;pre class="code"&gt;&lt;span style="color: green"&gt;// Loading the JSON file in an asynchronous manner
&lt;/span&gt;&lt;span style="color: blue"&gt;public async &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Task&lt;/span&gt;&lt;span style="color: black"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #2b91af"&gt;Mesh&lt;/span&gt;&lt;span style="color: black"&gt;[]&amp;gt; LoadJSONFileAsync(&lt;/span&gt;&lt;span style="color: blue"&gt;string &lt;/span&gt;&lt;span style="color: black"&gt;fileName)
{
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;meshes = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&lt;span style="color: black"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #2b91af"&gt;Mesh&lt;/span&gt;&lt;span style="color: black"&gt;&amp;gt;();
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;file = &lt;/span&gt;&lt;span style="color: blue"&gt;await &lt;/span&gt;&lt;span style="color: black"&gt;Windows.ApplicationModel.&lt;/span&gt;&lt;span style="color: #2b91af"&gt;Package&lt;/span&gt;&lt;span style="color: black"&gt;.Current.InstalledLocation.GetFileAsync(fileName);
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;data = &lt;/span&gt;&lt;span style="color: blue"&gt;await &lt;/span&gt;&lt;span style="color: black"&gt;Windows.Storage.&lt;/span&gt;&lt;span style="color: #2b91af"&gt;FileIO&lt;/span&gt;&lt;span style="color: black"&gt;.ReadTextAsync(file);
    &lt;/span&gt;&lt;span style="color: blue"&gt;dynamic &lt;/span&gt;&lt;span style="color: black"&gt;jsonObject = Newtonsoft.Json.&lt;/span&gt;&lt;span style="color: #2b91af"&gt;JsonConvert&lt;/span&gt;&lt;span style="color: black"&gt;.DeserializeObject(data);

    &lt;/span&gt;&lt;span style="color: blue"&gt;for &lt;/span&gt;&lt;span style="color: black"&gt;(&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;meshIndex = 0; meshIndex &amp;lt; jsonObject.meshes.Count; meshIndex++)
    {
        &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;verticesArray = jsonObject.meshes[meshIndex].vertices;
        &lt;/span&gt;&lt;span style="color: green"&gt;// Faces
        &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;indicesArray = jsonObject.meshes[meshIndex].indices;

        &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;uvCount = jsonObject.meshes[meshIndex].uvCount.Value;
        &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;verticesStep = 1;

        &lt;/span&gt;&lt;span style="color: green"&gt;// Depending of the number of texture's coordinates per vertex
        // we're jumping in the vertices array  by 6, 8 &amp;amp; 10 windows frame
        &lt;/span&gt;&lt;span style="color: blue"&gt;switch &lt;/span&gt;&lt;span style="color: black"&gt;((&lt;/span&gt;&lt;span style="color: blue"&gt;int&lt;/span&gt;&lt;span style="color: black"&gt;)uvCount)
        {
            &lt;/span&gt;&lt;span style="color: blue"&gt;case &lt;/span&gt;&lt;span style="color: black"&gt;0:
                verticesStep = 6;
                &lt;/span&gt;&lt;span style="color: blue"&gt;break&lt;/span&gt;&lt;span style="color: black"&gt;;
            &lt;/span&gt;&lt;span style="color: blue"&gt;case &lt;/span&gt;&lt;span style="color: black"&gt;1:
                verticesStep = 8;
                &lt;/span&gt;&lt;span style="color: blue"&gt;break&lt;/span&gt;&lt;span style="color: black"&gt;;
            &lt;/span&gt;&lt;span style="color: blue"&gt;case &lt;/span&gt;&lt;span style="color: black"&gt;2:
                verticesStep = 10;
                &lt;/span&gt;&lt;span style="color: blue"&gt;break&lt;/span&gt;&lt;span style="color: black"&gt;;
        }

        &lt;/span&gt;&lt;span style="color: green"&gt;// the number of interesting vertices information for us
        &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;verticesCount = verticesArray.Count / verticesStep;
        &lt;/span&gt;&lt;span style="color: green"&gt;// number of faces is logically the size of the array divided by 3 (A, B, C)
        &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;facesCount = indicesArray.Count / 3;
        &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;mesh = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Mesh&lt;/span&gt;&lt;span style="color: black"&gt;(jsonObject.meshes[meshIndex].name.Value, verticesCount, facesCount);

        &lt;/span&gt;&lt;span style="color: green"&gt;// Filling the Vertices array of our mesh first
        &lt;/span&gt;&lt;span style="color: blue"&gt;for &lt;/span&gt;&lt;span style="color: black"&gt;(&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;index = 0; index &amp;lt; verticesCount; index++)
        {
            &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;x = (&lt;/span&gt;&lt;span style="color: blue"&gt;float&lt;/span&gt;&lt;span style="color: black"&gt;)verticesArray[index * verticesStep].Value;
            &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;y = (&lt;/span&gt;&lt;span style="color: blue"&gt;float&lt;/span&gt;&lt;span style="color: black"&gt;)verticesArray[index * verticesStep + 1].Value;
            &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;z = (&lt;/span&gt;&lt;span style="color: blue"&gt;float&lt;/span&gt;&lt;span style="color: black"&gt;)verticesArray[index * verticesStep + 2].Value;
            mesh.Vertices[index] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector3&lt;/span&gt;&lt;span style="color: black"&gt;(x, y, z);
        }

        &lt;/span&gt;&lt;span style="color: green"&gt;// Then filling the Faces array
        &lt;/span&gt;&lt;span style="color: blue"&gt;for &lt;/span&gt;&lt;span style="color: black"&gt;(&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;index = 0; index &amp;lt; facesCount; index++)
        {
            &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;a = (&lt;/span&gt;&lt;span style="color: blue"&gt;int&lt;/span&gt;&lt;span style="color: black"&gt;)indicesArray[index * 3].Value;
            &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;b = (&lt;/span&gt;&lt;span style="color: blue"&gt;int&lt;/span&gt;&lt;span style="color: black"&gt;)indicesArray[index * 3 + 1].Value;
            &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;c = (&lt;/span&gt;&lt;span style="color: blue"&gt;int&lt;/span&gt;&lt;span style="color: black"&gt;)indicesArray[index * 3 + 2].Value;
            mesh.Faces[index] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Face &lt;/span&gt;&lt;span style="color: black"&gt;{ A = a, B = b, C = c };
        }

        &lt;/span&gt;&lt;span style="color: green"&gt;// Getting the position you've set in Blender
        &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;position = jsonObject.meshes[meshIndex].position;
        mesh.Position = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector3&lt;/span&gt;&lt;span style="color: black"&gt;((&lt;/span&gt;&lt;span style="color: blue"&gt;float&lt;/span&gt;&lt;span style="color: black"&gt;)position[0].Value, (&lt;/span&gt;&lt;span style="color: blue"&gt;float&lt;/span&gt;&lt;span style="color: black"&gt;)position[1].Value, (&lt;/span&gt;&lt;span style="color: blue"&gt;float&lt;/span&gt;&lt;span style="color: black"&gt;)position[2].Value);
        meshes.Add(mesh);
    }
    &lt;/span&gt;&lt;span style="color: blue"&gt;return &lt;/span&gt;&lt;span style="color: black"&gt;meshes.ToArray();
}&lt;/span&gt;&lt;/pre&gt;
    &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/div&gt;

  &lt;div id="loadjsonts" class="tabpane"&gt;
    &lt;pre class="code"&gt;&lt;span style="color: green"&gt;// Loading the JSON file in an asynchronous manner and
// calling back with the function passed providing the array of meshes loaded
&lt;/span&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: black"&gt;LoadJSONFileAsync(fileName: &lt;/span&gt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&lt;span style="color: black"&gt;, callback: (result: Mesh[]) =&amp;gt; &lt;/span&gt;&lt;span style="color: blue"&gt;any&lt;/span&gt;&lt;span style="color: black"&gt;): &lt;/span&gt;&lt;span style="color: blue"&gt;void &lt;/span&gt;&lt;span style="color: black"&gt;{
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;jsonObject = {};
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;xmlhttp = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;XMLHttpRequest();
    xmlhttp.open(&lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;GET&amp;quot;&lt;/span&gt;&lt;span style="color: black"&gt;, fileName, &lt;/span&gt;&lt;span style="color: blue"&gt;true&lt;/span&gt;&lt;span style="color: black"&gt;);
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;that = &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;;
    xmlhttp.onreadystatechange = &lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;&lt;span style="color: black"&gt;() {
        &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;&lt;span style="color: black"&gt;(xmlhttp.readyState == 4 &amp;amp;&amp;amp; xmlhttp.status == 200) {
            jsonObject = JSON.parse(xmlhttp.responseText);
            callback(that.CreateMeshesFromJSON(jsonObject));
        }
    };
    xmlhttp.send(&lt;/span&gt;&lt;span style="color: blue"&gt;null&lt;/span&gt;&lt;span style="color: black"&gt;);
}

&lt;/span&gt;&lt;span style="color: blue"&gt;private &lt;/span&gt;&lt;span style="color: black"&gt;CreateMeshesFromJSON(jsonObject): Mesh[] {
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;meshes: Mesh[] = [];
    &lt;/span&gt;&lt;span style="color: blue"&gt;for &lt;/span&gt;&lt;span style="color: black"&gt;(&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;meshIndex = 0; meshIndex &amp;lt; jsonObject.meshes.length; meshIndex++) {
        &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;verticesArray: &lt;/span&gt;&lt;span style="color: blue"&gt;number&lt;/span&gt;&lt;span style="color: black"&gt;[] = jsonObject.meshes[meshIndex].vertices;
        &lt;/span&gt;&lt;span style="color: green"&gt;// Faces
        &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;indicesArray: &lt;/span&gt;&lt;span style="color: blue"&gt;number&lt;/span&gt;&lt;span style="color: black"&gt;[] = jsonObject.meshes[meshIndex].indices;

        &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;uvCount: &lt;/span&gt;&lt;span style="color: blue"&gt;number &lt;/span&gt;&lt;span style="color: black"&gt;= jsonObject.meshes[meshIndex].uvCount;
        &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;verticesStep = 1;

        &lt;/span&gt;&lt;span style="color: green"&gt;// Depending of the number of texture's coordinates per vertex
        // we're jumping in the vertices array  by 6, 8 &amp;amp; 10 windows frame
        &lt;/span&gt;&lt;span style="color: blue"&gt;switch &lt;/span&gt;&lt;span style="color: black"&gt;(uvCount) {
            &lt;/span&gt;&lt;span style="color: blue"&gt;case &lt;/span&gt;&lt;span style="color: black"&gt;0:
                verticesStep = 6;
                &lt;/span&gt;&lt;span style="color: blue"&gt;break&lt;/span&gt;&lt;span style="color: black"&gt;;
            &lt;/span&gt;&lt;span style="color: blue"&gt;case &lt;/span&gt;&lt;span style="color: black"&gt;1:
                verticesStep = 8;
                &lt;/span&gt;&lt;span style="color: blue"&gt;break&lt;/span&gt;&lt;span style="color: black"&gt;;
            &lt;/span&gt;&lt;span style="color: blue"&gt;case &lt;/span&gt;&lt;span style="color: black"&gt;2:
                verticesStep = 10;
                &lt;/span&gt;&lt;span style="color: blue"&gt;break&lt;/span&gt;&lt;span style="color: black"&gt;;
        }

        &lt;/span&gt;&lt;span style="color: green"&gt;// the number of interesting vertices information for us
        &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;verticesCount = verticesArray.length / verticesStep;
        &lt;/span&gt;&lt;span style="color: green"&gt;// number of faces is logically the size of the array divided by 3 (A, B, C)
        &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;facesCount = indicesArray.length / 3;
        &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;mesh = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;SoftEngine.Mesh(jsonObject.meshes[meshIndex].name, verticesCount, facesCount);
                
        &lt;/span&gt;&lt;span style="color: green"&gt;// Filling the Vertices array of our mesh first
        &lt;/span&gt;&lt;span style="color: blue"&gt;for &lt;/span&gt;&lt;span style="color: black"&gt;(&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;index = 0; index &amp;lt; verticesCount; index++) {
            &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;x = verticesArray[index * verticesStep];
            &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;y = verticesArray[index * verticesStep + 1];
            &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;z = verticesArray[index * verticesStep + 2];
            mesh.Vertices[index] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Vector3(x, y, z);
        }
                
        &lt;/span&gt;&lt;span style="color: green"&gt;// Then filling the Faces array
        &lt;/span&gt;&lt;span style="color: blue"&gt;for &lt;/span&gt;&lt;span style="color: black"&gt;(&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;index = 0; index &amp;lt; facesCount; index++) {
            &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;a = indicesArray[index * 3];
            &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;b = indicesArray[index * 3 + 1];
            &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;c = indicesArray[index * 3 + 2];
            mesh.Faces[index] = {
                A: a,
                B: b,
                C: c
            };
        }
                
        &lt;/span&gt;&lt;span style="color: green"&gt;// Getting the position you've set in Blender
        &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;position = jsonObject.meshes[meshIndex].position;
        mesh.Position = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Vector3(position[0], position[1], position[2]);
        meshes.push(mesh);
    }
    &lt;/span&gt;&lt;span style="color: blue"&gt;return &lt;/span&gt;&lt;span style="color: black"&gt;meshes;
}&lt;/span&gt;&lt;/pre&gt;
    &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/div&gt;

  &lt;div id="loadjsonjs" class="tabpane"&gt;
    &lt;pre class="code"&gt;&lt;span style="color: green"&gt;// Loading the JSON file in an asynchronous manner and
// calling back with the function passed providing the array of meshes loaded
&lt;/span&gt;&lt;span style="color: black"&gt;Device.prototype.LoadJSONFileAsync = &lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;&lt;span style="color: black"&gt;(fileName, callback) {
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;jsonObject = {};
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;xmlhttp = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;XMLHttpRequest();
    xmlhttp.open(&lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;GET&amp;quot;&lt;/span&gt;&lt;span style="color: black"&gt;, fileName, &lt;/span&gt;&lt;span style="color: blue"&gt;true&lt;/span&gt;&lt;span style="color: black"&gt;);
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;that = &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;;
    xmlhttp.onreadystatechange = &lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;&lt;span style="color: black"&gt;() {
        &lt;/span&gt;&lt;span style="color: blue"&gt;if&lt;/span&gt;&lt;span style="color: black"&gt;(xmlhttp.readyState == 4 &amp;amp;&amp;amp; xmlhttp.status == 200) {
            jsonObject = JSON.parse(xmlhttp.responseText);
            callback(that.CreateMeshesFromJSON(jsonObject));
        }
    };
    xmlhttp.send(&lt;/span&gt;&lt;span style="color: blue"&gt;null&lt;/span&gt;&lt;span style="color: black"&gt;);
};
Device.prototype.CreateMeshesFromJSON = &lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;&lt;span style="color: black"&gt;(jsonObject) {
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;meshes = [];
    &lt;/span&gt;&lt;span style="color: blue"&gt;for&lt;/span&gt;&lt;span style="color: black"&gt;(&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;meshIndex = 0; meshIndex &amp;lt; jsonObject.meshes.length; meshIndex++) {
        &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;verticesArray = jsonObject.meshes[meshIndex].vertices;
        &lt;/span&gt;&lt;span style="color: green"&gt;// Faces
        &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;indicesArray = jsonObject.meshes[meshIndex].indices;

        &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;uvCount = jsonObject.meshes[meshIndex].uvCount;
        &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;verticesStep = 1;

        &lt;/span&gt;&lt;span style="color: green"&gt;// Depending of the number of texture's coordinates per vertex
        // we're jumping in the vertices array  by 6, 8 &amp;amp; 10 windows frame
        &lt;/span&gt;&lt;span style="color: blue"&gt;switch&lt;/span&gt;&lt;span style="color: black"&gt;(uvCount) {
            &lt;/span&gt;&lt;span style="color: blue"&gt;case &lt;/span&gt;&lt;span style="color: black"&gt;0:
                verticesStep = 6;
                &lt;/span&gt;&lt;span style="color: blue"&gt;break&lt;/span&gt;&lt;span style="color: black"&gt;;
            &lt;/span&gt;&lt;span style="color: blue"&gt;case &lt;/span&gt;&lt;span style="color: black"&gt;1:
                verticesStep = 8;
                &lt;/span&gt;&lt;span style="color: blue"&gt;break&lt;/span&gt;&lt;span style="color: black"&gt;;
            &lt;/span&gt;&lt;span style="color: blue"&gt;case &lt;/span&gt;&lt;span style="color: black"&gt;2:
                verticesStep = 10;
                &lt;/span&gt;&lt;span style="color: blue"&gt;break&lt;/span&gt;&lt;span style="color: black"&gt;;
        }

        &lt;/span&gt;&lt;span style="color: green"&gt;// the number of interesting vertices information for us
        &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;verticesCount = verticesArray.length / verticesStep;
        &lt;/span&gt;&lt;span style="color: green"&gt;// number of faces is logically the size of the array divided by 3 (A, B, C)
        &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;facesCount = indicesArray.length / 3;
        &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;mesh = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;SoftEngine.Mesh(jsonObject.meshes[meshIndex].name, verticesCount, facesCount);

        &lt;/span&gt;&lt;span style="color: green"&gt;// Filling the Vertices array of our mesh first
        &lt;/span&gt;&lt;span style="color: blue"&gt;for &lt;/span&gt;&lt;span style="color: black"&gt;(&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;index = 0; index &amp;lt; verticesCount; index++) {
            &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;x = verticesArray[index * verticesStep];
            &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;y = verticesArray[index * verticesStep + 1];
            &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;z = verticesArray[index * verticesStep + 2];
            mesh.Vertices[index] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Vector3(x, y, z);
        }

        &lt;/span&gt;&lt;span style="color: green"&gt;// Then filling the Faces array
        &lt;/span&gt;&lt;span style="color: blue"&gt;for&lt;/span&gt;&lt;span style="color: black"&gt;(&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;index = 0; index &amp;lt; facesCount; index++) {
            &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;a = indicesArray[index * 3];
            &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;b = indicesArray[index * 3 + 1];
            &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;c = indicesArray[index * 3 + 2];
            mesh.Faces[index] = {
                A: a,
                B: b,
                C: c
            };
        }

        &lt;/span&gt;&lt;span style="color: green"&gt;// Getting the position you've set in Blender
        &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;position = jsonObject.meshes[meshIndex].position;
        mesh.Position = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Vector3(position[0], position[1], position[2]);
        meshes.push(mesh);
    }
    &lt;/span&gt;&lt;span style="color: blue"&gt;return &lt;/span&gt;&lt;span style="color: black"&gt;meshes;
};&lt;/span&gt;&lt;/pre&gt;
    &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;You will probably wonder why we’re jumping by 6, 8 &amp;amp; 10 in the vertices array to take our 3D coordinate (X, Y, Z) of our vertices. Again, this is because the Babylon exporter adds more details that we currently need for our wireframe rendering. That’s why, &lt;strong&gt;we’re filtering those details &lt;/strong&gt;using this frame approach. This logic is specific to our file format. If you want to load the export from other (like the one from three.js), you’ll just have to identity where to retrieve the vertices and faces indices in another file format.&amp;#160; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Note:&lt;/u&gt;&lt;/strong&gt; to be able to load our .babylon files, &lt;strong&gt;TypeScript/JavaScript&lt;/strong&gt; developers, you need to define a new MIME type “&lt;strong&gt;application/babylon&lt;/strong&gt;” targeting the extension “.babylon”. In IIS, you need to declare it inside your &lt;strong&gt;web.config&lt;/strong&gt;:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;system.webServer&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;staticContent&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
      &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;mimeMap &lt;/span&gt;&lt;span style="color: red"&gt;fileExtension&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&lt;span style="color: black"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: blue"&gt;.babylon&lt;/span&gt;&lt;span style="color: black"&gt;&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;mimeType&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&lt;span style="color: black"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: blue"&gt;application/babylon&lt;/span&gt;&lt;span style="color: black"&gt;&amp;quot; &lt;/span&gt;&lt;span style="color: blue"&gt;/&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;staticContent&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
  &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;system.webServer&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt; developers, you need to change the properties of the file you will include in the solution. Switch “&lt;em&gt;Build Action&lt;/em&gt;” to “&lt;em&gt;Content&lt;/em&gt;” and always copy to the output directory:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8103.image_5F00_52D7D3C4.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0523.image_5F00_thumb_5F00_46D5E390.png" width="317" height="133" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Otherwise, the file won’t be found. &lt;/p&gt;

&lt;p&gt;Finally, we now need to update the equivalent of our main function to call this new LoadJSONFileAsync function instead of creating manually our cube. As we will also have potentially several meshes to animate, we need also to change the rotation values during each tick to every meshes loaded:&lt;/p&gt;

&lt;div id="tabset2" class="tabset"&gt;
  &lt;ul class="tabnavs"&gt;
    &lt;li&gt;&lt;a class="activeTab" href="#maincsharp"&gt;C#&lt;/a&gt; &lt;/li&gt;

    &lt;li&gt;&lt;a href="#maints"&gt;TypeScript&lt;/a&gt; &lt;/li&gt;

    &lt;li&gt;&lt;a href="#mainjs"&gt;JavaScript&lt;/a&gt; &lt;/li&gt;
  &lt;/ul&gt;

  &lt;div id="maincsharp" class="tabpane activePane"&gt;
    &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;private &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Device &lt;/span&gt;&lt;span style="color: black"&gt;device;
&lt;/span&gt;&lt;span style="color: #2b91af"&gt;Mesh&lt;/span&gt;&lt;span style="color: black"&gt;[] meshes;
&lt;/span&gt;&lt;span style="color: #2b91af"&gt;Camera &lt;/span&gt;&lt;span style="color: black"&gt;mera = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Camera&lt;/span&gt;&lt;span style="color: black"&gt;();

&lt;/span&gt;&lt;span style="color: blue"&gt;private async void &lt;/span&gt;&lt;span style="color: black"&gt;Page_Loaded(&lt;/span&gt;&lt;span style="color: blue"&gt;object &lt;/span&gt;&lt;span style="color: black"&gt;sender, &lt;/span&gt;&lt;span style="color: #2b91af"&gt;RoutedEventArgs &lt;/span&gt;&lt;span style="color: black"&gt;e)
{
    &lt;/span&gt;&lt;span style="color: green"&gt;// Choose the back buffer resolution here
    &lt;/span&gt;&lt;span style="color: #2b91af"&gt;WriteableBitmap &lt;/span&gt;&lt;span style="color: black"&gt;bmp = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;WriteableBitmap&lt;/span&gt;&lt;span style="color: black"&gt;(640, 480);

    &lt;/span&gt;&lt;span style="color: green"&gt;// Our Image XAML control
    &lt;/span&gt;&lt;span style="color: black"&gt;frontBuffer.Source = bmp;
            
    device = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Device&lt;/span&gt;&lt;span style="color: black"&gt;(bmp);
    meshes = &lt;/span&gt;&lt;span style="color: blue"&gt;await &lt;/span&gt;&lt;span style="color: black"&gt;device.LoadJSONFileAsync(&lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;monkey.babylon&amp;quot;&lt;/span&gt;&lt;span style="color: black"&gt;);
    mera.Position = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector3&lt;/span&gt;&lt;span style="color: black"&gt;(0, 0, 10.0f);
    mera.Target = &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector3&lt;/span&gt;&lt;span style="color: black"&gt;.Zero;

    &lt;/span&gt;&lt;span style="color: green"&gt;// Registering to the XAML rendering loop
    &lt;/span&gt;&lt;span style="color: #2b91af"&gt;CompositionTarget&lt;/span&gt;&lt;span style="color: black"&gt;.Rendering += CompositionTarget_Rendering;
}

&lt;/span&gt;&lt;span style="color: green"&gt;// Rendering loop handler
&lt;/span&gt;&lt;span style="color: blue"&gt;void &lt;/span&gt;&lt;span style="color: black"&gt;CompositionTarget_Rendering(&lt;/span&gt;&lt;span style="color: blue"&gt;object &lt;/span&gt;&lt;span style="color: black"&gt;sender, &lt;/span&gt;&lt;span style="color: blue"&gt;object &lt;/span&gt;&lt;span style="color: black"&gt;e)
{
    device.Clear(0, 0, 0, 255);

    &lt;/span&gt;&lt;span style="color: blue"&gt;foreach &lt;/span&gt;&lt;span style="color: black"&gt;(&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;mesh &lt;/span&gt;&lt;span style="color: blue"&gt;in &lt;/span&gt;&lt;span style="color: black"&gt;meshes) {
        &lt;/span&gt;&lt;span style="color: green"&gt;// rotating slightly the meshes during each frame rendered
        &lt;/span&gt;&lt;span style="color: black"&gt;mesh.Rotation = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector3&lt;/span&gt;&lt;span style="color: black"&gt;(mesh.Rotation.X + 0.01f, mesh.Rotation.Y + 0.01f, mesh.Rotation.Z);
    }

    &lt;/span&gt;&lt;span style="color: green"&gt;// Doing the various matrix operations
    &lt;/span&gt;&lt;span style="color: black"&gt;device.Render(mera, meshes);
    &lt;/span&gt;&lt;span style="color: green"&gt;// Flushing the back buffer into the front buffer
    &lt;/span&gt;&lt;span style="color: black"&gt;device.Present();
}&lt;/span&gt;&lt;/pre&gt;
    &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/div&gt;

  &lt;div id="maints" class="tabpane"&gt;
    &lt;pre class="code"&gt;&lt;span style="color: green"&gt;///&amp;lt;reference path=&amp;quot;SoftEngine.ts&amp;quot;/&amp;gt;

&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;canvas: HTMLCanvasElement; 
&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;device: SoftEngine.Device; 
&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;meshes: SoftEngine.Mesh[] = [];
&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;mera: SoftEngine.Camera;

document.addEventListener(&lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;DOMContentLoaded&amp;quot;&lt;/span&gt;&lt;span style="color: black"&gt;, init, &lt;/span&gt;&lt;span style="color: blue"&gt;false&lt;/span&gt;&lt;span style="color: black"&gt;);

&lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;&lt;span style="color: black"&gt;init() {
    canvas = &amp;lt;HTMLCanvasElement&amp;gt; document.getElementById(&lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;frontBuffer&amp;quot;&lt;/span&gt;&lt;span style="color: black"&gt;);
    mera = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;SoftEngine.Camera();
    device = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;SoftEngine.Device(canvas); 

    mera.Position = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Vector3(0, 0, 10);
    mera.Target = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Vector3(0, 0, 0);

    device.LoadJSONFileAsync(&lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;monkey.babylon&amp;quot;&lt;/span&gt;&lt;span style="color: black"&gt;, loadJSONCompleted)
}

&lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;&lt;span style="color: black"&gt;loadJSONCompleted(meshesLoaded: SoftEngine.Mesh[]) {
    meshes = meshesLoaded;
    &lt;/span&gt;&lt;span style="color: green"&gt;// Calling the HTML5 rendering loop
    &lt;/span&gt;&lt;span style="color: black"&gt;requestAnimationFrame(drawingLoop);
}

&lt;/span&gt;&lt;span style="color: green"&gt;// Rendering loop handler
&lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;&lt;span style="color: black"&gt;drawingLoop() {
    device.clear();

    &lt;/span&gt;&lt;span style="color: blue"&gt;for &lt;/span&gt;&lt;span style="color: black"&gt;(&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;i = 0; i &amp;lt; meshes.length; i++) {
        &lt;/span&gt;&lt;span style="color: green"&gt;// rotating slightly the mesh during each frame rendered
        &lt;/span&gt;&lt;span style="color: black"&gt;meshes[i].Rotation.x += 0.01;
        meshes[i].Rotation.y += 0.01;
    }

    &lt;/span&gt;&lt;span style="color: green"&gt;// Doing the various matrix operations
    &lt;/span&gt;&lt;span style="color: black"&gt;device.render(mera, meshes);
    &lt;/span&gt;&lt;span style="color: green"&gt;// Flushing the back buffer into the front buffer
    &lt;/span&gt;&lt;span style="color: black"&gt;device.present();

    &lt;/span&gt;&lt;span style="color: green"&gt;// Calling the HTML5 rendering loop recursively
    &lt;/span&gt;&lt;span style="color: black"&gt;requestAnimationFrame(drawingLoop);
}&lt;/span&gt;&lt;/pre&gt;
    &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/div&gt;

  &lt;div id="mainjs" class="tabpane"&gt;
    &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;canvas;
&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;device;
&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;meshes = [];
&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;mera;

document.addEventListener(&lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;DOMContentLoaded&amp;quot;&lt;/span&gt;&lt;span style="color: black"&gt;, init, &lt;/span&gt;&lt;span style="color: blue"&gt;false&lt;/span&gt;&lt;span style="color: black"&gt;);

&lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;&lt;span style="color: black"&gt;init() {
    canvas = document.getElementById(&lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;frontBuffer&amp;quot;&lt;/span&gt;&lt;span style="color: black"&gt;);
    mera = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;SoftEngine.Camera();
    device = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;SoftEngine.Device(canvas);
    mera.Position = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Vector3(0, 0, 10);
    mera.Target = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Vector3(0, 0, 0);
    device.LoadJSONFileAsync(&lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;monkey.babylon&amp;quot;&lt;/span&gt;&lt;span style="color: black"&gt;, loadJSONCompleted);
}

&lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;&lt;span style="color: black"&gt;loadJSONCompleted(meshesLoaded) {
    meshes = meshesLoaded;
    &lt;/span&gt;&lt;span style="color: green"&gt;// Calling the HTML5 rendering loop
    &lt;/span&gt;&lt;span style="color: black"&gt;requestAnimationFrame(drawingLoop);
}

&lt;/span&gt;&lt;span style="color: green"&gt;// Rendering loop handler
&lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;&lt;span style="color: black"&gt;drawingLoop() {
    device.clear();

    &lt;/span&gt;&lt;span style="color: blue"&gt;for &lt;/span&gt;&lt;span style="color: black"&gt;(&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;i = 0; i &amp;lt; meshes.length; i++) {
        &lt;/span&gt;&lt;span style="color: green"&gt;// rotating slightly the mesh during each frame rendered
        &lt;/span&gt;&lt;span style="color: black"&gt;meshes[i].Rotation.x += 0.01;
        meshes[i].Rotation.y += 0.01;
    }

    &lt;/span&gt;&lt;span style="color: green"&gt;// Doing the various matrix operations
    &lt;/span&gt;&lt;span style="color: black"&gt;device.render(mera, meshes);
    &lt;/span&gt;&lt;span style="color: green"&gt;// Flushing the back buffer into the front buffer
    &lt;/span&gt;&lt;span style="color: black"&gt;device.present();

    &lt;/span&gt;&lt;span style="color: green"&gt;// Calling the HTML5 rendering loop recursively
    &lt;/span&gt;&lt;span style="color: black"&gt;requestAnimationFrame(drawingLoop);
}&lt;/span&gt;&lt;/pre&gt;
    &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;You should now have a 3D engine which is capable of loading meshes exported by Blender and animate them in a wireframe rendering mode! I don’t know about you, but I was very excited to reach this stage. :)&lt;/p&gt;

&lt;p&gt;Again, you can &lt;strong&gt;download the solutions&lt;/strong&gt; containing the source code:&lt;/p&gt;

&lt;p&gt;- &lt;strong&gt;C#&lt;/strong&gt; : &lt;a href="http://david.blob.core.windows.net/softengine3d/SoftEngineCSharpPart3.zip"&gt;SoftEngineCSharpPart3.zip&lt;/a&gt; 

  &lt;br /&gt;- &lt;strong&gt;TypeScript &lt;/strong&gt;: &lt;a href="http://david.blob.core.windows.net/softengine3d/SoftEngineTSPart3.zip"&gt;SoftEngineTSPart3.zip&lt;/a&gt; 

  &lt;br /&gt;- &lt;strong&gt;JavaScript&lt;/strong&gt; : &lt;a href="http://david.blob.core.windows.net/softengine3d/SoftEngineJSPart3.zip"&gt;SoftEngineJSPart3.zip&lt;/a&gt; or simply right-click –&amp;gt; view source on the first embedded iframe&lt;/p&gt;

&lt;p&gt;So, what’s next now? Well, we need to &lt;strong&gt;fill the triangles&lt;/strong&gt;. This is called &lt;strong&gt;rasterization&lt;/strong&gt;. We will also handle what we name a &lt;strong&gt;Z-Buffer&lt;/strong&gt; to have a proper rendering. In the next tutorial, you’ll then learn how to obtain something like that:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4846.image_5F00_333936D6.png"&gt;&lt;img title="image" style="border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px; display: inline" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/1663.image_5F00_thumb_5F00_78718DFF.png" width="481" height="400" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;We will fill the triangles with a random color. See you in the fourth tutorial!&lt;/p&gt;

&lt;p&gt;David&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10426443" width="1" height="1"&gt;</content><author><name>David Rousset</name><uri>http://blogs.msdn.com/davrous/ProfileUrlRedirect.ashx</uri></author><category term="JSON" scheme="http://blogs.msdn.com/b/davrous/archive/tags/JSON/" /><category term="HTML5" scheme="http://blogs.msdn.com/b/davrous/archive/tags/HTML5/" /><category term="Canvas" scheme="http://blogs.msdn.com/b/davrous/archive/tags/Canvas/" /><category term="Windows 8" scheme="http://blogs.msdn.com/b/davrous/archive/tags/Windows+8/" /><category term="3DEngine" scheme="http://blogs.msdn.com/b/davrous/archive/tags/3DEngine/" /><category term="C#" scheme="http://blogs.msdn.com/b/davrous/archive/tags/C_2300_/" /><category term="TypeScript" scheme="http://blogs.msdn.com/b/davrous/archive/tags/TypeScript/" /></entry><entry><title>Tutorial part 2: learning how to write a 3D soft engine from scratch in C#, TS or JS – drawing lines &amp; triangles</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/davrous/archive/2013/06/14/tutorial-part-2-learning-how-to-write-a-3d-soft-engine-from-scratch-in-c-ts-or-js-drawing-lines-amp-triangles.aspx" /><id>http://blogs.msdn.com/b/davrous/archive/2013/06/14/tutorial-part-2-learning-how-to-write-a-3d-soft-engine-from-scratch-in-c-ts-or-js-drawing-lines-amp-triangles.aspx</id><published>2013-06-14T15:31:29Z</published><updated>2013-06-14T15:31:29Z</updated><content type="html">&lt;link rel="stylesheet" href="http://david.blob.core.windows.net/softengine3d/tabs.css" /&gt;&lt;script src="http://david.blob.core.windows.net/softengine3d/dw_tabs.js"&gt;&lt;/script&gt;&lt;script type="text/javascript"&gt;

        DYN_WEB.Tabs.setup({
            id: 'tabset1', // if of tabset
            css: 'css/tabs.css', // optional if you don't care about accessibility 
            useCookies: true // optional
        }, { id: 'tabset2', useCookies: true }, { id: 'tabset3', useCookies: true }, { id: 'tabset4', useCookies: true }, { id: 'tabset5', useCookies: true }, { id: 'tabset6', useCookies: true });

    &lt;/script&gt;  &lt;p&gt;Now that we have built the core of our 3D engine thanks to the previous tutorial &lt;a title="Tutorial series- learning how to write a 3D soft engine from scratch in C#, TypeScript or JavaSc" href="http://blogs.msdn.com/b/davrous/archive/2013/06/13/tutorial-series-learning-how-to-write-a-3d-soft-engine-from-scratch-in-c-typescript-or-javascript.aspx"&gt;Tutorial series- learning how to write a 3D soft engine from scratch in C#, TypeScript or JavaScript&lt;/a&gt;, we can work on enhancing the rendering. The next step is then to connect the dots to draw some lines in order to render what you probably know as a &lt;strong&gt;“wireframe” rendering&lt;/strong&gt;. &lt;/p&gt;  &lt;p&gt;In this tutorial, uou will learn how to draw lines, what a face is and how cool is the Bresenham algorithm to draw some triangles. &lt;/p&gt;  &lt;p&gt;Thanks to that, at the end, you will know how to code something as cool as that:&lt;/p&gt; &lt;iframe style="border-top: rgb(200,200,200) 1px solid; border-right: rgb(200,200,200) 1px solid; border-bottom: rgb(200,200,200) 1px solid; border-left: rgb(200,200,200) 1px solid" height="260" src="http://david.blob.core.windows.net/softengine3d/part2sample3/index.html" width="340" scrolling="no"&gt;&lt;/iframe&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;Yes! Our 3D rotating cube starts to really live on our screens! &lt;/p&gt;  &lt;h2&gt;First basic algorithm to draw a line between two points&lt;/h2&gt;  &lt;p&gt;Let’s start by coding a simple algorithm. To &lt;strong&gt;draw a line between 2 vertices&lt;/strong&gt;, we’re going to use the following logic:&lt;/p&gt;  &lt;p&gt;- if the distance between the 2 points (point0 &amp;amp; point1) is less than 2 pixels, there’s nothing to do    &lt;br /&gt;- otherwise, we’re finding the &lt;strong&gt;middle point&lt;/strong&gt; between both points (point0 coordinates + (point1 coordinates – point0 coordinates) / 2)     &lt;br /&gt;- we’re drawing that point on screen     &lt;br /&gt;- we’re launching this &lt;strong&gt;algorithm recursively&lt;/strong&gt; between point0 &amp;amp; middle point and between middle point &amp;amp; point1 &lt;/p&gt;  &lt;p&gt;Here is the code to do that:&lt;/p&gt;  &lt;div id="tabset1" class="tabset"&gt;   &lt;ul class="tabnavs"&gt;     &lt;li&gt;&lt;a class="activeTab" href="#drawlinecsharp"&gt;C#&lt;/a&gt; &lt;/li&gt;      &lt;li&gt;&lt;a href="#drawlinets"&gt;TypeScript&lt;/a&gt; &lt;/li&gt;      &lt;li&gt;&lt;a href="#drawlinejs"&gt;JavaScript&lt;/a&gt; &lt;/li&gt;   &lt;/ul&gt;    &lt;div id="drawlinecsharp" class="tabpane activePane"&gt;     &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public void &lt;/span&gt;&lt;span style="color: black"&gt;DrawLine(&lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector2 &lt;/span&gt;&lt;span style="color: black"&gt;point0, &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector2 &lt;/span&gt;&lt;span style="color: black"&gt;point1)
{
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;dist = (point1 - point0).Length();

    &lt;/span&gt;&lt;span style="color: green"&gt;// If the distance between the 2 points is less than 2 pixels
    // We're exiting
    &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;&lt;span style="color: black"&gt;(dist &amp;lt; 2)
        &lt;/span&gt;&lt;span style="color: blue"&gt;return&lt;/span&gt;&lt;span style="color: black"&gt;;

    &lt;/span&gt;&lt;span style="color: green"&gt;// Find the middle point between first &amp;amp; second point
    &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector2 &lt;/span&gt;&lt;span style="color: black"&gt;middlePoint = point0 + (point1 - point0)/2;
    &lt;/span&gt;&lt;span style="color: green"&gt;// We draw this point on screen
    &lt;/span&gt;&lt;span style="color: black"&gt;DrawPoint(middlePoint);
    &lt;/span&gt;&lt;span style="color: green"&gt;// Recursive algorithm launched between first &amp;amp; middle point
    // and between middle &amp;amp; second point
    &lt;/span&gt;&lt;span style="color: black"&gt;DrawLine(point0, middlePoint);
    DrawLine(middlePoint, point1);
}&lt;/span&gt;&lt;/pre&gt;
    &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/div&gt;

  &lt;div id="drawlinets" class="tabpane"&gt;
    &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: black"&gt;drawLine(point0: BABYLON.Vector2, point1: BABYLON.Vector2): &lt;/span&gt;&lt;span style="color: blue"&gt;void &lt;/span&gt;&lt;span style="color: black"&gt;{
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;dist = point1.subtract(point0).length();

    &lt;/span&gt;&lt;span style="color: green"&gt;// If the distance between the 2 points is less than 2 pixels
    // We're exiting
    &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;&lt;span style="color: black"&gt;(dist &amp;lt; 2)
        &lt;/span&gt;&lt;span style="color: blue"&gt;return&lt;/span&gt;&lt;span style="color: black"&gt;;

    &lt;/span&gt;&lt;span style="color: green"&gt;// Find the middle point between first &amp;amp; second point
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;middlePoint = point0.add((point1.subtract(point0)).scale(0.5));
    &lt;/span&gt;&lt;span style="color: green"&gt;// We draw this point on screen
    &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.drawPoint(middlePoint);
    &lt;/span&gt;&lt;span style="color: green"&gt;// Recursive algorithm launched between first &amp;amp; middle point
    // and between middle &amp;amp; second point
    &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.drawLine(point0, middlePoint);
    &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.drawLine(middlePoint, point1);
}&lt;/span&gt;&lt;/pre&gt;
    &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/div&gt;

  &lt;div id="drawlinejs" class="tabpane"&gt;
    &lt;pre class="code"&gt;&lt;span style="color: black"&gt;Device.prototype.drawLine = &lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;&lt;span style="color: black"&gt;(point0, point1) {
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;dist = point1.subtract(point0).length();

    &lt;/span&gt;&lt;span style="color: green"&gt;// If the distance between the 2 points is less than 2 pixels
    // We're exiting
    &lt;/span&gt;&lt;span style="color: blue"&gt;if&lt;/span&gt;&lt;span style="color: black"&gt;(dist &amp;lt; 2) {
        &lt;/span&gt;&lt;span style="color: blue"&gt;return&lt;/span&gt;&lt;span style="color: black"&gt;;
    }

    &lt;/span&gt;&lt;span style="color: green"&gt;// Find the middle point between first &amp;amp; second point
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;middlePoint = point0.add((point1.subtract(point0)).scale(0.5));
    &lt;/span&gt;&lt;span style="color: green"&gt;// We draw this point on screen
    &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.drawPoint(middlePoint);
    &lt;/span&gt;&lt;span style="color: green"&gt;// Recursive algorithm launched between first &amp;amp; middle point
    // and between middle &amp;amp; second point
    &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.drawLine(point0, middlePoint);
    &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.drawLine(middlePoint, point1);
};&lt;/span&gt;&lt;/pre&gt;
    &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;You need to update the rendering loop to use this new piece of code:&lt;/p&gt;

&lt;div id="tabset2" class="tabset"&gt;
  &lt;ul class="tabnavs"&gt;
    &lt;li&gt;&lt;a class="activeTab" href="#newforcsharp"&gt;C#&lt;/a&gt; &lt;/li&gt;

    &lt;li&gt;&lt;a href="#newforts"&gt;TypeScript&lt;/a&gt; &lt;/li&gt;

    &lt;li&gt;&lt;a href="#newforjs"&gt;JavaScript&lt;/a&gt; &lt;/li&gt;
  &lt;/ul&gt;

  &lt;div id="newforcsharp" class="tabpane activePane"&gt;
    &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;for &lt;/span&gt;&lt;span style="color: black"&gt;(&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;i = 0; i &amp;lt; mesh.Vertices.Length - 1; i++)
{
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;point0 = Project(mesh.Vertices[i], transformMatrix);
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;point1 = Project(mesh.Vertices[i + 1], transformMatrix);
    DrawLine(point0, point1);
}&lt;/span&gt;&lt;/pre&gt;
    &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/div&gt;

  &lt;div id="newforts" class="tabpane"&gt;
    &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;for &lt;/span&gt;&lt;span style="color: black"&gt;(&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;i = 0; i &amp;lt; cMesh.Vertices.length -1; i++){
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;point0 = &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.project(cMesh.Vertices[i], transformMatrix);
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;point1 = &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.project(cMesh.Vertices[i + 1], transformMatrix);
    &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.drawLine(point0, point1);
}&lt;/span&gt;&lt;/pre&gt;
    &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/div&gt;

  &lt;div id="newforjs" class="tabpane"&gt;
    &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;for &lt;/span&gt;&lt;span style="color: black"&gt;(&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;i = 0; i &amp;lt; cMesh.Vertices.length -1; i++){
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;point0 = &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.project(cMesh.Vertices[i], transformMatrix);
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;point1 = &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.project(cMesh.Vertices[i + 1], transformMatrix);
    &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.drawLine(point0, point1);
}&lt;/span&gt;&lt;/pre&gt;
    &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;And you should now obtain something like that:&lt;/p&gt;
&lt;iframe style="border-top: rgb(200,200,200) 1px solid; border-right: rgb(200,200,200) 1px solid; border-bottom: rgb(200,200,200) 1px solid; border-left: rgb(200,200,200) 1px solid" height="260" src="http://david.blob.core.windows.net/softengine3d/part2sample1/index.html" width="340" scrolling="no"&gt;&lt;/iframe&gt;

&lt;p&gt;
  &lt;br /&gt;I know this looks weird but this was the expected behavior. It should help you starting to understand what you need to do to display a 3D mesh. But to have a better rendering, we need to discover a new concept. &lt;/p&gt;

&lt;h2&gt;Displaying faces with triangles&lt;/h2&gt;

&lt;p&gt;Now that we know how to draw lines, we need a better way to render the mesh with them. The &lt;strong&gt;simplest geometric 2D shape is a triangle&lt;/strong&gt;. The idea in 3D is then to draw all our meshes by using those triangles. We then need to split each side of our cube into 2 triangles. We’re going to do this “manually” but we’ll see in the next tutorial that 3D modelers are doing this step automatically for us now. &lt;/p&gt;

&lt;p&gt;To draw triangles, you need to have 3 points/vertices. A face is then simply a structure containing 3 values which are indexes pointing to the proper vertices array of the mesh to be rendered. &lt;/p&gt;

&lt;p&gt;To be understand this concept, let’s take our previous figure with a Cube displayed by Blender:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/7532.image_5F00_43428C9F.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/6242.image_5F00_thumb_5F00_275157A7.png" width="321" height="300" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;We have 4 vertices displayed on this figure with the following indices: 0, 1, 2, 3. To draw the upper side of the cube, we need to draw 2 triangles. The first one, Face 0, will be drawn with 3 lines from vertex &lt;strong&gt;0&lt;/strong&gt; (-1, 1, 1) to vertex &lt;strong&gt;1&lt;/strong&gt; (1, 1, 1), from vertex &lt;strong&gt;1&lt;/strong&gt; (1, 1, 1) to vertex &lt;strong&gt;2 &lt;/strong&gt;(-1, –1, 1) and finally from vertex&lt;strong&gt; 2&lt;/strong&gt; (-1, –1, 1) to vertex&lt;strong&gt; 0&lt;/strong&gt; (-1, 1, 1). The second triangle, Face 1, will be drawn with the lines from vertex &lt;strong&gt;1 &lt;/strong&gt;to vertex &lt;strong&gt;2&lt;/strong&gt;, vertex &lt;strong&gt;2&lt;/strong&gt; to vertex &lt;strong&gt;3&lt;/strong&gt; and vertex &lt;strong&gt;3 &lt;/strong&gt;to vertex &lt;strong&gt;1&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;The equivalent code would be something like that:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;mesh = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;SoftEngine.&lt;/span&gt;&lt;span style="color: #2b91af"&gt;Mesh&lt;/span&gt;&lt;span style="color: black"&gt;(&lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;Square&amp;quot;&lt;/span&gt;&lt;span style="color: black"&gt;, 4, 2);
meshes.Add(mesh);
mesh.Vertices[0] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector3&lt;/span&gt;&lt;span style="color: black"&gt;(-1, 1, 1);
mesh.Vertices[1] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector3&lt;/span&gt;&lt;span style="color: black"&gt;(1, 1, 1);
mesh.Vertices[2] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector3&lt;/span&gt;&lt;span style="color: black"&gt;(-1, -1, 1);
mesh.Vertices[3] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector3&lt;/span&gt;&lt;span style="color: black"&gt;(1, -1, 1);

mesh.Faces[0] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Face &lt;/span&gt;&lt;span style="color: black"&gt;{ A = 0, B = 1, C = 2 };
mesh.Faces[1] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Face &lt;/span&gt;&lt;span style="color: black"&gt;{ A = 1, B = 2, C = 3 };&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;If you want to draw to whole cube, you need to find the 10 remaining faces as we’ve got &lt;strong&gt;12 faces&lt;/strong&gt; for the 6 sides of our cube to draw. &lt;/p&gt;

&lt;p&gt;Let’s now define the code for a &lt;strong&gt;Face&lt;/strong&gt; object. It’s a very simple object as this is just &lt;strong&gt;a set of 3 indexes&lt;/strong&gt;. Here’s the code of Face and the new Mesh definition which also now use it:&lt;/p&gt;

&lt;div id="tabset3" class="tabset"&gt;
  &lt;ul class="tabnavs"&gt;
    &lt;li&gt;&lt;a class="activeTab" href="#facecsharp"&gt;C#&lt;/a&gt; &lt;/li&gt;

    &lt;li&gt;&lt;a href="#facets"&gt;TypeScript&lt;/a&gt; &lt;/li&gt;

    &lt;li&gt;&lt;a href="#facejs"&gt;JavaScript&lt;/a&gt; &lt;/li&gt;
  &lt;/ul&gt;

  &lt;div id="facecsharp" class="tabpane activePane"&gt;
    &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;namespace &lt;/span&gt;&lt;span style="color: black"&gt;SoftEngine
{
    &lt;/span&gt;&lt;span style="color: blue"&gt;public struct &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Face
    &lt;/span&gt;&lt;span style="color: black"&gt;{
        &lt;/span&gt;&lt;span style="color: blue"&gt;public int &lt;/span&gt;&lt;span style="color: black"&gt;A;
        &lt;/span&gt;&lt;span style="color: blue"&gt;public int &lt;/span&gt;&lt;span style="color: black"&gt;B;
        &lt;/span&gt;&lt;span style="color: blue"&gt;public int &lt;/span&gt;&lt;span style="color: black"&gt;C;
    }
    &lt;/span&gt;&lt;span style="color: blue"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Mesh
    &lt;/span&gt;&lt;span style="color: black"&gt;{
        &lt;/span&gt;&lt;span style="color: blue"&gt;public string &lt;/span&gt;&lt;span style="color: black"&gt;Name { &lt;/span&gt;&lt;span style="color: blue"&gt;get&lt;/span&gt;&lt;span style="color: black"&gt;; &lt;/span&gt;&lt;span style="color: blue"&gt;set&lt;/span&gt;&lt;span style="color: black"&gt;; }
        &lt;/span&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector3&lt;/span&gt;&lt;span style="color: black"&gt;[] Vertices { &lt;/span&gt;&lt;span style="color: blue"&gt;get&lt;/span&gt;&lt;span style="color: black"&gt;; &lt;/span&gt;&lt;span style="color: blue"&gt;private set&lt;/span&gt;&lt;span style="color: black"&gt;; }
        &lt;/span&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Face&lt;/span&gt;&lt;span style="color: black"&gt;[] Faces { &lt;/span&gt;&lt;span style="color: blue"&gt;get&lt;/span&gt;&lt;span style="color: black"&gt;; &lt;/span&gt;&lt;span style="color: blue"&gt;set&lt;/span&gt;&lt;span style="color: black"&gt;; }
        &lt;/span&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector3 &lt;/span&gt;&lt;span style="color: black"&gt;Position { &lt;/span&gt;&lt;span style="color: blue"&gt;get&lt;/span&gt;&lt;span style="color: black"&gt;; &lt;/span&gt;&lt;span style="color: blue"&gt;set&lt;/span&gt;&lt;span style="color: black"&gt;; }
        &lt;/span&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector3 &lt;/span&gt;&lt;span style="color: black"&gt;Rotation { &lt;/span&gt;&lt;span style="color: blue"&gt;get&lt;/span&gt;&lt;span style="color: black"&gt;; &lt;/span&gt;&lt;span style="color: blue"&gt;set&lt;/span&gt;&lt;span style="color: black"&gt;; }

        &lt;/span&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: black"&gt;Mesh(&lt;/span&gt;&lt;span style="color: blue"&gt;string &lt;/span&gt;&lt;span style="color: black"&gt;name, &lt;/span&gt;&lt;span style="color: blue"&gt;int &lt;/span&gt;&lt;span style="color: black"&gt;verticesCount, &lt;/span&gt;&lt;span style="color: blue"&gt;int &lt;/span&gt;&lt;span style="color: black"&gt;facesCount)
        {
            Vertices = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector3&lt;/span&gt;&lt;span style="color: black"&gt;[verticesCount];
            Faces = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Face&lt;/span&gt;&lt;span style="color: black"&gt;[facesCount];
            Name = name;
        }
    }
}
&lt;/span&gt;&lt;/pre&gt;
    &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/div&gt;

  &lt;div id="facets" class="tabpane"&gt;
    &lt;pre class="code"&gt;&lt;span style="color: green"&gt;///&amp;lt;reference path=&amp;quot;babylon.math.ts&amp;quot;/&amp;gt;

&lt;/span&gt;&lt;span style="color: blue"&gt;module &lt;/span&gt;&lt;span style="color: black"&gt;SoftEngine {
    &lt;/span&gt;&lt;span style="color: blue"&gt;export interface &lt;/span&gt;&lt;span style="color: black"&gt;Face {
        A: &lt;/span&gt;&lt;span style="color: blue"&gt;number&lt;/span&gt;&lt;span style="color: black"&gt;;
        B: &lt;/span&gt;&lt;span style="color: blue"&gt;number&lt;/span&gt;&lt;span style="color: black"&gt;;
        C: &lt;/span&gt;&lt;span style="color: blue"&gt;number&lt;/span&gt;&lt;span style="color: black"&gt;;
    }

    &lt;/span&gt;&lt;span style="color: blue"&gt;export class &lt;/span&gt;&lt;span style="color: black"&gt;Mesh {
        Position: BABYLON.Vector3;
        Rotation: BABYLON.Vector3;
        Vertices: BABYLON.Vector3[];
        Faces: Face[];

        &lt;/span&gt;&lt;span style="color: blue"&gt;constructor&lt;/span&gt;&lt;span style="color: black"&gt;(&lt;/span&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: black"&gt;name: &lt;/span&gt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&lt;span style="color: black"&gt;, verticesCount: &lt;/span&gt;&lt;span style="color: blue"&gt;number&lt;/span&gt;&lt;span style="color: black"&gt;, facesCount: &lt;/span&gt;&lt;span style="color: blue"&gt;number&lt;/span&gt;&lt;span style="color: black"&gt;) {
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.Vertices = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;Array(verticesCount);
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.Faces = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;Array(facesCount);
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.Rotation = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Vector3(0, 0, 0);
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.Position = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Vector3(0, 0, 0);
        }
    }
}&lt;/span&gt;&lt;/pre&gt;
    &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/div&gt;

  &lt;div id="facejs" class="tabpane"&gt;
    &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;SoftEngine;
(&lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;&lt;span style="color: black"&gt;(SoftEngine) {
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;Mesh = (&lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;&lt;span style="color: black"&gt;() {
        &lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;&lt;span style="color: black"&gt;Mesh(name, verticesCount, facesCount) {
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.name = name;
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.Vertices = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;Array(verticesCount);
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.Faces = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;Array(facesCount);
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.Rotation = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLONTS.Vector3(0, 0, 0);
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.Position = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLONTS.Vector3(0, 0, 0);
        }
        &lt;/span&gt;&lt;span style="color: blue"&gt;return &lt;/span&gt;&lt;span style="color: black"&gt;Mesh;
    })();
    SoftEngine.Mesh = Mesh;    
})(SoftEngine || (SoftEngine = {}));&lt;/span&gt;&lt;/pre&gt;
    &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;We now need to update our &lt;strong&gt;Render()&lt;/strong&gt; function/method of our &lt;strong&gt;Device &lt;/strong&gt;object to iterate through all the faces defined and to draw the triangles associated. &lt;/p&gt;

&lt;div id="tabset4" class="tabset"&gt;
  &lt;ul class="tabnavs"&gt;
    &lt;li&gt;&lt;a class="activeTab" href="#newrendercsharp"&gt;C#&lt;/a&gt; &lt;/li&gt;

    &lt;li&gt;&lt;a href="#newrenderts"&gt;TypeScript&lt;/a&gt; &lt;/li&gt;

    &lt;li&gt;&lt;a href="#newrenderjs"&gt;JavaScript&lt;/a&gt; &lt;/li&gt;
  &lt;/ul&gt;

  &lt;div id="newrendercsharp" class="tabpane activePane"&gt;
    &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;foreach &lt;/span&gt;&lt;span style="color: black"&gt;(&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;face &lt;/span&gt;&lt;span style="color: blue"&gt;in &lt;/span&gt;&lt;span style="color: black"&gt;mesh.Faces)
{
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;vertexA = mesh.Vertices[face.A];
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;vertexB = mesh.Vertices[face.B];
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;vertexC = mesh.Vertices[face.C];

    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;pixelA = Project(vertexA, transformMatrix);
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;pixelB = Project(vertexB, transformMatrix);
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;pixelC = Project(vertexC, transformMatrix);

    DrawLine(pixelA, pixelB);
    DrawLine(pixelB, pixelC);
    DrawLine(pixelC, pixelA);
}&lt;/span&gt;&lt;/pre&gt;
    &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/div&gt;

  &lt;div id="newrenderts" class="tabpane"&gt;
    &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;for &lt;/span&gt;&lt;span style="color: black"&gt;(&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;indexFaces = 0; indexFaces &amp;lt; cMesh.Faces.length; indexFaces++)
{
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;currentFace = cMesh.Faces[indexFaces];
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;vertexA = cMesh.Vertices[currentFace.A];
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;vertexB = cMesh.Vertices[currentFace.B];
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;vertexC = cMesh.Vertices[currentFace.C];

    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;pixelA = &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.project(vertexA, transformMatrix);
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;pixelB = &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.project(vertexB, transformMatrix);
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;pixelC = &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.project(vertexC, transformMatrix);

    &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.drawLine(pixelA, pixelB);
    &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.drawLine(pixelB, pixelC);
    &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.drawLine(pixelC, pixelA);
}&lt;/span&gt;&lt;/pre&gt;
    &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/div&gt;

  &lt;div id="newrenderjs" class="tabpane"&gt;
    &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;for &lt;/span&gt;&lt;span style="color: black"&gt;(&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;indexFaces = 0; indexFaces &amp;lt; cMesh.Faces.length; indexFaces++)
{
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;currentFace = cMesh.Faces[indexFaces];
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;vertexA = cMesh.Vertices[currentFace.A];
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;vertexB = cMesh.Vertices[currentFace.B];
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;vertexC = cMesh.Vertices[currentFace.C];

    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;pixelA = &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.project(vertexA, transformMatrix);
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;pixelB = &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.project(vertexB, transformMatrix);
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;pixelC = &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.project(vertexC, transformMatrix);

    &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.drawLine(pixelA, pixelB);
    &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.drawLine(pixelB, pixelC);
    &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.drawLine(pixelC, pixelA);
}&lt;/span&gt;&lt;/pre&gt;
    &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;We finally need to declare the mesh associated with our &lt;strong&gt;Cube&lt;/strong&gt; properly with its &lt;strong&gt;12 faces&lt;/strong&gt; to make this new code working as expected. &lt;/p&gt;

&lt;p&gt;Here is the new declaration:&lt;/p&gt;

&lt;div id="tabset5" class="tabset"&gt;
  &lt;ul class="tabnavs"&gt;
    &lt;li&gt;&lt;a class="activeTab" href="#newcubecsharp"&gt;C#&lt;/a&gt; &lt;/li&gt;

    &lt;li&gt;&lt;a href="#newcubets"&gt;TypeScript&lt;/a&gt; &lt;/li&gt;

    &lt;li&gt;&lt;a href="#newcubejs"&gt;JavaScript&lt;/a&gt; &lt;/li&gt;
  &lt;/ul&gt;

  &lt;div id="newcubecsharp" class="tabpane activePane"&gt;
    &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;mesh = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;SoftEngine.&lt;/span&gt;&lt;span style="color: #2b91af"&gt;Mesh&lt;/span&gt;&lt;span style="color: black"&gt;(&lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;Cube&amp;quot;&lt;/span&gt;&lt;span style="color: black"&gt;, 8, 12);
meshes.Add(mesh);
mesh.Vertices[0] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector3&lt;/span&gt;&lt;span style="color: black"&gt;(-1, 1, 1);
mesh.Vertices[1] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector3&lt;/span&gt;&lt;span style="color: black"&gt;(1, 1, 1);
mesh.Vertices[2] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector3&lt;/span&gt;&lt;span style="color: black"&gt;(-1, -1, 1);
mesh.Vertices[3] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector3&lt;/span&gt;&lt;span style="color: black"&gt;(1, -1, 1);
mesh.Vertices[4] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector3&lt;/span&gt;&lt;span style="color: black"&gt;(-1, 1, -1);
mesh.Vertices[5] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector3&lt;/span&gt;&lt;span style="color: black"&gt;(1, 1, -1);
mesh.Vertices[6] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector3&lt;/span&gt;&lt;span style="color: black"&gt;(1, -1, -1);
mesh.Vertices[7] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector3&lt;/span&gt;&lt;span style="color: black"&gt;(-1, -1, -1);

mesh.Faces[0] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Face &lt;/span&gt;&lt;span style="color: black"&gt;{ A = 0, B = 1, C = 2 };
mesh.Faces[1] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Face &lt;/span&gt;&lt;span style="color: black"&gt;{ A = 1, B = 2, C = 3 };
mesh.Faces[2] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Face &lt;/span&gt;&lt;span style="color: black"&gt;{ A = 1, B = 3, C = 6 };
mesh.Faces[3] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Face &lt;/span&gt;&lt;span style="color: black"&gt;{ A = 1, B = 5, C = 6 };
mesh.Faces[4] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Face &lt;/span&gt;&lt;span style="color: black"&gt;{ A = 0, B = 1, C = 4 };
mesh.Faces[5] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Face &lt;/span&gt;&lt;span style="color: black"&gt;{ A = 1, B = 4, C = 5 };

mesh.Faces[6] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Face &lt;/span&gt;&lt;span style="color: black"&gt;{ A = 2, B = 3, C = 7 };
mesh.Faces[7] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Face &lt;/span&gt;&lt;span style="color: black"&gt;{ A = 3, B = 6, C = 7 };
mesh.Faces[8] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Face &lt;/span&gt;&lt;span style="color: black"&gt;{ A = 0, B = 2, C = 7 };
mesh.Faces[9] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Face &lt;/span&gt;&lt;span style="color: black"&gt;{ A = 0, B = 4, C = 7 };
mesh.Faces[10] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Face &lt;/span&gt;&lt;span style="color: black"&gt;{ A = 4, B = 5, C = 6 };
mesh.Faces[11] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Face &lt;/span&gt;&lt;span style="color: black"&gt;{ A = 4, B = 6, C = 7 };&lt;/span&gt;&lt;/pre&gt;
    &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/div&gt;

  &lt;div id="newcubets" class="tabpane"&gt;
    &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;mesh = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;SoftEngine.Mesh(&lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;Cube&amp;quot;&lt;/span&gt;&lt;span style="color: black"&gt;, 8, 12);
meshes.push(mesh);
mesh.Vertices[0] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Vector3(-1, 1, 1);
mesh.Vertices[1] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Vector3(1, 1, 1);
mesh.Vertices[2] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Vector3(-1, -1, 1);
mesh.Vertices[3] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Vector3(1, -1, 1);
mesh.Vertices[4] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Vector3(-1, 1, -1);
mesh.Vertices[5] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Vector3(1, 1, -1);
mesh.Vertices[6] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Vector3(1, -1, -1);
mesh.Vertices[7] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Vector3(-1, -1, -1);

mesh.Faces[0] = { A:0, B:1, C:2 };
mesh.Faces[1] = { A:1, B:2, C:3 };
mesh.Faces[2] = { A:1, B:3, C:6 };
mesh.Faces[3] = { A:1, B:5, C:6 };
mesh.Faces[4] = { A:0, B:1, C:4 };
mesh.Faces[5] = { A:1, B:4, C:5 };

mesh.Faces[6] = { A:2, B:3, C:7 };
mesh.Faces[7] = { A:3, B:6, C:7 };
mesh.Faces[8] = { A:0, B:2, C:7 };
mesh.Faces[9] = { A:0, B:4, C:7 };
mesh.Faces[10] = { A:4, B:5, C:6 };
mesh.Faces[11] = { A:4, B:6, C:7 };&lt;/span&gt;&lt;/pre&gt;
    &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/div&gt;

  &lt;div id="newcubejs" class="tabpane"&gt;
    &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;mesh = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;SoftEngine.Mesh(&lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;Cube&amp;quot;&lt;/span&gt;&lt;span style="color: black"&gt;, 8, 12);
meshes.push(mesh);
mesh.Vertices[0] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Vector3(-1, 1, 1);
mesh.Vertices[1] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Vector3(1, 1, 1);
mesh.Vertices[2] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Vector3(-1, -1, 1);
mesh.Vertices[3] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Vector3(1, -1, 1);
mesh.Vertices[4] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Vector3(-1, 1, -1);
mesh.Vertices[5] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Vector3(1, 1, -1);
mesh.Vertices[6] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Vector3(1, -1, -1);
mesh.Vertices[7] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Vector3(-1, -1, -1);

mesh.Faces[0] = { A:0, B:1, C:2 };
mesh.Faces[1] = { A:1, B:2, C:3 };
mesh.Faces[2] = { A:1, B:3, C:6 };
mesh.Faces[3] = { A:1, B:5, C:6 };
mesh.Faces[4] = { A:0, B:1, C:4 };
mesh.Faces[5] = { A:1, B:4, C:5 };

mesh.Faces[6] = { A:2, B:3, C:7 };
mesh.Faces[7] = { A:3, B:6, C:7 };
mesh.Faces[8] = { A:0, B:2, C:7 };
mesh.Faces[9] = { A:0, B:4, C:7 };
mesh.Faces[10] = { A:4, B:5, C:6 };
mesh.Faces[11] = { A:4, B:6, C:7 };&lt;/span&gt;&lt;/pre&gt;
    &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;You should now have this beautiful rotating cube:&lt;/p&gt;
&lt;iframe style="border-top: rgb(200,200,200) 1px solid; border-right: rgb(200,200,200) 1px solid; border-bottom: rgb(200,200,200) 1px solid; border-left: rgb(200,200,200) 1px solid" height="260" src="http://david.blob.core.windows.net/softengine3d/part2sample2/index.html" width="340" scrolling="no"&gt;&lt;/iframe&gt;

&lt;p&gt;
  &lt;br /&gt;Congrats! :) &lt;/p&gt;

&lt;h2&gt;Enhancing the line drawing algorithm with Bresenham&lt;/h2&gt;

&lt;p&gt;There is an optimized way to draw our lines using the &lt;a title="http://en.wikipedia.org/wiki/Bresenham&amp;#39;s_line_algorithm" href="http://en.wikipedia.org/wiki/Bresenham's_line_algorithm"&gt;Bresenham's line algorithm&lt;/a&gt;. It’s faster &amp;amp; sharper than our current simple recursive version. The story of this algorithm is fascinating. Please read the Wikipedia definition of this algorithm to discover how Bresenham build it and for which reasons. &lt;/p&gt;

&lt;p&gt;Here are the versions of this algorithm in C#, TypeScript and JavaScript:&lt;/p&gt;

&lt;div id="tabset6" class="tabset"&gt;
  &lt;ul class="tabnavs"&gt;
    &lt;li&gt;&lt;a class="activeTab" href="#bresenhamcsharp"&gt;C#&lt;/a&gt; &lt;/li&gt;

    &lt;li&gt;&lt;a href="#bresenhamts"&gt;TypeScript&lt;/a&gt; &lt;/li&gt;

    &lt;li&gt;&lt;a href="#bresenhamjs"&gt;JavaScript&lt;/a&gt; &lt;/li&gt;
  &lt;/ul&gt;

  &lt;div id="bresenhamcsharp" class="tabpane activePane"&gt;
    &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public void &lt;/span&gt;&lt;span style="color: black"&gt;DrawBline(&lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector2 &lt;/span&gt;&lt;span style="color: black"&gt;point0, &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector2 &lt;/span&gt;&lt;span style="color: black"&gt;point1)
{
    &lt;/span&gt;&lt;span style="color: blue"&gt;int &lt;/span&gt;&lt;span style="color: black"&gt;x0 = (&lt;/span&gt;&lt;span style="color: blue"&gt;int&lt;/span&gt;&lt;span style="color: black"&gt;)point0.X;
    &lt;/span&gt;&lt;span style="color: blue"&gt;int &lt;/span&gt;&lt;span style="color: black"&gt;y0 = (&lt;/span&gt;&lt;span style="color: blue"&gt;int&lt;/span&gt;&lt;span style="color: black"&gt;)point0.Y;
    &lt;/span&gt;&lt;span style="color: blue"&gt;int &lt;/span&gt;&lt;span style="color: black"&gt;x1 = (&lt;/span&gt;&lt;span style="color: blue"&gt;int&lt;/span&gt;&lt;span style="color: black"&gt;)point1.X;
    &lt;/span&gt;&lt;span style="color: blue"&gt;int &lt;/span&gt;&lt;span style="color: black"&gt;y1 = (&lt;/span&gt;&lt;span style="color: blue"&gt;int&lt;/span&gt;&lt;span style="color: black"&gt;)point1.Y;
            
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;dx = &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Math&lt;/span&gt;&lt;span style="color: black"&gt;.Abs(x1 - x0);
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;dy = &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Math&lt;/span&gt;&lt;span style="color: black"&gt;.Abs(y1 - y0);
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;sx = (x0 &amp;lt; x1) ? 1 : -1;
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;sy = (y0 &amp;lt; y1) ? 1 : -1;
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;err = dx - dy;

    &lt;/span&gt;&lt;span style="color: blue"&gt;while &lt;/span&gt;&lt;span style="color: black"&gt;(&lt;/span&gt;&lt;span style="color: blue"&gt;true&lt;/span&gt;&lt;span style="color: black"&gt;) {
        DrawPoint(&lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector2&lt;/span&gt;&lt;span style="color: black"&gt;(x0, y0));

        &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;&lt;span style="color: black"&gt;((x0 == x1) &amp;amp;&amp;amp; (y0 == y1)) &lt;/span&gt;&lt;span style="color: blue"&gt;break&lt;/span&gt;&lt;span style="color: black"&gt;;
        &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;e2 = 2 * err;
        &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;&lt;span style="color: black"&gt;(e2 &amp;gt; -dy) { err -= dy; x0 += sx; }
        &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;&lt;span style="color: black"&gt;(e2 &amp;lt; dx) { err += dx; y0 += sy; }
    }
}&lt;/span&gt;&lt;/pre&gt;
    &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/div&gt;

  &lt;div id="bresenhamts" class="tabpane"&gt;
    &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: black"&gt;drawBline(point0: BABYLON.Vector2, point1: BABYLON.Vector2): &lt;/span&gt;&lt;span style="color: blue"&gt;void &lt;/span&gt;&lt;span style="color: black"&gt;{
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;x0 = point0.x &amp;gt;&amp;gt; 0;
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;y0 = point0.y &amp;gt;&amp;gt; 0;
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;x1 = point1.x &amp;gt;&amp;gt; 0;
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;y1 = point1.y &amp;gt;&amp;gt; 0;
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;dx = Math.abs(x1 - x0);
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;dy = Math.abs(y1 - y0);
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;sx = (x0 &amp;lt; x1) ? 1 : -1;
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;sy = (y0 &amp;lt; y1) ? 1 : -1;
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;err = dx - dy;

    &lt;/span&gt;&lt;span style="color: blue"&gt;while &lt;/span&gt;&lt;span style="color: black"&gt;(&lt;/span&gt;&lt;span style="color: blue"&gt;true&lt;/span&gt;&lt;span style="color: black"&gt;) {
        &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.drawPoint(&lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Vector2(x0, y0));

        &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;&lt;span style="color: black"&gt;((x0 == x1) &amp;amp;&amp;amp; (y0 == y1)) &lt;/span&gt;&lt;span style="color: blue"&gt;break&lt;/span&gt;&lt;span style="color: black"&gt;;
        &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;e2 = 2 * err;
        &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;&lt;span style="color: black"&gt;(e2 &amp;gt; -dy) { err -= dy; x0 += sx; }
        &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;&lt;span style="color: black"&gt;(e2 &amp;lt; dx) { err += dx; y0 += sy; }
    }
};&lt;/span&gt;&lt;/pre&gt;
    &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/div&gt;

  &lt;div id="bresenhamjs" class="tabpane"&gt;
    &lt;pre class="code"&gt;&lt;span style="color: black"&gt;Device.prototype.drawBline = &lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;&lt;span style="color: black"&gt;(point0, point1) {
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;x0 = point0.x &amp;gt;&amp;gt; 0;
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;y0 = point0.y &amp;gt;&amp;gt; 0;
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;x1 = point1.x &amp;gt;&amp;gt; 0;
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;y1 = point1.y &amp;gt;&amp;gt; 0;
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;dx = Math.abs(x1 - x0);
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;dy = Math.abs(y1 - y0);
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;sx = (x0 &amp;lt; x1) ? 1 : -1;
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;sy = (y0 &amp;lt; y1) ? 1 : -1;
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;err = dx - dy;
    &lt;/span&gt;&lt;span style="color: blue"&gt;while&lt;/span&gt;&lt;span style="color: black"&gt;(&lt;/span&gt;&lt;span style="color: blue"&gt;true&lt;/span&gt;&lt;span style="color: black"&gt;) {
        &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.drawPoint(&lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Vector2(x0, y0));
        &lt;/span&gt;&lt;span style="color: blue"&gt;if&lt;/span&gt;&lt;span style="color: black"&gt;((x0 == x1) &amp;amp;&amp;amp; (y0 == y1)) &lt;/span&gt;&lt;span style="color: blue"&gt;break&lt;/span&gt;&lt;span style="color: black"&gt;;
        &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;e2 = 2 * err;
        &lt;/span&gt;&lt;span style="color: blue"&gt;if&lt;/span&gt;&lt;span style="color: black"&gt;(e2 &amp;gt; -dy) { err -= dy; x0 += sx; }
        &lt;/span&gt;&lt;span style="color: blue"&gt;if&lt;/span&gt;&lt;span style="color: black"&gt;(e2 &amp;lt; dx) { err += dx; y0 += sy; }
    }
};&lt;/span&gt;&lt;/pre&gt;
    &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;In the render function, replace the call do DrawLine by DrawBline and you should notice that this is a bit more fluid &amp;amp; a bit more sharp:&lt;/p&gt;
&lt;iframe style="border-top: rgb(200,200,200) 1px solid; border-right: rgb(200,200,200) 1px solid; border-bottom: rgb(200,200,200) 1px solid; border-left: rgb(200,200,200) 1px solid" height="260" src="http://david.blob.core.windows.net/softengine3d/part2sample3/index.html" width="340" scrolling="no"&gt;&lt;/iframe&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;If you’re observing it with attention, you should see that this version using Bresenham is less choppy than our first algorithm.&lt;/p&gt;

&lt;p&gt;Again, you can &lt;strong&gt;download the solutions&lt;/strong&gt; containing the source code:&lt;/p&gt;

&lt;p&gt;- &lt;strong&gt;C#&lt;/strong&gt; : &lt;a href="http://david.blob.core.windows.net/softengine3d/SoftEngineCSharpPart2.zip"&gt;SoftEngineCSharpPart2.zip&lt;/a&gt; 

  &lt;br /&gt;- &lt;strong&gt;TypeScript &lt;/strong&gt;: &lt;a href="http://david.blob.core.windows.net/softengine3d/SoftEngineTSPart2.zip"&gt;SoftEngineTSPart2.zip&lt;/a&gt; 

  &lt;br /&gt;- &lt;strong&gt;JavaScript&lt;/strong&gt; : &lt;a href="http://david.blob.core.windows.net/softengine3d/SoftEngineJSPart2.zip"&gt;SoftEngineJSPart2.zip&lt;/a&gt; or simply right-click –&amp;gt; view source on the embedded iframe&lt;/p&gt;

&lt;p&gt;In next tutorial, you will learn how to &lt;strong&gt;export some Meshes from Blender&lt;/strong&gt;, a free 3D modeler tool, into a JSON format. We will then &lt;strong&gt;load this JSON file to display it with our wireframe engine&lt;/strong&gt;. Indeed, we already have everything setup to display much more complex meshes like these one:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/3323.image_5F00_08997040.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/3755.image_5F00_thumb_5F00_31C1087E.png" width="240" height="197" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;See you in the third part: &lt;a title="Tutorial part 3- learning how to write a 3D soft engine in C#, TS or JS – loading meshes exporte" href="http://blogs.msdn.com/b/davrous/archive/2013/06/17/tutorial-part-3-learning-how-to-write-a-3d-soft-engine-in-c-ts-or-js-loading-meshes-exported-from-blender.aspx"&gt;learning how to write a 3D soft engine in C#, TS or JS – loading meshes exported from Blender&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;David&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10425982" width="1" height="1"&gt;</content><author><name>David Rousset</name><uri>http://blogs.msdn.com/davrous/ProfileUrlRedirect.ashx</uri></author><category term="Tutorial" scheme="http://blogs.msdn.com/b/davrous/archive/tags/Tutorial/" /><category term="HTML5" scheme="http://blogs.msdn.com/b/davrous/archive/tags/HTML5/" /><category term="Canvas" scheme="http://blogs.msdn.com/b/davrous/archive/tags/Canvas/" /><category term="JavaScript" scheme="http://blogs.msdn.com/b/davrous/archive/tags/JavaScript/" /><category term="Windows 8" scheme="http://blogs.msdn.com/b/davrous/archive/tags/Windows+8/" /><category term="3DEngine" scheme="http://blogs.msdn.com/b/davrous/archive/tags/3DEngine/" /><category term="C#" scheme="http://blogs.msdn.com/b/davrous/archive/tags/C_2300_/" /><category term="TypeScript" scheme="http://blogs.msdn.com/b/davrous/archive/tags/TypeScript/" /></entry><entry><title>Tutorial series: learning how to write a 3D soft engine from scratch in C#, TypeScript or JavaScript</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/davrous/archive/2013/06/13/tutorial-series-learning-how-to-write-a-3d-soft-engine-from-scratch-in-c-typescript-or-javascript.aspx" /><id>http://blogs.msdn.com/b/davrous/archive/2013/06/13/tutorial-series-learning-how-to-write-a-3d-soft-engine-from-scratch-in-c-typescript-or-javascript.aspx</id><published>2013-06-13T19:31:35Z</published><updated>2013-06-13T19:31:35Z</updated><content type="html">&lt;link rel="stylesheet" href="http://david.blob.core.windows.net/softengine3d/tabs.css" /&gt;&lt;script src="http://david.blob.core.windows.net/softengine3d/dw_tabs.js"&gt;&lt;/script&gt;&lt;script type="text/javascript"&gt;

DYN_WEB.Tabs.setup({
    id: 'tabset1', // if of tabset
    css: 'css/tabs.css', // optional if you don't care about accessibility 
    useCookies: true // optional
}, {id: 'tabset2', useCookies: true}, {id: 'tabset3', useCookies: true});

&lt;/script&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/7558.image_5F00_20459D10.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; margin: 0px 5px; display: inline; border-top-width: 0px" border="0" alt="image" align="right" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/2703.image_5F00_thumb_5F00_37FCD476.png" width="240" height="206" /&gt;&lt;/a&gt; I’d to like to share with you how I’ve learned to build what’s known as a “&lt;strong&gt;3D soft engine&lt;/strong&gt;” through a series of tutorials. “Software engine” means that we &lt;strong&gt;will use only the CPU&lt;/strong&gt; to build a 3D engine in an old school way (remember Doom on your 80386 ?). I’ll share with you the &lt;strong&gt;C#, TypeScript and JavaScript&lt;/strong&gt; versions of the code. In this list, you should then find your favorite language or at least something near your favorite one. The idea is to help you transposing the following samples &amp;amp; concepts on your favorite platform. You’ll find the Visual Studio 2012 C#/TS/JS solutions to download at the end also. &lt;/p&gt;  &lt;p&gt;So why building a 3D soft engine? Well, it’s simply because it really helps understanding how modern 3D works with our GPUs. Indeed, I’m currently learning the basics of 3D thanks to internal workshops delivered within Microsoft by the awesome &lt;a href="http://blogs.msdn.com/eternalcoding"&gt;David Catuhe&lt;/a&gt;. He’s been mastering 3D for many years now and matrices operations is hard-coded in his brain. When I was young, I was dreaming to be able to write such engines but I had the feeling it was too complex for me. Finally, you’ll see that this is not – that - complex. You simply need someone that will help you understanding the underlying principles in a simple way. &lt;/p&gt;  &lt;p&gt;Through this series, you will learn how to project some 3D coordinates (X, Y, Z) associated to a point (a vertex) on a 2D screen, how to draw lines between each point, how to fill some triangles, to handle lights, materials and so on. This first tutorial will simply show you how to display 8 points associated to a cube and how to move them in a virtual 3D world. &lt;/p&gt;  &lt;p&gt;This tutorial is part of the following series:&lt;/p&gt;  &lt;p&gt;1 – Writing the core logic for camera, mesh &amp;amp; device object (this article)   &lt;br /&gt;2 – &lt;a href="http://blogs.msdn.com/b/davrous/archive/2013/06/14/tutorial-part-2-learning-how-to-write-a-3d-soft-engine-from-scratch-in-c-ts-or-js-drawing-lines-amp-triangles.aspx"&gt;Drawing lines and triangles to obtain a wireframe rendering&lt;/a&gt;    &lt;br /&gt;3 – &lt;a href="http://blogs.msdn.com/b/davrous/archive/2013/06/17/tutorial-part-3-learning-how-to-write-a-3d-soft-engine-in-c-ts-or-js-loading-meshes-exported-from-blender.aspx"&gt;Loading meshes exported from Blender in a JSON format&lt;/a&gt;    &lt;br /&gt;4 – Filling the triangle with rasterization and using a Z-Buffer (to be published)&lt;/p&gt;  &lt;p&gt;By properly following this tutorial, you will have the following result at the end:&lt;/p&gt; &lt;iframe style="border-top: rgb(200,200,200) 1px solid; border-right: rgb(200,200,200) 1px solid; border-bottom: rgb(200,200,200) 1px solid; border-left: rgb(200,200,200) 1px solid" height="220" src="http://david.blob.core.windows.net/softengine3d/part1/index.html" width="340" scrolling="no"&gt;&lt;/iframe&gt;  &lt;p&gt;&lt;/p&gt;  &lt;h2&gt;Reading prerequisites&lt;/h2&gt;  &lt;p&gt;I’ve been thinking on how to write these tutorials for a long time now. And I’ve finally decided not to explain each required principle myself. There is a lot of good resources on the web that will explain those important principles better than I. But I’ve then spent quite some time browsing the web for you to choose, according to myself, the best one to read:&lt;/p&gt;  &lt;p&gt;- &lt;a title="http://robertokoci.com/world-view-projection-matrix-unveiled/" href="http://robertokoci.com/world-view-projection-matrix-unveiled/"&gt;World, View and Projection Matrix Unveiled&lt;/a&gt;     &lt;br /&gt;- &lt;a title="http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/" href="http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/"&gt;Tutorial 3 : Matrices&lt;/a&gt; that will provide you an introduction to matrices, the model, view &amp;amp; projection matrices.     &lt;br /&gt;- &lt;a title="http://db-in.com/blog/2011/04/cameras-on-opengl-es-2-x/" href="http://db-in.com/blog/2011/04/cameras-on-opengl-es-2-x/"&gt;Cameras on OpenGL ES 2.x – The ModelViewProjection Matrix&lt;/a&gt; : this one is really interesting also as it explains the story starting by how cameras and lenses work.     &lt;br /&gt;- &lt;a title="http://msdn.microsoft.com/en-us/library/windows/desktop/bb206269(v=vs.85).aspx" href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb206269(v=vs.85).aspx"&gt;Transforms (Direct3D 9)&lt;/a&gt;     &lt;br /&gt;- &lt;a href="http://inear.se/talk/a_brief_introduction_to_3d.pptx"&gt;A brief introduction to 3D&lt;/a&gt;: an excellent PowerPoint slides deck ! Read at least up to slide 27. After that, it’s too linked to a technology talking to GPU (OpenGL or DirectX).     &lt;br /&gt;- &lt;a title="http://www.songho.ca/opengl/gl_transform.html" href="http://www.songho.ca/opengl/gl_transform.html"&gt;OpenGL Transformation&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;img alt="OpenGL vertex transformation" src="http://www.songho.ca/opengl/files/gl_transform02.png" width="706" height="88" /&gt;&lt;/p&gt;  &lt;p&gt;Read those articles by not focusing on the technology associated (like OpenGL or DirectX) or on the concept of triangles you may have seen in the figures. We will see that later on. &lt;/p&gt;  &lt;p&gt;By reading those articles, you really need to understand that there is a series of transformations done that way:&amp;#160;&amp;#160; &lt;br /&gt;    &lt;br /&gt;- we start by a &lt;strong&gt;3D object centered on itself&lt;/strong&gt;     &lt;br /&gt;- the same object is then &lt;strong&gt;moved into the virtual 3D world&lt;/strong&gt; by translation, scaling or rotation operations via matrices     &lt;br /&gt;- a &lt;strong&gt;camera will look at this 3D object&lt;/strong&gt; positioned in the 3D world     &lt;br /&gt;- the final &lt;strong&gt;projection&lt;/strong&gt; of all that will be done into a &lt;strong&gt;2D space&lt;/strong&gt; which is your screen&lt;/p&gt;  &lt;p&gt;&lt;img title="Diagram of how world coordinates and local coordinates are related" alt="Diagram of how world coordinates and local coordinates are related" src="http://i.msdn.microsoft.com/dynimg/IC412718.png" /&gt;&amp;#160;&lt;img alt="OpenGL Perspective Frustum and NDC" src="http://www.songho.ca/opengl/files/gl_projectionmatrix01.png" width="470" height="230" /&gt;&lt;/p&gt;  &lt;p&gt;All this magic is done by cumulating transformations through matrices operations. &lt;strong&gt;You should really be at least a bit familiar with those concepts before running through these tutorials&lt;/strong&gt;. Even if you don’t understand everything by reading them the first time. You should read them first. You will probably go back to those articles later on while writing your own version of this 3D soft engine. This is completely normal, don’t worry! ;) The best way to learn 3D if by experimenting and doing mistakes. &lt;/p&gt;  &lt;p&gt;We won’t neither spend some times on how matrix operations works. The good news is that you don’t really need to understand matrices. Simply view it as a black box doing the right operations for you. I’m not a master of matrices but I’ve managed to write a 3D soft engine by myself. So you should also succeed in doing so. &lt;/p&gt;  &lt;p&gt;We will then use libraries that will do the job for us: &lt;strong&gt;SharpDX&lt;/strong&gt;, a managed wrapper on top of DirectX, for C# developers and &lt;strong&gt;babylon.math.js&lt;/strong&gt; written by David Catuhe for JavaScript developers. I’ve rewritten it in TypeScript also. &lt;/p&gt;  &lt;h2&gt;Software prerequisites&lt;/h2&gt;  &lt;p&gt;We will write a WinRT/&lt;strong&gt;XAML Windows Store Apps&lt;/strong&gt; in C# and/or a &lt;strong&gt;HTML5 application&lt;/strong&gt; with TypeScript/JavaScript. So if you want to use the C# samples as-is, you need to install:&lt;/p&gt;  &lt;p&gt;1 - Windows 8    &lt;br /&gt;2 - Visual Studio 2012 Express for Windows Store Apps. You can download it for free: &lt;a title="http://msdn.microsoft.com/en-US/windows/apps/br211386" href="http://msdn.microsoft.com/en-US/windows/apps/br211386"&gt;http://msdn.microsoft.com/en-US/windows/apps/br211386&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;If you choose to use the &lt;strong&gt;TypeScript&lt;/strong&gt; samples, you need to install it from: &lt;a title="http://www.typescriptlang.org/#Download" href="http://www.typescriptlang.org/#Download"&gt;http://www.typescriptlang.org/#Download&lt;/a&gt; . &lt;/p&gt;  &lt;p&gt;You will find the plug-in for Visual Studio 2012 but there are other options available: &lt;a title="http://msopentech.com/blog/2012/10/01/sublime-text-vi-emacs-typescript-enabled" href="http://msopentech.com/blog/2012/10/01/sublime-text-vi-emacs-typescript-enabled"&gt;Sublime Text, Vi, Emacs: TypeScript enabled!&lt;/a&gt; On my side, I’ve learned TypeScript by porting the C# version of my code to TypeScript. If you’re also interested in learning TypeScript, a first good introduction is this webcast: &lt;a title="http://channel9.msdn.com/posts/Anders-Hejlsberg-Introducing-TypeScript" href="http://channel9.msdn.com/posts/Anders-Hejlsberg-Introducing-TypeScript"&gt;Anders Hejlsberg: Introducing TypeScript&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;If you choose &lt;strong&gt;JavaScript&lt;/strong&gt;, you just need your favorite IDE and a HTML5 compatible browser. :)&lt;/p&gt;  &lt;p&gt;Please create a project named “&lt;strong&gt;&lt;em&gt;SoftEngine&lt;/em&gt;&lt;/strong&gt;” targeting the language you’d like to use. If it’s &lt;strong&gt;C#&lt;/strong&gt;, add the “&lt;strong&gt;SharpDX core assembly&lt;/strong&gt;” by using NuGet on your solution:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/3108.image_5F00_13610CD0.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/1460.image_5F00_thumb_5F00_315F1AC4.png" width="640" height="120" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;If it’s &lt;strong&gt;TypeScript&lt;/strong&gt;, download&lt;strong&gt; &lt;/strong&gt;&lt;a href="http://david.blob.core.windows.net/softengine3d/babylon.math.ts"&gt;&lt;strong&gt;babylon.math.ts&lt;/strong&gt;&lt;/a&gt;. If' it’s &lt;strong&gt;JavaScript&lt;/strong&gt; download &lt;a href="http://david.blob.core.windows.net/softengine3d/babylon.math.js"&gt;&lt;strong&gt;babylon.math.js&lt;/strong&gt;&lt;/a&gt;. Add a reference to those files in both cases. &lt;/p&gt;  &lt;h2&gt;Back buffer &amp;amp; rendering loop&lt;/h2&gt;  &lt;p&gt;In a 3D engine, we’re rendering the complete scene during each frame with the hope of keeping an optimal 60 frames per second (FPS) to keep fluid animations. To do our rendering job, we need what we call a back buffer. This could be seen as 2 dimensional array mapping the screen/window size. Every cell of the array is mapped to a pixel on the screen. &lt;/p&gt;  &lt;p&gt;In our &lt;strong&gt;XAML&lt;/strong&gt; Windows Store Apps, we will use a &lt;font color="#0000ff"&gt;byte&lt;/font&gt;[] array that will act as our dynamic &lt;strong&gt;back buffer&lt;/strong&gt;. For every frame being rendered in the animation loop (tick), this buffer will be affected to a &lt;font color="#2b91af"&gt;WriteableBitmap&lt;/font&gt; acting as the source of a XAML image control that will be called the &lt;strong&gt;front buffer&lt;/strong&gt;. For the rendering loop, we’re going to ask to the XAML rendering engine to call us for every frame it will generate. The registration is done thanks to this line of code:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: #2b91af"&gt;CompositionTarget&lt;/span&gt;&lt;span style="color: black"&gt;.Rendering += CompositionTarget_Rendering;&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;In &lt;strong&gt;HTML5&lt;/strong&gt;, we’re going to use of course the &lt;strong&gt;&amp;lt;canvas /&amp;gt;&lt;/strong&gt; element. The canvas element has already a back buffer data array associated to it. You can access it through the &lt;em&gt;&lt;strong&gt;getImageData()&lt;/strong&gt;&lt;/em&gt; and &lt;em&gt;&lt;strong&gt;setImageData()&lt;/strong&gt;&lt;/em&gt; functions. The animation loop will be handled by the &lt;em&gt;&lt;a href="http://msdn.microsoft.com/library/ie/hh920765(v=vs.85).aspx"&gt;requestAnimationFrame()&lt;/a&gt;&lt;/em&gt; function. This one is much more efficient that an equivalent of a &lt;em&gt;setTimeout(function() {], 1000/60)&lt;/em&gt; as it’s handled natively by the browser that will callback our code only when it will be ready to draw. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Note:&lt;/u&gt;&lt;/strong&gt; in both cases, you can render the frames in a different resolution that the actual width &amp;amp; height of the final window. For instance, you can have a back buffer of 640x480 pixels whereas the final display screen (front buffer) will be in 1920x1080. In XAML and thanks to CSS in HTML5, you will then benefit from “&lt;em&gt;hardware scaling&lt;/em&gt;”. The rendering engines of XAML and of the browser will stretch the back buffer data to the front buffer window by even using an anti-aliasing algorithm. In both cases, this task is done by the GPU. This is why we call it “hardware scaling” (hardware is the GPU). You can read more about this topic addressed in HTML5 here: &lt;a title="http://blogs.msdn.com/b/eternalcoding/archive/2012/03/22/unleash-the-power-of-html-5-canvas-for-gaming-part-1.aspx?Redirected=true" href="http://blogs.msdn.com/b/eternalcoding/archive/2012/03/22/unleash-the-power-of-html-5-canvas-for-gaming-part-1.aspx?Redirected=true"&gt;Unleash the power of HTML 5 Canvas for gaming&lt;/a&gt; . This approach is often used in games for instance to boost the performance as you have less pixels to address. &lt;/p&gt;

&lt;h2&gt;Camera &amp;amp; Mesh objects&lt;/h2&gt;

&lt;p&gt;Let’s start coding. First, we need to define some objects that will embed the details needed for a camera and for a mesh. A mesh is a cool name to describe a 3D object.&lt;/p&gt;

&lt;p&gt;Our &lt;em&gt;Camera&lt;/em&gt; will have 2 properties: its position in the 3D world and where it’s looking at, the target. Both are made of 3D coordinates named a Vector3. C# will use &lt;strong&gt;SharpDX.Vector3&lt;/strong&gt; and TypeScript &amp;amp; JavaScript will use &lt;strong&gt;BABYLON.Vector3&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;Our &lt;em&gt;Mesh&lt;/em&gt; will have a collection of vertices (several vertex or 3D points) that will be used to build our 3D object, its position in the 3D world and its rotation state. To identify it, it will also have a name.&lt;/p&gt;

&lt;p&gt;To resume, we need the following code: 
  &lt;br /&gt;&lt;/p&gt;

&lt;div id="tabset1" class="tabset"&gt;
  &lt;ul class="tabnavs"&gt;
    &lt;li&gt;&lt;a class="activeTab" href="#one"&gt;C#&lt;/a&gt; &lt;/li&gt;

    &lt;li&gt;&lt;a href="#two"&gt;TypeScript&lt;/a&gt; &lt;/li&gt;

    &lt;li&gt;&lt;a href="#three"&gt;JavaScript&lt;/a&gt; &lt;/li&gt;
  &lt;/ul&gt;

  &lt;div id="one" class="tabpane activePane"&gt;
    &lt;pre class="code"&gt;&lt;span style="color: green"&gt;// Camera.cs &amp;amp; Mesh.cs
&lt;/span&gt;&lt;span style="color: blue"&gt;using &lt;/span&gt;&lt;span style="color: black"&gt;SharpDX;

&lt;/span&gt;&lt;span style="color: blue"&gt;namespace &lt;/span&gt;&lt;span style="color: black"&gt;SoftEngine
{
    &lt;/span&gt;&lt;span style="color: blue"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Camera
    &lt;/span&gt;&lt;span style="color: black"&gt;{
        &lt;/span&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector3 &lt;/span&gt;&lt;span style="color: black"&gt;Position { &lt;/span&gt;&lt;span style="color: blue"&gt;get&lt;/span&gt;&lt;span style="color: black"&gt;; &lt;/span&gt;&lt;span style="color: blue"&gt;set&lt;/span&gt;&lt;span style="color: black"&gt;; }
        &lt;/span&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector3 &lt;/span&gt;&lt;span style="color: black"&gt;Target { &lt;/span&gt;&lt;span style="color: blue"&gt;get&lt;/span&gt;&lt;span style="color: black"&gt;; &lt;/span&gt;&lt;span style="color: blue"&gt;set&lt;/span&gt;&lt;span style="color: black"&gt;; }
    }
    &lt;/span&gt;&lt;span style="color: blue"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Mesh
    &lt;/span&gt;&lt;span style="color: black"&gt;{
        &lt;/span&gt;&lt;span style="color: blue"&gt;public string &lt;/span&gt;&lt;span style="color: black"&gt;Name { &lt;/span&gt;&lt;span style="color: blue"&gt;get&lt;/span&gt;&lt;span style="color: black"&gt;; &lt;/span&gt;&lt;span style="color: blue"&gt;set&lt;/span&gt;&lt;span style="color: black"&gt;; }
        &lt;/span&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector3&lt;/span&gt;&lt;span style="color: black"&gt;[] Vertices { &lt;/span&gt;&lt;span style="color: blue"&gt;get&lt;/span&gt;&lt;span style="color: black"&gt;; &lt;/span&gt;&lt;span style="color: blue"&gt;private set&lt;/span&gt;&lt;span style="color: black"&gt;; }
        &lt;/span&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector3 &lt;/span&gt;&lt;span style="color: black"&gt;Position { &lt;/span&gt;&lt;span style="color: blue"&gt;get&lt;/span&gt;&lt;span style="color: black"&gt;; &lt;/span&gt;&lt;span style="color: blue"&gt;set&lt;/span&gt;&lt;span style="color: black"&gt;; }
        &lt;/span&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector3 &lt;/span&gt;&lt;span style="color: black"&gt;Rotation { &lt;/span&gt;&lt;span style="color: blue"&gt;get&lt;/span&gt;&lt;span style="color: black"&gt;; &lt;/span&gt;&lt;span style="color: blue"&gt;set&lt;/span&gt;&lt;span style="color: black"&gt;; }

        &lt;/span&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: black"&gt;Mesh(&lt;/span&gt;&lt;span style="color: blue"&gt;string &lt;/span&gt;&lt;span style="color: black"&gt;name, &lt;/span&gt;&lt;span style="color: blue"&gt;int &lt;/span&gt;&lt;span style="color: black"&gt;verticesCount)
        {
            Vertices = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector3&lt;/span&gt;&lt;span style="color: black"&gt;[verticesCount];
            Name = name;
        }
    }
}&lt;/span&gt;&lt;/pre&gt;
  &lt;/div&gt;

  &lt;div id="two" class="tabpane"&gt;
    &lt;pre class="code"&gt;&lt;span style="color: green"&gt;//&amp;lt;reference path=&amp;quot;babylon.math.ts&amp;quot;/&amp;gt;
&lt;/span&gt;&lt;span style="color: blue"&gt;module &lt;/span&gt;&lt;span style="color: black"&gt;SoftEngine {
    &lt;/span&gt;&lt;span style="color: blue"&gt;export class &lt;/span&gt;&lt;span style="color: black"&gt;Camera {
        Position: BABYLON.Vector3;
        Target: BABYLON.Vector3;

        &lt;/span&gt;&lt;span style="color: blue"&gt;constructor&lt;/span&gt;&lt;span style="color: black"&gt;() {
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.Position = BABYLON.Vector3.Zero();
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.Target = BABYLON.Vector3.Zero();
        }
    }
    &lt;/span&gt;&lt;span style="color: blue"&gt;export class &lt;/span&gt;&lt;span style="color: black"&gt;Mesh {
        Position: BABYLON.Vector3;
        Rotation: BABYLON.Vector3;
        Vertices: BABYLON.Vector3[];

        &lt;/span&gt;&lt;span style="color: blue"&gt;constructor&lt;/span&gt;&lt;span style="color: black"&gt;(&lt;/span&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: black"&gt;name: &lt;/span&gt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&lt;span style="color: black"&gt;, verticesCount: &lt;/span&gt;&lt;span style="color: blue"&gt;number&lt;/span&gt;&lt;span style="color: black"&gt;) {
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.Vertices = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;Array(verticesCount);
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.Rotation = BABYLON.Vector3.Zero();
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.Position = BABYLON.Vector3.Zero();
        }
    }
}&lt;/span&gt;&lt;/pre&gt;
    &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/div&gt;

  &lt;div id="three" class="tabpane"&gt;
    &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;SoftEngine;
(&lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;&lt;span style="color: black"&gt;(SoftEngine) {
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;Camera = (&lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;&lt;span style="color: black"&gt;() {
        &lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;&lt;span style="color: black"&gt;Camera() {
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.Position = BABYLON.Vector3.Zero();
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.Target = BABYLON.Vector3.Zero();
        }
        &lt;/span&gt;&lt;span style="color: blue"&gt;return &lt;/span&gt;&lt;span style="color: black"&gt;Camera;
    })();
    SoftEngine.Camera = Camera;    
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;Mesh = (&lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;&lt;span style="color: black"&gt;() {
        &lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;&lt;span style="color: black"&gt;Mesh(name, verticesCount) {
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.name = name;
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.Vertices = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;Array(verticesCount);
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.Rotation = BABYLON.Vector3.Zero();
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.Position = BABYLON.Vector3.Zero();
        }
        &lt;/span&gt;&lt;span style="color: blue"&gt;return &lt;/span&gt;&lt;span style="color: black"&gt;Mesh;
    })();
    SoftEngine.Mesh = Mesh;    
})(SoftEngine || (SoftEngine = {}));&lt;/span&gt;&lt;/pre&gt;
    &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;!-- end tabset --&gt;

&lt;p&gt;For instance, if you want to describe a cube using our Mesh object, you need to create 8 vertices associated to the 8 points of the cube. Here are the coordinates on a cube displayed in Blender:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4540.image_5F00_2D374352.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5140.image_5F00_thumb_5F00_2BF2AA73.png" width="240" height="224" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;With a left-handed world. Remember also that when you’re creating a mesh, the coordinates system is starting at the center of the mesh. So, X=0, Y=0, Z=0 is the center of the cube. &lt;/p&gt;

&lt;p&gt;This could be created via this kind of code:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;mesh = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Mesh&lt;/span&gt;&lt;span style="color: black"&gt;(&lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;Cube&amp;quot;&lt;/span&gt;&lt;span style="color: black"&gt;, 8);
mesh.Vertices[0] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector3&lt;/span&gt;&lt;span style="color: black"&gt;(-1, 1, 1);
mesh.Vertices[1] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector3&lt;/span&gt;&lt;span style="color: black"&gt;(1, 1, 1);
mesh.Vertices[2] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector3&lt;/span&gt;&lt;span style="color: black"&gt;(-1, -1, 1);
mesh.Vertices[3] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector3&lt;/span&gt;&lt;span style="color: black"&gt;(-1, -1, -1);
mesh.Vertices[4] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector3&lt;/span&gt;&lt;span style="color: black"&gt;(-1, 1, -1);
mesh.Vertices[5] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector3&lt;/span&gt;&lt;span style="color: black"&gt;(1, 1, -1);
mesh.Vertices[6] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector3&lt;/span&gt;&lt;span style="color: black"&gt;(1, -1, 1);
mesh.Vertices[7] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector3&lt;/span&gt;&lt;span style="color: black"&gt;(1, -1, -1);&lt;/span&gt;&lt;/pre&gt;

&lt;h2&gt;The most important part: the Device object&lt;/h2&gt;

&lt;p&gt;Now that we have our basic objects and we know how to build 3D meshes, we need the most important part: the &lt;strong&gt;Device object. It’s the core of our 3D engine&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;In it’s rendering function, we will build the view matrix and the projection matrix based on the camera we will have defined before.&lt;/p&gt;

&lt;p&gt;Then, we will iterate through each available mesh to build their associated world matrix based on their current rotation and translation values. Finally, once done, the final transformation matrix to apply is:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;transformMatrix = worldMatrix * viewMatrix * projectionMatrix;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;This is the concept you absolutely need to understand by reading the previous prerequisites resources. Otherwise, you will probably simply copy/paste the code without understanding anything about the magic underneath. This is not a very big problem for further tutorials but again, it’s better to know what’s you’re coding. &lt;/p&gt;

&lt;p&gt;Using this transformation matrix, we’re going to project each vertex of each mesh in the 2D world to obtain X,Y coordinates from their X,Y,Z coordinates. To finally draw on screen, we’re adding a small clip logic to only display visible pixels via a PutPixel method/function. &lt;/p&gt;

&lt;p&gt;Here are the various versions of the Device object. I’ve tried to comment the code to help you understanding it as much as possible. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Note:&lt;/u&gt;&lt;/strong&gt; Microsoft Windows is drawing using the BGRA color space (Blue, Green, Red, Alpha) whereas the HTML5 canvas is drawing using the &lt;a href="http://en.wikipedia.org/wiki/RGBA_color_space"&gt;RGBA&lt;/a&gt; (Red, Green, Blue, Alpha) color space. That’s why, you will notice some slight differences in the code between C# and HTML5.&lt;/p&gt;

&lt;div id="tabset2" class="tabset"&gt;
  &lt;ul class="tabnavs"&gt;
    &lt;li&gt;&lt;a class="activeTab" href="#devicecsharp"&gt;C#&lt;/a&gt; &lt;/li&gt;

    &lt;li&gt;&lt;a href="#devicetypescript"&gt;TypeScript&lt;/a&gt; &lt;/li&gt;

    &lt;li&gt;&lt;a href="#devicejavascript"&gt;JavaScript&lt;/a&gt; &lt;/li&gt;
  &lt;/ul&gt;

  &lt;div id="devicecsharp" class="tabpane activePane"&gt;
    &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;using &lt;/span&gt;&lt;span style="color: black"&gt;Windows.UI.Xaml.Media.Imaging;
&lt;/span&gt;&lt;span style="color: blue"&gt;using &lt;/span&gt;&lt;span style="color: black"&gt;System.Runtime.InteropServices.WindowsRuntime;
&lt;/span&gt;&lt;span style="color: blue"&gt;using &lt;/span&gt;&lt;span style="color: black"&gt;SharpDX;

&lt;/span&gt;&lt;span style="color: blue"&gt;namespace &lt;/span&gt;&lt;span style="color: black"&gt;SoftEngine
{
    &lt;/span&gt;&lt;span style="color: blue"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Device
    &lt;/span&gt;&lt;span style="color: black"&gt;{
        &lt;/span&gt;&lt;span style="color: blue"&gt;private byte&lt;/span&gt;&lt;span style="color: black"&gt;[] backBuffer;
        &lt;/span&gt;&lt;span style="color: blue"&gt;private &lt;/span&gt;&lt;span style="color: #2b91af"&gt;WriteableBitmap &lt;/span&gt;&lt;span style="color: black"&gt;bmp;

        &lt;/span&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: black"&gt;Device(&lt;/span&gt;&lt;span style="color: #2b91af"&gt;WriteableBitmap &lt;/span&gt;&lt;span style="color: black"&gt;bmp)
        {
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.bmp = bmp;
            &lt;/span&gt;&lt;span style="color: green"&gt;// the back buffer size is equal to the number of pixels to draw
            // on screen (width*height) * 4 (R,G,B &amp;amp; Alpha values). 
            &lt;/span&gt;&lt;span style="color: black"&gt;backBuffer = &lt;/span&gt;&lt;span style="color: blue"&gt;new byte&lt;/span&gt;&lt;span style="color: black"&gt;[bmp.PixelWidth * bmp.PixelHeight * 4];
        }

        &lt;/span&gt;&lt;span style="color: green"&gt;// This method is called to clear the back buffer with a specific color
        &lt;/span&gt;&lt;span style="color: blue"&gt;public void &lt;/span&gt;&lt;span style="color: black"&gt;Clear(&lt;/span&gt;&lt;span style="color: blue"&gt;byte &lt;/span&gt;&lt;span style="color: black"&gt;r, &lt;/span&gt;&lt;span style="color: blue"&gt;byte &lt;/span&gt;&lt;span style="color: black"&gt;g, &lt;/span&gt;&lt;span style="color: blue"&gt;byte &lt;/span&gt;&lt;span style="color: black"&gt;b, &lt;/span&gt;&lt;span style="color: blue"&gt;byte &lt;/span&gt;&lt;span style="color: black"&gt;a) {
            &lt;/span&gt;&lt;span style="color: blue"&gt;for &lt;/span&gt;&lt;span style="color: black"&gt;(&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;index = 0; index &amp;lt; backBuffer.Length; index += 4)
            {
                &lt;/span&gt;&lt;span style="color: green"&gt;// BGRA is used by Windows instead by RGBA in HTML5
                &lt;/span&gt;&lt;span style="color: black"&gt;backBuffer[index] = b;
                backBuffer[index + 1] = g;
                backBuffer[index + 2] = r;
                backBuffer[index + 3] = a;
            }
        }

        &lt;/span&gt;&lt;span style="color: green"&gt;// Once everything is ready, we can flush the back buffer
        // into the front buffer. 
        &lt;/span&gt;&lt;span style="color: blue"&gt;public void &lt;/span&gt;&lt;span style="color: black"&gt;Present()
        {
            &lt;/span&gt;&lt;span style="color: blue"&gt;using &lt;/span&gt;&lt;span style="color: black"&gt;(&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;stream = bmp.PixelBuffer.AsStream())
            {
                &lt;/span&gt;&lt;span style="color: green"&gt;// writing our byte[] back buffer into our WriteableBitmap stream
                &lt;/span&gt;&lt;span style="color: black"&gt;stream.Write(backBuffer, 0, backBuffer.Length);
            }
            &lt;/span&gt;&lt;span style="color: green"&gt;// request a redraw of the entire bitmap
            &lt;/span&gt;&lt;span style="color: black"&gt;bmp.Invalidate();
        }

        &lt;/span&gt;&lt;span style="color: green"&gt;// Called to put a pixel on screen at a specific X,Y coordinates
        &lt;/span&gt;&lt;span style="color: blue"&gt;public void &lt;/span&gt;&lt;span style="color: black"&gt;PutPixel(&lt;/span&gt;&lt;span style="color: blue"&gt;int &lt;/span&gt;&lt;span style="color: black"&gt;x, &lt;/span&gt;&lt;span style="color: blue"&gt;int &lt;/span&gt;&lt;span style="color: black"&gt;y, &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Color4 &lt;/span&gt;&lt;span style="color: black"&gt;color)
        {
            &lt;/span&gt;&lt;span style="color: green"&gt;// As we have a 1-D Array for our back buffer
            // we need to know the equivalent cell in 1-D based
            // on the 2D coordinates on screen
            &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;index = (x + y * bmp.PixelWidth) * 4;

            backBuffer[index] = (&lt;/span&gt;&lt;span style="color: blue"&gt;byte&lt;/span&gt;&lt;span style="color: black"&gt;)(color.Blue * 255);
            backBuffer[index + 1] = (&lt;/span&gt;&lt;span style="color: blue"&gt;byte&lt;/span&gt;&lt;span style="color: black"&gt;)(color.Green * 255);
            backBuffer[index + 2] = (&lt;/span&gt;&lt;span style="color: blue"&gt;byte&lt;/span&gt;&lt;span style="color: black"&gt;)(color.Red * 255);
            backBuffer[index + 3] = (&lt;/span&gt;&lt;span style="color: blue"&gt;byte&lt;/span&gt;&lt;span style="color: black"&gt;)(color.Alpha * 255);
        }

        &lt;/span&gt;&lt;span style="color: green"&gt;// Project takes some 3D coordinates and transform them
        // in 2D coordinates using the transformation matrix
        &lt;/span&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector2 &lt;/span&gt;&lt;span style="color: black"&gt;Project(&lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector3 &lt;/span&gt;&lt;span style="color: black"&gt;coord, &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Matrix &lt;/span&gt;&lt;span style="color: black"&gt;transMat)
        {
            &lt;/span&gt;&lt;span style="color: green"&gt;// transforming the coordinates
            &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;point = &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector3&lt;/span&gt;&lt;span style="color: black"&gt;.TransformCoordinate(coord, transMat);
            &lt;/span&gt;&lt;span style="color: green"&gt;// The transformed coordinates will be based on coordinate system
            // starting on the center of the screen. But drawing on screen normally starts
            // from top left. We then need to transform them again to have x:0, y:0 on top left.
            &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;x = point.X * bmp.PixelWidth + bmp.PixelWidth / 2.0f;
            &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;y = -point.Y * bmp.PixelHeight + bmp.PixelHeight / 2.0f;
            &lt;/span&gt;&lt;span style="color: blue"&gt;return &lt;/span&gt;&lt;span style="color: black"&gt;(&lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector2&lt;/span&gt;&lt;span style="color: black"&gt;(x, y));
        }

        &lt;/span&gt;&lt;span style="color: green"&gt;// DrawPoint calls PutPixel but does the clipping operation before
        &lt;/span&gt;&lt;span style="color: blue"&gt;public void &lt;/span&gt;&lt;span style="color: black"&gt;DrawPoint(&lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector2 &lt;/span&gt;&lt;span style="color: black"&gt;point)
        {
            &lt;/span&gt;&lt;span style="color: green"&gt;// Clipping what's visible on screen
            &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;&lt;span style="color: black"&gt;(point.X &amp;gt;= 0 &amp;amp;&amp;amp; point.Y &amp;gt;= 0 &amp;amp;&amp;amp; point.X &amp;lt; bmp.PixelWidth &amp;amp;&amp;amp; point.Y &amp;lt; bmp.PixelHeight)
            {
                &lt;/span&gt;&lt;span style="color: green"&gt;// Drawing a yellow point
                &lt;/span&gt;&lt;span style="color: black"&gt;PutPixel((&lt;/span&gt;&lt;span style="color: blue"&gt;int&lt;/span&gt;&lt;span style="color: black"&gt;)point.X, (&lt;/span&gt;&lt;span style="color: blue"&gt;int&lt;/span&gt;&lt;span style="color: black"&gt;)point.Y, &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Color4&lt;/span&gt;&lt;span style="color: black"&gt;(1.0f, 1.0f, 0.0f, 1.0f));
            }
        }

        &lt;/span&gt;&lt;span style="color: green"&gt;// The main method of the engine that re-compute each vertex projection
        // during each frame
        &lt;/span&gt;&lt;span style="color: blue"&gt;public void &lt;/span&gt;&lt;span style="color: black"&gt;Render(&lt;/span&gt;&lt;span style="color: #2b91af"&gt;Camera &lt;/span&gt;&lt;span style="color: black"&gt;camera, &lt;/span&gt;&lt;span style="color: blue"&gt;params &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Mesh&lt;/span&gt;&lt;span style="color: black"&gt;[] meshes)
        {
            &lt;/span&gt;&lt;span style="color: green"&gt;// To understand this part, please read the prerequisites resources
            &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;viewMatrix = &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Matrix&lt;/span&gt;&lt;span style="color: black"&gt;.LookAtLH(camera.Position, camera.Target, &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector3&lt;/span&gt;&lt;span style="color: black"&gt;.UnitY);
            &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;projectionMatrix = &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Matrix&lt;/span&gt;&lt;span style="color: black"&gt;.PerspectiveFovRH(0.78f, 
                                                           (&lt;/span&gt;&lt;span style="color: blue"&gt;float&lt;/span&gt;&lt;span style="color: black"&gt;)bmp.PixelWidth / bmp.PixelHeight, 
                                                           0.01f, 1.0f);

            &lt;/span&gt;&lt;span style="color: blue"&gt;foreach &lt;/span&gt;&lt;span style="color: black"&gt;(&lt;/span&gt;&lt;span style="color: #2b91af"&gt;Mesh &lt;/span&gt;&lt;span style="color: black"&gt;mesh &lt;/span&gt;&lt;span style="color: blue"&gt;in &lt;/span&gt;&lt;span style="color: black"&gt;meshes) 
            {
                &lt;/span&gt;&lt;span style="color: green"&gt;// Beware to apply rotation before translation 
                &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;worldMatrix = &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Matrix&lt;/span&gt;&lt;span style="color: black"&gt;.RotationYawPitchRoll(mesh.Rotation.Y, &lt;br /&gt;                                                              mesh.Rotation.X, mesh.Rotation.Z) * 
                                  &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Matrix&lt;/span&gt;&lt;span style="color: black"&gt;.Translation(mesh.Position);

                &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;transformMatrix = worldMatrix * viewMatrix * projectionMatrix;

                &lt;/span&gt;&lt;span style="color: blue"&gt;foreach &lt;/span&gt;&lt;span style="color: black"&gt;(&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;vertex &lt;/span&gt;&lt;span style="color: blue"&gt;in &lt;/span&gt;&lt;span style="color: black"&gt;mesh.Vertices)
                {
                    &lt;/span&gt;&lt;span style="color: green"&gt;// First, we project the 3D coordinates into the 2D space
                    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;point = Project(vertex, transformMatrix);
                    &lt;/span&gt;&lt;span style="color: green"&gt;// Then we can draw on screen
                    &lt;/span&gt;&lt;span style="color: black"&gt;DrawPoint(point);
                }
            }
        }
    }
}
&lt;/span&gt;&lt;/pre&gt;
    &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/div&gt;

  &lt;div id="devicetypescript" class="tabpane"&gt;
    &lt;pre class="code"&gt;&lt;span style="color: green"&gt;///&amp;lt;reference path=&amp;quot;babylon.math.ts&amp;quot;/&amp;gt;

&lt;/span&gt;&lt;span style="color: blue"&gt;module &lt;/span&gt;&lt;span style="color: black"&gt;SoftEngine {
&lt;/span&gt;&lt;span style="color: black"&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;export class &lt;/span&gt;&lt;span style="color: black"&gt;Device {
        &lt;/span&gt;&lt;span style="color: green"&gt;// the back buffer size is equal to the number of pixels to draw
        // on screen (width*height) * 4 (R,G,B &amp;amp; Alpha values). 
        &lt;/span&gt;&lt;span style="color: blue"&gt;private &lt;/span&gt;&lt;span style="color: black"&gt;backbuffer: ImageData;
        &lt;/span&gt;&lt;span style="color: blue"&gt;private &lt;/span&gt;&lt;span style="color: black"&gt;workingCanvas: HTMLCanvasElement;
        &lt;/span&gt;&lt;span style="color: blue"&gt;private &lt;/span&gt;&lt;span style="color: black"&gt;workingContext: CanvasRenderingContext2D;
        &lt;/span&gt;&lt;span style="color: blue"&gt;private &lt;/span&gt;&lt;span style="color: black"&gt;workingWidth: &lt;/span&gt;&lt;span style="color: blue"&gt;number&lt;/span&gt;&lt;span style="color: black"&gt;;
        &lt;/span&gt;&lt;span style="color: blue"&gt;private &lt;/span&gt;&lt;span style="color: black"&gt;workingHeight: &lt;/span&gt;&lt;span style="color: blue"&gt;number&lt;/span&gt;&lt;span style="color: black"&gt;;
        &lt;/span&gt;&lt;span style="color: green"&gt;// equals to backbuffer.data
        &lt;/span&gt;&lt;span style="color: blue"&gt;private &lt;/span&gt;&lt;span style="color: black"&gt;backbufferdata;

        &lt;/span&gt;&lt;span style="color: blue"&gt;constructor&lt;/span&gt;&lt;span style="color: black"&gt;(canvas: HTMLCanvasElement) {
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.workingCanvas = canvas;
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.workingWidth = canvas.width;
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.workingHeight = canvas.height;
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.workingContext = &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.workingCanvas.getContext(&lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;2d&amp;quot;&lt;/span&gt;&lt;span style="color: black"&gt;);
        }

        &lt;/span&gt;&lt;span style="color: green"&gt;// This function is called to clear the back buffer with a specific color
        &lt;/span&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: black"&gt;clear(): &lt;/span&gt;&lt;span style="color: blue"&gt;void &lt;/span&gt;&lt;span style="color: black"&gt;{
            &lt;/span&gt;&lt;span style="color: green"&gt;// Clearing with black color by default
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.workingContext.clearRect(0, 0, &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.workingWidth, &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.workingHeight);
            &lt;/span&gt;&lt;span style="color: green"&gt;// once cleared with black pixels, we're getting back the associated image data to 
            // clear out back buffer
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.backbuffer = &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.workingContext.getImageData(0, 0, &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.workingWidth, &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.workingHeight);
        }

        &lt;/span&gt;&lt;span style="color: green"&gt;// Once everything is ready, we can flush the back buffer
        // into the front buffer. 
        &lt;/span&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: black"&gt;present(): &lt;/span&gt;&lt;span style="color: blue"&gt;void &lt;/span&gt;&lt;span style="color: black"&gt;{
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.workingContext.putImageData(&lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.backbuffer, 0, 0);
        }

        &lt;/span&gt;&lt;span style="color: green"&gt;// Called to put a pixel on screen at a specific X,Y coordinates
        &lt;/span&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: black"&gt;putPixel(x: &lt;/span&gt;&lt;span style="color: blue"&gt;number&lt;/span&gt;&lt;span style="color: black"&gt;, y: &lt;/span&gt;&lt;span style="color: blue"&gt;number&lt;/span&gt;&lt;span style="color: black"&gt;, color: BABYLON.Color4): &lt;/span&gt;&lt;span style="color: blue"&gt;void &lt;/span&gt;&lt;span style="color: black"&gt;{
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.backbufferdata = &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.backbuffer.data;
            &lt;/span&gt;&lt;span style="color: green"&gt;// As we have a 1-D Array for our back buffer
            // we need to know the equivalent cell index in 1-D based
            // on the 2D coordinates of the screen
            &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;index: &lt;/span&gt;&lt;span style="color: blue"&gt;number &lt;/span&gt;&lt;span style="color: black"&gt;= ((x &amp;gt;&amp;gt; 0) + (y &amp;gt;&amp;gt; 0) * &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.workingWidth) * 4;&lt;/span&gt;
    &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

    &lt;span style="color: blue"&gt;&lt;/span&gt;&lt;span style="color: black"&gt;
            &lt;/span&gt;&lt;span style="color: green"&gt;// RGBA color space is used by the HTML5 canvas
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.backbufferdata[index] = color.r * 255;
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.backbufferdata[index + 1] = color.g * 255;
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.backbufferdata[index + 2] = color.b * 255;
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.backbufferdata[index + 3] = color.a * 255;
        }

        &lt;/span&gt;&lt;span style="color: green"&gt;// Project takes some 3D coordinates and transform them
        // in 2D coordinates using the transformation matrix
        &lt;/span&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: black"&gt;project(coord: BABYLON.Vector3, transMat: BABYLON.Matrix): BABYLON.Vector2 {
            &lt;/span&gt;&lt;span style="color: green"&gt;// transforming the coordinates
            &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;point = BABYLON.Vector3.TransformCoordinates(coord, transMat);
            &lt;/span&gt;&lt;span style="color: green"&gt;// The transformed coordinates will be based on coordinate system
            // starting on the center of the screen. But drawing on screen normally starts
            // from top left. We then need to transform them again to have x:0, y:0 on top left.
            &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;x = point.x * &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.workingWidth + &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.workingWidth / 2.0 &amp;gt;&amp;gt; 0;
            &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;y = -point.y * &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.workingHeight + &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.workingHeight / 2.0 &amp;gt;&amp;gt; 0;
            &lt;/span&gt;&lt;span style="color: blue"&gt;return &lt;/span&gt;&lt;span style="color: black"&gt;(&lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Vector2(x, y));
        }

        &lt;/span&gt;&lt;span style="color: green"&gt;// drawPoint calls putPixel but does the clipping operation before
        &lt;/span&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: black"&gt;drawPoint(point: BABYLON.Vector2): &lt;/span&gt;&lt;span style="color: blue"&gt;void &lt;/span&gt;&lt;span style="color: black"&gt;{
            &lt;/span&gt;&lt;span style="color: green"&gt;// Clipping what's visible on screen
            &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;&lt;span style="color: black"&gt;(point.x &amp;gt;= 0 &amp;amp;&amp;amp; point.y &amp;gt;= 0 &amp;amp;&amp;amp; point.x &amp;lt; &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.workingWidth &lt;br /&gt;                                             &amp;amp;&amp;amp; point.y &amp;lt; &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.workingHeight) {
                &lt;/span&gt;&lt;span style="color: green"&gt;// Drawing a yellow point
                &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.putPixel(point.x, point.y, &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Color4(1, 1, 0, 1));
            }
        }

        &lt;/span&gt;&lt;span style="color: green"&gt;// The main method of the engine that re-compute each vertex projection
        // during each frame
        &lt;/span&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: black"&gt;render(camera: Camera, meshes: Mesh[]): &lt;/span&gt;&lt;span style="color: blue"&gt;void &lt;/span&gt;&lt;span style="color: black"&gt;{
            &lt;/span&gt;&lt;span style="color: green"&gt;// To understand this part, please read the prerequisites resources
            &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;viewMatrix = BABYLON.Matrix.LookAtLH(camera.Position, camera.Target, BABYLON.Vector3.Up());
            &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;projectionMatrix = BABYLON.Matrix.PerspectiveFovLH(0.78, &lt;br /&gt;                                                  &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.workingWidth / &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.workingHeight, 0.01, 1.0);

            &lt;/span&gt;&lt;span style="color: blue"&gt;for &lt;/span&gt;&lt;span style="color: black"&gt;(&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;index = 0; index &amp;lt; meshes.length; index++) {
                &lt;/span&gt;&lt;span style="color: green"&gt;// current mesh to work on
                &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;cMesh = meshes[index];
                &lt;/span&gt;&lt;span style="color: green"&gt;// Beware to apply rotation before translation
                &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;worldMatrix = BABYLON.Matrix.RotationYawPitchRoll(
                        cMesh.Rotation.y, cMesh.Rotation.x, cMesh.Rotation.z)
                        .multiply(BABYLON.Matrix.Translation(
                            cMesh.Position.x, cMesh.Position.y, cMesh.Position.z));

                &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;transformMatrix = worldMatrix.multiply(viewMatrix).multiply(projectionMatrix);

                &lt;/span&gt;&lt;span style="color: blue"&gt;for &lt;/span&gt;&lt;span style="color: black"&gt;(&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;indexVertices = 0; indexVertices &amp;lt; cMesh.Vertices.length; indexVertices++) {
                    &lt;/span&gt;&lt;span style="color: green"&gt;// First, we project the 3D coordinates into the 2D space
                    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;projectedPoint = &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.project(cMesh.Vertices[indexVertices], transformMatrix);
                    &lt;/span&gt;&lt;span style="color: green"&gt;// Then we can draw on screen
                    &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.drawPoint(projectedPoint);
                }
            }
        }
    }
}
&lt;/span&gt;&lt;/pre&gt;
    &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/div&gt;

  &lt;div id="devicejavascript" class="tabpane"&gt;
    &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;SoftEngine;
(&lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;&lt;span style="color: black"&gt;(SoftEngine) {  
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;Device = (&lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;&lt;span style="color: black"&gt;() {
        &lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;&lt;span style="color: black"&gt;Device(canvas) {
            &lt;/span&gt;&lt;span style="color: green"&gt;// Note: the back buffer size is equal to the number of pixels to draw
            // on screen (width*height) * 4 (R,G,B &amp;amp; Alpha values). 
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.workingCanvas = canvas;
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.workingWidth = canvas.width;
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.workingHeight = canvas.height;
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.workingContext = &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.workingCanvas.getContext(&lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;2d&amp;quot;&lt;/span&gt;&lt;span style="color: black"&gt;);
        }

        &lt;/span&gt;&lt;span style="color: green"&gt;// This function is called to clear the back buffer with a specific color
        &lt;/span&gt;&lt;span style="color: black"&gt;Device.prototype.clear = &lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;&lt;span style="color: black"&gt;() {
            &lt;/span&gt;&lt;span style="color: green"&gt;// Clearing with black color by default
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.workingContext.clearRect(0, 0, &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.workingWidth, &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.workingHeight);
            &lt;/span&gt;&lt;span style="color: green"&gt;// once cleared with black pixels, we're getting back the associated image data to 
            // clear out back buffer
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.backbuffer = &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.workingContext.getImageData(0, 0, &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.workingWidth, &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.workingHeight);
        };

        &lt;/span&gt;&lt;span style="color: green"&gt;// Once everything is ready, we can flush the back buffer
        // into the front buffer. 
        &lt;/span&gt;&lt;span style="color: black"&gt;Device.prototype.present = &lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;&lt;span style="color: black"&gt;() {
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.workingContext.putImageData(&lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.backbuffer, 0, 0);
        };

        &lt;/span&gt;&lt;span style="color: green"&gt;// Called to put a pixel on screen at a specific X,Y coordinates
        &lt;/span&gt;&lt;span style="color: black"&gt;Device.prototype.putPixel = &lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;&lt;span style="color: black"&gt;(x, y, color) {
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.backbufferdata = &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.backbuffer.data;
            &lt;/span&gt;&lt;span style="color: green"&gt;// As we have a 1-D Array for our back buffer
            // we need to know the equivalent cell index in 1-D based
            // on the 2D coordinates of the screen
            &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;index = ((x &amp;gt;&amp;gt; 0) + (y &amp;gt;&amp;gt; 0) * &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.workingWidth) * 4;&lt;/span&gt;
    &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

    &lt;span style="color: blue"&gt;&lt;/span&gt;&lt;span style="color: black"&gt;
            &lt;/span&gt;&lt;span style="color: green"&gt;// RGBA color space is used by the HTML5 canvas
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.backbufferdata[index] = color.r * 255;
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.backbufferdata[index + 1] = color.g * 255;
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.backbufferdata[index + 2] = color.b * 255;
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.backbufferdata[index + 3] = color.a * 255;
        };

        &lt;/span&gt;&lt;span style="color: green"&gt;// Project takes some 3D coordinates and transform them
        // in 2D coordinates using the transformation matrix
        &lt;/span&gt;&lt;span style="color: black"&gt;Device.prototype.project = &lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;&lt;span style="color: black"&gt;(coord, transMat) {
            &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;point = BABYLON.Vector3.TransformCoordinates(coord, transMat);
            &lt;/span&gt;&lt;span style="color: green"&gt;// The transformed coordinates will be based on coordinate system
            // starting on the center of the screen. But drawing on screen normally starts
            // from top left. We then need to transform them again to have x:0, y:0 on top left.
            &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;x = point.x * &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.workingWidth + &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.workingWidth / 2.0 &amp;gt;&amp;gt; 0;
            &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;y = -point.y * &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.workingHeight + &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.workingHeight / 2.0 &amp;gt;&amp;gt; 0;
            &lt;/span&gt;&lt;span style="color: blue"&gt;return &lt;/span&gt;&lt;span style="color: black"&gt;(&lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Vector2(x, y));
        };

        &lt;/span&gt;&lt;span style="color: green"&gt;// drawPoint calls putPixel but does the clipping operation before
        &lt;/span&gt;&lt;span style="color: black"&gt;Device.prototype.drawPoint = &lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;&lt;span style="color: black"&gt;(point) {
            &lt;/span&gt;&lt;span style="color: green"&gt;// Clipping what's visible on screen
            &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;&lt;span style="color: black"&gt;(point.x &amp;gt;= 0 &amp;amp;&amp;amp; point.y &amp;gt;= 0 &amp;amp;&amp;amp; point.x &amp;lt; &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.workingWidth &lt;br /&gt;                                             &amp;amp;&amp;amp; point.y &amp;lt; &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.workingHeight) {
                &lt;/span&gt;&lt;span style="color: green"&gt;// Drawing a yellow point
                &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.putPixel(point.x, point.y, &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Color4(1, 1, 0, 1));
            }
        };

        &lt;/span&gt;&lt;span style="color: green"&gt;// The main method of the engine that re-compute each vertex projection
        // during each frame
        &lt;/span&gt;&lt;span style="color: black"&gt;Device.prototype.render = &lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;&lt;span style="color: black"&gt;(camera, meshes) {
            &lt;/span&gt;&lt;span style="color: green"&gt;// To understand this part, please read the prerequisites resources
            &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;viewMatrix = BABYLON.Matrix.LookAtLH(camera.Position, camera.Target, BABYLON.Vector3.Up());
            &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;projectionMatrix = BABYLON.Matrix.PerspectiveFovLH(0.78, &lt;br /&gt;                                           &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.workingWidth / &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.workingHeight, 0.01, 1.0);

            &lt;/span&gt;&lt;span style="color: blue"&gt;for &lt;/span&gt;&lt;span style="color: black"&gt;(&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;index = 0; index &amp;lt; meshes.length; index++) {
                &lt;/span&gt;&lt;span style="color: green"&gt;// current mesh to work on
                &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;cMesh = meshes[index];
                &lt;/span&gt;&lt;span style="color: green"&gt;// Beware to apply rotation before translation
                &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;worldMatrix = BABYLON.Matrix.RotationYawPitchRoll(
                    cMesh.Rotation.y, cMesh.Rotation.x, cMesh.Rotation.z)
                     .multiply(BABYLON.Matrix.Translation(
                       cMesh.Position.x, cMesh.Position.y, cMesh.Position.z));

                &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;transformMatrix = worldMatrix.multiply(viewMatrix).multiply(projectionMatrix);

                &lt;/span&gt;&lt;span style="color: blue"&gt;for &lt;/span&gt;&lt;span style="color: black"&gt;(&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;indexVertices = 0; indexVertices &amp;lt; cMesh.Vertices.length; indexVertices++) {
                    &lt;/span&gt;&lt;span style="color: green"&gt;// First, we project the 3D coordinates into the 2D space
                    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;projectedPoint = &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.project(cMesh.Vertices[indexVertices], transformMatrix);
                    &lt;/span&gt;&lt;span style="color: green"&gt;// Then we can draw on screen
                    &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: black"&gt;.drawPoint(projectedPoint);
                }
            }
        };
        &lt;/span&gt;&lt;span style="color: blue"&gt;return &lt;/span&gt;&lt;span style="color: black"&gt;Device;
    })();
    SoftEngine.Device = Device;    
})(SoftEngine || (SoftEngine = {}));&lt;/span&gt;&lt;/pre&gt;
    &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;!-- end tabset --&gt;

&lt;h2&gt;Putting it all together &lt;/h2&gt;

&lt;p&gt;We finally need to create a mesh (our cube), create a camera and target our mesh &amp;amp; instantiate our Device object. &lt;/p&gt;

&lt;p&gt;Once done, we will launch the animation/rendering loop. In optimal cases, this loop will be called every 16ms (60 FPS). During each tick (call to the handler registered to the rendering loop), we will launch the following logic every time:&lt;/p&gt;

&lt;p&gt;1 – &lt;strong&gt;Clear the screen&lt;/strong&gt; and all associated pixels with black ones (&lt;em&gt;Clear()&lt;/em&gt; function) 

  &lt;br /&gt;2 – &lt;strong&gt;Update the various position &amp;amp; rotation values&lt;/strong&gt; of our meshes 

  &lt;br /&gt;3 – &lt;strong&gt;Render them&lt;/strong&gt; into the back buffer by doing the required matrix operations (&lt;em&gt;Render()&lt;/em&gt; function) 

  &lt;br /&gt;4 – &lt;strong&gt;Display them&lt;/strong&gt; on screen by flushing the back buffer data into the front buffer (&lt;em&gt;Present()&lt;/em&gt; function)&lt;/p&gt;

&lt;div id="tabset3" class="tabset"&gt;
  &lt;ul class="tabnavs"&gt;
    &lt;li&gt;&lt;a class="activeTab" href="#maincsharp"&gt;C#&lt;/a&gt; &lt;/li&gt;

    &lt;li&gt;&lt;a href="#maintypescript"&gt;TypeScript&lt;/a&gt; &lt;/li&gt;

    &lt;li&gt;&lt;a href="#mainjavascript"&gt;JavaScript&lt;/a&gt; &lt;/li&gt;
  &lt;/ul&gt;

  &lt;div id="maincsharp" class="tabpane activePane"&gt;
    &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;private &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Device &lt;/span&gt;&lt;span style="color: black"&gt;device;
&lt;/span&gt;&lt;span style="color: #2b91af"&gt;Mesh &lt;/span&gt;&lt;span style="color: black"&gt;mesh = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Mesh&lt;/span&gt;&lt;span style="color: black"&gt;(&lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;Cube&amp;quot;&lt;/span&gt;&lt;span style="color: black"&gt;, 8);
&lt;/span&gt;&lt;span style="color: #2b91af"&gt;Camera &lt;/span&gt;&lt;span style="color: black"&gt;mera = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Camera&lt;/span&gt;&lt;span style="color: black"&gt;();

&lt;/span&gt;&lt;span style="color: blue"&gt;private void &lt;/span&gt;&lt;span style="color: black"&gt;Page_Loaded(&lt;/span&gt;&lt;span style="color: blue"&gt;object &lt;/span&gt;&lt;span style="color: black"&gt;sender, &lt;/span&gt;&lt;span style="color: #2b91af"&gt;RoutedEventArgs &lt;/span&gt;&lt;span style="color: black"&gt;e)
{
    &lt;/span&gt;&lt;span style="color: green"&gt;// Choose the back buffer resolution here
    &lt;/span&gt;&lt;span style="color: #2b91af"&gt;WriteableBitmap &lt;/span&gt;&lt;span style="color: black"&gt;bmp = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;WriteableBitmap&lt;/span&gt;&lt;span style="color: black"&gt;(640, 480);

    device = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Device&lt;/span&gt;&lt;span style="color: black"&gt;(bmp);

    &lt;/span&gt;&lt;span style="color: green"&gt;// Our XAML Image control
    &lt;/span&gt;&lt;span style="color: black"&gt;frontBuffer.Source = bmp;

    mesh.Vertices[0] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector3&lt;/span&gt;&lt;span style="color: black"&gt;(-1, 1, 1);
    mesh.Vertices[1] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector3&lt;/span&gt;&lt;span style="color: black"&gt;(1, 1, 1);
    mesh.Vertices[2] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector3&lt;/span&gt;&lt;span style="color: black"&gt;(-1, -1, 1);
    mesh.Vertices[3] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector3&lt;/span&gt;&lt;span style="color: black"&gt;(-1, -1, -1);
    mesh.Vertices[4] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector3&lt;/span&gt;&lt;span style="color: black"&gt;(-1, 1, -1);
    mesh.Vertices[5] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector3&lt;/span&gt;&lt;span style="color: black"&gt;(1, 1, -1);
    mesh.Vertices[6] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector3&lt;/span&gt;&lt;span style="color: black"&gt;(1, -1, 1);
    mesh.Vertices[7] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector3&lt;/span&gt;&lt;span style="color: black"&gt;(1, -1, -1);

    mera.Position = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector3&lt;/span&gt;&lt;span style="color: black"&gt;(0, 0, 10.0f);
    mera.Target = &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector3&lt;/span&gt;&lt;span style="color: black"&gt;.Zero;

    &lt;/span&gt;&lt;span style="color: green"&gt;// Registering to the XAML rendering loop
    &lt;/span&gt;&lt;span style="color: #2b91af"&gt;CompositionTarget&lt;/span&gt;&lt;span style="color: black"&gt;.Rendering += CompositionTarget_Rendering;
}

&lt;/span&gt;&lt;span style="color: green"&gt;// Rendering loop handler
&lt;/span&gt;&lt;span style="color: blue"&gt;void &lt;/span&gt;&lt;span style="color: black"&gt;CompositionTarget_Rendering(&lt;/span&gt;&lt;span style="color: blue"&gt;object &lt;/span&gt;&lt;span style="color: black"&gt;sender, &lt;/span&gt;&lt;span style="color: blue"&gt;object &lt;/span&gt;&lt;span style="color: black"&gt;e)
{
    device.Clear(0, 0, 0, 255);

    &lt;/span&gt;&lt;span style="color: green"&gt;// rotating slightly the cube during each frame rendered
    &lt;/span&gt;&lt;span style="color: black"&gt;mesh.Rotation = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Vector3&lt;/span&gt;&lt;span style="color: black"&gt;(mesh.Rotation.X + 0.01f, mesh.Rotation.Y + 0.01f, mesh.Rotation.Z);

    &lt;/span&gt;&lt;span style="color: green"&gt;// Doing the various matrix operations
    &lt;/span&gt;&lt;span style="color: black"&gt;device.Render(mera, mesh);
    &lt;/span&gt;&lt;span style="color: green"&gt;// Flushing the back buffer into the front buffer
    &lt;/span&gt;&lt;span style="color: black"&gt;device.Present();
}&lt;/span&gt;&lt;/pre&gt;
    &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/div&gt;

  &lt;div id="maintypescript" class="tabpane"&gt;
    &lt;pre class="code"&gt;&lt;span style="color: green"&gt;///&amp;lt;reference path=&amp;quot;SoftEngine.ts&amp;quot;/&amp;gt;

&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;canvas: HTMLCanvasElement; 
&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;device: SoftEngine.Device;
&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;mesh: SoftEngine.Mesh;
&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;meshes: SoftEngine.Mesh[] = [];
&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;mera: SoftEngine.Camera;

document.addEventListener(&lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;DOMContentLoaded&amp;quot;&lt;/span&gt;&lt;span style="color: black"&gt;, init, &lt;/span&gt;&lt;span style="color: blue"&gt;false&lt;/span&gt;&lt;span style="color: black"&gt;);

&lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;&lt;span style="color: black"&gt;init() {
    canvas = &amp;lt;HTMLCanvasElement&amp;gt; document.getElementById(&lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;frontBuffer&amp;quot;&lt;/span&gt;&lt;span style="color: black"&gt;);
    mesh = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;SoftEngine.Mesh(&lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;Cube&amp;quot;&lt;/span&gt;&lt;span style="color: black"&gt;, 8);
    meshes.push(mesh);
    mera = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;SoftEngine.Camera();
    device = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;SoftEngine.Device(canvas);

    mesh.Vertices[0] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Vector3(-1, 1, 1);
    mesh.Vertices[1] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Vector3(1, 1, 1);
    mesh.Vertices[2] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Vector3(-1, -1, 1);
    mesh.Vertices[3] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Vector3(-1, -1, -1);
    mesh.Vertices[4] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Vector3(-1, 1, -1);
    mesh.Vertices[5] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Vector3(1, 1, -1);
    mesh.Vertices[6] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Vector3(1, -1, 1);
    mesh.Vertices[7] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Vector3(1, -1, -1);

    mera.Position = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Vector3(0, 0, 10);
    mera.Target = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Vector3(0, 0, 0);

    &lt;/span&gt;&lt;span style="color: green"&gt;// Calling the HTML5 rendering loop
    &lt;/span&gt;&lt;span style="color: black"&gt;requestAnimationFrame(drawingLoop);
}

&lt;/span&gt;&lt;span style="color: green"&gt;// Rendering loop handler
&lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;&lt;span style="color: black"&gt;drawingLoop() {
    device.clear();

    &lt;/span&gt;&lt;span style="color: green"&gt;// rotating slightly the cube during each frame rendered
    &lt;/span&gt;&lt;span style="color: black"&gt;mesh.Rotation.x += 0.01;
    mesh.Rotation.y += 0.01;

    &lt;/span&gt;&lt;span style="color: green"&gt;// Doing the various matrix operations
    &lt;/span&gt;&lt;span style="color: black"&gt;device.render(mera, meshes);
    &lt;/span&gt;&lt;span style="color: green"&gt;// Flushing the back buffer into the front buffer
    &lt;/span&gt;&lt;span style="color: black"&gt;device.present();

    &lt;/span&gt;&lt;span style="color: green"&gt;// Calling the HTML5 rendering loop recursively
    &lt;/span&gt;&lt;span style="color: black"&gt;requestAnimationFrame(drawingLoop);
}&lt;/span&gt;&lt;/pre&gt;
    &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/div&gt;

  &lt;div id="mainjavascript" class="tabpane"&gt;
    &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;canvas;
&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;device;
&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;mesh;
&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;meshes = [];
&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;&lt;span style="color: black"&gt;mera;

document.addEventListener(&lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;DOMContentLoaded&amp;quot;&lt;/span&gt;&lt;span style="color: black"&gt;, init, &lt;/span&gt;&lt;span style="color: blue"&gt;false&lt;/span&gt;&lt;span style="color: black"&gt;);

&lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;&lt;span style="color: black"&gt;init() {
    canvas = document.getElementById(&lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;frontBuffer&amp;quot;&lt;/span&gt;&lt;span style="color: black"&gt;);
    mesh = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;SoftEngine.Mesh(&lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;Cube&amp;quot;&lt;/span&gt;&lt;span style="color: black"&gt;, 8);
    meshes.push(mesh);
    mera = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;SoftEngine.Camera();
    device = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;SoftEngine.Device(canvas);

    mesh.Vertices[0] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Vector3(-1, 1, 1);
    mesh.Vertices[1] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Vector3(1, 1, 1);
    mesh.Vertices[2] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Vector3(-1, -1, 1);
    mesh.Vertices[3] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Vector3(-1, -1, -1);
    mesh.Vertices[4] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Vector3(-1, 1, -1);
    mesh.Vertices[5] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Vector3(1, 1, -1);
    mesh.Vertices[6] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Vector3(1, -1, 1);
    mesh.Vertices[7] = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Vector3(1, -1, -1);

    mera.Position = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Vector3(0, 0, 10);
    mera.Target = &lt;/span&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: black"&gt;BABYLON.Vector3(0, 0, 0);

    &lt;/span&gt;&lt;span style="color: green"&gt;// Calling the HTML5 rendering loop
    &lt;/span&gt;&lt;span style="color: black"&gt;requestAnimationFrame(drawingLoop);
}

&lt;/span&gt;&lt;span style="color: green"&gt;// Rendering loop handler
&lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;&lt;span style="color: black"&gt;drawingLoop() {
    device.clear();

    &lt;/span&gt;&lt;span style="color: green"&gt;// rotating slightly the cube during each frame rendered
    &lt;/span&gt;&lt;span style="color: black"&gt;mesh.Rotation.x += 0.01;
    mesh.Rotation.y += 0.01;

    &lt;/span&gt;&lt;span style="color: green"&gt;// Doing the various matrix operations
    &lt;/span&gt;&lt;span style="color: black"&gt;device.render(mera, meshes);
    &lt;/span&gt;&lt;span style="color: green"&gt;// Flushing the back buffer into the front buffer
    &lt;/span&gt;&lt;span style="color: black"&gt;device.present();

    &lt;/span&gt;&lt;span style="color: green"&gt;// Calling the HTML5 rendering loop recursively
    &lt;/span&gt;&lt;span style="color: black"&gt;requestAnimationFrame(drawingLoop);
}&lt;/span&gt;&lt;/pre&gt;
    &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;!-- end tabset --&gt;

&lt;p&gt;If you’ve managed to follow properly this first tutorial, you should obtain something like that:&lt;/p&gt;
&lt;iframe style="border-top: rgb(200,200,200) 1px solid; border-right: rgb(200,200,200) 1px solid; border-bottom: rgb(200,200,200) 1px solid; border-left: rgb(200,200,200) 1px solid" height="220" src="http://david.blob.core.windows.net/softengine3d/part1/index.html" width="340" scrolling="no"&gt;&lt;/iframe&gt;

&lt;p&gt;
  &lt;br /&gt;If not, &lt;strong&gt;download the solutions&lt;/strong&gt; containing the source code:&lt;/p&gt;

&lt;p&gt;- &lt;strong&gt;C#&lt;/strong&gt; : &lt;a title="http://david.blob.core.windows.net/softengine3d/SoftEngineCSharpPart1.zip" href="http://david.blob.core.windows.net/softengine3d/SoftEngineCSharpPart1.zip"&gt;SoftEngineCSharpPart1.zip&lt;/a&gt; 

  &lt;br /&gt;- &lt;strong&gt;TypeScript &lt;/strong&gt;: &lt;a title="http://david.blob.core.windows.net/softengine3d/SoftEngineTSPart1.zip" href="http://david.blob.core.windows.net/softengine3d/SoftEngineTSPart1.zip"&gt;SoftEngineTSPart1.zip&lt;/a&gt; 

  &lt;br /&gt;- &lt;strong&gt;JavaScript&lt;/strong&gt; : &lt;a title="http://david.blob.core.windows.net/softengine3d/SoftEngineJSPart1.zip" href="http://david.blob.core.windows.net/softengine3d/SoftEngineJSPart1.zip"&gt;SoftEngineJSPart1.zip&lt;/a&gt; or simply right-click –&amp;gt; view source on the embedded iframe&lt;/p&gt;

&lt;p&gt;Simply review the code and try to find what’s wrong with yours. :)&lt;/p&gt;

&lt;p&gt;In the next tutorial, we’re going to&lt;strong&gt; learn how to draw lines between each vertex&lt;/strong&gt; &amp;amp; the concept of faces/&lt;strong&gt;triangles&lt;/strong&gt; to obtain something like that:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8228.image_5F00_445B9E1D.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/7178.image_5F00_thumb_5F00_5C12D583.png" width="240" height="198" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;See you in the second part of this series: &lt;a title="http://blogs.msdn.com/b/davrous/archive/2013/06/14/tutorial-part-2-learning-how-to-write-a-3d-soft-engine-from-scratch-in-c-ts-or-js-drawing-lines-amp-triangles.aspx" href="http://blogs.msdn.com/b/davrous/archive/2013/06/14/tutorial-part-2-learning-how-to-write-a-3d-soft-engine-from-scratch-in-c-ts-or-js-drawing-lines-amp-triangles.aspx"&gt;Tutorial part 2: learning how to write a 3D soft engine from scratch in C#, TS or JS – drawing lines &amp;amp; triangles&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;David&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10425763" width="1" height="1"&gt;</content><author><name>David Rousset</name><uri>http://blogs.msdn.com/davrous/ProfileUrlRedirect.ashx</uri></author><category term="GPU" scheme="http://blogs.msdn.com/b/davrous/archive/tags/GPU/" /><category term="Tutorial" scheme="http://blogs.msdn.com/b/davrous/archive/tags/Tutorial/" /><category term="HTML5" scheme="http://blogs.msdn.com/b/davrous/archive/tags/HTML5/" /><category term="Canvas" scheme="http://blogs.msdn.com/b/davrous/archive/tags/Canvas/" /><category term="JavaScript" scheme="http://blogs.msdn.com/b/davrous/archive/tags/JavaScript/" /><category term="Windows 8" scheme="http://blogs.msdn.com/b/davrous/archive/tags/Windows+8/" /><category term="3DEngine" scheme="http://blogs.msdn.com/b/davrous/archive/tags/3DEngine/" /><category term="C#" scheme="http://blogs.msdn.com/b/davrous/archive/tags/C_2300_/" /><category term="TypeScript" scheme="http://blogs.msdn.com/b/davrous/archive/tags/TypeScript/" /></entry><entry><title>HTML5 Gaming: benchmarking your sprites animations to target all devices &amp; browsers</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/davrous/archive/2013/04/26/html5-gaming-benchmarking-sprites-animations-on-your-targeted-devices-amp-browsers.aspx" /><id>http://blogs.msdn.com/b/davrous/archive/2013/04/26/html5-gaming-benchmarking-sprites-animations-on-your-targeted-devices-amp-browsers.aspx</id><published>2013-04-26T16:06:57Z</published><updated>2013-04-26T16:06:57Z</updated><content type="html">&lt;p&gt;While meeting some game studios, I often have the same question coming over and over: if I’m writing/porting my game &lt;strong&gt;in HTML5, will it run well on the various targeted devices&lt;/strong&gt;? Will it be playable or will the gameplay suffer too much? To answer to that question, I often use my own experience based on what I know and what worked well during my own tests. But I also had the feeling it wasn’t enough to provide some good advices. In the meantime, there were some obvious facts. For instance, we all know that mobile devices can’t animate as many sprites as desktop PC and &lt;strong&gt;preserve 60 fps&lt;/strong&gt;. We know also that combining SVG and Canvas is a good idea to write games that scale across devices but this could also impact the performance. Moreover, even if GPU and hardware acceleration is available on mobile, their hardware architectures differ a lot from the PC and this impacts also a lot the performances. There is dozen of scenarios like that to address and to be aware of while writing HTML5 games for mobiles. But in which proportions?&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/7103.HTML5Potatoes_5F00_22E5699B.png"&gt;&lt;img title="HTML5 Potatoes logo" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; margin: 0px 10px 0px 0px; display: inline; border-top-width: 0px" border="0" alt="HTML5 Potatoes logo" align="left" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8171.HTML5Potatoes_5F00_thumb_5F00_5C880385.png" width="240" height="136" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;With my friend &lt;a href="http://blogs.msdn.com/b/eternalcoding/"&gt;David Catuhe&lt;/a&gt;, we then decided to measure these various scenarios and build a &lt;strong&gt;benchmark framework&lt;/strong&gt; to have a better idea on what to pay attention for. It’s named the HTML5 Potatoes Gaming Bench framework. The concept is then to help you benchmarking your targeted platforms and to obtain indicators for your future games: number of simultaneous sprites supported, SVG &amp;amp; Canvas composition performance, usage of videos, etc. It’s a tool we’d like to provide you to help you benchmarking your own scenarios for your games.&lt;/p&gt;  &lt;p&gt;David has published here an article explaining how we’ve built our benchmark framework: &lt;a title="http://blogs.msdn.com/b/eternalcoding/archive/2013/05/21/benchmarking-a-html5-game-html5-potatoes-gaming-bench.aspx" href="http://blogs.msdn.com/b/eternalcoding/archive/2013/05/21/benchmarking-a-html5-game-html5-potatoes-gaming-bench.aspx"&gt;Benchmarking a HTML5 game: HTML5 Potatoes Gaming Bench&lt;/a&gt; . It took us time to validate it against tools like the ones that ship wit the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/jj585574(v=vs.85).aspx"&gt;Windows Performance Toolkit&lt;/a&gt; for instance. But we won’t dig into that part here. But this is an important article to read as we needed to rely on the stability of the framework for all the future benchmarks we will build on top of it. &lt;/p&gt;  &lt;p&gt;This article will illustrate how to use this tool and will concentrate &lt;strong&gt;on the number of sprites you can use in your game to maintain a good frame rate on all platforms&lt;/strong&gt;. We will also discover interesting details on how GPU are actually being used during these scenarios. &lt;/p&gt;  &lt;h2&gt;The questions I was asking to myself before benchmarking&lt;/h2&gt;  &lt;p&gt;During my various discussions with some games developers, we were often wondering ourselves a list of recurring questions:&lt;/p&gt;  &lt;p&gt;- What the FPS of the benchmarked machine/browser with 200, 1000, 5000 sprites?    &lt;br /&gt;- What is the &lt;strong&gt;optimum&lt;/strong&gt; number of sprites the benchmarked device can display &lt;strong&gt;at 30 fps and 60 fps&lt;/strong&gt;?     &lt;br /&gt;- What is the &lt;strong&gt;impact of the resolution&lt;/strong&gt; of the canvas used to draw the sprites? Can I use a canvas of 800x480 only or can I scale up to 1920x1080? If so, what’s the performance cost?     &lt;br /&gt;- What is the &lt;strong&gt;performance cost of using &lt;a href="http://blogs.msdn.com/b/eternalcoding/archive/2012/03/22/unleash-the-power-of-html-5-canvas-for-gaming-part-1.aspx"&gt;hardware scaling&lt;/a&gt;&lt;/strong&gt; (i.e. setting a &lt;i&gt;style.width&lt;/i&gt; &amp;amp; &lt;i&gt;style.height&lt;/i&gt; higher than the canvas size itself)?&lt;/p&gt;  &lt;p&gt;I was wondering also if the performance was due to &lt;strong&gt;GPU or CPU limited scenarios&lt;/strong&gt;. The idea is to know if the CPU is waiting for the GPU to do its job or the opposite. &lt;/p&gt;  &lt;p&gt;To answer all these questions, I’ve built some specific benchmarks to measure the scenario.&lt;/p&gt;  &lt;h2&gt;The core used by all benchmarks in this article&lt;/h2&gt;  &lt;p&gt;To animate my sprites, I’ve re-used some of my existing assets like these 2 articles:&lt;/p&gt;  &lt;p&gt;- &lt;a href="http://blogs.msdn.com/b/davrous/archive/2011/07/21/html5-gaming-animating-sprites-in-canvas-with-easeljs.aspx"&gt;HTML5 Gaming: animating sprites in Canvas with EaselJS&lt;/a&gt;     &lt;br /&gt;- &lt;a href="http://blogs.msdn.com/b/davrous/archive/2011/07/29/html5-gaming-building-the-core-objects-amp-handling-collisions-with-easeljs.aspx"&gt;HTML5 Gaming: building the core objects &amp;amp; handling collisions with EaselJS&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;We will then use the famous &lt;a href="http://www.createjs.com/#!/EaselJS"&gt;EaselJS framework&lt;/a&gt; from the &lt;a href="http://www.createjs.com/#!/CreateJS"&gt;CreateJS suite&lt;/a&gt; as I know it runs everywhere and has already been optimized for performance. &lt;/p&gt;  &lt;p&gt;Please read the main logic exposed in this embedded demo available on JSFiddle:&lt;/p&gt; &lt;iframe style="border-top: rgb(255,255,255) 0px solid; height: 300px; border-right: rgb(255,255,255) 0px solid; border-bottom: rgb(255,255,255) 0px solid; border-left: rgb(255,255,255) 0px solid; width: 100%" src="http://jsfiddle.net/ppwFT/embedded/js,result/" scrolling="no"&gt;&lt;/iframe&gt;  &lt;p&gt;   &lt;br /&gt;We’re going to re-use the very same logic inside our benchmark framework.&lt;/p&gt;  &lt;p&gt;The various benchmarks are described like the simplified code below to be able to be integrated in the HTML5 Potatoes Gaming Bench framework:&lt;/p&gt;  &lt;pre class="code"&gt;(&lt;span style="color: blue"&gt;function &lt;/span&gt;() {
    &lt;span style="color: maroon"&gt;&amp;quot;use strict&amp;quot;&lt;/span&gt;;

    &lt;span style="color: blue"&gt;var &lt;/span&gt;canvas, context, stage, screen_width, screen_height, Monsters, contentManager;

    &lt;span style="color: blue"&gt;var &lt;/span&gt;spritesNumber, displayBench, currentWorkBench, dynamicSpritesNumberLabel;
    &lt;span style="color: blue"&gt;var &lt;/span&gt;shadowsEnabled = &lt;span style="color: blue"&gt;false&lt;/span&gt;;
    &lt;span style="color: blue"&gt;var &lt;/span&gt;useRAF = &lt;span style="color: blue"&gt;false&lt;/span&gt;;

    &lt;span style="color: blue"&gt;var &lt;/span&gt;init = &lt;span style="color: blue"&gt;function &lt;/span&gt;(workbench, spritesNumParam, shadowsEnabledParam, canvasSizeXParam, &lt;br /&gt;                         canvasSizeYParam, then) {
        &lt;span style="color: #006400"&gt;// Initialization logic, creating the canvas, the EaselJS Stage, etc.
&lt;/span&gt;    };

    &lt;span style="color: blue"&gt;var &lt;/span&gt;buildFixNumberOfSprites = &lt;span style="color: blue"&gt;function &lt;/span&gt;() {
        &lt;span style="color: #006400"&gt;// Our Monsters collection
        &lt;/span&gt;Monsters = &lt;span style="color: blue"&gt;new &lt;/span&gt;Array();

        &lt;span style="color: blue"&gt;for &lt;/span&gt;(&lt;span style="color: blue"&gt;var &lt;/span&gt;xMonsters = 0; xMonsters &amp;lt; spritesNumber; xMonsters++) {
            &lt;span style="color: blue"&gt;var &lt;/span&gt;newRandomMonster = &lt;span style="color: blue"&gt;new &lt;/span&gt;Monster(contentManager, shadowsEnabled, screen_width, screen_height);
            Monsters.push(newRandomMonster);
            stage.addChild(newRandomMonster);
        }

&lt;span style="color: #006400"&gt;        &lt;/span&gt;createjs.Ticker.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;tick&amp;quot;&lt;/span&gt;, tick);
        &lt;span style="color: #006400"&gt;// Best Framerate targeted (60 FPS)
        &lt;/span&gt;createjs.Ticker.useRAF = useRAF;
        createjs.Ticker.setFPS(60);

        &lt;span style="color: #006400"&gt;// Waiting 1s before doing taking first FPS due to some warm up needed on most machines
        &lt;/span&gt;setTimeout(displayBench, 1000);
    };

    &lt;span style="color: #006400"&gt;// tick function called-back by EaselJS
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;tick = &lt;span style="color: blue"&gt;function &lt;/span&gt;() {
        &lt;span style="color: #006400"&gt;// looping inside the Monsters collection
        &lt;/span&gt;&lt;span style="color: blue"&gt;for &lt;/span&gt;(&lt;span style="color: blue"&gt;var &lt;/span&gt;monster &lt;span style="color: blue"&gt;in &lt;/span&gt;Monsters) {
            &lt;span style="color: blue"&gt;var &lt;/span&gt;m = Monsters[monster];
            &lt;span style="color: #006400"&gt;// Calling explicitly each tick method 
            // to launch the update logic of each monster
            &lt;/span&gt;m.tick();
        }

        &lt;span style="color: #006400"&gt;// update the stage:
        &lt;/span&gt;stage.update();
    }

    &lt;span style="color: blue"&gt;var &lt;/span&gt;stopEaselJSBench = &lt;span style="color: blue"&gt;function &lt;/span&gt;() {
        &lt;span style="color: #006400"&gt;// cleaning things &lt;/span&gt;
    }

    &lt;span style="color: blue"&gt;var &lt;/span&gt;easelJSSpritesBench_200_NoShadow_640_480 = &lt;span style="color: blue"&gt;new &lt;/span&gt;POTATOES.GamingBench.Bench(&lt;span style="color: maroon"&gt;&amp;quot;Drawing 200 sprites &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: maroon"&gt;(640x480)&amp;quot;&lt;/span&gt;, &lt;span style="color: maroon"&gt;&amp;quot;http://blogs.msdn.com/davrous&amp;quot;&lt;/span&gt;,
        &lt;span style="color: blue"&gt;function &lt;/span&gt;(workbench) { &lt;span style="color: #006400"&gt;// Init
            &lt;/span&gt;init(workbench, 200, &lt;span style="color: blue"&gt;false&lt;/span&gt;, 640, 480, &lt;span style="color: blue"&gt;this&lt;/span&gt;.onInitCompleted);
        }, &lt;span style="color: blue"&gt;function &lt;/span&gt;() { }, &lt;span style="color: blue"&gt;function &lt;/span&gt;(workbench) { &lt;span style="color: #006400"&gt;// End
            &lt;/span&gt;stopEaselJSBench();
        });

    POTATOES.GamingBench.registerBench(easelJSSpritesBench_200_NoShadow_640_480);
})();&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;You will need to build equivalent code to build your own benchmarks that will be monitored by the framework. The key point is to add your benchmark definition into the monitored collection via the &lt;em&gt;registerBench&lt;/em&gt; function.&lt;/p&gt;

&lt;p&gt;To validate my layout (but not the performance) on the various available browsers and devices, I’ve used &lt;strong&gt;Browser Stack.&lt;/strong&gt; Thanks to &lt;a href="http://modern.ie"&gt;Modern.IE&lt;/a&gt;, you can obtain a 3 months trial. It lets you test and validate your websites layouts on &lt;strong&gt;IE from 6 to 10, Firefox, Chrome, Opera, Android &amp;amp; iOS devices&lt;/strong&gt;. A very useful tool you should have a look to. &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/3527.image_5F00_3EDB2BD6.png"&gt;&lt;img title="Using Browser Stack to test IE10, Firefox, Chrome, Opera, iOS &amp;amp; Android" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="Using Browser Stack to test IE10, Firefox, Chrome, Opera, iOS &amp;amp; Android" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/1057.image_5F00_thumb_5F00_6B17B2BA.png" width="640" height="301" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Most of the below shared results were done on an Asus Ultrabook UX31A (Zenbook Touch) running &lt;strong&gt;Windows 8 Pro on a Core i5 integrating an HD4000 GPU&lt;/strong&gt; from Intel. But I’ve done also some tests on the &lt;strong&gt;Nokia Lumia 920, &lt;/strong&gt;on an &lt;strong&gt;iPad 2&lt;/strong&gt; under iOS 6.0, &lt;strong&gt;Surface RT&lt;/strong&gt; and &lt;strong&gt;Xbox 360&lt;/strong&gt;. I’m letting you testing the shared benchmarks on your own devices. &lt;/p&gt;

&lt;h2&gt;Average FPS with 200, 1000 &amp;amp; 5000 sprites&lt;/h2&gt;

&lt;p&gt;Let’s start by testing some arbitrary numbers of sprites to check how your device/browser will handle that. &lt;/p&gt;

&lt;p&gt;Just below, inside an iframe, I’ve inserted a series of benchmarks that will run &lt;strong&gt;some sprints of 20 seconds&lt;/strong&gt; to display in a 640x480 canvas: 200 sprites without shadow, 200 sprites with shadows enabled, 1000 sprites &amp;amp; 5000 sprites without shadow.&lt;/p&gt;

&lt;p&gt;Just &lt;strong&gt;press the “&lt;em&gt;launch prefixed sprites numbers series&lt;/em&gt;” button&lt;/strong&gt; and it will run all of them. &lt;/p&gt;
&lt;iframe style="border-top: rgb(200,200,200) 1px solid; height: 600px; border-right: rgb(200,200,200) 1px solid; border-bottom: rgb(200,200,200) 1px solid; border-left: rgb(200,200,200) 1px solid; width: 914px" src="http://david.blob.core.windows.net/html5/perf/prefixednumbers/index.htm" scrolling="no"&gt;&lt;/iframe&gt;

&lt;p&gt;
  &lt;br /&gt;You can also run this benchmark in full screen or in a separate window via this link: &lt;a href="http://david.blob.core.windows.net/html5/perf/prefixednumbers/index.htm"&gt;prefixed sprites numbers series benchmark&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;At the end, you will have a summary of all benchmarks with a score. The score is simply the number of frames that your device was able to render in 20 seconds. &lt;strong&gt;The best logical score is then 1200&lt;/strong&gt;. As you can render 60 frames per seconds * 20 seconds = 1200 frames. We’re using requestAnimationFrame when available. So it could sometimes occurs where the tick is calling us back just a bit above 16ms, that why you could have some cases where you will have 1201 like in the following screenshot:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4135.image_5F00_457BD36B.png"&gt;&lt;img title="HTML5 Potatoes Gaming Bench summary scores" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="HTML5 Potatoes Gaming Bench summary scores" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4213.image_5F00_thumb_5F00_78D796C7.png" width="400" height="259" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;If you’re clicking on the average FPS computed, it will display the graph of all instant measured FPS during the complete duration of the benchmark. We’re using the famous &lt;a href="http://d3js.org/"&gt;d3.js&lt;/a&gt; framework for that which generate some SVG. &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/6011.image_5F00_181D3B95.png"&gt;&lt;img title="HTML5 Potatoes Gaming Bench FPS chart" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="HTML5 Potatoes Gaming Bench FPS chart" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5430.image_5F00_thumb_5F00_0FB9663E.png" width="400" height="259" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Press the “Back” button to go back to the summary screen or simply touch the graph also. &lt;/p&gt;

&lt;h3&gt;Some results and their analysis&lt;/h3&gt;

&lt;p&gt;I’ve first run this benchmark on my Windows 8 machine with IE10, Chrome 26, Firefox 20 all with hardware acceleration enabled. The good news is that&lt;strong&gt; all the modern desktop browsers have some really good hardware acceleration layers &lt;/strong&gt;in place. IE10 seems to have the best overall score (3030 on my machine) but can’t handle the shadows as well as Chrome (average 27 fps with 200 sprites vs 12 for IE10). Chrome has an overall score of 2870. It can’t maintain 60 fps with 1000 sprites on my screen whereas IE10 and Firefox don’t have any problem to achieve that. Firefox 20 has an overall score of 2913. The most difficult test for it is to handle the 200 sprites with shadows (average of 6 fps vs 12 and 27 for IE10 and Chrome). Except that, it has the exact same scores as IE10.&lt;/p&gt;

&lt;p&gt;So, what should we conclude at this stage? The first thing is that &lt;strong&gt;you absolutely shouldn’t tell to your users: “please use this browser instead”&lt;/strong&gt; as we’re talking here about building games for the web and all platforms. The users shouldn’t adapt their usages to your code, your code should adapt itself to the usages of your users on the web. This is a different story if you’re building a game only targeting the Windows Store Apps. In this case, you just have to benchmark IE10 to determine your assets limits. &lt;/p&gt;

&lt;p&gt;But if we think about the web in general, we see that &lt;strong&gt;all browsers on can easily handle between 500 and 1000 sprites at 60 fps on my desktop machine&lt;/strong&gt;. We absolutely shouldn’t use shadows if we want to keep a good frame rate. For an HTML5 desktop game targeting integrated Intel GPU like mine, you can use a bit less than 1000 animated sprites on screen without any issue. Please keep in mind that this test doesn’t take into account some collisions tests and/or the impact of a physics engine. But it already gives some interesting data.&lt;/p&gt;

&lt;p&gt;On the mobile side, I’ve run the same series on my Nokia Lumia 920 (Windows Phone 8 is embedding IE10). It can maintain an average of 36 fps for 200 sprites without shadow. Activating shadows is a no-go as we’re falling at 1 fps. &lt;/p&gt;

&lt;p&gt;So, we already have some interesting information to digest. The same rendering and JavaScript engine (IE10) is able to display 1000 sprites at 60 fps on a desktop PC using an integrated GPU but 200 sprites is already too much to handle for low-end hardware like the current ARM architectures. &lt;strong&gt;There is a 5X to 10X performance difference between a mobile and a desktop device&lt;/strong&gt;. So the next step now is to find what is the optimum number of sprites to maintain 60 fps (for a good desktop experience) and also 30 fps (for a relatively good mobile experience). &lt;/p&gt;

&lt;h2&gt;Optimum number of sprites at 30 and 60 fps&lt;/h2&gt;

&lt;p&gt;To help you finding the best optimal lower number of sprites that will keep a 30 or 60 fps target, I’ve built the following benchmark series:&lt;/p&gt;
&lt;iframe style="border-top: rgb(200,200,200) 1px solid; height: 600px; border-right: rgb(200,200,200) 1px solid; border-bottom: rgb(200,200,200) 1px solid; border-left: rgb(200,200,200) 1px solid; width: 914px" src="http://david.blob.core.windows.net/html5/perf/dynamicnumbers/index.htm" scrolling="no"&gt;&lt;/iframe&gt;

&lt;p&gt;
  &lt;br /&gt;You can also run this benchmark in full screen or in a separate window via this link: &lt;a href="http://david.blob.core.windows.net/html5/perf/dynamicnumbers/index.htm"&gt;launch 30 and 60 fps target series&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;Some results and their analysis&lt;/h3&gt;

&lt;p&gt;This time &lt;strong&gt;the score provided at the end is the number of optimal sprites to maintain 30 or 60 fps&lt;/strong&gt;. On IE10 on my Windows 8 Asus machine, the HD4000 is able to display 3750+ sprites at 30 fps and 1600 sprites at 60 fps. IE10 on my Nokia Lumia 920 running Windows Phone 8, I’m able to display 286 sprites at 30 fps and 75 at 60 fps. On Surface RT, IE10 is able to display 370+ sprites at 30 fps and 100+ sprites at 60 fps. &lt;/p&gt;

&lt;p&gt;We’re then &lt;strong&gt;falling from 1600 sprites on desktop to 75 on mobile&lt;/strong&gt;! &lt;/p&gt;

&lt;p&gt;I’ve even gone further: I’ve &lt;strong&gt;benchmarked the version of IE available on the Xbox 360&lt;/strong&gt;. Indeed, we can imagine building a HTML5 game running inside the Xbox 360 browser. I’ve done it with my game for instance. You can test it here: &lt;a href="http://aka.ms/platformer"&gt;http://aka.ms/platformer&lt;/a&gt; . You can play to the game with the gamepad and we’ve got 60+ FPS! You can also play to the game on mobile/table touch devices thanks to Hand.JS (more details here: &lt;a title="http://blogs.msdn.com/b/davrous/archive/2013/02/22/creating-an-universal-virtual-touch-joystick-working-for-all-touch-models-thanks-to-hand-js.aspx" href="http://blogs.msdn.com/b/davrous/archive/2013/02/22/creating-an-universal-virtual-touch-joystick-working-for-all-touch-models-thanks-to-hand-js.aspx"&gt;Creating an universal virtual touch joystick working for all Touch models thanks to Hand.JS&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;Let benchmark it with the 30/60 fps target series:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4265.WP_5F00_20130426_5F00_005_5F00_51E32734.jpg"&gt;&lt;img title="Xbox 360 running HTML5 Potatoes FX 1" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="Xbox 360 running HTML5 Potatoes FX 1" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0647.WP_5F00_20130426_5F00_005_5F00_thumb_5F00_4575040B.jpg" width="640" height="360" /&gt;&lt;/a&gt; 

  &lt;br /&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8562.WP_5F00_20130426_5F00_008_5F00_644B77E9.jpg"&gt;&lt;img title="Xbox 360 running HTML5 Potatoes FX 2" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="Xbox 360 running HTML5 Potatoes FX 2" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/3771.WP_5F00_20130426_5F00_008_5F00_thumb_5F00_5534990F.jpg" width="320" height="180" /&gt;&lt;/a&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/3683.WP_5F00_20130426_5F00_014_5F00_622E7920.jpg"&gt;&lt;img title="Xbox 360 running HTML5 Potatoes FX 3" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="Xbox 360 running HTML5 Potatoes FX 3" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0647.WP_5F00_20130426_5F00_014_5F00_thumb_5F00_0AE9DE6A.jpg" width="320" height="180" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;The Xbox 360 can display 171 sprites to maintain 30 fps and 43 to maintain 60 fps. &lt;/p&gt;

&lt;p&gt;So, using Internet Explorer as a base of comparison, &lt;strong&gt;Asus Zenbook &amp;gt; Surface RT &amp;gt; Nokia Lumia 920 &amp;gt; Xbox 360 to maintain 60 fps&lt;/strong&gt; in HTML5 games with sprites animations. &lt;/p&gt;

&lt;p&gt;I was also curious about changing another parameter to confirm some of my thoughts. I was convinced that the most importance piece of hardware to boost the performance in my HTML5 games was the GPU. Indeed, all modern browsers are now heavily using them to offload the job needed to be done for the layout engine. I needed then to have the same machine with 2 GPUs available. Everything else should remain the same (CPU, memory, hard drive, screen resolution, etc.). For that, I’ve been using a Sony Vaio Z13 that has an Intel Core i7 Sandy Bridge processor with an integrated HD3000 GPU plus a discrete nVidia GT330m GPU. &lt;/p&gt;

&lt;p&gt;Using Intel HD3000, the Vaio is able to display 2900 sprites @30fps and 1100 sprites @60fps. Using the nVidia GT330m, the very same Vaio is able to display 5400 sprites @30fps and 2500 @60fps. We then have approximately a X2 performance boost by switching from the Intel GPU to the nVidia GPU. &lt;strong&gt;GPU really matters for HTML5 games even for 2D canvas games&lt;/strong&gt;. &lt;/p&gt;

&lt;table cellspacing="0" cellpadding="2" width="450" border="0"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td width="225"&gt;
        &lt;table cellspacing="0" cellpadding="0" width="450" border="1"&gt;&lt;tbody&gt;
            &lt;tr&gt;
              &lt;td width="199"&gt;
                &lt;p align="center"&gt;&lt;strong&gt;Device tested&lt;/strong&gt;&lt;/p&gt;
              &lt;/td&gt;

              &lt;td width="124"&gt;
                &lt;p align="center"&gt;&lt;strong&gt;Max sprites @30fps&lt;/strong&gt;&lt;/p&gt;
              &lt;/td&gt;

              &lt;td width="125"&gt;
                &lt;p align="center"&gt;&lt;strong&gt;Max sprites @60fps&lt;/strong&gt;&lt;/p&gt;
              &lt;/td&gt;
            &lt;/tr&gt;

            &lt;tr&gt;
              &lt;td width="199"&gt;Asus Zenbook with &lt;strong&gt;HD4000&lt;/strong&gt;&lt;/td&gt;

              &lt;td width="124"&gt;
                &lt;p align="center"&gt;3750&lt;/p&gt;
              &lt;/td&gt;

              &lt;td width="125"&gt;
                &lt;p align="center"&gt;1600&lt;/p&gt;
              &lt;/td&gt;
            &lt;/tr&gt;

            &lt;tr&gt;
              &lt;td width="199"&gt;Sony Vaio Z13 with &lt;strong&gt;HD3000&lt;/strong&gt;&lt;/td&gt;

              &lt;td width="124"&gt;
                &lt;p align="center"&gt;2900&lt;/p&gt;
              &lt;/td&gt;

              &lt;td width="125"&gt;
                &lt;p align="center"&gt;1100&lt;/p&gt;
              &lt;/td&gt;
            &lt;/tr&gt;

            &lt;tr&gt;
              &lt;td width="199"&gt;Sony Vaio Z13 with &lt;strong&gt;GT330m&lt;/strong&gt;&lt;/td&gt;

              &lt;td width="124"&gt;
                &lt;p align="center"&gt;5400&lt;/p&gt;
              &lt;/td&gt;

              &lt;td width="125"&gt;
                &lt;p align="center"&gt;2500&lt;/p&gt;
              &lt;/td&gt;
            &lt;/tr&gt;

            &lt;tr&gt;
              &lt;td width="199"&gt;&lt;strong&gt;Surface RT&lt;/strong&gt;&lt;/td&gt;

              &lt;td width="124"&gt;
                &lt;p align="center"&gt;370&lt;/p&gt;
              &lt;/td&gt;

              &lt;td width="125"&gt;
                &lt;p align="center"&gt;100&lt;/p&gt;
              &lt;/td&gt;
            &lt;/tr&gt;

            &lt;tr&gt;
              &lt;td width="199"&gt;Nokia &lt;strong&gt;Lumia 920&lt;/strong&gt;&lt;/td&gt;

              &lt;td width="124"&gt;
                &lt;p align="center"&gt;286&lt;/p&gt;
              &lt;/td&gt;

              &lt;td width="125"&gt;
                &lt;p align="center"&gt;75&lt;/p&gt;
              &lt;/td&gt;
            &lt;/tr&gt;

            &lt;tr&gt;
              &lt;td width="199"&gt;&lt;strong&gt;Xbox 360&lt;/strong&gt;&lt;/td&gt;

              &lt;td width="124"&gt;
                &lt;p align="center"&gt;171&lt;/p&gt;
              &lt;/td&gt;

              &lt;td width="125"&gt;
                &lt;p align="center"&gt;43 &lt;/p&gt;
              &lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;&lt;/table&gt;
      &lt;/td&gt;

      &lt;td valign="top" width="225"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/2451.image_5F00_49FF5706.png"&gt;&lt;img title="Comparing 30/60 FPS results on Internet Explorer between devices" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; margin-left: 0px; display: inline; border-top-width: 0px; margin-right: 0px" border="0" alt="Comparing 30/60 FPS results on Internet Explorer between devices" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/7242.image_5F00_thumb_5F00_6F88D467.png" width="480" height="388" /&gt;&lt;/a&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;
      &lt;br /&gt;Conclusion:&lt;/u&gt;&lt;/strong&gt; you have 3 options here to build a cross-platforms game running fine everywhere.&amp;#160; You’re &lt;strong&gt;taking the lowest value&lt;/strong&gt; (43 sprites here) and you will never put more that this number of sprites on screen to be sure to have 60 fps everywhere on Xbox 360, Windows Phone 8, Surface RT and Windows 8 machine running HD4000 GPUs. Of course, you need to run the same benchmark on your other targeted platforms: Android tablets &amp;amp; phone, iOS tablets &amp;amp; phone, and so on to find the optimal magic number. &lt;/p&gt;

&lt;p&gt;Taking this first option is the easiest one but it’s a pity that desktop machines are under exploited. A&lt;strong&gt; second option is then to build 2 versions of the game&lt;/strong&gt; (like 2 versions of your websites): 1 for mobile and 1 for phone. You will just adjust the graphical complexity based on the performance of each platform. Or you can also take the optimal number on mobile to target 30 fps and you will be sure to run @60 fps on desktop. The idea is then to target 30 fps on mobile/tablets and 60 on desktop. &lt;/p&gt;

&lt;p&gt;Lastly, the third and &lt;strong&gt;last option is to build a game engine that will itself dynamically adjust the complexity of the graphical engine&lt;/strong&gt; based on the performance detected. Something that some game studios are frequently doing on PC for instance. It requires more work for sure and you need also to decide the kind of assets that will be displayed or not in your game without impacting the global gameplay. &lt;/p&gt;

&lt;p&gt;But today, doing this kind of benchmark is really critical if you’re targeting the mobile markets. Use a &lt;strong&gt;“mobile first” approach&lt;/strong&gt;, otherwise you will get into trouble to optimize the performance for these lower GPUs. &lt;/p&gt;

&lt;h2&gt;Impact of the canvas resolution&lt;/h2&gt;

&lt;p&gt;This time we’re going to always display the same number of sprites (500) but we’re going to vary the &lt;strong&gt;resolution&lt;/strong&gt; of the canvas: &lt;strong&gt;320x200&lt;/strong&gt;, &lt;strong&gt;640x480&lt;/strong&gt;, &lt;strong&gt;1024x768&lt;/strong&gt; and &lt;strong&gt;1920x1080&lt;/strong&gt;. I was convinced on my side that increasing the resolution would lower the average FPS for sure, even just to display some animated sprites. Well, let’s check that:&lt;/p&gt;
&lt;iframe style="border-top: rgb(200,200,200) 1px solid; height: 600px; border-right: rgb(200,200,200) 1px solid; border-bottom: rgb(200,200,200) 1px solid; border-left: rgb(200,200,200) 1px solid; width: 914px" src="http://david.blob.core.windows.net/html5/perf/variousresolutions/index.htm" scrolling="no"&gt;&lt;/iframe&gt;

&lt;p&gt;
  &lt;br /&gt;You can also run this benchmark in full screen or in a separate window via this link: &lt;a href="http://david.blob.core.windows.net/html5/perf/variousresolutions/index.htm"&gt;launch various canvas resolutions series &lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;Some results and their analysis&lt;/h3&gt;

&lt;p&gt;Well, look at the result in IE10 on my machine:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5430.image_5F00_30ED291F.png"&gt;&lt;img title="IE10 scores 1200 on all resolutions" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="IE10 scores 1200 on all resolutions" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8078.image_5F00_thumb_5F00_086E470B.png" width="400" height="241" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;On my machine, the &lt;strong&gt;various resolutions had 0 impact on the average framerate&lt;/strong&gt;! This is also confirmed on my mobile WP8 devices and on Xbox 360. Only Chrome has a lower average FPS only in 320x200 for an unknown reason. This doesn’t seem logical. But it’s probably because of a specific optimization I’m not aware of. Firefox and all other rendering/JavaScript engines I’ve been testing on several devices provide the same result: resolutions has no impact on the global performance in my scenario.&lt;/p&gt;

&lt;p&gt;Please note also that&lt;strong&gt; this doesn’t mean you shouldn’t take care of the resolution of your canvas&lt;/strong&gt; for your global performance. This just means that for sprites animations, and with this specific benchmark, the resolution has no impact. The GPU seems to take the load without any problem even on mobile platforms. I was very surprised by these first results so I’ve done further tests and benchmarks. &lt;/p&gt;

&lt;p&gt;To double check that GPUs weren’t saturated, I had the following idea. As I’ve got a laptop machine embedding 2 GPUs, a Sony Vaio Z13. It has a nVidia GT330m and an Intel HD3000 integrated GPU. The Intel HD3000 contains up to 12 scalar 128-bit execution units where the nVidia GT330m contains 48 128-bit execution units. &lt;/p&gt;

&lt;p&gt;There are also tools that help to check the load of the GPU. For instance, &lt;a href="http://www.techpowerup.com/gpuz/"&gt;GPU-Z&lt;/a&gt; can &lt;strong&gt;provide you the GPU Load in realtime&lt;/strong&gt;. I’ve then run the last benchmark series first on the nVidia GPU with GPU-Z opened on the “&lt;em&gt;Sensors&lt;/em&gt;” tab to verify the GPU load: &lt;strong&gt;15%&lt;/strong&gt; at 320x200, &lt;strong&gt;30%&lt;/strong&gt; at 640x480, &lt;strong&gt;25%&lt;/strong&gt; at 1024x768, &lt;strong&gt;55%&lt;/strong&gt; at 1920x1080 (don’t ask me why it’s lower in 1024 than in 640, I really don’t know why ;)). &lt;/p&gt;

&lt;p&gt;Then, I’ve re-run the same benchmark on the HD3000: &lt;strong&gt;30%&lt;/strong&gt; at 320x200, &lt;strong&gt;40%&lt;/strong&gt; at 640x480, &lt;strong&gt;62%&lt;/strong&gt; at 1024x768 &amp;amp; &lt;strong&gt;100%&lt;/strong&gt; at 1920x1080. Logically, this time, the average FPS drop from 60 fps in 320x200 –&amp;gt; 1024x768 to 55 fps in 1080p. &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5270.intelHD3000_5F00_GPULOAD_5F00_Optimal60fps_5F00_26DFA4C2.jpg"&gt;&lt;img title="intel HD3000 GPULOAD 100%" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; margin: 0px 15px 0px 0px; display: inline; border-top-width: 0px" border="0" alt="intel HD3000 GPULOAD 100%" align="left" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0676.intelHD3000_5F00_GPULOAD_5F00_Optimal60fps_5F00_thumb_5F00_259B0BE3.jpg" width="195" height="240" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Being below 60 fps is because we’re falling into a GPU limited scenario. You can’t do anything else than lowering the rendering resolution and/or display less sprites, etc. By the way, I’ve done some testing and using “&lt;strong&gt;hardware scaling&lt;/strong&gt;” like described in this article: &lt;a title="http://blogs.msdn.com/b/eternalcoding/archive/2012/03/22/unleash-the-power-of-html-5-canvas-for-gaming-part-1.aspx" href="http://blogs.msdn.com/b/eternalcoding/archive/2012/03/22/unleash-the-power-of-html-5-canvas-for-gaming-part-1.aspx"&gt;Unleash the power of HTML 5 Canvas for gaming&lt;/a&gt; has almost no impact on the global average FPS as this operation seems to be done with no effort by today’s GPU even on mobile. This is then a real good option to have in mind. If the frame rate is too low due to a too high GPU load, try to render your canvas in a lower resolution and stretch it full screen using this hardware scaling method. &lt;/p&gt;

&lt;p&gt;There could be cases where the lost of frames will be due to CPU limited scenarios. To monitor that, you need profiler tools like the one embedded in most recent browsers. You will then see which parts of your code you should try to work on to regain some FPS. You need to avoid that the GPU is waiting too long for the CPU to do its job. Some cases could be optimized using the &lt;a href="http://blogs.msdn.com/b/davrous/archive/2011/07/15/introduction-to-the-html5-web-workers-the-javascript-multithreading-approach.aspx"&gt;HTML5 Web Workers&lt;/a&gt; for instance.&lt;/p&gt;

&lt;p&gt;But I’ve found also some very specific cases where dropping under 60 fps was due to more complex reasons. Here is one of them: GPU-Z shows a GPU load around 50% but the FPS is below 60 fps. Using the F12 tool included in IE10 to profile the code shows the following result:&amp;#160; &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/3122.image_5F00_0DAEF690.png"&gt;&lt;img title="IE10 F12 screenshot" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="IE10 F12 screenshot" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5661.image_5F00_thumb_5F00_4BC81141.png" width="640" height="318" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;It will only show that you’re limited by the &lt;em&gt;drawImage&lt;/em&gt; function. &lt;em&gt;drawImage&lt;/em&gt; is a native function handled by the browser. It’s probably mixing CPU usage and GPU usage. You can’t optimize this part at this level in JavaScript. So, you just need to deal with it!&lt;/p&gt;

&lt;h3&gt;Going even further&lt;/h3&gt;

&lt;p&gt;You can have a look to the set of tools available in the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/jj585574(v=vs.85).aspx"&gt;Windows Performance Toolkit&lt;/a&gt; and read the following methodology: &lt;a title="http://blogs.msdn.com/b/ie/archive/2010/06/21/measuring-browser-performance-with-the-windows-performance-tools.aspx" href="http://blogs.msdn.com/b/ie/archive/2010/06/21/measuring-browser-performance-with-the-windows-performance-tools.aspx"&gt;Measuring Browser Performance with the Windows Performance Tools&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You’re also probably wondering why we have such slight FPS drops even with a relatively constant 60 average fps:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/6886.image_5F00_6E63A0CC.png"&gt;&lt;img title="Graph showing FPS drops because of GC" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="Graph showing FPS drops because of GC" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/2161.image_5F00_thumb_5F00_4D03FB30.png" width="450" height="253" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;With &lt;a href="http://blogs.msdn.com/b/eternalcoding/"&gt;David Catuhe&lt;/a&gt;, we had a precise idea why. But again it’s better to be able to verify it. I’ve then used the following methodology: &lt;/p&gt;

&lt;p&gt;- Create a blank Visual Studio 2012 &lt;strong&gt;Windows Store App project&lt;/strong&gt;. Indeed, as &lt;strong&gt;Windows 8 is using IE10 to run Windows Store App in HTML5&lt;/strong&gt;, I had just to copy/paste the code of one of the benchmarks and I had a Windows Store app ready to be analyzed by Visual Studio. :) You can download this test project here if you’d like: &lt;a title="http://david.blob.core.windows.net/html5/perf/HTML5PotatoesModernApp.zip" href="http://david.blob.core.windows.net/html5/perf/HTML5PotatoesModernApp.zip"&gt;HTML5PotatoesModernApp.zip&lt;/a&gt; 

  &lt;br /&gt;- I’ve setup a unique bench displaying 1000 sprites and gone into “&lt;strong&gt;Analyze&lt;/strong&gt;” –&amp;gt; “&lt;strong&gt;JavaScript Analysis&lt;/strong&gt;” –&amp;gt; “&lt;strong&gt;UI Responsiveness&lt;/strong&gt;” –&amp;gt; “&lt;strong&gt;Launch Startup Project&lt;/strong&gt;”:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/1682.image_5F00_5ED1F716.png"&gt;&lt;img title="How to launch Visual Studio JavaScript Analysis tool" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="How to launch Visual Studio JavaScript Analysis tool" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5808.image_5F00_thumb_5F00_240A4E40.png" width="640" height="348" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;After some processing, you will obtain such results:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/7065.image_5F00_467EDCFB.png"&gt;&lt;img title="Visual Studio JavaScript UI Responsiveness tool" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="Visual Studio JavaScript UI Responsiveness tool" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/3755.image_5F00_thumb_5F00_00F9DCD0.png" width="900" height="311" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;We can see that this is the GC which is responsible for the drop of some frames. I remember reading interesting details about GC in this article: &lt;a title="http://phoboslab.org/log/2011/08/are-we-fast-yet" href="http://phoboslab.org/log/2011/08/are-we-fast-yet"&gt;Are We Fast Yet?&lt;/a&gt; associated to this other benchmark: &lt;a title="http://html5-benchmark.com/" href="http://html5-benchmark.com/"&gt;HTML5-Benchmark&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;You know what I really like about this whole story? Even with a high level layer like HTML5, &lt;strong&gt;understanding the targeted architectures will always help you to optimize your code for your HTML5 games&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;This is really what you should keep in mind to build your games that should scale across all HTML5 compatible devices. It’s now possible to have a unique code base to run everywhere. But layout &amp;amp; JavaScript compatibilities is just a small part of the story. You need to know which devices you’re going to target, understand their limitations &amp;amp; GPU characteristics and finally benchmark all of them to take the appropriate design decisions for your games.&lt;/p&gt;

&lt;p&gt;I really hope that this article and our benchmark framework will help you in your future HTML5 games. We will soon work on similar articles focused on other topics important for HTML5 games.&amp;#160; &lt;/p&gt;

&lt;p&gt;David&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10414279" width="1" height="1"&gt;</content><author><name>David Rousset</name><uri>http://blogs.msdn.com/davrous/ProfileUrlRedirect.ashx</uri></author><category term="GPU" scheme="http://blogs.msdn.com/b/davrous/archive/tags/GPU/" /><category term="HTML5" scheme="http://blogs.msdn.com/b/davrous/archive/tags/HTML5/" /><category term="Canvas" scheme="http://blogs.msdn.com/b/davrous/archive/tags/Canvas/" /><category term="IE10" scheme="http://blogs.msdn.com/b/davrous/archive/tags/IE10/" /><category term="EaselJS" scheme="http://blogs.msdn.com/b/davrous/archive/tags/EaselJS/" /><category term="Windows 8" scheme="http://blogs.msdn.com/b/davrous/archive/tags/Windows+8/" /><category term="Windows Phone 8" scheme="http://blogs.msdn.com/b/davrous/archive/tags/Windows+Phone+8/" /><category term="HandJS" scheme="http://blogs.msdn.com/b/davrous/archive/tags/HandJS/" /></entry><entry><title>Introduction aux Pointer Events ou comment simplifier l’usage du tactile dans vos sites web pour tous les navigateurs</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/davrous/archive/2013/03/29/introduction-aux-pointer-events-et-comment-simplifier-le-support-du-tactile-au-sein-de-tous-les-navigateurs.aspx" /><id>http://blogs.msdn.com/b/davrous/archive/2013/03/29/introduction-aux-pointer-events-et-comment-simplifier-le-support-du-tactile-au-sein-de-tous-les-navigateurs.aspx</id><published>2013-03-29T18:17:03Z</published><updated>2013-03-29T18:17:03Z</updated><content type="html">&lt;!-- Include the VideoJS Library --&gt;&lt;script type="text/javascript" charset="utf-8" src="http://david.blob.core.windows.net/videos/video-js/video.js"&gt;&lt;/script&gt;&lt;script type="text/javascript"&gt;// &lt;![CDATA[
    
	VideoJS.setupAllWhenReady();
  
// ]]&gt;&lt;/script&gt;&lt;link title="Video JS" rel="stylesheet" type="text/css" href="http://david.blob.core.windows.net/videos/video-js/video-js.css" media="screen" /&gt;  &lt;p&gt;Aujourd’hui, la gestion du tactile (ou « touch » en anglais) est devenu obligatoire sur vos sites web. C’est un passage obligé si vous voulez que votre site soit bien adapté aux nombreux périphériques tactiles du marché : tablettes, smartphones et la panoplie de nouveaux PC tactiles. Ce n’est pas pour autant quelque chose de forcément simple à mettre à œuvre. Entre les différentes implémentations disponibles et l’obligation de continuer à supporter la souris en parallèle, il faut parfois écrire du code un peu rébarbatif à réaliser. J’aimerais ainsi vous présenter dans cet article notre approche appelée &lt;a href="http://blogs.msdn.com/b/ie/archive/2011/09/20/touch-input-for-ie10-and-metro-style-apps.aspx"&gt;MSPointers&lt;/a&gt;, une technologie multi-touch émergeante permettant de mieux gérer ce scénario. J’aimerais aussi vous parler des solutions de support multi-navigateurs grâce entre autres à un polyfill que nous avons écrit en France pour rendre le support cette technologie moins complexe. Grâce à tout cela, vous devriez être en mesure de commencer à expérimenter des solutions multi-touch universelles sur vos sites web. &lt;/p&gt;  &lt;p&gt;Avant toute chose, il faut savoir qu’il y a plusieurs modèles aujourd’hui disponibles sur le web. Ainsi, pour supporter tous les navigateurs, en plus de nos &lt;a href="http://blogs.msdn.com/b/ie/archive/2011/09/20/touch-input-for-ie10-and-metro-style-apps.aspx"&gt;MSPointers&lt;/a&gt;, il vous faut jeter un œil au modèle de &lt;a href="http://developer.apple.com/library/safari/#documentation/UserExperience/Reference/TouchEventClassReference/TouchEvent/TouchEvent.html"&gt;touch iOS&lt;/a&gt; en plus du bien connu &lt;a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-eventgroupings-mouseevents"&gt;modèle W3C pour gérer la souris&lt;/a&gt;. Cela fait donc 3 manières différentes à gérer pour l’instant dont une seule de véritablement standardisée : la souris. Heureusement, il y a une volonté grandissante de standardisation sur le tactile puisque ce dernier est devenu de plus en plus critique. En septembre dernier, Microsoft a ainsi soumis &lt;a href="http://www.w3.org/Submission/pointer-events/"&gt;le modèle MSPointers auprès du W3C pour une standardisation&lt;/a&gt; et nous sommes passés depuis le 19 février au statut du Last Call Draft : &lt;a href="http://www.w3.org/TR/pointerevents"&gt;http://www.w3.org/TR/pointerevents&lt;/a&gt;, ce qui est très bon signe. Par ailleurs, notre équipe &lt;a href="http://blogs.msdn.com/b/interoperability/"&gt;MS Open Tech&lt;/a&gt; a également publié un &lt;a href="http://blogs.msdn.com/b/interoperability/archive/2012/12/18/open-source-release-from-ms-open-tech-pointer-events-initial-prototype-for-webkit.aspx"&gt;1er prototype pour supporter les Pointer Events au sein de Webkit&lt;/a&gt;. &lt;/p&gt;  &lt;p&gt;Il faut donc s’intéresser au modèle Pointer Events en faisant abstraction de la part de marché des périphériques le supportant. Je pense que l’approche de Microsoft sur la gestion des différents types d’interactions est vraiment différente de ce qu’il se passe sur le web actuellement et mérite que l’on s’y attarde pour avoir un aperçu de ce que pourrait devenir rapidement ce futur standard. La différence principale avec les autres modèles est que le développeur va écrire son code de manière unique en visant une abstraction de toutes les formes d’entrées via ce que nous appelons un pointeur (« Pointer »). Un pointeur peut représenter n’importe quelle forme d’interaction avec l’écran : le pointeur d’une souris, un stylet, un ou plusieurs doigts. Ainsi, vous n’aurez plus besoin de perdre votre temps à coder pour chacune des formes de manière séparée. &lt;/p&gt;  &lt;p&gt;Durant cet article, nous allons commencer par analyser le comportement d’applications fonctionnant au sein d’&lt;a href="http://ietestdrive.com/"&gt;Internet Explorer 10&lt;/a&gt; qui expose les évènements MSPointers. Nous verrons ensuite les solutions permettant de continuer à supporter tous les navigateurs tout en visant le modèle des Pointer Events. C’est quand même là bien le but du web : écrire du code pour tous les navigateurs.&lt;/p&gt;  &lt;p&gt;Dans un second temps, nous verrons alors comment bénéficier du service de reconnaissance de gestuelles propriétaire à IE10. Ce service vous permettra de coder les fameuses « gestures » en JavaScript de manière extrêmement simple. Pour finir, comme Windows 8 et Windows Phone 8 partage le même moteur IE, le code et les concepts présentés ici seront identiques pour chacune des 2 plateformes. De la même manière, tout ce que vous apprendrez dans cet article vous permettra de réaliser exactement les mêmes choses au sein des &lt;a href="http://windowsstore.com/"&gt;Windows Store apps&lt;/a&gt; écrite en HTML5 puisque, à nouveau, c’est toujours le même moteur derrière : IE10. &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;h2&gt;Les concepts&lt;/h2&gt;  &lt;p&gt;L’idée derrière l’objet MSPointer est donc de vous permettre d’adresser la souris, le stylet et les périphériques tactiles en utilisant une seule base de code via un pattern identique à celui que vous connaissez déjà pour gérer la souris. En effet, la souris, un stylet et un point de contact tactile ont des propriétés en commun : vous pouvez déplacer un pointeur avec eux et vous pouvez aussi cliquer sur un élément avec. Il suffit alors d’adresser les scénarios communs avec exactement le même code. Le modèle de Pointers s’occupera alors d’agréger ces propriétés communes et de les exposer de manière similaire à ce que vous connaissez déjà aujourd’hui avec les évènements souris. &lt;/p&gt;  &lt;p&gt;Les évènements communs les plus évidents sont bien sûr : &lt;a href="http://msdn.microsoft.com/en-us/library/hh771909(v=vs.85).aspx"&gt;MSPointerDown&lt;/a&gt; , &lt;a href="http://msdn.microsoft.com/en-us/library/hh771911(v=vs.85).aspx"&gt;MSPointerMove&lt;/a&gt; &amp;amp; &lt;a href="http://msdn.microsoft.com/en-us/library/hh771914(v=vs.85).aspx"&gt;MSPointerUp&lt;/a&gt; qui se calquent directement sur les évènements souris équivalents. Vous aurez ainsi des coordonnées en X et Y sur l’écran disponibles au sein de ces évènements.&lt;/p&gt;  &lt;p&gt;Mais vous avez aussi des évènements plus spécifiques comme : &lt;a href="http://msdn.microsoft.com/en-us/library/hh771913(v=vs.85).aspx"&gt;MSPointerOver&lt;/a&gt; , &lt;a href="http://msdn.microsoft.com/en-us/library/hh771912(v=vs.85).aspx"&gt;MSPointerOut&lt;/a&gt; , &lt;a href="http://msdn.microsoft.com/en-us/library/hh771910(v=vs.85).aspx"&gt;MSPointerHover&lt;/a&gt; ou &lt;a href="http://msdn.microsoft.com/en-us/library/hh846776(v=vs.85).aspx"&gt;MSPointerCancel&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/hh846776(v=vs.85).aspx"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8004.clip_5F00_image001_5F00_43511543.png"&gt;&lt;img title="clip_image001" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="clip_image001" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4300.clip_5F00_image001_5F00_thumb_5F00_4E7D303E.png" width="233" height="240" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Il y a également des cas où vous allez souhaiter gérer le tactile de manière différente de la souris afin de fournir une ergonomie adaptée à votre utilisateur en fonction de sa façon d’interagir avec votre site. Par ailleurs, grâce aux écrans multipoints, un utilisateur peut facilement zoomer ou faire tourner un élément à l’aide de 2 doigts ou plus. De son côté, un stylet peut fournir des informations de pression sur l’écran qu’une souris ne peut vous renvoyer. Le modèle de Pointer Events s’occupera à nouveau d’agréger ses différences de manière à vous permettre facilement d’écrire du code spécifique à chaque usage. &lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;u&gt;Note :&lt;/u&gt;&lt;/b&gt; pour tester les exemples qui vont suivre, il serait bien entendu préférable de disposer d’un écran tactile branché sur un périphérique Windows 8/RT ou sur un téléphone Windows Phone 8. Cependant, vous avez quelques solutions alternatives :&lt;/p&gt;  &lt;p&gt;1. Vous aurez un 1&lt;sup&gt;er&lt;/sup&gt; niveau d’expérience tactile via le simulateur Windows 8 disponible gratuitement avec la suite de développement Visual Studio 2012 Express. Pour plus de détails à ce sujet, rendez-vous dans cet article : &lt;a href="http://blogs.msdn.com/b/davrous/archive/2012/07/11/tester-et-d-233-boguer-les-touch-events-d-ie10-et-votre-responsive-web-design-gr-226-ce-au-simulateur-de-windows-8-et-vs-2012.aspx"&gt;Tester et déboguer les Touch Events d’IE10 et votre Responsive Web Design grâce au simulateur de Windows 8 et VS 2012&lt;/a&gt;     &lt;br /&gt;2. Utilisez un service de test multi-navigateurs comme &lt;a href="http://browserstack.com/"&gt;BrowserStack&lt;/a&gt; pour tester IE10 même si vous n’avez pas de machines Windows 7/8 à votre disposition. Vous pouvez &lt;a href="http://modern.ie/virtualization-tools"&gt;vous servir gratuitement du service BrowserStack pendant 3 mois&lt;/a&gt;, grâce à l’opération menée par l’équipe d’Internet Explorer sur &lt;a href="http://modern.ie/"&gt;modern.IE&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Par ailleurs, je vous conseille en complément de cet article cette excellente session des Microsoft Techdays 2013: &lt;a href="http://www.microsoft.com/france/mstechdays/programmes/2013/fiche-session.aspx?ID=5bd8f617-2ecb-476a-b0fb-3e2ef58305f1"&gt;HTML5, JavaScript et CSS3: Concevoir des interfaces tactiles à destination de Windows 8 et du web (WEB202)&lt;/a&gt; animée par Philippe Didiergeorges et Etienne Margraff.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;h2&gt;&lt;b&gt;Gérer les évènements tactiles simples&lt;/b&gt;&lt;/h2&gt;  &lt;h3&gt;&lt;b&gt;Etape 1 : ne rien faire d’autre que d’ajouter une ligne de CSS&lt;/b&gt;&lt;/h3&gt;  &lt;p&gt;Ok, commençons par les bases. Vous pouvez très facilement reprendre n’importe lequel de votre code JavaScript exploitant les évènements souris et il fonctionnera tel quel avec les stylets et périphériques tactiles sous Internet Explorer 10. En effet, IE10 lance les évènements souris en dernier ressort si vous ne gérez pas directement les Pointer Events dans votre code. C’est pour cela que vous pouvez cliquer sur un bouton ou n’importe lequel des éléments d’une page web avec vos doigts même si le développeur n’avait jamais imaginé que quelqu’un le fasse un jour ainsi. Bref, n’importe quel code s’abonnant aux évènements &lt;em&gt;mousedown&lt;/em&gt; et/ou &lt;em&gt;mouseup&lt;/em&gt; fonctionnera sans aucune modification du tout. Mais qu’en est-il de &lt;em&gt;mousemove&lt;/em&gt; ?&lt;/p&gt;  &lt;p&gt;Pour le savoir, passons en revue le comportement par défaut en analysant le résultat de cet exemple de code :&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;!&lt;/span&gt;&lt;span style="color: maroon"&gt;DOCTYPE &lt;/span&gt;&lt;span style="color: red"&gt;html&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;html&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;head&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;title&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;Touch article sample 1&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;title&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;head&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;body&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;canvas &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;drawSurface&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;width&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;400px&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;height&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;400px&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;style&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;&lt;/span&gt;&lt;span style="color: red"&gt;border&lt;/span&gt;&lt;span style="color: blue"&gt;: 1px dashed black;&amp;quot;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;canvas&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;script&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        var &lt;/span&gt;canvas = document.getElementById(&lt;span style="color: maroon"&gt;&amp;quot;drawSurface&amp;quot;&lt;/span&gt;);
        &lt;span style="color: blue"&gt;var &lt;/span&gt;context = canvas.getContext(&lt;span style="color: maroon"&gt;&amp;quot;2d&amp;quot;&lt;/span&gt;);
        context.fillStyle = &lt;span style="color: maroon"&gt;&amp;quot;rgba(0, 0, 255, 0.5)&amp;quot;&lt;/span&gt;;

        canvas.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;mousemove&amp;quot;&lt;/span&gt;, paint, &lt;span style="color: blue"&gt;false&lt;/span&gt;);

        &lt;span style="color: blue"&gt;function &lt;/span&gt;paint(event) {
            context.fillRect(event.clientX, event.clientY, 10, 10);
        }
    &lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;script&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;body&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;html&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Ce code s’occupe simplement de dessiner des carrés bleus de 10 pixels par 10 pixels en suivant les mouvements de la souris au sein d’un canvas HTML5. &lt;i&gt;Pour le tester, il vous suffit donc de bouger le curseur de la souris à l’intérieur de la boîte délimitée par les pointillés. Si vous avez un écran tactile, essayez d’interagir avec le canvas pour découvrir par vous-même le comportement actuel :&lt;/i&gt;&lt;/p&gt;

&lt;table cellspacing="0" cellpadding="2" width="900" border="0"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="450"&gt;&lt;iframe style="border-top: rgb(255,255,255) 0px solid; border-right: rgb(255,255,255) 0px solid; border-bottom: rgb(255,255,255) 0px solid; border-left: rgb(255,255,255) 0px solid" height="420" src="http://david.blob.core.windows.net/html5/touchsample1.htm" width="410" scrolling="no"&gt;&lt;/iframe&gt;&lt;/td&gt;

      &lt;td valign="top" width="450"&gt;
        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&lt;em&gt;Exemple 0&lt;/em&gt; : &lt;strong&gt;comportement par défaut &lt;/strong&gt;si vous ne faîtes rien &lt;/p&gt;

        &lt;p align="center"&gt;&lt;em&gt;Résultat&lt;/em&gt; : &lt;strong&gt;seul MouseDown/Up/Click fonctionnent&lt;/strong&gt; au touch&lt;/p&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;Vous voyez ainsi que lorsque vous bougez la souris au sein du canvas, cela dessine des séries de petits carrés bleus. Mais si vous utilisez l’écran tactile à la place, vous ne pourrez uniquement afficher un seul carré bleu à l’endroit précis où vous taperez le canvas avec l’un de vos doigts. Dès que vous allez essayer de bouger votre doigt à l’intérieur du canvas, le navigateur va naturellement faire défiler le contenu de la page puisque c’est le comportement qu’on lui demande d’avoir par défaut.&lt;/p&gt;

&lt;p&gt;Il nous faut donc indiquer au navigateur de changer de comportement et de rediriger les évènements tactiles vers votre code JavaScript plutôt que d’essayer les interpréter lui-même. Pour cela, il vous suffit de cibler les éléments de votre page qui ne doivent plus réagir au comportement par défaut en appliquant cette règle CSS :&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: red"&gt;-ms-touch-action&lt;/span&gt;: &lt;span style="color: blue"&gt;auto | none | manipulation | double-tap-zoom | inherit&lt;/span&gt;;&lt;/pre&gt;

&lt;p&gt;Vous avez différentes valeurs possibles en fonction de ce que vous souhaitez filtrer ou non. Vous trouverez la signification de ces valeurs dans cet article : &lt;a href="http://blogs.msdn.com/b/ie/archive/2012/04/20/guidelines-for-building-touch-friendly-sites.aspx"&gt;Guidelines for Building Touch-friendly Sites&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Le cas d’usage typique est le contrôle de cartographie que vous insérez dans votre page. Vous voulez alors en général laisser l’utilisateur se déplacer dans la carte avec les gestuelles classiques du touch (pour zoomer et se déplacer) mais garder le comportement par défaut sur le reste de la page. Dans ce cas, il faut simplement appliquer la règle ci-dessus avec la valeur &lt;em&gt;none&lt;/em&gt; uniquement sur le conteneur HTML embarquant la cartographie. &lt;/p&gt;

&lt;p&gt;Dans notre cas, il faut ajouter ce bloc de CSS : &lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;style&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &lt;/span&gt;&lt;span style="color: maroon"&gt;#drawSurface
    &lt;/span&gt;{
        &lt;span style="color: red"&gt;-ms-touch-action&lt;/span&gt;: &lt;span style="color: blue"&gt;none&lt;/span&gt;; &lt;span style="color: #006400"&gt;/* Désactive tous les comportements tactiles par défaut, comme le défilement et le zoom */
    &lt;/span&gt;}
&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;style&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Cela nous donne le résultat suivant : &lt;/p&gt;

&lt;table cellspacing="0" cellpadding="2" width="900" border="0"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="450"&gt;&lt;iframe style="border-top: rgb(255,255,255) 0px solid; border-right: rgb(255,255,255) 0px solid; border-bottom: rgb(255,255,255) 0px solid; border-left: rgb(255,255,255) 0px solid" height="420" src="http://david.blob.core.windows.net/html5/touchsample2.htm" width="410" scrolling="no"&gt;&lt;/iframe&gt;&lt;/td&gt;

      &lt;td valign="top" width="450"&gt;
        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&lt;em&gt;Exemple 1&lt;/em&gt;: juste après avoir ajouté &lt;strong&gt;&lt;span style="color: red"&gt;-ms-touch-action&lt;/span&gt;: &lt;span style="color: blue"&gt;none&lt;/span&gt;&lt;/strong&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&lt;em&gt;Résultat&lt;/em&gt;: comportement par défaut du navigateur annulé et &lt;strong&gt;MouseMove fonctionne mais uniquement avec 1 doigt à la fois&lt;/strong&gt;&lt;/p&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;Maintenant, si vous bougez l’un de vos doigts à l’intérieur du canvas, il se comportera comme un pointeur de souris. C’est cool non ? Mais vous devriez rapidement vous poser alors la question suivante : pourquoi cela ne suit-il qu’un seul de mes doigts ? Tout simplement car nous tombons actuellement dans le cas de dernier ressort justement. IE10 se contente de mapper l’un de vos doigts au pointeur de la souris. Et autant que je sache, on utilise qu’une seule souris à la fois. Donc 1 souris === 1 point de contact tactile maximum en utilisant cette approche. Bon, alors, comment vraiment gérer le multipoints alors ?&lt;/p&gt;

&lt;h3&gt;Etape 2 : utilisez les évènements MSPointer en lieu et place de ceux de la souris&lt;/h3&gt;

&lt;p&gt;Prenez n’importe lequel de votre code existant et remplacer vos abonnements aux évènements « mousedown/up/move » par « MSPointerDown/Up/Move » et votre code deviendra alors directement compatible avec le support multi-touch d’IE10 !&lt;/p&gt;

&lt;p&gt;Par exemple, dans l’exemple précédent, il suffit de changer cette ligne de code :&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;pre class="code"&gt;canvas.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;mousemove&amp;quot;&lt;/span&gt;, paint, &lt;span style="color: blue"&gt;false&lt;/span&gt;);&lt;/pre&gt;

&lt;p&gt;par celle-ci :&lt;/p&gt;

&lt;pre class="code"&gt;canvas.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;MSPointerMove&amp;quot;&lt;/span&gt;, paint, &lt;span style="color: blue"&gt;false&lt;/span&gt;);&lt;/pre&gt;

&lt;p&gt;Et vous obtiendrez alors ce résultat : &lt;/p&gt;

&lt;table cellspacing="0" cellpadding="2" width="900" border="0"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="450"&gt;&lt;iframe style="border-top: rgb(255,255,255) 0px solid; border-right: rgb(255,255,255) 0px solid; border-bottom: rgb(255,255,255) 0px solid; border-left: rgb(255,255,255) 0px solid" height="420" src="http://david.blob.core.windows.net/html5/touchsample3.htm" width="410" scrolling="no"&gt;&lt;/iframe&gt;&lt;/td&gt;

      &lt;td valign="top" width="450"&gt;
        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&lt;em&gt;Exemple 2&lt;/em&gt;: utilisation de &lt;strong&gt;MSPointerMove&lt;/strong&gt; à la place de mousemove&lt;/p&gt;

        &lt;p align="center"&gt;&lt;em&gt;Résultat&lt;/em&gt;: le &lt;strong&gt;multi-touch fonctionne&lt;/strong&gt;&lt;/p&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;Vous pouvez désormais dessiner autant de séries de carrés que votre écran ne supporte de points de contacts et/ou que vous n’avez de doigts ! Encore mieux, le même code marche pour gérer le tactile, la souris et le stylet. Cela veut dire par exemple que vous pouvez dessiner une série de carrés à la souris tout en en dessinant d’autres en même temps avec vos doigts. &lt;img class="wlEmoticon wlEmoticon-winkingsmile" style="border-top-style: none; border-left-style: none; border-bottom-style: none; border-right-style: none" alt="Clignement d&amp;#39;œil" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0434.wlEmoticon_2D00_winkingsmile_5F00_05155995.png" /&gt;&lt;/p&gt;

&lt;p&gt;Mais si vous souhaitez aller plus loin et changer le comportement de votre code en fonction du type d’entrée, il faut alors tester la valeur de la propriété &lt;em&gt;pointerType&lt;/em&gt;. Par exemple, imaginez que vous souhaitez dessiner des séries de 10x10 pixels rouges pour le tactile, 5x5 pixels verts pour le stylet et 2x2 pixels bleus pour la souris. Vous devez alors remplacer le gestionnaire précédent (la fonction &lt;em&gt;paint&lt;/em&gt;) par celui-ci :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;paint(event) {
    &lt;span style="color: blue"&gt;if &lt;/span&gt;(event.pointerType) {
        &lt;span style="color: blue"&gt;switch &lt;/span&gt;(event.pointerType) {
            &lt;span style="color: blue"&gt;case &lt;/span&gt;event.MSPOINTER_TYPE_TOUCH:
                &lt;span style="color: #006400"&gt;// Un écran tactile est utilisé
                // On dessine en rouge un carré de 10
                &lt;/span&gt;context.fillStyle = &lt;span style="color: maroon"&gt;&amp;quot;rgba(255, 0, 0, 0.5)&amp;quot;&lt;/span&gt;;
                squaresize = 10;
                &lt;span style="color: blue"&gt;break&lt;/span&gt;;
            &lt;span style="color: blue"&gt;case &lt;/span&gt;event.MSPOINTER_TYPE_PEN:
                &lt;span style="color: #006400"&gt;// Un stylet est utilisé
                // On dessine en vert un carré de 5
                &lt;/span&gt;context.fillStyle = &lt;span style="color: maroon"&gt;&amp;quot;rgba(0, 255, 0, 0.5)&amp;quot;&lt;/span&gt;;
                squaresize = 5;
                &lt;span style="color: blue"&gt;break&lt;/span&gt;;
            &lt;span style="color: blue"&gt;case &lt;/span&gt;event.MSPOINTER_TYPE_MOUSE:
                &lt;span style="color: #006400"&gt;// Une souris est utilisée
                // On dessine en blue un carré de 2
                &lt;/span&gt;context.fillStyle = &lt;span style="color: maroon"&gt;&amp;quot;rgba(0, 0, 255, 0.5)&amp;quot;&lt;/span&gt;;
                squaresize = 2;
                &lt;span style="color: blue"&gt;break&lt;/span&gt;;
        }

        context.fillRect(event.clientX, event.clientY, squaresize, squaresize);
    }
}&lt;/pre&gt;

&lt;p&gt;Et vous pouvez tester le nouveau résultat ici :&lt;/p&gt;

&lt;table cellspacing="0" cellpadding="2" width="900" border="0"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="450"&gt;&lt;iframe style="border-top: rgb(255,255,255) 0px solid; border-right: rgb(255,255,255) 0px solid; border-bottom: rgb(255,255,255) 0px solid; border-left: rgb(255,255,255) 0px solid" height="420" src="http://david.blob.core.windows.net/html5/touchsample4.htm" width="410" scrolling="no"&gt;&lt;/iframe&gt;&lt;/td&gt;

      &lt;td valign="top" width="450"&gt;
        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&lt;em&gt;Exemple 2b&lt;/em&gt;: test de &lt;strong&gt;pointerType&lt;/strong&gt; pour différencier tactile/stylet ou&amp;#160; souris&lt;/p&gt;

        &lt;p align="center"&gt;&lt;em&gt;Résultat&lt;/em&gt;: Vous pouvez &lt;strong&gt;changer le comportement de votre code pour chacune des entrées&lt;/strong&gt; mais depuis 2a le &lt;strong&gt;&lt;font color="#804040"&gt;code ne marche maintenant &lt;em&gt;uniquement&lt;/em&gt; dans IE10&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;Si vous faîtes partis des chanceux à disposer d’une machine supportant les 3 types d’entrées (comme le &lt;i&gt;Sony Duo 11&lt;/i&gt;, la &lt;i&gt;Microsoft Surface Pro&lt;/i&gt; ou la &lt;i&gt;tablette Samsung&lt;/i&gt; que certains d’entre nous avions eu à la BUILD2011), vous serez en mesure de voir les différences visuelles entre les 3. &lt;/p&gt;

&lt;p&gt;Bon, tout cela est bien sympathique mais nous avons désormais un problème de taille avec ce code. Il gère désormais bien tous les types d’entrées au sein d’IE10 mais ne marche pas du tout dans les navigateurs ne supportant pas encore le modèle de Pointer Events comme IE9, Chrome, Firefox, Opera &amp;amp; Safari ! &lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;h3&gt;Etape 3 : détection de fonctionnalité pour fournir une expérience alternative&lt;/h3&gt;

&lt;p&gt;Comme tout bon développeur web qui se respecte, vous savez déjà surement que la meilleure approche pour supporter l’ensemble des navigateurs est de faire de la détection de fonctionnalités. Dans notre cas, cela consiste à tester cette fonctionnalité :&lt;/p&gt;

&lt;pre class="code"&gt;window.navigator.msPointerEnabled&lt;/pre&gt;

&lt;p&gt;Faites attention cependant à ce test. Il vous indiquera uniquement si le navigateur actuel supporte les MSPointers. Il ne vous dira pas si un écran tactile est disponible ou pas. Pour tester la fonctionnalité tactile, il vous faut en plus vérifier &lt;a href="http://msdn.microsoft.com/en-us/library/hh772144(v=vs.85).aspx"&gt;&lt;b&gt;msMaxTouchPoints&lt;/b&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;En conclusion, pour avoir un code fonctionnel supportant à la fois le modèle MSPointer d’IE10 et proposant une expérience alternative dégradée vers le pointeur de souris pour les autres navigateurs, vous avez besoin du code suivant :&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;canvas = document.getElementById(&lt;span style="color: maroon"&gt;&amp;quot;drawSurface&amp;quot;&lt;/span&gt;);
&lt;span style="color: blue"&gt;var &lt;/span&gt;context = canvas.getContext(&lt;span style="color: maroon"&gt;&amp;quot;2d&amp;quot;&lt;/span&gt;);
context.fillStyle = &lt;span style="color: maroon"&gt;&amp;quot;rgba(0, 0, 255, 0.5)&amp;quot;&lt;/span&gt;;
&lt;span style="color: blue"&gt;if &lt;/span&gt;(window.navigator.msPointerEnabled) {
    &lt;span style="color: #006400"&gt;// Si les Pointer events sont supportés.
    &lt;/span&gt;canvas.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;MSPointerMove&amp;quot;&lt;/span&gt;, paint, &lt;span style="color: blue"&gt;false&lt;/span&gt;);
}
&lt;span style="color: blue"&gt;else &lt;/span&gt;{
    canvas.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;mousemove&amp;quot;&lt;/span&gt;, paint, &lt;span style="color: blue"&gt;false&lt;/span&gt;);
}

&lt;span style="color: blue"&gt;function &lt;/span&gt;paint(event) {
    &lt;span style="color: blue"&gt;var &lt;/span&gt;squaresize = 2;
    &lt;span style="color: blue"&gt;if &lt;/span&gt;(event.pointerType) {
        &lt;span style="color: blue"&gt;switch &lt;/span&gt;(event.pointerType) {
            &lt;span style="color: blue"&gt;case &lt;/span&gt;event.MSPOINTER_TYPE_TOUCH:
&lt;span style="color: #006400"&gt;                &lt;/span&gt;context.fillStyle = &lt;span style="color: maroon"&gt;&amp;quot;rgba(255, 0, 0, 0.5)&amp;quot;&lt;/span&gt;;
                squaresize = 10;
                &lt;span style="color: blue"&gt;break&lt;/span&gt;;
            &lt;span style="color: blue"&gt;case &lt;/span&gt;event.MSPOINTER_TYPE_PEN:
&lt;span style="color: #006400"&gt;                &lt;/span&gt;context.fillStyle = &lt;span style="color: maroon"&gt;&amp;quot;rgba(0, 255, 0, 0.5)&amp;quot;&lt;/span&gt;;
                squaresize = 5;
                &lt;span style="color: blue"&gt;break&lt;/span&gt;;
            &lt;span style="color: blue"&gt;case &lt;/span&gt;event.MSPOINTER_TYPE_MOUSE:
&lt;span style="color: #006400"&gt;                &lt;/span&gt;context.fillStyle = &lt;span style="color: maroon"&gt;&amp;quot;rgba(0, 0, 255, 0.5)&amp;quot;&lt;/span&gt;;
                squaresize = 2;
                &lt;span style="color: blue"&gt;break&lt;/span&gt;;
        }
    }

    context.fillRect(event.clientX, event.clientY, squaresize, squaresize);
}&lt;/pre&gt;

&lt;p&gt;A nouveau, vous pouvez vérifier le résultat ici : &lt;/p&gt;

&lt;table cellspacing="0" cellpadding="2" width="900" border="0"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="450"&gt;&lt;iframe style="border-top: rgb(255,255,255) 0px solid; border-right: rgb(255,255,255) 0px solid; border-bottom: rgb(255,255,255) 0px solid; border-left: rgb(255,255,255) 0px solid" height="420" src="http://david.blob.core.windows.net/html5/touchsample5.htm" width="410" scrolling="no"&gt;&lt;/iframe&gt;&lt;/td&gt;

      &lt;td valign="top" width="450"&gt;
        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&lt;em&gt;Exemple 3&lt;/em&gt;: détection de la fonctionnalité &lt;strong&gt;msPointerEnabled&lt;/strong&gt; pour fournir une dégradation&lt;/p&gt;

        &lt;p align="center"&gt;&lt;em&gt;Résultat&lt;/em&gt;: expérience complète au sein d’IE10 et &lt;strong&gt;comportement classique à la souris dans les autres navigateurs&lt;/strong&gt;&lt;/p&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;L’exemple 3 fonctionnera alors en multipoints, à la souris et au stylet dans IE10 et uniquement à la souris dans IE9, Chrome, Firefox, Opera, Safari.&lt;/p&gt;

&lt;h3&gt;Etape 4 : supporter tous les modèles de touch&lt;/h3&gt;

&lt;p&gt;J’imagine que vous aimeriez bien aller plus loin qu’une simple expérience souris dégradée pour les navigateurs autre qu’IE10. Pour cela, il vous faut alors supporter les 3 modèles dont je parlais au début : Touch Events d’Apple, évènements souris W3C et MSPointer en attendant sa standardisation finale. Il y a 2 manières de mettre cela en place :&lt;/p&gt;

&lt;p&gt;1 – Ecrire du code pour adresser tous les types d’évènements en parallèle comme expliqué (en anglais) dans cet article de l’équipe IE : &lt;a href="http://blogs.msdn.com/b/ie/archive/2011/10/19/handling-multi-touch-and-mouse-input-in-all-browsers.aspx"&gt;Handling Multi-touch and Mouse Input in All Browsers&lt;/a&gt; 

  &lt;br /&gt;2 – Ajouter simplement une référence à Hand.JS, une librairie de polyfill en JavaScript conçue par mon ami David Catuhe comme il l’explique dans son article ici : &lt;a href="http://blogs.msdn.com/b/eternalcoding/archive/2013/01/16/hand-js-a-polyfill-for-supporting-pointer-events-on-every-browser.aspx"&gt;HandJS a polyfill for supporting pointer events on every browser&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;En effet, David a écrit cette superbe librairie vous permettant de viser la spécification Pointer Events du W3C. Comme je vous l’ai indiqué en début d’article, Microsoft a soumis son modèle MSPointer Events au W3C pour standardisation. &lt;/p&gt;

&lt;p&gt;Cependant, bien que déjà au statut de « Last Call », la spécification Pointer Events n’est pas encore un standard. Mais grâce à cette librairie, vous pouvez déjà implémenter dans votre code ce futur standard et être prêt lorsqu’elle deviendra adoptée par tous les navigateurs modernes. En attendant, la librairie de David s’occupera de propager les Pointer Events vers la forme actuellement propriétaires MSPointer Events dans IE10, vers les Touch Events pour les navigateurs implémentant le modèle d’Apple, voir même vers les évènements souris en dernier ressort pour les anciens navigateurs ! Je vous invite donc à lire son article pour savoir comment cela fonctionne. &lt;/p&gt;

&lt;p&gt;Pour avoir une idée de comment utiliser cette librairie, je me suis amusé à m’en servir dans cet article : &lt;a href="http://blogs.msdn.com/b/davrous/archive/2013/02/16/creating-an-universal-virtual-touch-joystick-working-for-all-touch-models-thanks-to-hand-js.aspx"&gt;Creating an universal virtual touch joystick working for all Touch models thanks to Hand.JS&lt;/a&gt; qui montre comment écrire un joystick tactile virtuel utilisant les Pointer Events. Grâce à Hand.JS, il fonctionne dans IE10 sur Windows 8/RT, Windows Phone 8, iPad/iPhone et sur les périphérique Android/Firefox OS avec la même base de code !&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;h2&gt;Reconnaitre des gestuelles&lt;/h2&gt;

&lt;p&gt;Maintenant que nous savons comment fonctionnent les bases du multi-touch, regardons comment reconnaître des gestuelles simples comme taper un élément ou le maintenir puis ensuite des gestuelles plus avancées comme déplacer ou agrandir/rétrécir un élément. &lt;/p&gt;

&lt;p&gt;IE10 fournit un objet nommé MSGesture qui va bien nous aider pour ce travail. Notez d’ailleurs que cet objet est spécifique à IE10 et ne fait pas partie de notre soumission au W3C. Combiné avec l’élément &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh453593.aspx"&gt;MSCSSMatrix&lt;/a&gt; (notre equivalent à &lt;a href="http://developer.apple.com/library/safari/#documentation/AudioVideo/Reference/WebKitCSSMatrixClassReference/WebKitCSSMatrix/WebKitCSSMatrix.html"&gt;WebKitCSSMatrix&lt;/a&gt;), vous serez en mesure de construire des expériences multi-touch très intéressantes le tout de manière fort simple. MSCSSMatrix représente en effet une matrice 4x4 homogène permettant un accès au DOM par script aux fonctionnalités CSS 2-D et 3-D. Mais avant de jouer avec cela, commençons naturellement par les bases de la reconnaissance de gestuelles (ou « gesture » en anglais).&lt;/p&gt;

&lt;p&gt;Ce qu’il faut retenir en premier lieu est qu’il est d’abord nécessaire de s’abonner à l’évènement&lt;b&gt; MSPointerDown&lt;/b&gt;. Ensuite, à l’intérieur du handler prenant en charge MSPointerDown, vous devrez &lt;b&gt;choisir quels sont les pointeurs que vous souhaitez envoyer à l’objet MSGesture&lt;/b&gt; pour qu’il s’occupe de détecter certaines gestuelles spécifiques. Ce dernier renverra alors l’un de ces évènements : &lt;a href="http://msdn.microsoft.com/en-us/library/hh771901(v=vs.85).aspx"&gt;&lt;b&gt;MSGestureTap&lt;/b&gt;&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-us/library/hh771894(v=vs.85).aspx"&gt;&lt;b&gt;MSGestureHold&lt;/b&gt;&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-us/library/hh771898(v=vs.85).aspx"&gt;&lt;b&gt;MSGestureStart&lt;/b&gt;&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-us/library/hh771887(v=vs.85).aspx"&gt;&lt;b&gt;MSGestureChange&lt;/b&gt;&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-us/library/hh771892(v=vs.85).aspx"&gt;&lt;b&gt;MSGestureEnd&lt;/b&gt;&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-us/library/hh771906(v=vs.85).aspx"&gt;&lt;b&gt;MSInertiaStart&lt;/b&gt;&lt;/a&gt;. En effet, l’objet MSGesture travaille sur un jeu de pointeurs en entrée et s’occupe ensuite d’appliquer un algorithme de reconnaissance de gestuelles par-dessus. La seule chose que vous devez faire est donc de choisir/filtrer les pointeurs devant faire partie de la gestuelle (basé sur leurs identifiants, coordonnées à l’écran, etc… à vous d’imaginer la logique qui vous correspond). L’objet MSGesture s’occupera alors magiquement du reste.&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;h3&gt;Exemple 1 : gérer la gestuelle de maintien (hold gesture)&lt;/h3&gt;

&lt;p&gt;Nous allons voir ici comment maintenir un élément (un simple élément DIV contenant une image en arrière-plan). Cette gestuelle est souvent utilisée pour simuler les actions contextuelles à l’élément de la même manière que le bouton droit de la souris. Une fois que notre élément sera maintenu, nous allons ajouter des petits triangles aux quatre coins pour indiquer à l’utilisateur qu’il a bien sélectionné l’élément. Ces coins seront générés dynamiquement en créant 4 DIV ajoutés au-dessus de chacun des coins de l’image. Ensuite, grâce à quelques astuces CSS à base de transformation 2D et gradients linéaires, nous obtiendrons la chose suivante :&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/6840.image_5F00_576B37A6.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5025.image_5F00_thumb_5F00_1D7E856B.png" width="240" height="187" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;La séquence sera donc la suivante :&lt;/p&gt;

&lt;p&gt;1 – abonnement aux évènements MSPointerDown &amp;amp; &lt;a href="http://msdn.microsoft.com/en-us/library/hh771894(v=vs.85).aspx"&gt;MSPointerHold&lt;/a&gt; au-dessus de l’élément HTML qui vous intéresse

  &lt;br /&gt;2 – création d’un objet MSGesture qui visera le même élément HTML

  &lt;br /&gt;3 – au sein du gestionnaire de MSPointerDown, ajout à l’objet MSGesture la prise en charge des différents PointerID que l’on souhaite surveiller (tous ou un sous-ensemble d’entre eux en fonction de ce que vous souhaitez réaliser)

  &lt;br /&gt;4 – au sein du gestionnaire MSPointerHold, vérification au sein des détails fournis dans l’évènement si l’utilisateur a juste démarré la gestuelle de maintien (via le flag MSGESTURE_FLAG_BEGIN). Si oui, on ajoute les coins spéciaux, sinon, on les retire.&lt;/p&gt;

&lt;p&gt;Cela nous amène au code suivant :&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;!&lt;/span&gt;&lt;span style="color: maroon"&gt;DOCTYPE &lt;/span&gt;&lt;span style="color: red"&gt;html&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;html&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;head&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;title&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;Touch article sample 5: simple gesture handler&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;title&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;link &lt;/span&gt;&lt;span style="color: red"&gt;rel&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;stylesheet&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;type&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;text/css&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;href&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;toucharticle.css&amp;quot; /&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;script &lt;/span&gt;&lt;span style="color: red"&gt;src&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Corners.js&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;script&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;head&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;body&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;div &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;myGreatPicture&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;class&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;container&amp;quot; /&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;script&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        var &lt;/span&gt;myGreatPic = document.getElementById(&lt;span style="color: maroon"&gt;&amp;quot;myGreatPicture&amp;quot;&lt;/span&gt;);
        &lt;span style="color: #006400"&gt;// Création d’un nouveau MSGesture qui surveillera l’élément DOM myGreatPic
        &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;myGreatPicAssociatedGesture = &lt;span style="color: blue"&gt;new &lt;/span&gt;MSGesture();
        myGreatPicAssociatedGesture.target = myGreatPic;

        &lt;span style="color: #006400"&gt;// Vous devez d’abord vous abonner à MSPointerDown pour pouvoir
        // avoir accès à des évènements gestuelles plus complexes 
        &lt;/span&gt;myGreatPic.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;MSPointerDown&amp;quot;&lt;/span&gt;, pointerdown, &lt;span style="color: blue"&gt;false&lt;/span&gt;);
        myGreatPic.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;MSGestureHold&amp;quot;&lt;/span&gt;, holded, &lt;span style="color: blue"&gt;false&lt;/span&gt;);

        &lt;span style="color: #006400"&gt;// Une fois l’évènement levé, on se contente d’envoyer tous les pointeurs vers MSGesture
        &lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;pointerdown(event) {
            myGreatPicAssociatedGesture.addPointer(event.pointerId);
        }

        &lt;span style="color: #006400"&gt;// Cet évènement sera levé par l’objet MSGesture
        // en fonction des pointeurs fournis pendant l’évènement MSPointerDown
        &lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;holded(event) {
            &lt;span style="color: #006400"&gt;// La gestuelle commence, on ajoute les coins
            &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(event.detail === event.MSGESTURE_FLAG_BEGIN) {
                Corners.append(myGreatPic);
            }
            &lt;span style="color: blue"&gt;else &lt;/span&gt;{
                &lt;span style="color: #006400"&gt;// L’utilisateur a relâché son doigt, la gestuelle se termine
                // On retire donc les coins
                &lt;/span&gt;Corners.remove(myGreatPic);
            }
        }

        &lt;span style="color: #006400"&gt;// Pour éviter d’avoir l’équivalent d’un menu contextuel affiché   
        // comme sur un click droit &amp;quot;right click&amp;quot; sur MSPointerUp, 
        // on annule le comportement du navigateur par défaut
        &lt;/span&gt;myGreatPic.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;contextmenu&amp;quot;&lt;/span&gt;, &lt;span style="color: blue"&gt;function &lt;/span&gt;(e) {
            e.preventDefault();    &lt;span style="color: #006400"&gt;
        &lt;/span&gt;}, &lt;span style="color: blue"&gt;false&lt;/span&gt;);
    &lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;script&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;body&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;html&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Et voici le résultat :&lt;/p&gt;
&lt;iframe style="border-top: rgb(255,255,255) 0px solid; border-right: rgb(255,255,255) 0px solid; border-bottom: rgb(255,255,255) 0px solid; border-left: rgb(255,255,255) 0px solid" height="400" src="http://david.blob.core.windows.net/html5/touchsample6.html" width="450" scrolling="no"&gt;&lt;/iframe&gt;

&lt;br /&gt;

&lt;br /&gt;

&lt;p&gt;Essayez de juste taper l’élément ou de cliquer dessus à la souris, rien ne se passe. Touchez le et maintenez seulement 1 doigt au-dessus de l’image ou effectuez un click gauche long dessus : les coins apparaissent. Relâchez votre doigt, les coins disparaissent bien.&lt;/p&gt;

&lt;p&gt;Touchez et maintenez 2 ou plus de doigts sur l’image, rien ne se passe. En effet, la gestuelle de maintien est uniquement levée que lorsqu’un seul doigt maintient l’élément. &lt;/p&gt;

&lt;p&gt;&lt;b&gt;&lt;u&gt;Note :&lt;/u&gt;&lt;/b&gt; les bords blancs, les coins et l’image de fond sont définis par CSS dans le fichier &lt;i&gt;toucharticle.css&lt;/i&gt;. &lt;i&gt;Corners.js&lt;/i&gt; s’occupe simplement de créer les 4 DIVs (avec la fonction append) et les place au-dessus de l’élément dans chacun des coins à l’aide de classes CSS appropriées.&lt;/p&gt;

&lt;p&gt;Malgré tout, il reste un comportement avec lequel je ne suis pas très satisfait. Une fois que vous maintenez l’image, dès que vous bougez votre doigt ne serait-ce que très légèrement, le drapeau MSGESTURE_FLAG_CANCEL est levé et récupéré par le gestionnaire d’évènement qui retire aussitôt les coins. Je préférais retirer les coins uniquement lorsque l’utilisateur relâche son doigt n’importe où au-dessus de l’image ou aussitôt que son doigt sorte de la zone délimitée par l’image en elle-même. Pour effectuer cela, nous allons retirer les coins uniquement après les évènements MSPointerUp ou MSPointerOut. Cela nous donne le code suivant à la place :&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;myGreatPic = document.getElementById(&lt;span style="color: maroon"&gt;&amp;quot;myGreatPicture&amp;quot;&lt;/span&gt;);
&lt;span style="color: blue"&gt;var &lt;/span&gt;myGreatPicAssociatedGesture = &lt;span style="color: blue"&gt;new &lt;/span&gt;MSGesture();
myGreatPicAssociatedGesture.target = myGreatPic;

myGreatPic.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;MSPointerDown&amp;quot;&lt;/span&gt;, pointerdown, &lt;span style="color: blue"&gt;false&lt;/span&gt;);
myGreatPic.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;MSGestureHold&amp;quot;&lt;/span&gt;, holded, &lt;span style="color: blue"&gt;false&lt;/span&gt;);
myGreatPic.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;MSPointerUp&amp;quot;&lt;/span&gt;, removecorners, &lt;span style="color: blue"&gt;false&lt;/span&gt;);
myGreatPic.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;MSPointerOut&amp;quot;&lt;/span&gt;, removecorners, &lt;span style="color: blue"&gt;false&lt;/span&gt;);

&lt;span style="color: blue"&gt;function &lt;/span&gt;pointerdown(event) {
    myGreatPicAssociatedGesture.addPointer(event.pointerId);
}

&lt;span style="color: blue"&gt;function &lt;/span&gt;holded(event) {&lt;span style="color: #006400"&gt;
    &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(event.detail === event.MSGESTURE_FLAG_BEGIN) {
        Corners.append(myGreatPic);
    }
}

&lt;span style="color: #006400"&gt;// On retire désormais les coins que sur Pointer Up ou Out
&lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;removecorners(event) {
    Corners.remove(myGreatPic);
}

myGreatPic.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;contextmenu&amp;quot;&lt;/span&gt;, &lt;span style="color: blue"&gt;function &lt;/span&gt;(e) {
    e.preventDefault();    &lt;span style="color: #006400"&gt;
&lt;/span&gt;}, &lt;span style="color: blue"&gt;false&lt;/span&gt;);&lt;/pre&gt;

&lt;p&gt;Qui fournit le comportement que je cherchais vraiment à obtenir :&lt;/p&gt;

&lt;p&gt;&lt;iframe style="border-top: rgb(255,255,255) 0px solid; border-right: rgb(255,255,255) 0px solid; border-bottom: rgb(255,255,255) 0px solid; border-left: rgb(255,255,255) 0px solid" height="400" src="http://david.blob.core.windows.net/html5/touchsample6b.html" width="450" scrolling="no"&gt;&lt;/iframe&gt;

  &lt;br /&gt;&lt;/p&gt;

&lt;h3&gt;Exemple 2 : gestion des déplacements, rotation et mise à l’échelle&lt;/h3&gt;

&lt;p&gt;Maintenant que vous savez presque tout, vous allez voir que mettre à l’échelle, déplacer ou tourner un élément est l’enfance de l’art grâce à quelques lignes de code. Vous devez tout d’abord vous abonner à l’évènement &lt;a href="http://msdn.microsoft.com/en-us/library/hh771887(v=vs.85).aspx"&gt;MSGestureChange&lt;/a&gt;. Cet évènement va vous envoyer les différents attributs comme définis dans la documentation de &lt;a href="http://msdn.microsoft.com/en-us/library/hh772076(v=vs.85).aspx"&gt;l’objet MSGestureEvent&lt;/a&gt; comme les valeurs actuellement positionnées sur votre élément HTML.&lt;/p&gt;

&lt;p&gt;Encore mieux, par défaut, l’objet MSGesture fournit un algorithme inertiel automatique. Cela signifie que vous pouvez prendre n’importe quel élément HTML et le jeter à travers l’écran en utilisant vos petits doigts et l’animation naturelle sera gérée pour vous.&lt;/p&gt;

&lt;p&gt;Pour finir, afin de refléter ces changements envoyés par MSGesture, vous devez bien entendu bouger l’élément vous-même. La manière la plus simple consiste à appliquer une transformation CSS parfaitement calquée sur les valeurs de rotation, mise à l’échelle et déplacement fournies par la gestuelle reconnue. Pour cela, utilisez l’élément &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh453593.aspx"&gt;MSCSSMatrix&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;En conclusion, si vous souhaitez mettre en place toutes ces gestuelles sympathiques et modernes dans l’exemple précédent, abonnez vous à l’évènement ainsi : &lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;pre class="code"&gt;myGreatPic.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;MSGestureChange&amp;quot;&lt;/span&gt;, manipulateElement, &lt;span style="color: blue"&gt;false&lt;/span&gt;);&lt;/pre&gt;

&lt;p&gt;Puis utilisez le gestionnaire suivant : &lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;manipulateElement(e) {
    &lt;span style="color: #006400"&gt;// Décommenter le code suivant si vous voulez désactiver l’algorithme d’inertie automatique 
    // fournit par le mécanisme de reconnaissance de gestuelles
    // if (e.detail == e.MSGESTURE_FLAG_INERTIA)
    // return;

    // On récupère la dernière transformation CSS appliquée à l’élément
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;m = &lt;span style="color: blue"&gt;new &lt;/span&gt;MSCSSMatrix(e.target.currentStyle.transform); 
    e.target.style.transform = m
    .translate(e.offsetX, e.offsetY) &lt;span style="color: #006400"&gt;// On bouge l’origine au centre de la gestuelle
    &lt;/span&gt;.rotate(e.rotation * 180 / Math.PI) &lt;span style="color: #006400"&gt;// On applique la rotation
    &lt;/span&gt;.scale(e.scale) &lt;span style="color: #006400"&gt;// La mise à l’échelle
    &lt;/span&gt;.translate(e.translationX, e.translationY) &lt;span style="color: #006400"&gt;// Le déplacement
    &lt;/span&gt;.translate(-e.offsetX, -e.offsetY); &lt;span style="color: #006400"&gt;// Et on remet l’origine à sa place initiale
&lt;/span&gt;}&lt;/pre&gt;

&lt;p&gt;Ce qui donne le résultat final suivant : &lt;/p&gt;

&lt;p&gt;&lt;iframe style="border-top: rgb(255,255,255) 0px solid; border-right: rgb(255,255,255) 0px solid; border-bottom: rgb(255,255,255) 0px solid; border-left: rgb(255,255,255) 0px solid" height="500" src="http://david.blob.core.windows.net/html5/touchsample7.html" width="900" scrolling="no"&gt;&lt;/iframe&gt;

  &lt;br /&gt;&lt;/p&gt;

&lt;p&gt;Essayez de déplacer et lancer l’image dans la zone à fond noir avec 1 ou plusieurs doigts. Essayez également de zoomer ou faire tourner l’image avec 2 ou plusieurs doigts. Le résultat est vraiment agréable et le code pour le réaliser extrêmement simple puisque toute la complexité a été prise en charge nativement par IE10.&lt;/p&gt;

&lt;h2&gt;Liens directs vers tous les exemples&lt;/h2&gt;

&lt;p&gt;Si vous n’avez pas d’écran tactile ou si vous n’avez pas de moyens simples de tester IE10 (malgré le site &lt;a href="http://modern.ie/virtualization-tools"&gt;Modern.IE&lt;/a&gt;), n’hésitez pas à jeter un œil à la session Microsoft Techdays 2013 : &lt;a href="http://www.microsoft.com/france/mstechdays/programmes/2013/fiche-session.aspx?ID=5bd8f617-2ecb-476a-b0fb-3e2ef58305f1"&gt;HTML5, JavaScript et CSS3: Concevoir des interfaces tactiles à destination de Windows 8 et du web (WEB202)&lt;/a&gt; pour voir l’ensemble en action.&lt;/p&gt;

&lt;p&gt;Sinon, voici la liste des exemples embarqués dans les iframes de cet article:&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;- &lt;a title="http://david.blob.core.windows.net/html5/touchsample1.htm" href="http://david.blob.core.windows.net/html5/touchsample1.htm"&gt;Simple touch sample 0 with nothing done&lt;/a&gt;&amp;#160; &lt;br /&gt;- &lt;a title="http://david.blob.core.windows.net/html5/touchsample2.htm" href="http://david.blob.core.windows.net/html5/touchsample2.htm"&gt;Simple touch sample 1 with CSS -ms-touch-action&lt;/a&gt;&amp;#160; &lt;br /&gt;- &lt;a title="http://david.blob.core.windows.net/html5/touchsample3.htm" href="http://david.blob.core.windows.net/html5/touchsample3.htm"&gt;Simple touch sample 2a with basic MSPointerMove implementation&lt;/a&gt;&amp;#160; &lt;br /&gt;- &lt;a title="http://david.blob.core.windows.net/html5/touchsample4.htm" href="http://david.blob.core.windows.net/html5/touchsample4.htm"&gt;Simple touch sample 2b with pointerType differentiation&lt;/a&gt;&amp;#160; &lt;br /&gt;- &lt;a title="http://david.blob.core.windows.net/html5/touchsample5.htm" href="http://david.blob.core.windows.net/html5/touchsample5.htm"&gt;Simple touch sample 3 with MSPointers and mouse fallback&lt;/a&gt;&amp;#160; &lt;br /&gt;- &lt;a title="http://david.blob.core.windows.net/html5/touchsample6.html" href="http://david.blob.core.windows.net/html5/touchsample6.html"&gt;MSGesture sample 1: MSGestureHold handler&lt;/a&gt;&amp;#160; &lt;br /&gt;- &lt;a title="http://david.blob.core.windows.net/html5/touchsample6b.html" href="http://david.blob.core.windows.net/html5/touchsample6b.html"&gt;MSGesture sample 1b: MSGestureHold handler&lt;/a&gt;&amp;#160; &lt;br /&gt;- &lt;a title="http://david.blob.core.windows.net/html5/touchsample7.html" href="http://david.blob.core.windows.net/html5/touchsample7.html"&gt;MSGesture sample 2: MSGestureChange&lt;/a&gt;&amp;#160;&lt;/p&gt;

&lt;h2&gt;Quelques ressources associées : &lt;/h2&gt;

&lt;p&gt;- &lt;a href="http://www.w3.org/TR/pointerevents/"&gt;W3C Pointer Events Specification&lt;/a&gt; 

  &lt;br /&gt;- &lt;a href="http://blogs.msdn.com/b/eternalcoding/archive/2013/01/16/hand-js-a-polyfill-for-supporting-pointer-events-on-every-browser.aspx"&gt;HandJS a polyfill for supporting pointer events on every browser&lt;/a&gt; : la librairie JavaScript de polyfill de David Catuhe

  &lt;br /&gt;- &lt;a href="http://msdn.microsoft.com/en-us/library/hh673557(v=vs.85).aspx"&gt;Pointer and gesture events&lt;/a&gt; 

  &lt;br /&gt;- &lt;a title="http://blogs.msdn.com/b/ie/archive/2012/06/20/go-beyond-pan-zoom-and-tap-using-gesture-events.aspx" href="http://blogs.msdn.com/b/ie/archive/2012/06/20/go-beyond-pan-zoom-and-tap-using-gesture-events.aspx"&gt;Go Beyond Pan, Zoom, and Tap Using Gesture Events&lt;/a&gt; 

  &lt;br /&gt;- &lt;a href="http://ie.microsoft.com/testdrive/Browser/BrowserSurface/"&gt;IE Test Drive Browser Surface&lt;/a&gt; qui a grandement inspiré mes démos 

  &lt;br /&gt;- N’hésitez pas à essayer des expériences tactiles dans IE10. Vous en trouverez un joli florilège ici : &lt;a title="http://www.internetexplorer.fr/touchgallery" href="http://www.internetexplorer.fr/touchgallery"&gt;http://www.internetexplorer.fr/touchgallery&lt;/a&gt; . Je vous conseille notamment :

  &lt;br /&gt;&amp;#160; - &lt;a href="http://www.contrejour.ie"&gt;Contre Jour&lt;/a&gt; , un excellent jeu en HTML5 accompagné de son retour d’expérience à lire en français ici : &lt;a href="http://www.contrejour.ie/BehindTheScenes.html"&gt;Behind The Scenes&lt;/a&gt; !

  &lt;br /&gt;&amp;#160; - &lt;a href="http://atari.com/arcade"&gt;Atari Arcade Games&lt;/a&gt; , la suite de jeux Atari portés en HTML5 grâce à CreateJS.&lt;/p&gt;

&lt;p&gt;Logiquement, avec tous les détails que je vous ai partagés dans cet article ainsi que les ressources associées, vous devriez &lt;b&gt;être en mesure de commencer à implémenter le modèle de Pointer Events dans vos sites web&lt;/b&gt; &amp;amp; vos applications pour le Windows Store. Vous avez désormais l’opportunité de facilement augmenter l’expérience utilisateur de vos sites sous Internet Explorer 10.&lt;/p&gt;

&lt;p&gt;David&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10406362" width="1" height="1"&gt;</content><author><name>David Rousset</name><uri>http://blogs.msdn.com/davrous/ProfileUrlRedirect.ashx</uri></author><category term="HTML5" scheme="http://blogs.msdn.com/b/davrous/archive/tags/HTML5/" /><category term="IE10" scheme="http://blogs.msdn.com/b/davrous/archive/tags/IE10/" /><category term="Windows 8" scheme="http://blogs.msdn.com/b/davrous/archive/tags/Windows+8/" /><category term="Touch Events" scheme="http://blogs.msdn.com/b/davrous/archive/tags/Touch+Events/" /><category term="Windows Phone 8" scheme="http://blogs.msdn.com/b/davrous/archive/tags/Windows+Phone+8/" /><category term="Pointer Events" scheme="http://blogs.msdn.com/b/davrous/archive/tags/Pointer+Events/" /></entry><entry><title>Coding4fun: the Star Wars intro in pure CSS3 thanks to 3D transform &amp; animations</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/davrous/archive/2013/02/25/coding4fun-the-star-wars-intro-in-pure-css3-thanks-to-3dt-amp-animations.aspx" /><id>http://blogs.msdn.com/b/davrous/archive/2013/02/25/coding4fun-the-star-wars-intro-in-pure-css3-thanks-to-3dt-amp-animations.aspx</id><published>2013-02-25T19:54:40Z</published><updated>2013-02-25T19:54:40Z</updated><content type="html">&lt;!-- Include the VideoJS Library --&gt;&lt;script type="text/javascript" charset="utf-8" src="http://david.blob.core.windows.net/videos/video-js/video.js"&gt;&lt;/script&gt;&lt;script type="text/javascript"&gt;// &lt;![CDATA[
    
	VideoJS.setupAllWhenReady();
  
// ]]&gt;&lt;/script&gt;&lt;link title="Video JS" rel="stylesheet" type="text/css" href="http://david.blob.core.windows.net/videos/video-js/video-js.css" media="screen" /&gt;  &lt;p&gt;During the &lt;a href="http://www.mstechdays.fr/"&gt;French Microsoft Techdays&lt;/a&gt; that occurred from the 12&lt;sup&gt;th&lt;/sup&gt; to the 14&lt;sup&gt;th&lt;/sup&gt; of February 2013, I’ve built a fun &amp;amp; stupid demo to &lt;a href="http://www.microsoft.com/france/mstechdays/Live.aspx?day=j1&amp;amp;time=32719"&gt;start the Coding4Fun session&lt;/a&gt;. The idea was to rebuild the famous StarWars intro with the 3D scrolling text and the slide down effect with a star destroyer ship coming at the end. This useless demo was built using only some CSS3 3D transform &amp;amp; animation and the HTML5 audio &amp;amp; video tags. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;em&gt;Yes, it uses 0 line of JavaScript !!!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;This demo is mainly based on this awesome article: &lt;a title="http://www.sitepoint.com/css3-starwars-scrolling-text/" href="http://www.sitepoint.com/css3-starwars-scrolling-text/"&gt;Star Wars 3D Scrolling Text in CSS3&lt;/a&gt; from &lt;a href="http://www.sitepoint.com/author/craig-buckler/"&gt;Craig Buckler&lt;/a&gt;. But I’ve tweaked it a little bit by adding some parts at the beginning. The most cool part was added at the end of the text scrolling. &lt;/p&gt;  &lt;p&gt;Here is a video of the result running inside IE10:&lt;/p&gt;  &lt;div class="video-js-box"&gt;&lt;!-- Using the Video for Everybody Embed Code http://camendesign.com/code/video_for_everybody --&gt;&lt;video id="MSPointerEventsArticleVideo" class="video-js" poster="http://david.blob.core.windows.net/techdays2013/coding4fun/coding4fun_intro_starwars_css.jpg" width="512" height="288" controls="controls" preload="preload"&gt;&lt;source src="http://david.blob.core.windows.net/techdays2013/coding4fun/coding4fun_intro_starwars_css.mp4" type="video/mp4; codecs=&amp;quot;avc1.42E01E, mp4a.40.2&amp;quot;" /&gt;&lt;source src="http://david.blob.core.windows.net/techdays2013/coding4fun/coding4fun_intro_starwars_css.webm" type="video/webm; codecs=&amp;quot;vp8, vorbis&amp;quot;" /&gt;&lt;!-- Flash Fallback. Use any flash video player here. Make sure to keep the vjs-flash-fallback class. --&gt;&lt;object id="flash_fallback_1" class="vjs-flash-fallback" data="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf"
                    width="640" type="application/x-shockwave-flash" height="360"&gt;                     &lt;param name="movie" value="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" /&gt;                     &lt;param name="allowfullscreen" value="true" /&gt;                     &lt;param name="flashvars" value="config={&amp;quot;playlist&amp;quot;:[&amp;quot;http://david.blob.core.windows.net/techdays2013/coding4fun/coding4fun_intro_starwars_css.jpg&amp;quot;, {&amp;quot;url&amp;quot;: &amp;quot;http://david.blob.core.windows.net/techdays2013/coding4fun/coding4fun_intro_starwars_css.mp4&amp;quot;,&amp;quot;autoPlay&amp;quot;:false,&amp;quot;autoBuffering&amp;quot;:true}]}" /&gt;                     &lt;!-- Image Fallback. Typically the same as the poster image. --&gt;                     &lt;img title="No video playback capabilities." alt="Poster Image" src="http://david.blob.core.windows.net/techdays2013/coding4fun/coding4fun_intro_starwars_css.jpg" width="512" height="288" /&gt;                 &lt;/object&gt;&lt;/video&gt;&lt;!-- Download links provided for devices that can't play video in the browser. --&gt;    &lt;p class="vjs-no-video"&gt;&lt;strong&gt;Download Video:&lt;/strong&gt; &lt;a href="http://david.blob.core.windows.net/techdays2013/coding4fun/coding4fun_intro_starwars_css.mp4"&gt;MP4&lt;/a&gt;, &lt;a href="http://david.blob.core.windows.net/techdays2013/coding4fun/coding4fun_intro_starwars_css.webm"&gt;WebM&lt;/a&gt;, &lt;!-- Support VideoJS by keeping this link. --&gt;&lt;a href="http://videojs.com"&gt;HTML5 Video Player&lt;/a&gt; by VideoJS&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;   &lt;br /&gt;And you can of course &lt;strong&gt;&lt;u&gt;run the same demo directly in your favorite browser from here:&lt;/u&gt;&lt;/strong&gt; &lt;a title="http://david.blob.core.windows.net/techdays2013/index.html" href="http://david.blob.core.windows.net/techdays2013/coding4fun/index.html"&gt;Coding4Fun StarWars Intro in pure CSS&lt;/a&gt; . It lasts approximately 140 seconds to run the complete demo. Of course, you won’t have audio in this demo as John Williams’ music is copyrighted. So, if you’d like to have the complete video &amp;amp; &lt;strong&gt;audio experience&lt;/strong&gt;, go buy the music composed by John Williams (the best composer in the universe !) and convert it to mp3 and/or ogg to map the audio tag definition you’ll find in the source code. In my case, I’ve just added 24 seconds of blank sound to synchronize my keyframes with the music itself.&amp;#160; &lt;/p&gt;  &lt;p&gt;If you don’t speak French, don’t pay attention to the text. I was too lazy to translate it in English as it’s using some French developer’s unique humor. I’m sure you don’t want to share that. &lt;img class="wlEmoticon wlEmoticon-winkingsmile" style="border-top-style: none; border-left-style: none; border-bottom-style: none; border-right-style: none" alt="Clignement d&amp;#39;œil" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8867.wlEmoticon_2D00_winkingsmile_5F00_0DABEC50.png" /&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Update:&lt;/u&gt; &lt;/strong&gt;some of my UK friends, like &lt;a href="https://twitter.com/thebeebs"&gt;Martin Beeby&lt;/a&gt;, noted that as it’s only some pure HTML text used, you just need an online translator to target the language of your choice! For instance, try the &lt;a href="http://www.microsofttranslator.com/bv.aspx?from=&amp;amp;to=en&amp;amp;a=http%3A%2F%2Fdavid.blob.core.windows.net%2Ftechdays2013%2Fcoding4fun%2Findex.html"&gt;English version&lt;/a&gt; or the &lt;a href="http://t.co/rVKuVZYdxf"&gt;Chinese version&lt;/a&gt;. &lt;img class="wlEmoticon wlEmoticon-openmouthedsmile" style="border-top-style: none; border-left-style: none; border-bottom-style: none; border-right-style: none" alt="Rire" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8422.wlEmoticon_2D00_openmouthedsmile_5F00_53455B1A.png" /&gt;&lt;/p&gt;  &lt;p&gt;The demo itself should run fine inside &lt;strong&gt;&lt;font color="#008000"&gt;IE10&lt;/font&gt;&lt;/strong&gt; on Windows 7/Windows 8/Windows Phone 8, &lt;strong&gt;&lt;font color="#008000"&gt;Firefox&lt;/font&gt;&lt;/strong&gt;, &lt;strong&gt;&lt;font color="#008000"&gt;Safari&lt;/font&gt;&lt;/strong&gt; &amp;amp; &lt;strong&gt;&lt;font color="#008000"&gt;Chrome&lt;/font&gt;&lt;/strong&gt;. Opera, which doesn’t support yet 3D transform, will then not run properly all parts. The experience is slightly better in IE10 as it’s the only one supporting the &lt;a href="http://go.microsoft.com/fwlink/p/?linkid=233011"&gt;CSS Viewport specification&lt;/a&gt;. It’s also super fluid on my PC running a simple HD4000 GPU and on my Nokia Lumia 920. Hardware acceleration is definitely great for that! &lt;/p&gt;  &lt;p&gt;If you’d like to understand how it works, all the demo logic is contained inside &lt;strong&gt;index.css&lt;/strong&gt; which use a lot of keyframes definition with the appropriate timings. Note that it uses the standard &lt;strong&gt;CSS animation &amp;amp; transform unprefixed specification&lt;/strong&gt; supported by IE10, Firefox and Opera. To support older experimental Webkit implementations, I’ve added a &lt;strong&gt;webkit-index.css&lt;/strong&gt; file containing the very same logic but with the –webkit prefix for Chrome &amp;amp; Safari browsers. Let’s hope that those browsers will soon implement the unprefixed versions to join the club made of IE10, Firefox &amp;amp; Opera to definitely get rid of vendor prefixes on those specifications.&lt;/p&gt;  &lt;p&gt;Compared to the original Craig’s demo, I’ve added a simple intro with some fading effects and an additional vertical scrolling at the end of the 3d text scrolling which ends to a html5 looping video. &lt;/p&gt;  &lt;p&gt;Here is a series of images showing this final sequence done:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/2234.image_5F00_5519AAEE.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5466.image_5F00_thumb_5F00_70E05188.png" width="180" height="102" /&gt;&lt;/a&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5873.image_5F00_4A14CBF9.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4380.image_5F00_thumb_5F00_0255D3C3.png" width="180" height="102" /&gt;&lt;/a&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/7433.image_5F00_32137C42.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/7838.image_5F00_thumb_5F00_608F1C93.png" width="180" height="102" /&gt;&lt;/a&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5873.image_5F00_092D889B.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/1641.image_5F00_thumb_5F00_20E9E163.png" width="180" height="102" /&gt;&lt;/a&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5873.image_5F00_7775A022.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/7026.image_5F00_thumb_5F00_0F9E2BE0.png" width="180" height="102" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The final Star Detroyer is simply using the CSS 3D transform trick coupled with a CSS animation. The HTML associated with this sequence is very very simple:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;video &lt;/span&gt;&lt;span style="color: red"&gt;class&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;fondvideo&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;poster&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;fondfixe.jpg&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;autoplay loop&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;source &lt;/span&gt;&lt;span style="color: red"&gt;src&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;hprichv.mp4&amp;quot; /&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;source &lt;/span&gt;&lt;span style="color: red"&gt;src&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;hprichv.ogv&amp;quot; /&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;video&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;

&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;img &lt;/span&gt;&lt;span style="color: red"&gt;class&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;galaxy&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;src&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;bg_image.jpg&amp;quot; /&amp;gt;

&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;img &lt;/span&gt;&lt;span style="color: red"&gt;class&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;destroyer&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;src&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;stardestroyer.png&amp;quot; /&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;div &lt;/span&gt;&lt;span style="color: red"&gt;class&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;finalfadding&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;div&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;And here is the associated CSS to achieve the animations:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: #006400"&gt;/* Final ship animation. The trick is to play on 3D rotation and Z translation */
/* To mimic again the first Star Destroyer animation */
&lt;/span&gt;&lt;span style="color: blue"&gt;@keyframes &lt;/span&gt;scrollship {
    0% {
        &lt;span style="color: red"&gt;opacity&lt;/span&gt;: &lt;span style="color: blue"&gt;0&lt;/span&gt;;
        &lt;span style="color: red"&gt;transform&lt;/span&gt;: &lt;span style="color: blue"&gt;perspective(300px) translateZ(150px) rotateX(-80deg)&lt;/span&gt;;
    }

    3% {
        &lt;span style="color: red"&gt;opacity&lt;/span&gt;: &lt;span style="color: blue"&gt;1&lt;/span&gt;;
    }

    100% {
        &lt;span style="color: red"&gt;opacity&lt;/span&gt;: &lt;span style="color: blue"&gt;1&lt;/span&gt;;
        &lt;span style="color: red"&gt;transform&lt;/span&gt;: &lt;span style="color: blue"&gt;perspective(300px) translateZ(-4000px) rotateX(-80deg)&lt;/span&gt;;
    }
}

&lt;span style="color: #006400"&gt;/* Translating the galaxy image background on the Y axis to again */
/* mimic the StarWars intro */
&lt;/span&gt;&lt;span style="color: blue"&gt;@keyframes &lt;/span&gt;galaxyscrolling {
    0% {
        &lt;span style="color: red"&gt;top&lt;/span&gt;: &lt;span style="color: blue"&gt;0%&lt;/span&gt;;
    }

    100% {
        &lt;span style="color: red"&gt;top&lt;/span&gt;: &lt;span style="color: blue"&gt;-100%&lt;/span&gt;;
    }
}

&lt;span style="color: #006400"&gt;/* The video tag is animated in the same time as the galaxy  */
/* to achieve a continuous animation */
&lt;/span&gt;&lt;span style="color: blue"&gt;@keyframes &lt;/span&gt;videoscrolling {
    0% {
        &lt;span style="color: red"&gt;top&lt;/span&gt;: &lt;span style="color: blue"&gt;55%&lt;/span&gt;;
    }

    100% {
        &lt;span style="color: red"&gt;top&lt;/span&gt;: &lt;span style="color: blue"&gt;-40%&lt;/span&gt;;
    }
}

&lt;span style="color: #006400"&gt;/* Final black fading */
&lt;/span&gt;&lt;span style="color: blue"&gt;@keyframes &lt;/span&gt;finalfaddingkeyframes {
    0% {
        &lt;span style="color: red"&gt;opacity&lt;/span&gt;: &lt;span style="color: blue"&gt;0&lt;/span&gt;;
    }

    100% {
        &lt;span style="color: red"&gt;opacity&lt;/span&gt;: &lt;span style="color: blue"&gt;1&lt;/span&gt;;
    }
}

&lt;span style="color: #006400"&gt;/* First image background */
&lt;/span&gt;&lt;span style="color: maroon"&gt;.galaxy &lt;/span&gt;{
    &lt;span style="color: red"&gt;width&lt;/span&gt;: &lt;span style="color: blue"&gt;100%&lt;/span&gt;;
    &lt;span style="color: red"&gt;height&lt;/span&gt;: &lt;span style="color: blue"&gt;100%&lt;/span&gt;;
    &lt;span style="color: red"&gt;position&lt;/span&gt;: &lt;span style="color: blue"&gt;absolute&lt;/span&gt;;
    &lt;span style="color: red"&gt;top&lt;/span&gt;: &lt;span style="color: blue"&gt;0%&lt;/span&gt;;
    &lt;span style="color: red"&gt;animation&lt;/span&gt;: &lt;span style="color: blue"&gt;galaxyscrolling 15s ease-out 111s 1&lt;/span&gt;;
    &lt;span style="color: red"&gt;animation-fill-mode&lt;/span&gt;: &lt;span style="color: blue"&gt;forwards&lt;/span&gt;;
}

&lt;span style="color: #006400"&gt;/* background HTML5 looping video */
&lt;/span&gt;&lt;span style="color: maroon"&gt;.fondvideo &lt;/span&gt;{
    &lt;span style="color: red"&gt;position&lt;/span&gt;: &lt;span style="color: blue"&gt;absolute&lt;/span&gt;;
    &lt;span style="color: red"&gt;width&lt;/span&gt;: &lt;span style="color: blue"&gt;100%&lt;/span&gt;;
    &lt;span style="color: red"&gt;height&lt;/span&gt;: &lt;span style="color: blue"&gt;200%&lt;/span&gt;;
    &lt;span style="color: red"&gt;top&lt;/span&gt;: &lt;span style="color: blue"&gt;55%&lt;/span&gt;;
    &lt;span style="color: red"&gt;animation&lt;/span&gt;: &lt;span style="color: blue"&gt;videoscrolling 15s ease-out 111s 1&lt;/span&gt;;
    &lt;span style="color: red"&gt;animation-fill-mode&lt;/span&gt;: &lt;span style="color: blue"&gt;forwards&lt;/span&gt;;
}

&lt;span style="color: #006400"&gt;/* Final destroyer animation. It's just a PNG image animated using 3D Transform */
&lt;/span&gt;&lt;span style="color: maroon"&gt;.destroyer &lt;/span&gt;{
    &lt;span style="color: red"&gt;position&lt;/span&gt;: &lt;span style="color: blue"&gt;absolute&lt;/span&gt;;
    &lt;span style="color: red"&gt;top&lt;/span&gt;: &lt;span style="color: blue"&gt;-70%&lt;/span&gt;;
    &lt;span style="color: red"&gt;opacity&lt;/span&gt;: &lt;span style="color: blue"&gt;0&lt;/span&gt;;
    &lt;span style="color: red"&gt;transform-origin&lt;/span&gt;: &lt;span style="color: blue"&gt;50% 100%&lt;/span&gt;;
    &lt;span style="color: red"&gt;width&lt;/span&gt;: &lt;span style="color: blue"&gt;100%&lt;/span&gt;;
    &lt;span style="color: red"&gt;height&lt;/span&gt;: &lt;span style="color: blue"&gt;100%&lt;/span&gt;;
    &lt;span style="color: red"&gt;transform&lt;/span&gt;: &lt;span style="color: blue"&gt;perspective(300px) translateZ(150px) rotateX(-80deg)&lt;/span&gt;;
    &lt;span style="color: red"&gt;animation&lt;/span&gt;: &lt;span style="color: blue"&gt;scrollship 120s linear 125s 1&lt;/span&gt;;
    &lt;span style="color: red"&gt;animation-fill-mode&lt;/span&gt;: &lt;span style="color: blue"&gt;forwards&lt;/span&gt;;
}

&lt;span style="color: #006400"&gt;/* final fading using a black div */
&lt;/span&gt;&lt;span style="color: maroon"&gt;.finalfadding &lt;/span&gt;{
    &lt;span style="color: red"&gt;position&lt;/span&gt;: &lt;span style="color: blue"&gt;absolute&lt;/span&gt;;
    &lt;span style="color: red"&gt;width&lt;/span&gt;: &lt;span style="color: blue"&gt;100%&lt;/span&gt;;
    &lt;span style="color: red"&gt;height&lt;/span&gt;: &lt;span style="color: blue"&gt;100%&lt;/span&gt;;
    &lt;span style="color: red"&gt;opacity&lt;/span&gt;: &lt;span style="color: blue"&gt;0&lt;/span&gt;;
    &lt;span style="color: red"&gt;background-color&lt;/span&gt;: &lt;span style="color: blue"&gt;black&lt;/span&gt;;
    &lt;span style="color: red"&gt;animation&lt;/span&gt;: &lt;span style="color: blue"&gt;finalfaddingkeyframes 5s ease-out 140s 1&lt;/span&gt;;
    &lt;span style="color: red"&gt;animation-fill-mode&lt;/span&gt;: &lt;span style="color: blue"&gt;forwards&lt;/span&gt;;
}&lt;/pre&gt;

&lt;p&gt;The timing are the one currently set for the global sequence. You see for instance that the final fading only occurs after 140s. You can see also that the final ending black fading is simply done with an overlay black DIV getting from opacity 0 to 1. &lt;/p&gt;

&lt;p&gt;The super cool HTML5 video is the earth shooted by the NASA from the space and showing some magic aurora effects:&lt;/p&gt;
&lt;video poster="http://david.blob.core.windows.net/techdays2013/coding4fun/fondfixe.jpg" width="683px" loop autoplay&gt;&lt;source src="http://david.blob.core.windows.net/techdays2013/coding4fun/hprichv.mp4" /&gt;&lt;source src="http://david.blob.core.windows.net/techdays2013/coding4fun/hprichv.ogv" /&gt;&lt;/video&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Credit&lt;/u&gt;&lt;/strong&gt;: &lt;em&gt;Image Science &amp;amp; Analysis Laboratory, NASA Johnson Space Center&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;You may find other videos like that from the NASA on their website: &lt;a href="http://eol.jsc.nasa.gov/Videos/CrewEarthObservationsVideos/Videos_Aurora.htm"&gt;Videos Aurora&lt;/a&gt; or here &lt;a href="http://eol.jsc.nasa.gov/Videos/CrewEarthObservationsVideos/"&gt;Crew Earth Observations Videos&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally, to try to control the viewport to have the same experience across resolutions, I’m using the &lt;a href="http://msdn.microsoft.com/en-us/library/ie/hh869615(v=vs.85).aspx"&gt;@viewport CSS specification&lt;/a&gt; coming from &lt;a href="http://go.microsoft.com/fwlink/p/?linkid=233011"&gt;CSS Device Adaptation&lt;/a&gt;, Section 4. &lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;@-webkit-viewport &lt;/span&gt;{&lt;span style="color: red"&gt;width&lt;/span&gt;: &lt;span style="color: blue"&gt;1366px&lt;/span&gt;;&lt;span style="color: red"&gt;height&lt;/span&gt;: &lt;span style="color: blue"&gt;768px&lt;/span&gt;;}
&lt;span style="color: blue"&gt;@-moz-viewport &lt;/span&gt;{&lt;span style="color: red"&gt;width&lt;/span&gt;: &lt;span style="color: blue"&gt;1366px&lt;/span&gt;;&lt;span style="color: red"&gt;height&lt;/span&gt;: &lt;span style="color: blue"&gt;768px&lt;/span&gt;;}
&lt;span style="color: blue"&gt;@-ms-viewport &lt;/span&gt;{&lt;span style="color: red"&gt;width&lt;/span&gt;: &lt;span style="color: blue"&gt;1366px&lt;/span&gt;;&lt;span style="color: red"&gt;height&lt;/span&gt;: &lt;span style="color: blue"&gt;768px&lt;/span&gt;;}
&lt;span style="color: blue"&gt;@-o-viewport &lt;/span&gt;{&lt;span style="color: red"&gt;width&lt;/span&gt;: &lt;span style="color: blue"&gt;1366px&lt;/span&gt;;&lt;span style="color: red"&gt;height&lt;/span&gt;: &lt;span style="color: blue"&gt;768px&lt;/span&gt;;}
&lt;span style="color: blue"&gt;@viewport &lt;/span&gt;{&lt;span style="color: red"&gt;width&lt;/span&gt;: &lt;span style="color: blue"&gt;1366px&lt;/span&gt;;&lt;span style="color: red"&gt;height&lt;/span&gt;: &lt;span style="color: blue"&gt;768px&lt;/span&gt;;}&lt;/pre&gt;

&lt;p&gt;This specification is currently only supported by IE10 in the desktop world. The demo doesn’t break in other browsers. But the experience is a bit better in IE10 as we have more control on the various resolutions thanks to the viewport rule. &lt;/p&gt;

&lt;p&gt;Under Internet Explorer 10, try for instance to resize the window during each sequence of the demo and you’ll see what I mean. If you don’t have a way to test Internet Explorer 10, you have 2 options:&lt;/p&gt;

&lt;p&gt;1 – Use &lt;a href="http://www.modern.ie/virtualization-tools"&gt;Browser Stack&lt;/a&gt; to test it. You have a 3 months offering thanks to our &lt;a href="http://modern.ie"&gt;Modern.IE&lt;/a&gt; website. You should have a look to it! 

  &lt;br /&gt;2 – Have a look to this short video:&lt;/p&gt;

&lt;div class="video-js-box"&gt;&lt;!-- Using the Video for Everybody Embed Code http://camendesign.com/code/video_for_everybody --&gt;&lt;video id="MSPointerEventsArticleVideo" class="video-js" poster="http://david.blob.core.windows.net/techdays2013/coding4fun/DemoIE10ResizeCSSViewport.jpg" width="512" height="288" controls="controls" preload="preload"&gt;&lt;source src="http://david.blob.core.windows.net/techdays2013/coding4fun/DemoIE10ResizeCSSViewport.mp4" type="video/mp4; codecs=&amp;quot;avc1.42E01E, mp4a.40.2&amp;quot;" /&gt;&lt;source src="http://david.blob.core.windows.net/techdays2013/coding4fun/DemoIE10ResizeCSSViewport.webm" type="video/webm; codecs=&amp;quot;vp8, vorbis&amp;quot;" /&gt;&lt;!-- Flash Fallback. Use any flash video player here. Make sure to keep the vjs-flash-fallback class. --&gt;&lt;object id="flash_fallback_1" class="vjs-flash-fallback" data="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf"
                    width="640" type="application/x-shockwave-flash" height="360"&gt;                     &lt;param name="movie" value="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" /&gt;                     &lt;param name="allowfullscreen" value="true" /&gt;                     &lt;param name="flashvars" value="config={&amp;quot;playlist&amp;quot;:[&amp;quot;http://david.blob.core.windows.net/techdays2013/coding4fun/DemoIE10ResizeCSSViewport.jpg&amp;quot;, {&amp;quot;url&amp;quot;: &amp;quot;http://david.blob.core.windows.net/techdays2013/coding4fun/DemoIE10ResizeCSSViewport.mp4&amp;quot;,&amp;quot;autoPlay&amp;quot;:false,&amp;quot;autoBuffering&amp;quot;:true}]}" /&gt;                     &lt;!-- Image Fallback. Typically the same as the poster image. --&gt;                     &lt;img title="No video playback capabilities." alt="Poster Image" src="http://david.blob.core.windows.net/techdays2013/coding4fun/DemoIE10ResizeCSSViewport.jpg" width="512" height="288" /&gt;                 &lt;/object&gt;&lt;/video&gt;&lt;!-- Download links provided for devices that can't play video in the browser. --&gt;

  &lt;p class="vjs-no-video"&gt;&lt;strong&gt;Download Video:&lt;/strong&gt; &lt;a href="http://david.blob.core.windows.net/techdays2013/coding4fun/DemoIE10ResizeCSSViewport.mp4"&gt;MP4&lt;/a&gt;, &lt;a href="http://david.blob.core.windows.net/techdays2013/coding4fun/DemoIE10ResizeCSSViewport.webm"&gt;WebM&lt;/a&gt;, &lt;!-- Support VideoJS by keeping this link. --&gt;&lt;a href="http://videojs.com"&gt;HTML5 Video Player&lt;/a&gt; by VideoJS&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;
  &lt;br /&gt;That’s all folks. I hope that some of you will enjoy this funky experiment. &lt;img class="wlEmoticon wlEmoticon-winkingsmile" style="border-top-style: none; border-left-style: none; border-bottom-style: none; border-right-style: none" alt="Clignement d&amp;#39;œil" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8867.wlEmoticon_2D00_winkingsmile_5F00_0DABEC50.png" /&gt;&lt;/p&gt;

&lt;p&gt;David&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10396905" width="1" height="1"&gt;</content><author><name>David Rousset</name><uri>http://blogs.msdn.com/davrous/ProfileUrlRedirect.ashx</uri></author><category term="HTML5" scheme="http://blogs.msdn.com/b/davrous/archive/tags/HTML5/" /><category term="CSS3" scheme="http://blogs.msdn.com/b/davrous/archive/tags/CSS3/" /><category term="IE10" scheme="http://blogs.msdn.com/b/davrous/archive/tags/IE10/" /><category term="coding4fun" scheme="http://blogs.msdn.com/b/davrous/archive/tags/coding4fun/" /></entry><entry><title>Creating an universal virtual touch joystick working for all Touch models thanks to Hand.JS</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/davrous/archive/2013/02/22/creating-an-universal-virtual-touch-joystick-working-for-all-touch-models-thanks-to-hand-js.aspx" /><id>http://blogs.msdn.com/b/davrous/archive/2013/02/22/creating-an-universal-virtual-touch-joystick-working-for-all-touch-models-thanks-to-hand-js.aspx</id><published>2013-02-22T13:28:00Z</published><updated>2013-02-22T13:28:00Z</updated><content type="html">&lt;!-- Include the VideoJS Library --&gt;&lt;script type="text/javascript" charset="utf-8" src="http://david.blob.core.windows.net/videos/video-js/video.js"&gt;&lt;/script&gt;&lt;script type="text/javascript"&gt;// &lt;![CDATA[
    
	VideoJS.setupAllWhenReady();
  
// ]]&gt;&lt;/script&gt;&lt;link title="Video JS" rel="stylesheet" type="text/css" href="http://david.blob.core.windows.net/videos/video-js/video-js.css" media="screen" /&gt;  &lt;p&gt;I’m currently working on several gaming projects for modern browsers and Windows 8 Store projects. Some of them are using HTML5 as a base in order to simplify multi-devices targeting. I was then looking for a unified way to address all inputs on all platforms: Windows 8/RT, Windows Phone 8, iPad, Android &amp;amp; FirefoxOS.&lt;/p&gt;  &lt;p&gt;As you’ve maybe discovered in my previous article &lt;a title="Unifying touch and mouse- how Pointer Events will make cross-browsers touch support easy" href="http://blogs.msdn.com/b/davrous/archive/2013/02/20/handling-touch-in-your-html5-apps-thanks-to-the-pointer-events-of-ie10-and-windows-8.aspx"&gt;Unifying touch and mouse- how Pointer Events will make cross-browsers touch support easy&lt;/a&gt;&lt;i&gt;, &lt;/i&gt;IE10 on Windows 8/RT &amp;amp; Windows Phone 8 implement the Pointer Events model we’ve submitted to the W3C. In order to address in a unified way this Pointer Events model and the one implemented in WebKit based browsers, we’re going to use &lt;a href="https://twitter.com/deltakosh"&gt;David Catuhe&lt;/a&gt;’s HandJS library. Check out his blog’s post here: &lt;a href="http://blogs.msdn.com/b/eternalcoding/archive/2013/01/16/hand-js-a-polyfill-for-supporting-pointer-events-on-every-browser.aspx"&gt;HandJS a polyfill for supporting pointer events on every browser&lt;/a&gt;. This idea is to target the Pointer model and the library will propagate the touch events to all platforms specifics. &lt;/p&gt;  &lt;p&gt;Once I had all the technical pieces in hand, I was looking for a great way to implement a virtual touch joystick in my game. I’m not a huge fan of arrow keys buttons to be touched. On another side, the virtual analogic pad are often not very well placed. But I’ve finally discovered that &lt;a href="http://seb.ly/author/seb/"&gt;Seb Lee-Delisle&lt;/a&gt; had already digested this and has created this awesome concept described in &lt;a href="http://seb.ly/2011/04/multi-touch-game-controller-in-javascripthtml5-for-ipad"&gt;Multi-touch game controller in JavaScript/HTML5 for iPad&lt;/a&gt; . The code is available on GitHub here: &lt;a href="https://github.com/sebleedelisle/JSTouchController"&gt;JSTouchController &lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The idea was then to take his code and refactor the touch part to target the Pointer model instead of the original WebKit Touch approach. While working on that several months ago, I’ve discovered that Boris Smus from Google had already started to more or less do it. It’s been done while he was working on his own &lt;a href="https://github.com/borismus/pointer.js"&gt;Pointer.js&lt;/a&gt; library as described in his article &lt;a href="http://smus.com/mouse-touch-pointer"&gt;Generalized input on the cross-device web&lt;/a&gt;. However, at that time, Boris was mimicking an old version of the IE10 Pointer Events implementation and his library wasn’t working in IE10. That’s why, even if Boris’ work was awesome, we’ve decided to work on our own version. Indeed, David’s library is currently targeting the last and very recent &lt;a href="http://www.w3.org/TR/pointerevents"&gt;W3C version currently in last call draft&lt;/a&gt;. If you’re having a look to both librairies, you’ll see also that HandJS is using some different approaches in several parts of the code. We will then use HandJS in this article to build our touch joystick. &lt;/p&gt;  &lt;h2&gt;Sample 1: Pointers tracker&lt;/h2&gt;  &lt;p&gt;This sample helps you tracking the various inputs on the screen. It tracks and follow the various fingers pressing the canvas element. It’s based on Seb’s sample available on GitHub here: &lt;a title="Touches.html" href="https://github.com/sebleedelisle/JSTouchController/blob/master/Touches.html"&gt;Touches.html&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Thanks to Hand.js, we’re going to make it compatible for all browsers. It’s even also going to track the stylus and/or the mouse based on the type of hardware you’re currently testing on!&lt;/p&gt;  &lt;p&gt;Here is an HTML5 video of the result in IE10 running under Windows 8. You’ll find see some cyan circles tracking the fingers, then a red circle tracking the mouse and a green circle tracking the pen:&lt;/p&gt;  &lt;div class="video-js-box"&gt;&lt;!-- Using the Video for Everybody Embed Code http://camendesign.com/code/video_for_everybody --&gt;&lt;video id="MSPointerEventsArticleVideo" class="video-js" height="495" width="800" controls="controls" preload="preload" poster="http://david.blob.core.windows.net/html5/touchjoystick/PointersTrackerHandJS.jpg"&gt;&lt;source src="http://david.blob.core.windows.net/html5/touchjoystick/PointersTrackerHandJS.mp4" type="video/mp4; codecs=&amp;quot;avc1.42E01E, mp4a.40.2&amp;quot;" /&gt;&lt;source src="http://david.blob.core.windows.net/html5/touchjoystick/PointersTrackerHandJS.webm" type="video/webm; codecs=&amp;quot;vp8, vorbis&amp;quot;" /&gt;&lt;!-- Flash Fallback. Use any flash video player here. Make sure to keep the vjs-flash-fallback class. --&gt;&lt;object id="flash_fallback_1" class="vjs-flash-fallback" data="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf"
                    width="800" type="application/x-shockwave-flash" height="495"&gt;                     &lt;param name="movie" value="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" /&gt;                     &lt;param name="allowfullscreen" value="true" /&gt;                     &lt;param name="flashvars" value="config={&amp;quot;playlist&amp;quot;:[&amp;quot;http://david.blob.core.windows.net/html5/touchjoystick/PointersTrackerHandJS.jpg&amp;quot;, {&amp;quot;url&amp;quot;: &amp;quot;http://david.blob.core.windows.net/html5/touchjoystick/PointersTrackerHandJS.mp4&amp;quot;,&amp;quot;autoPlay&amp;quot;:false,&amp;quot;autoBuffering&amp;quot;:true}]}" /&gt;                     &lt;!-- Image Fallback. Typically the same as the poster image. --&gt;                     &lt;img title="No video playback capabilities." alt="Poster Image" src="http://david.blob.core.windows.net/html5/touchjoystick/PointersTrackerHandJS.jpg" width="800" height="495" /&gt;                 &lt;/object&gt;&lt;/video&gt;&lt;!-- Download links provided for devices that can't play video in the browser. --&gt;    &lt;p class="vjs-no-video"&gt;&lt;strong&gt;Download Video:&lt;/strong&gt; &lt;a href="http://david.blob.core.windows.net/html5/touchjoystick/PointersTrackerHandJS.mp4"&gt;MP4&lt;/a&gt;, &lt;a href="http://david.blob.core.windows.net/html5/touchjoystick/PointersTrackerHandJS.webm"&gt;WebM&lt;/a&gt;, &lt;!-- Support VideoJS by keeping this link. --&gt;&lt;a href="http://videojs.com"&gt;HTML5 Video Player&lt;/a&gt; by VideoJS&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;   &lt;br /&gt;The same webpage provides the very same result under Chrome on Windows 8 or on an iOS/Android/FirefoxOS devices (except that pen is only supported by IE10). Thanks to HandJS, write it once and it will run everywhere! &lt;img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-left-style: none; border-bottom-style: none; border-right-style: none" alt="Sourire" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/1007.wlEmoticon_2D00_smile_5F00_05704716.png" /&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;You’ve seen in the video that the cyan pointers are of type “TOUCH” whereas the red one is of type “MOUSE”. If you have a touch screen, you can experience the same result by testing this page embedded in this iframe:&lt;/p&gt; &lt;iframe style="border-top: rgb(255,255,255) 0px solid; border-right: rgb(255,255,255) 0px solid; border-bottom: rgb(255,255,255) 0px solid; border-left: rgb(255,255,255) 0px solid" height="400" src="http://david.blob.core.windows.net/html5/touchjoystick/Touches.html" width="800" scrolling="no"&gt;&lt;/iframe&gt;  &lt;p&gt;   &lt;br /&gt;This sample works fine on a Windows 8/RT touch device, a Windows Phone 8, an iPad/iPhone or Android/FirefoxOS device! If you don’t have a touch device, HandJS will automatically fallback to mouse. You should then be able to track at least 1 pointer with your mouse.&amp;#160; &lt;/p&gt;  &lt;p&gt;Let’s see how to obtain this result in a unified way. All the code lives in &lt;em&gt;Touches.js&lt;/em&gt;:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: maroon"&gt;&amp;quot;use strict&amp;quot;&lt;/span&gt;;

&lt;span style="color: #006400"&gt;// shim layer with setTimeout fallback
&lt;/span&gt;window.requestAnimFrame = (&lt;span style="color: blue"&gt;function &lt;/span&gt;() {
    &lt;span style="color: blue"&gt;return &lt;/span&gt;window.requestAnimationFrame ||
    window.webkitRequestAnimationFrame ||
    window.mozRequestAnimationFrame ||
    window.oRequestAnimationFrame ||
    window.msRequestAnimationFrame ||
    &lt;span style="color: blue"&gt;function &lt;/span&gt;(callback) {
        window.setTimeout(callback, 1000 / 60);
    };
})();

&lt;span style="color: blue"&gt;var &lt;/span&gt;pointers; &lt;span style="color: #006400"&gt;// collections of pointers

&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;canvas,
c; &lt;span style="color: #006400"&gt;// c is the canvas' context 2D

&lt;/span&gt;document.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;DOMContentLoaded&amp;quot;&lt;/span&gt;, init);

window.onorientationchange = resetCanvas;
window.onresize = resetCanvas;

&lt;span style="color: blue"&gt;function &lt;/span&gt;init() {
    setupCanvas();
    pointers = &lt;span style="color: blue"&gt;new &lt;/span&gt;Collection();
    canvas.addEventListener(&lt;span style="color: maroon"&gt;'pointerdown'&lt;/span&gt;, onPointerDown, &lt;span style="color: blue"&gt;false&lt;/span&gt;);
    canvas.addEventListener(&lt;span style="color: maroon"&gt;'pointermove'&lt;/span&gt;, onPointerMove, &lt;span style="color: blue"&gt;false&lt;/span&gt;);
    canvas.addEventListener(&lt;span style="color: maroon"&gt;'pointerup'&lt;/span&gt;, onPointerUp, &lt;span style="color: blue"&gt;false&lt;/span&gt;);
    canvas.addEventListener(&lt;span style="color: maroon"&gt;'pointerout'&lt;/span&gt;, onPointerUp, &lt;span style="color: blue"&gt;false&lt;/span&gt;);
    requestAnimFrame(draw);
}

&lt;span style="color: blue"&gt;function &lt;/span&gt;resetCanvas(e) {
    &lt;span style="color: #006400"&gt;// resize the canvas - but remember - this clears the canvas too.
    &lt;/span&gt;canvas.width = window.innerWidth;
    canvas.height = window.innerHeight;

    &lt;span style="color: #006400"&gt;//make sure we scroll to the top left.
    &lt;/span&gt;window.scrollTo(0, 0);
}

&lt;span style="color: blue"&gt;function &lt;/span&gt;draw() {
    c.clearRect(0, 0, canvas.width, canvas.height);

    pointers.forEach(&lt;span style="color: blue"&gt;function &lt;/span&gt;(pointer) {
        c.beginPath();
        c.fillStyle = &lt;span style="color: maroon"&gt;&amp;quot;white&amp;quot;&lt;/span&gt;;
        c.fillText(pointer.type + &lt;span style="color: maroon"&gt;&amp;quot; id : &amp;quot; &lt;/span&gt;+ pointer.identifier + &lt;span style="color: maroon"&gt;&amp;quot; x:&amp;quot; &lt;/span&gt;+ pointer.x + &lt;span style="color: maroon"&gt;&amp;quot; y:&amp;quot; &lt;/span&gt;+ &lt;br /&gt;                   pointer.y, pointer.x + 30, pointer.y - 30);

        c.beginPath();
        c.strokeStyle = pointer.color;
        c.lineWidth = &lt;span style="color: maroon"&gt;&amp;quot;6&amp;quot;&lt;/span&gt;;
        c.arc(pointer.x, pointer.y, 40, 0, Math.PI * 2, &lt;span style="color: blue"&gt;true&lt;/span&gt;);
        c.stroke();
    });

    requestAnimFrame(draw);
}

&lt;span style="color: blue"&gt;function &lt;/span&gt;createPointerObject(event) {
    &lt;span style="color: blue"&gt;var &lt;/span&gt;type;
    &lt;span style="color: blue"&gt;var &lt;/span&gt;color;
    &lt;span style="color: blue"&gt;switch &lt;/span&gt;(event.pointerType) {
        &lt;span style="color: blue"&gt;case &lt;/span&gt;event.POINTER_TYPE_MOUSE:
            type = &lt;span style="color: maroon"&gt;&amp;quot;MOUSE&amp;quot;&lt;/span&gt;;
            color = &lt;span style="color: maroon"&gt;&amp;quot;red&amp;quot;&lt;/span&gt;;
            &lt;span style="color: blue"&gt;break&lt;/span&gt;;
        &lt;span style="color: blue"&gt;case &lt;/span&gt;event.POINTER_TYPE_PEN:
            type = &lt;span style="color: maroon"&gt;&amp;quot;PEN&amp;quot;&lt;/span&gt;;
            color = &lt;span style="color: maroon"&gt;&amp;quot;lime&amp;quot;&lt;/span&gt;;
            &lt;span style="color: blue"&gt;break&lt;/span&gt;;
        &lt;span style="color: blue"&gt;case &lt;/span&gt;event.POINTER_TYPE_TOUCH:
            type = &lt;span style="color: maroon"&gt;&amp;quot;TOUCH&amp;quot;&lt;/span&gt;;
            color = &lt;span style="color: maroon"&gt;&amp;quot;cyan&amp;quot;&lt;/span&gt;;
            &lt;span style="color: blue"&gt;break&lt;/span&gt;;
    }
    &lt;span style="color: blue"&gt;return &lt;/span&gt;{ identifier: event.pointerId, x: event.clientX, y: event.clientY, type: type, color: color };
}

&lt;span style="color: blue"&gt;function &lt;/span&gt;onPointerDown(e) {
    pointers.add(e.pointerId, createPointerObject(e));
}

&lt;span style="color: blue"&gt;function &lt;/span&gt;onPointerMove(e) {
    &lt;span style="color: blue"&gt;if &lt;/span&gt;(pointers.item(e.pointerId)) {
        pointers.item(e.pointerId).x = e.clientX;
        pointers.item(e.pointerId).y = e.clientY;
    }
}

&lt;span style="color: blue"&gt;function &lt;/span&gt;onPointerUp(e) {
    pointers.remove(e.pointerId);
}

&lt;span style="color: blue"&gt;function &lt;/span&gt;setupCanvas() {
    canvas = document.getElementById(&lt;span style="color: maroon"&gt;'canvasSurface'&lt;/span&gt;);
    c = canvas.getContext(&lt;span style="color: maroon"&gt;'2d'&lt;/span&gt;);
    canvas.width = window.innerWidth;
    canvas.height = window.innerHeight;
    c.strokeStyle = &lt;span style="color: maroon"&gt;&amp;quot;#ffffff&amp;quot;&lt;/span&gt;;
    c.lineWidth = 2;
}&lt;/pre&gt;

&lt;p&gt;Well, I think the code is pretty straightforward. I’m registering to the pointerdown/move/up event like described in &lt;a href="http://blogs.msdn.com/b/davrous/archive/2013/02/20/handling-touch-in-your-html5-apps-thanks-to-the-pointer-events-of-ie10-and-windows-8.aspx"&gt;my introduction article on MSPointer Events&lt;/a&gt;. In the &lt;em&gt;pointerdown&lt;/em&gt; handler, I’m catching the ID, the X &amp;amp; Y coordinates and the type of pointers (touch, pen or mouse) inside an object generated on the fly pushed in the &lt;em&gt;pointers&lt;/em&gt; collection object. This collection is indexed by the id of the pointers. The collection object is described in &lt;em&gt;Collection.js&lt;/em&gt;. The &lt;em&gt;draw()&lt;/em&gt; function is then enumerating this collection to draw some cyan/red/lime circles based on the type at the exact position where you’re touching the screen. It also adds some text on each circle’s side to display the pointer’s details. The &lt;em&gt;pointermove&lt;/em&gt; handler updates the coordinates of the associated pointer in the collection and the &lt;em&gt;pointerup/out&lt;/em&gt; simply removes it from the collection. Hand.JS makes this code compatible for IE10 by propagating pointerdown/move/up/&lt;em&gt;out&lt;/em&gt; to the associated MSPointerDown/Move/Up/Out events and to the touchstart/move/end events for WebKit’s browsers.&amp;#160; &lt;/p&gt;

&lt;p&gt;If you wish, you can view the complete source code here: &lt;a title="http://david.blob.core.windows.net/html5/touchjoystick/Touches.html" href="http://david.blob.core.windows.net/html5/touchjoystick/Touches.html"&gt;http://david.blob.core.windows.net/html5/touchjoystick/Touches.html&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;Sample 2: Video game controller with a simple spaceship game &lt;/h2&gt;

&lt;p&gt;Let’s now see the sample I was the most interested in. You will probably also if you’re looking for a virtual analog touch pad for your HTML5 games. The idea is to touch anywhere on the left side of the screen. At the exact position where you’ll touch the screen, it will display a simple but very efficient pad. Moving your finger will update the virtual touch pad and will move a simple spaceship. Touching the right side of the screen will display some red circles and those circles will generate some bullets getting out of the spaceship. Once again, It’s based on Seb’s sample available on GitHub here: &lt;a title="TouchControl.html" href="https://github.com/sebleedelisle/JSTouchController/blob/master/TouchControl.html"&gt;TouchControl.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is a video of the updated sample result in IE10 under Windows 8:&lt;/p&gt;

&lt;div class="video-js-box"&gt;&lt;!-- Using the Video for Everybody Embed Code http://camendesign.com/code/video_for_everybody --&gt;&lt;video id="MSPointerEventsArticleVideo" class="video-js" height="495" width="800" controls="controls" preload="preload" poster="http://david.blob.core.windows.net/html5/touchjoystick/VirtualTouchJoystickHandyJS.jpg"&gt;&lt;source src="http://david.blob.core.windows.net/html5/touchjoystick/VirtualTouchJoystickHandyJS.mp4" type="video/mp4; codecs=&amp;quot;avc1.42E01E, mp4a.40.2&amp;quot;" /&gt;&lt;source src="http://david.blob.core.windows.net/html5/touchjoystick/VirtualTouchJoystickHandyJS.webm" type="video/webm; codecs=&amp;quot;vp8, vorbis&amp;quot;" /&gt;&lt;!-- Flash Fallback. Use any flash video player here. Make sure to keep the vjs-flash-fallback class. --&gt;&lt;object id="flash_fallback_1" class="vjs-flash-fallback" data="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf"
                    width="800" type="application/x-shockwave-flash" height="495"&gt;                     &lt;param name="movie" value="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" /&gt;                     &lt;param name="allowfullscreen" value="true" /&gt;                     &lt;param name="flashvars" value="config={&amp;quot;playlist&amp;quot;:[&amp;quot;http://david.blob.core.windows.net/html5/touchjoystick/VirtualTouchJoystickHandyJS.jpg&amp;quot;, {&amp;quot;url&amp;quot;: &amp;quot;http://david.blob.core.windows.net/html5/touchjoystick/VirtualTouchJoystickHandyJS.mp4&amp;quot;,&amp;quot;autoPlay&amp;quot;:false,&amp;quot;autoBuffering&amp;quot;:true}]}" /&gt;                     &lt;!-- Image Fallback. Typically the same as the poster image. --&gt;                     &lt;img title="No video playback capabilities." alt="Poster Image" src="http://david.blob.core.windows.net/html5/touchjoystick/VirtualTouchJoystickHandyJS.jpg" width="800" height="495" /&gt;                 &lt;/object&gt;&lt;/video&gt;&lt;!-- Download links provided for devices that can't play video in the browser. --&gt;

  &lt;p class="vjs-no-video"&gt;&lt;strong&gt;Download Video:&lt;/strong&gt; &lt;a href="http://david.blob.core.windows.net/html5/touchjoystick/VirtualTouchJoystickHandyJS.mp4"&gt;MP4&lt;/a&gt;, &lt;a href="http://david.blob.core.windows.net/html5/touchjoystick/VirtualTouchJoystickHandyJS.webm"&gt;WebM&lt;/a&gt;, &lt;!-- Support VideoJS by keeping this link. --&gt;&lt;a href="http://videojs.com"&gt;HTML5 Video Player&lt;/a&gt; by VideoJS&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;
  &lt;br /&gt;If you have a touch screen, you can live test the page in this iframe:&lt;/p&gt;
&lt;iframe style="border-top: rgb(255,255,255) 0px solid; border-right: rgb(255,255,255) 0px solid; border-bottom: rgb(255,255,255) 0px solid; border-left: rgb(255,255,255) 0px solid" height="400" src="http://david.blob.core.windows.net/html5/touchjoystick/TouchControl.html" width="800" scrolling="no"&gt;&lt;/iframe&gt;

&lt;p&gt;
  &lt;br /&gt;Otherwise, you will only be able to move the ship using your mouse by clicking on the left of the screen or firing by clicking on the right side, but you won’t be able to achieve both actions simultaneously. Indeed, HandJS is providing a mouse fallback if the browser or platform doesn’t support touch.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Note:&lt;/u&gt;&lt;/strong&gt; the iPad seems to suffer from an unknown bug which prevents this second iframe to work correctly. &lt;a href="http://david.blob.core.windows.net/html5/touchjoystick/TouchControl.html"&gt;Open the sample&lt;/a&gt; directly in another tab to make it works on your iPad.&lt;/p&gt;

&lt;p&gt;Let’s see again how to obtain this result in a unified way. All the code lives this time in &lt;em&gt;TouchControl.js&lt;/em&gt;:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: #006400"&gt;// shim layer with setTimeout fallback
&lt;/span&gt;window.requestAnimFrame = (&lt;span style="color: blue"&gt;function &lt;/span&gt;() {
    &lt;span style="color: blue"&gt;return &lt;/span&gt;window.requestAnimationFrame ||
    window.webkitRequestAnimationFrame ||
    window.mozRequestAnimationFrame ||
    window.oRequestAnimationFrame ||
    window.msRequestAnimationFrame ||
    &lt;span style="color: blue"&gt;function &lt;/span&gt;(callback) {
        window.setTimeout(callback, 1000 / 60);
    };
})();

&lt;span style="color: blue"&gt;var &lt;/span&gt;canvas,
c, &lt;span style="color: #006400"&gt;// c is the canvas' context 2D
&lt;/span&gt;container,
halfWidth,
halfHeight,
leftPointerID = -1,
leftPointerPos = &lt;span style="color: blue"&gt;new &lt;/span&gt;Vector2(0, 0),
leftPointerStartPos = &lt;span style="color: blue"&gt;new &lt;/span&gt;Vector2(0, 0),
leftVector = &lt;span style="color: blue"&gt;new &lt;/span&gt;Vector2(0, 0);

&lt;span style="color: blue"&gt;var &lt;/span&gt;pointers; &lt;span style="color: #006400"&gt;// collections of pointers
&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;ship;
bullets = [],
spareBullets = [];

document.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;DOMContentLoaded&amp;quot;&lt;/span&gt;, init);

window.onorientationchange = resetCanvas;
window.onresize = resetCanvas;

&lt;span style="color: blue"&gt;function &lt;/span&gt;init() {
    setupCanvas();
    pointers = &lt;span style="color: blue"&gt;new &lt;/span&gt;Collection();
    ship = &lt;span style="color: blue"&gt;new &lt;/span&gt;ShipMoving(halfWidth, halfHeight);
    document.body.appendChild(ship.canvas);
    canvas.addEventListener(&lt;span style="color: maroon"&gt;'pointerdown'&lt;/span&gt;, onPointerDown, &lt;span style="color: blue"&gt;false&lt;/span&gt;);
    canvas.addEventListener(&lt;span style="color: maroon"&gt;'pointermove'&lt;/span&gt;, onPointerMove, &lt;span style="color: blue"&gt;false&lt;/span&gt;);
    canvas.addEventListener(&lt;span style="color: maroon"&gt;'pointerup'&lt;/span&gt;, onPointerUp, &lt;span style="color: blue"&gt;false&lt;/span&gt;);
    canvas.addEventListener(&lt;span style="color: maroon"&gt;'pointerout'&lt;/span&gt;, onPointerUp, &lt;span style="color: blue"&gt;false&lt;/span&gt;);
    requestAnimFrame(draw);
}

&lt;span style="color: blue"&gt;function &lt;/span&gt;resetCanvas(e) {
    &lt;span style="color: #006400"&gt;// resize the canvas - but remember - this clears the canvas too. 
    &lt;/span&gt;canvas.width = window.innerWidth;
    canvas.height = window.innerHeight;

    halfWidth = canvas.width / 2;
    halfHeight = canvas.height / 2;

    &lt;span style="color: #006400"&gt;//make sure we scroll to the top left. 
    &lt;/span&gt;window.scrollTo(0, 0);
}

&lt;span style="color: blue"&gt;function &lt;/span&gt;draw() {
    c.clearRect(0, 0, canvas.width, canvas.height);

    ship.targetVel.copyFrom(leftVector);
    ship.targetVel.multiplyEq(0.15);
    ship.update();

    &lt;span style="color: blue"&gt;with &lt;/span&gt;(ship.pos) {
        &lt;span style="color: blue"&gt;if &lt;/span&gt;(x &amp;lt; 0) x = canvas.width;
        &lt;span style="color: blue"&gt;else if &lt;/span&gt;(x &amp;gt; canvas.width) x = 0;
        &lt;span style="color: blue"&gt;if &lt;/span&gt;(y &amp;lt; 0) y = canvas.height;
        &lt;span style="color: blue"&gt;else if &lt;/span&gt;(y &amp;gt; canvas.height) y = 0;
    }

    ship.draw();

    &lt;span style="color: blue"&gt;for &lt;/span&gt;(&lt;span style="color: blue"&gt;var &lt;/span&gt;i = 0; i &amp;lt; bullets.length; i++) {
        &lt;span style="color: blue"&gt;var &lt;/span&gt;bullet = bullets[i];
        &lt;span style="color: blue"&gt;if &lt;/span&gt;(!bullet.enabled) &lt;span style="color: blue"&gt;continue&lt;/span&gt;;
        bullet.update();
        bullet.draw(c);
        &lt;span style="color: blue"&gt;if &lt;/span&gt;(!bullet.enabled) {
            spareBullets.push(bullet);

        }
    }

    pointers.forEach(&lt;span style="color: blue"&gt;function &lt;/span&gt;(pointer) {
        &lt;span style="color: blue"&gt;if &lt;/span&gt;(pointer.identifier == leftPointerID) {
            c.beginPath();
            c.strokeStyle = &lt;span style="color: maroon"&gt;&amp;quot;cyan&amp;quot;&lt;/span&gt;;
            c.lineWidth = 6;
            c.arc(leftPointerStartPos.x, leftPointerStartPos.y, 40, 0, Math.PI * 2, &lt;span style="color: blue"&gt;true&lt;/span&gt;);
            c.stroke();
            c.beginPath();
            c.strokeStyle = &lt;span style="color: maroon"&gt;&amp;quot;cyan&amp;quot;&lt;/span&gt;;
            c.lineWidth = 2;
            c.arc(leftPointerStartPos.x, leftPointerStartPos.y, 60, 0, Math.PI * 2, &lt;span style="color: blue"&gt;true&lt;/span&gt;);
            c.stroke();
            c.beginPath();
            c.strokeStyle = &lt;span style="color: maroon"&gt;&amp;quot;cyan&amp;quot;&lt;/span&gt;;
            c.arc(leftPointerPos.x, leftPointerPos.y, 40, 0, Math.PI * 2, &lt;span style="color: blue"&gt;true&lt;/span&gt;);
            c.stroke();

        } &lt;span style="color: blue"&gt;else &lt;/span&gt;{

            c.beginPath();
            c.fillStyle = &lt;span style="color: maroon"&gt;&amp;quot;white&amp;quot;&lt;/span&gt;;
            c.fillText(&lt;span style="color: maroon"&gt;&amp;quot;type : &amp;quot; &lt;/span&gt;+ pointer.type + &lt;span style="color: maroon"&gt;&amp;quot; id : &amp;quot; &lt;/span&gt;+ pointer.identifier + &lt;span style="color: maroon"&gt;&amp;quot; x:&amp;quot; &lt;/span&gt;+ pointer.x + &lt;br /&gt;                       &lt;span style="color: maroon"&gt;&amp;quot; y:&amp;quot; &lt;/span&gt;+ pointer.y, pointer.x + 30, pointer.y - 30);

            c.beginPath();
            c.strokeStyle = &lt;span style="color: maroon"&gt;&amp;quot;red&amp;quot;&lt;/span&gt;;
            c.lineWidth = &lt;span style="color: maroon"&gt;&amp;quot;6&amp;quot;&lt;/span&gt;;
            c.arc(pointer.x, pointer.y, 40, 0, Math.PI * 2, &lt;span style="color: blue"&gt;true&lt;/span&gt;);
            c.stroke();
        }
    });

    requestAnimFrame(draw);
}

&lt;span style="color: blue"&gt;function &lt;/span&gt;makeBullet() {
    &lt;span style="color: blue"&gt;var &lt;/span&gt;bullet;

    &lt;span style="color: blue"&gt;if &lt;/span&gt;(spareBullets.length &amp;gt; 0) {

        bullet = spareBullets.pop();
        bullet.reset(ship.pos.x, ship.pos.y, ship.angle);

    } &lt;span style="color: blue"&gt;else &lt;/span&gt;{

        bullet = &lt;span style="color: blue"&gt;new &lt;/span&gt;Bullet(ship.pos.x, ship.pos.y, ship.angle);
        bullets.push(bullet);

    }

    bullet.vel.plusEq(ship.vel);
}

&lt;span style="color: blue"&gt;function &lt;/span&gt;givePointerType(event) {
    &lt;span style="color: blue"&gt;switch &lt;/span&gt;(event.pointerType) {
        &lt;span style="color: blue"&gt;case &lt;/span&gt;event.POINTER_TYPE_MOUSE:
            &lt;span style="color: blue"&gt;return &lt;/span&gt;&lt;span style="color: maroon"&gt;&amp;quot;MOUSE&amp;quot;&lt;/span&gt;;
            &lt;span style="color: blue"&gt;break&lt;/span&gt;;
        &lt;span style="color: blue"&gt;case &lt;/span&gt;event.POINTER_TYPE_PEN:
            &lt;span style="color: blue"&gt;return &lt;/span&gt;&lt;span style="color: maroon"&gt;&amp;quot;PEN&amp;quot;&lt;/span&gt;;
            &lt;span style="color: blue"&gt;break&lt;/span&gt;;
        &lt;span style="color: blue"&gt;case &lt;/span&gt;event.POINTER_TYPE_TOUCH:
            &lt;span style="color: blue"&gt;return &lt;/span&gt;&lt;span style="color: maroon"&gt;&amp;quot;TOUCH&amp;quot;&lt;/span&gt;;
            &lt;span style="color: blue"&gt;break&lt;/span&gt;;
    }
}

&lt;span style="color: blue"&gt;function &lt;/span&gt;onPointerDown(e) {
    &lt;span style="color: blue"&gt;var &lt;/span&gt;newPointer = { identifier: e.pointerId, x: e.clientX, y: e.clientY, type: givePointerType(e) };
    &lt;span style="color: blue"&gt;if &lt;/span&gt;((leftPointerID &amp;lt; 0) &amp;amp;&amp;amp; (e.clientX &amp;lt; halfWidth)) {
        leftPointerID = e.pointerId;
        leftPointerStartPos.reset(e.clientX, e.clientY);
        leftPointerPos.copyFrom(leftPointerStartPos);
        leftVector.reset(0, 0);
    }
    &lt;span style="color: blue"&gt;else &lt;/span&gt;{
        makeBullet();

    }
    pointers.add(e.pointerId, newPointer);
}

&lt;span style="color: blue"&gt;function &lt;/span&gt;onPointerMove(e) {
    &lt;span style="color: blue"&gt;if &lt;/span&gt;(leftPointerID == e.pointerId) {
        leftPointerPos.reset(e.clientX, e.clientY);
        leftVector.copyFrom(leftPointerPos);
        leftVector.minusEq(leftPointerStartPos);
    }
    &lt;span style="color: blue"&gt;else &lt;/span&gt;{
        &lt;span style="color: blue"&gt;if &lt;/span&gt;(pointers.item(e.pointerId)) {
            pointers.item(e.pointerId).x = e.clientX;
            pointers.item(e.pointerId).y = e.clientY;
        }
    }
}

&lt;span style="color: blue"&gt;function &lt;/span&gt;onPointerUp(e) {
    &lt;span style="color: blue"&gt;if &lt;/span&gt;(leftPointerID == e.pointerId) {
        leftPointerID = -1;
        leftVector.reset(0, 0);

    }
    leftVector.reset(0, 0);

    pointers.remove(e.pointerId);
}

&lt;span style="color: blue"&gt;function &lt;/span&gt;setupCanvas() {
    canvas = document.getElementById(&lt;span style="color: maroon"&gt;'canvasSurfaceGame'&lt;/span&gt;);
    c = canvas.getContext(&lt;span style="color: maroon"&gt;'2d'&lt;/span&gt;);
    resetCanvas();
    c.strokeStyle = &lt;span style="color: maroon"&gt;&amp;quot;#ffffff&amp;quot;&lt;/span&gt;;
    c.lineWidth = 2;
}&lt;/pre&gt;

&lt;p&gt;The code is again very straightforward, I won’t spend time explaining it. You can view the complete source code here: &lt;a title="http://david.blob.core.windows.net/html5/touchjoystick/Touches.html" href="http://david.blob.core.windows.net/html5/touchjoystick/TouchControl.html"&gt;http://david.blob.core.windows.net/html5/touchjoystick/TouchControl.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In conclusion, thanks to the job done by &lt;a href="http://seb.ly/author/seb/"&gt;Seb Lee-Delisle&lt;/a&gt; and &lt;a href="http://blogs.msdn.com/eternalcoding"&gt;David Catuhe&lt;/a&gt;, you now have all the pieces needed to implement your own virtual touch joypad for your HTML5 games. The result will work on all touch devices supporting HTML5! &lt;/p&gt;

&lt;p&gt;David&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10394421" width="1" height="1"&gt;</content><author><name>David Rousset</name><uri>http://blogs.msdn.com/davrous/ProfileUrlRedirect.ashx</uri></author><category term="HTML5" scheme="http://blogs.msdn.com/b/davrous/archive/tags/HTML5/" /><category term="Canvas" scheme="http://blogs.msdn.com/b/davrous/archive/tags/Canvas/" /><category term="IE10" scheme="http://blogs.msdn.com/b/davrous/archive/tags/IE10/" /><category term="Touch Events" scheme="http://blogs.msdn.com/b/davrous/archive/tags/Touch+Events/" /><category term="Pointer Events" scheme="http://blogs.msdn.com/b/davrous/archive/tags/Pointer+Events/" /><category term="HandJS" scheme="http://blogs.msdn.com/b/davrous/archive/tags/HandJS/" /></entry><entry><title>Unifying touch and mouse: how Pointer Events will make cross-browsers touch support easy</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/davrous/archive/2013/02/20/handling-touch-in-your-html5-apps-thanks-to-the-pointer-events-of-ie10-and-windows-8.aspx" /><id>http://blogs.msdn.com/b/davrous/archive/2013/02/20/handling-touch-in-your-html5-apps-thanks-to-the-pointer-events-of-ie10-and-windows-8.aspx</id><published>2013-02-20T11:14:39Z</published><updated>2013-02-20T11:14:39Z</updated><content type="html">&lt;!-- Include the VideoJS Library --&gt;&lt;script type="text/javascript" charset="utf-8" src="http://david.blob.core.windows.net/videos/video-js/video.js"&gt;&lt;/script&gt;&lt;script type="text/javascript"&gt;// &lt;![CDATA[
    
	VideoJS.setupAllWhenReady();
  
// ]]&gt;&lt;/script&gt;&lt;link title="Video JS" rel="stylesheet" type="text/css" href="http://david.blob.core.windows.net/videos/video-js/video-js.css" media="screen" /&gt;  &lt;p&gt;I often get questions from developers like, “&lt;i&gt;with so many touch-enabled devices on phones and tablets, where do I start?&lt;/i&gt;” and “&lt;i&gt;what is the easiest way to build for touch-input?&lt;/i&gt;” Short answer: &lt;i&gt;“It’s complex.” &lt;/i&gt;Surely there’s a more unified way to handle multi-touch input on the web – in modern, touch-enabled browsers or as a fallback for older browsers. In this article I’d like to show you some browser experiments using &lt;a href="http://blogs.msdn.com/b/ie/archive/2011/09/20/touch-input-for-ie10-and-metro-style-apps.aspx"&gt;MSPointers&lt;/a&gt; – an emerging multi-touch technology and polyfills that make cross-browser support, well &lt;i&gt;less complex&lt;/i&gt;. The kind of code you can also experiment with and easily use on your own site.&lt;/p&gt;  &lt;p&gt;First of all, many touch technologies are evolving on the web – for browser support you need to look the &lt;a href="http://developer.apple.com/library/safari/#documentation/UserExperience/Reference/TouchEventClassReference/TouchEvent/TouchEvent.html"&gt;iOS touch event&lt;/a&gt; model and the &lt;a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-eventgroupings-mouseevents"&gt;W3C mouse event&lt;/a&gt; model in additional to at &lt;a href="http://blogs.msdn.com/b/ie/archive/2011/09/20/touch-input-for-ie10-and-metro-style-apps.aspx"&gt;MSPointers&lt;/a&gt;, to support all browsers. Yet there is growing support (and willingness) to standardize. In September, Microsoft submitted &lt;a href="http://www.w3.org/Submission/pointer-events/"&gt;MSPointers to the W3C for standardization&lt;/a&gt; and yesterday, we’ve already reached the Last Call Draft: &lt;a title="http://www.w3.org/TR/pointerevents" href="http://www.w3.org/TR/pointerevents"&gt;http://www.w3.org/TR/pointerevents&lt;/a&gt;. The &lt;a href="http://blogs.msdn.com/b/interoperability/"&gt;MS Open Tech&lt;/a&gt; team also recently released an &lt;a href="http://blogs.msdn.com/b/interoperability/archive/2012/12/18/open-source-release-from-ms-open-tech-pointer-events-initial-prototype-for-webkit.aspx"&gt;initial Pointer Events prototype for Webkit&lt;/a&gt;. &lt;/p&gt;  &lt;p&gt;The reason why I experiment with MSPointers is not based on device share – it’s because Microsoft’s approach to basic input handling is quite different than what’s currently available on the web and it deserves a look for what it &lt;i&gt;could become&lt;/i&gt;. The difference is that developers can write to a more abstract form of input, called a “Pointer.” A Pointer can be any point of contact on the screen made by a mouse cursor, pen, finger, or multiple fingers. So you don’t waste time coding for every type of input separately.&lt;/p&gt;  &lt;h2&gt;The concepts&lt;/h2&gt;  &lt;p&gt;We will begin by reviewing apps running inside &lt;a href="http://ietestdrive.com"&gt;Internet Explorer 10&lt;/a&gt; which exposes the MSPointer events API and then solutions to support all browsers. After that, we will see how you can take advantage of IE10 gestures services that will help you handling touch in your JavaScript code in an easy way. As Windows 8 and Windows Phone 8 share the same browser engine, the code &amp;amp; concepts are identical for both platforms. Moreover, everything you’ll learn on touch in this article will help you do the very same tasks in &lt;a href="http://windowsstore.com"&gt;Windows Store apps&lt;/a&gt; built with HTML5/JS, as this is again the same engine that is being used. &lt;/p&gt;  &lt;p&gt;The idea behind the MSPointer is to let you addressing mouse, pen &amp;amp; touch devices via a single code base using a pattern that match the classical mouse events you already know. Indeed, mouse, pen &amp;amp; touch have some properties in common: you can move a pointer with them and you can click on element with them for instance. Let’s then address these scenarios via the very same piece of code! Pointers will aggregate those common properties and expose them in a similar way than the mouse events. &lt;/p&gt;  &lt;p&gt;The most obvious common events are then: &lt;a href="http://msdn.microsoft.com/en-us/library/hh771909(v=vs.85).aspx"&gt;MSPointerDown&lt;/a&gt; , &lt;a href="http://msdn.microsoft.com/en-us/library/hh771911(v=vs.85).aspx"&gt;MSPointerMove&lt;/a&gt; &amp;amp; &lt;a href="http://msdn.microsoft.com/en-us/library/hh771914(v=vs.85).aspx"&gt;MSPointerUp&lt;/a&gt; which directly map to the mouse events equivalent. You will have the X &amp;amp; Y coordinates of the screen as an output. &lt;/p&gt;  &lt;p&gt;You have also specific events like: &lt;a href="http://msdn.microsoft.com/en-us/library/hh771913(v=vs.85).aspx"&gt;MSPointerOver&lt;/a&gt; , &lt;a href="http://msdn.microsoft.com/en-us/library/hh771912(v=vs.85).aspx"&gt;MSPointerOut&lt;/a&gt; , &lt;a href="http://msdn.microsoft.com/en-us/library/hh771910(v=vs.85).aspx"&gt;MSPointerHover&lt;/a&gt; or &lt;a href="http://msdn.microsoft.com/en-us/library/hh846776(v=vs.85).aspx"&gt;MSPointerCancel&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8004.clip_5F00_image001_5F00_43511543.png"&gt;&lt;img title="clip_image001" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="clip_image001" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4300.clip_5F00_image001_5F00_thumb_5F00_4E7D303E.png" width="233" height="240" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;But of course, there could be also some cases where you want to address touch in a different manner than the default mouse behavior to provide a different UX. Moreover, thanks to the multi-touch screens, you can easily let the user rotate, zoom or pan some elements. Pens/stylus can even provide you some pressure information a mouse can’t. The Pointer Events will still aggregate those differences and will let you build some custom code for each devices’ specifics. &lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;u&gt;Note:&lt;/u&gt;&lt;/b&gt; it would be better to test the following embedded samples if you have a touch screen of course on a Windows 8/RT device or if you’re using a Windows Phone 8. Still, you can have some options:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;1. Get a first level of experience by using the Windows 8 Simulator that ships with the free Visual Studio 2012 Express development tools. For more details on how this works, please read this article: &lt;a href="http://blogs.msdn.com/b/davrous/archive/2012/07/10/using-the-windows-8-simulator-amp-vs-2012-to-debug-the-ie10-touch-events-amp-your-responsive-design.aspx"&gt;Using the Windows 8 Simulator &amp;amp; VS 2012 to debug the IE10 touch events &amp;amp; your responsive design&lt;/a&gt; .       &lt;br /&gt;2. Have a look to &lt;a href="http://david.blob.core.windows.net/videos/MSPointerEventsArticleVideo.mp4"&gt;this video&lt;/a&gt; also available in other formats at the end of the article. The &lt;a href="http://david.blob.core.windows.net/videos/MSPointerEventsArticleVideo.mp4"&gt;video demonstrates all the below samples&lt;/a&gt; on a Windows 8 tablet supporting touch, pen &amp;amp; mouse.       &lt;br /&gt;3. Use a virtual cross-browsing testing service like &lt;a href="http://browserstack.com"&gt;BrowserStack&lt;/a&gt; to test interactively if you don’t have access to the Windows 8 device. You can &lt;a href="http://modern.ie/virtualization-tools"&gt;use BrowserStack for free for 3 months&lt;/a&gt;, courtesy of the Internet Explorer team on &lt;a href="http://modern.IE"&gt;modern.IE&lt;/a&gt;. &lt;/p&gt; &lt;/blockquote&gt;  &lt;h2&gt;Handling simple touch events&lt;/h2&gt;  &lt;h3&gt;Step 1: do nothing in JS but add a line of CSS&lt;/h3&gt;  &lt;p&gt;Let’s start with the basics. You can easily take any of your existing JavaScript code that handles mouse events and it will just work as-is using some pens or touch devices in Internet Explorer 10. IE10 is indeed firing mouse events as a last resort if you’re not handling Pointers Events in your code. That’s why, you can “click” on a button or on any element of any webpage using your fingers even if the developer never thought that one day someone would have done it this way. So any code registering to mouvedown and/or mouseup events will work with no modification at all. But what about mouvemove? &lt;/p&gt;  &lt;p&gt;Let’s review the default behavior to answer to that question. For instance, let’s take this piece of code:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;!&lt;/span&gt;&lt;span style="color: maroon"&gt;DOCTYPE &lt;/span&gt;&lt;span style="color: red"&gt;html&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;html&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;head&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;title&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;Touch article sample 1&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;title&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;head&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;body&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;canvas &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;drawSurface&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;width&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;400px&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;height&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;400px&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;style&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;&lt;/span&gt;&lt;span style="color: red"&gt;border&lt;/span&gt;&lt;span style="color: blue"&gt;: 1px dashed black;&amp;quot;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;canvas&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;script&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        var &lt;/span&gt;canvas = document.getElementById(&lt;span style="color: maroon"&gt;&amp;quot;drawSurface&amp;quot;&lt;/span&gt;);
        &lt;span style="color: blue"&gt;var &lt;/span&gt;context = canvas.getContext(&lt;span style="color: maroon"&gt;&amp;quot;2d&amp;quot;&lt;/span&gt;);
        context.fillStyle = &lt;span style="color: maroon"&gt;&amp;quot;rgba(0, 0, 255, 0.5)&amp;quot;&lt;/span&gt;;

        canvas.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;mousemove&amp;quot;&lt;/span&gt;, paint, &lt;span style="color: blue"&gt;false&lt;/span&gt;);

        &lt;span style="color: blue"&gt;function &lt;/span&gt;paint(event) {
            context.fillRect(event.clientX, event.clientY, 10, 10);
        }
    &lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;script&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;body&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;html&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;It simply draws some blue 10px by 10px squares inside an HTML5 canvas element by tracking the movements of the mouse. &lt;i&gt;To test it, move your mouse inside the box. If you have a touch screen, try to interact with the canvas to check by yourself the current behavior&lt;/i&gt;:&lt;/p&gt;

&lt;table cellspacing="0" cellpadding="2" width="900" border="0"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="450"&gt;&lt;iframe style="border-top: rgb(255,255,255) 0px solid; border-right: rgb(255,255,255) 0px solid; border-bottom: rgb(255,255,255) 0px solid; border-left: rgb(255,255,255) 0px solid" height="420" src="http://david.blob.core.windows.net/html5/touchsample1.htm" width="410" scrolling="no"&gt;&lt;/iframe&gt;&lt;/td&gt;

      &lt;td valign="top" width="450"&gt;
        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&lt;em&gt;Sample 0&lt;/em&gt; : &lt;strong&gt;default behavior&lt;/strong&gt; if you do nothing &lt;/p&gt;

        &lt;p align="center"&gt;&lt;em&gt;Result&lt;/em&gt; : &lt;strong&gt;only MouseDown/Up/Click works&lt;/strong&gt; with touch&lt;/p&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;You’ll see than when you’re moving the mouse inside the canvas element, it will draw some series of blue squares. But using touch instead, it will only draw a unique square at the exact position where you will tap the canvas element. As soon as you will try to move your finger in the canvas element, the browser will try to pan inside the page as it’s the default behavior being defined. &lt;/p&gt;

&lt;p&gt;You then need to specify you’d like to override the default behavior of the browser and tell it to redirect the touch events to your JavaScript code rather than trying to interpret it. For that, target the elements of your page that shouldn’t react anymore to the default behavior and apply this CSS rule to them:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: red"&gt;-ms-touch-action&lt;/span&gt;: &lt;span style="color: blue"&gt;auto | none | manipulation | double-tap-zoom | inherit&lt;/span&gt;;&lt;/pre&gt;

&lt;p&gt;You have various values available based on what you’d like to filter or not. You’ll find the values described in this article: &lt;a href="http://blogs.msdn.com/b/ie/archive/2012/04/20/guidelines-for-building-touch-friendly-sites.aspx"&gt;Guidelines for Building Touch-friendly Sites&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The classic use case is when you have a map control in your page. You want to let the user pan &amp;amp; zoom inside the map area but keep the default behavior for the rest of the page. In this case, you will apply this CSS rule only on the HTML container exposing the map. &lt;/p&gt;

&lt;p&gt;In our case, add this block of CSS:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;style&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &lt;/span&gt;&lt;span style="color: maroon"&gt;#drawSurface
    &lt;/span&gt;{
        &lt;span style="color: red"&gt;-ms-touch-action&lt;/span&gt;: &lt;span style="color: blue"&gt;none&lt;/span&gt;; &lt;span style="color: #006400"&gt;/* Disable touch behaviors, like pan and zoom */
    &lt;/span&gt;}
&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;style&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Which now generates this result:&lt;/p&gt;

&lt;table cellspacing="0" cellpadding="2" width="900" border="0"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="450"&gt;&lt;iframe style="border-top: rgb(255,255,255) 0px solid; border-right: rgb(255,255,255) 0px solid; border-bottom: rgb(255,255,255) 0px solid; border-left: rgb(255,255,255) 0px solid" height="420" src="http://david.blob.core.windows.net/html5/touchsample2.htm" width="410" scrolling="no"&gt;&lt;/iframe&gt;&lt;/td&gt;

      &lt;td valign="top" width="450"&gt;
        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&lt;em&gt;Sample 1&lt;/em&gt;: just after adding &lt;strong&gt;&lt;span style="color: red"&gt;-ms-touch-action&lt;/span&gt;: &lt;span style="color: blue"&gt;none&lt;/span&gt;&lt;/strong&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&lt;em&gt;Result&lt;/em&gt;: default browser panning disabled and &lt;strong&gt;MouseMove works but with 1 finger only&lt;/strong&gt;&lt;/p&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;Now, when you’re moving your finger inside the canvas element, it behaves like a mouse pointer. That’s cool! But you will quickly ask yourself this question: why does this code only track 1 finger? Well, this is because we’re just falling in the last thing IE10 is doing to provide a very basic touch experience: mapping one of your fingers to simulate a mouse. And as far as I know, we’re using only 1 mouse at a time. So 1 mouse === 1 finger max using this approach. Then, how to handle multi-touch events?&lt;/p&gt;

&lt;h3&gt;Step 2: use MSPointer Events instead of mouse events&lt;/h3&gt;

&lt;p&gt;Take any of your existing code and replace your registration to “mousedown/up/move” by “MSPointerDown/Up/Move” and your code will directly support a multi-touch experience inside IE10! &lt;/p&gt;

&lt;p&gt;For instance, in the previous sample, change this line of code:&lt;/p&gt;

&lt;pre class="code"&gt;canvas.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;mousemove&amp;quot;&lt;/span&gt;, paint, &lt;span style="color: blue"&gt;false&lt;/span&gt;);&lt;/pre&gt;

&lt;p&gt;to this one:&lt;/p&gt;

&lt;pre class="code"&gt;canvas.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;MSPointerMove&amp;quot;&lt;/span&gt;, paint, &lt;span style="color: blue"&gt;false&lt;/span&gt;);&lt;/pre&gt;

&lt;p&gt;And you will get this result:&lt;/p&gt;

&lt;table cellspacing="0" cellpadding="2" width="900" border="0"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="450"&gt;&lt;iframe style="border-top: rgb(255,255,255) 0px solid; border-right: rgb(255,255,255) 0px solid; border-bottom: rgb(255,255,255) 0px solid; border-left: rgb(255,255,255) 0px solid" height="420" src="http://david.blob.core.windows.net/html5/touchsample3.htm" width="410" scrolling="no"&gt;&lt;/iframe&gt;&lt;/td&gt;

      &lt;td valign="top" width="450"&gt;
        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&lt;em&gt;Sample 2&lt;/em&gt;: using &lt;strong&gt;MSPointerMove&lt;/strong&gt; instead of mousemove&lt;/p&gt;

        &lt;p align="center"&gt;&lt;em&gt;Result&lt;/em&gt;: &lt;strong&gt;multi-touch works&lt;/strong&gt;&lt;/p&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;You can now draw as many squares series as touch points your screen supports! Even better, the same code works for touch, mouse &amp;amp; pen. This means for instance that you can use your mouse to draw some lines at the same time you are using your fingers to draw other lines. &lt;img class="wlEmoticon wlEmoticon-winkingsmile" style="border-top-style: none; border-left-style: none; border-bottom-style: none; border-right-style: none" alt="Clignement d&amp;#39;œil" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0434.wlEmoticon_2D00_winkingsmile_5F00_05155995.png" /&gt;&lt;/p&gt;

&lt;p&gt;If you’d like to change the behavior of your code based on the type of input, you can test that through the &lt;code&gt;pointerType &lt;/code&gt;property value. For instance, let’s imagine that we want to draw some 10px by 10px red squares for fingers, 5px by 5px green squares for pen and 2px by 2px blue squares for mouse. You need to replace the previous handler (the paint function) with this one:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;paint(event) {
    &lt;span style="color: blue"&gt;if &lt;/span&gt;(event.pointerType) {
        &lt;span style="color: blue"&gt;switch &lt;/span&gt;(event.pointerType) {
            &lt;span style="color: blue"&gt;case &lt;/span&gt;event.MSPOINTER_TYPE_TOUCH:
                &lt;span style="color: #006400"&gt;// A touchscreen was used
                // Drawing in red with a square of 10
                &lt;/span&gt;context.fillStyle = &lt;span style="color: maroon"&gt;&amp;quot;rgba(255, 0, 0, 0.5)&amp;quot;&lt;/span&gt;;
                squaresize = 10;
                &lt;span style="color: blue"&gt;break&lt;/span&gt;;
            &lt;span style="color: blue"&gt;case &lt;/span&gt;event.MSPOINTER_TYPE_PEN:
                &lt;span style="color: #006400"&gt;// A pen was used
                // Drawing in green with a square of 5
                &lt;/span&gt;context.fillStyle = &lt;span style="color: maroon"&gt;&amp;quot;rgba(0, 255, 0, 0.5)&amp;quot;&lt;/span&gt;;
                squaresize = 5;
                &lt;span style="color: blue"&gt;break&lt;/span&gt;;
            &lt;span style="color: blue"&gt;case &lt;/span&gt;event.MSPOINTER_TYPE_MOUSE:
                &lt;span style="color: #006400"&gt;// A mouse was used
                // Drawing in blue with a squre of 2
                &lt;/span&gt;context.fillStyle = &lt;span style="color: maroon"&gt;&amp;quot;rgba(0, 0, 255, 0.5)&amp;quot;&lt;/span&gt;;
                squaresize = 2;
                &lt;span style="color: blue"&gt;break&lt;/span&gt;;
        }

        context.fillRect(event.clientX, event.clientY, squaresize, squaresize);
    }
}&lt;/pre&gt;

&lt;p&gt;And you can test the result here:&lt;/p&gt;

&lt;table cellspacing="0" cellpadding="2" width="900" border="0"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="450"&gt;&lt;iframe style="border-top: rgb(255,255,255) 0px solid; border-right: rgb(255,255,255) 0px solid; border-bottom: rgb(255,255,255) 0px solid; border-left: rgb(255,255,255) 0px solid" height="420" src="http://david.blob.core.windows.net/html5/touchsample4.htm" width="410" scrolling="no"&gt;&lt;/iframe&gt;&lt;/td&gt;

      &lt;td valign="top" width="450"&gt;
        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&lt;em&gt;Sample 2b&lt;/em&gt;: testing &lt;strong&gt;pointerType&lt;/strong&gt; to test touch/pen or mouse&lt;/p&gt;

        &lt;p align="center"&gt;&lt;em&gt;Result&lt;/em&gt;: You can change the &lt;strong&gt;behavior for mouse/pen/touch&lt;/strong&gt; but since 2a the &lt;strong&gt;&lt;font color="#804040"&gt;code now works &lt;em&gt;only&lt;/em&gt; in IE10+&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;If you’re lucky enough to have a device supporting the 3 types of inputs (like the&lt;em&gt; Sony Duo 11, &lt;/em&gt;the &lt;em&gt;Microsoft Surface Pro&lt;/em&gt; or the &lt;em&gt;Samsung Tablet&lt;/em&gt; some of you had during BUILD2011), you will be able to see 3 kind of drawing based on the input type. Great, isn’t it?&lt;/p&gt;

&lt;p&gt;Still, there is a problem with this code. It now handles all type of inputs properly in IE10 but doesn’t work at all for browsers that don’t support the MSPointer Events like IE9, Chrome, Firefox, Opera &amp;amp; Safari. &lt;/p&gt;

&lt;h3&gt;Step 3: do feature detection to provide a fallback code&lt;/h3&gt;

&lt;p&gt;As you’re probably already aware, the best approach to handle multi-browsers support is to do features detection. In our case, you need to test this:&lt;/p&gt;

&lt;pre class="code"&gt;window.navigator.msPointerEnabled&lt;/pre&gt;

&lt;p&gt;Beware that this only tells you if the current browser supports MSPointer. It doesn’t tell you if touch is supported or not. To test support for touch or not, you need to check &lt;a href="http://msdn.microsoft.com/en-us/library/hh772144(v=vs.85).aspx"&gt;&lt;strong&gt;msMaxTouchPoints&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In conclusion, to have a code supporting MSPointer in IE10 and falling back properly to mouse events in other browsers, you need a code like that:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;canvas = document.getElementById(&lt;span style="color: maroon"&gt;&amp;quot;drawSurface&amp;quot;&lt;/span&gt;);
&lt;span style="color: blue"&gt;var &lt;/span&gt;context = canvas.getContext(&lt;span style="color: maroon"&gt;&amp;quot;2d&amp;quot;&lt;/span&gt;);
context.fillStyle = &lt;span style="color: maroon"&gt;&amp;quot;rgba(0, 0, 255, 0.5)&amp;quot;&lt;/span&gt;;
&lt;span style="color: blue"&gt;if &lt;/span&gt;(window.navigator.msPointerEnabled) {
    &lt;span style="color: #006400"&gt;// Pointer events are supported.
    &lt;/span&gt;canvas.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;MSPointerMove&amp;quot;&lt;/span&gt;, paint, &lt;span style="color: blue"&gt;false&lt;/span&gt;);
}
&lt;span style="color: blue"&gt;else &lt;/span&gt;{
    canvas.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;mousemove&amp;quot;&lt;/span&gt;, paint, &lt;span style="color: blue"&gt;false&lt;/span&gt;);
}

&lt;span style="color: blue"&gt;function &lt;/span&gt;paint(event) {
    &lt;span style="color: blue"&gt;var &lt;/span&gt;squaresize = 2;
    &lt;span style="color: blue"&gt;if &lt;/span&gt;(event.pointerType) {
        &lt;span style="color: blue"&gt;switch &lt;/span&gt;(event.pointerType) {
            &lt;span style="color: blue"&gt;case &lt;/span&gt;event.MSPOINTER_TYPE_TOUCH:
                &lt;span style="color: #006400"&gt;// A touchscreen was used
                // Drawing in red with a square of 10
                &lt;/span&gt;context.fillStyle = &lt;span style="color: maroon"&gt;&amp;quot;rgba(255, 0, 0, 0.5)&amp;quot;&lt;/span&gt;;
                squaresize = 10;
                &lt;span style="color: blue"&gt;break&lt;/span&gt;;
            &lt;span style="color: blue"&gt;case &lt;/span&gt;event.MSPOINTER_TYPE_PEN:
                &lt;span style="color: #006400"&gt;// A pen was used
                // Drawing in green with a square of 5
                &lt;/span&gt;context.fillStyle = &lt;span style="color: maroon"&gt;&amp;quot;rgba(0, 255, 0, 0.5)&amp;quot;&lt;/span&gt;;
                squaresize = 5;
                &lt;span style="color: blue"&gt;break&lt;/span&gt;;
            &lt;span style="color: blue"&gt;case &lt;/span&gt;event.MSPOINTER_TYPE_MOUSE:
                &lt;span style="color: #006400"&gt;// A mouse was used
                // Drawing in blue with a square of 2
                &lt;/span&gt;context.fillStyle = &lt;span style="color: maroon"&gt;&amp;quot;rgba(0, 0, 255, 0.5)&amp;quot;&lt;/span&gt;;
                squaresize = 2;
                &lt;span style="color: blue"&gt;break&lt;/span&gt;;
        }
    }

    context.fillRect(event.clientX, event.clientY, squaresize, squaresize);
}&lt;/pre&gt;

&lt;p&gt;And again you can test the result here:&lt;/p&gt;

&lt;table cellspacing="0" cellpadding="2" width="900" border="0"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="450"&gt;&lt;iframe style="border-top: rgb(255,255,255) 0px solid; border-right: rgb(255,255,255) 0px solid; border-bottom: rgb(255,255,255) 0px solid; border-left: rgb(255,255,255) 0px solid" height="420" src="http://david.blob.core.windows.net/html5/touchsample5.htm" width="410" scrolling="no"&gt;&lt;/iframe&gt;&lt;/td&gt;

      &lt;td valign="top" width="450"&gt;
        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&amp;#160;&lt;/p&gt;

        &lt;p align="center"&gt;&lt;em&gt;Sample 3&lt;/em&gt;: feature detecting &lt;strong&gt;msPointerEnabled&lt;/strong&gt; to provide a fallback&lt;/p&gt;

        &lt;p align="center"&gt;&lt;em&gt;Result&lt;/em&gt;: full complete experience in IE10 and &lt;strong&gt;default mouse events in other browsers&lt;/strong&gt;&lt;/p&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;h3&gt;Step 4: support all touch implementation&lt;/h3&gt;

&lt;p&gt;If you’d like to go even further and support all browsers &amp;amp; all touch implementations, you have 2 choices:&lt;/p&gt;

&lt;p&gt;1 – Write the code to address both events models in parallel like described for instance in this article: &lt;a href="http://blogs.msdn.com/b/ie/archive/2011/10/19/handling-multi-touch-and-mouse-input-in-all-browsers.aspx"&gt;Handling Multi-touch and Mouse Input in All Browsers&lt;/a&gt; 

  &lt;br /&gt;2 – Just add a reference to HandJS, the awesome JavaScript polyfill library written by my friend David Catuhe like described in his article:&amp;#160; &lt;a href="http://blogs.msdn.com/b/eternalcoding/archive/2013/01/16/hand-js-a-polyfill-for-supporting-pointer-events-on-every-browser.aspx"&gt;HandJS a polyfill for supporting pointer events on every browser&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;David wrote a cool little library that lets you write code leveraging the Pointer Events specification. As I mentioned in the introduction of this article, Microsoft recently&lt;a href="http://blogs.msdn.com/b/ie/archive/2012/09/24/towards-interoperable-pointer-events-evolving-input-events-for-multiple-devices.aspx"&gt; submitted the MSPointer Events specification to W3C&lt;/a&gt; for standardization. The W3C created a new Working Group and it has already published &lt;a href="http://www.w3.org/TR/pointerevents/"&gt;a last call working draft&lt;/a&gt; based on Microsoft’s proposal. The MS Open Tech team also recently released an &lt;a href="http://blogs.msdn.com/b/interoperability/archive/2012/12/18/open-source-release-from-ms-open-tech-pointer-events-initial-prototype-for-webkit.aspx"&gt;initial Pointer Events prototype for Webkit&lt;/a&gt; that you might be interested in.&lt;/p&gt;

&lt;p&gt;While the Pointer Events specification is not yet a standard, you can still already implement code that supports it leveraging &lt;a href="http://blogs.msdn.com/b/eternalcoding/archive/2013/01/16/hand-js-a-polyfill-for-supporting-pointer-events-on-every-browser.aspx"&gt;David’s Polyfill&lt;/a&gt; and be ready for when Pointer Events will be a standard implemented in all modern browsers. With David’s library the events will be propagated to MSPointer on IE10, to Touch Events on Webkit based browsers and finally to mouse events as a last resort. It’s damn cool! Check out his article to discover and understand how it works. Note that this polyfill will also be very useful then to support older browser with elegant fallbacks to mouse events.&lt;/p&gt;

&lt;p&gt;To have an idea on how to use this library, please have a look to this article: &lt;a title="http://blogs.msdn.com/b/davrous/archive/2013/02/16/creating-an-universal-virtual-touch-joystick-working-for-all-touch-models-thanks-to-hand-js.aspx" href="http://blogs.msdn.com/b/davrous/archive/2013/02/16/creating-an-universal-virtual-touch-joystick-working-for-all-touch-models-thanks-to-hand-js.aspx"&gt;Creating an universal virtual touch joystick working for all Touch models thanks to Hand.JS&lt;/a&gt; which shows you how to write a virtual touch joystick using pointer events. Thanks to HandJS, it will work on IE10 on Windows 8/RT, Windows Phone 8, iPad/iPhone &amp;amp; Android devices with the very same code base!&lt;/p&gt;

&lt;h2&gt;Recognizing simple gestures&lt;/h2&gt;

&lt;p&gt;Now that we’ve seen how to handle multi-touch, let’s see how to recognize simple gestures like tapping or holding an element and then some more advanced gestures like translating or scaling an element. &lt;/p&gt;

&lt;p&gt;Thankfully, IE10 provides a MSGesture object that’s going to help us. Note that this object is currently specific to IE10 and not part of the W3C submission. Combined with the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh453593.aspx"&gt;MSCSSMatrix&lt;/a&gt; element (our equivalent to the &lt;a href="http://developer.apple.com/library/safari/#documentation/AudioVideo/Reference/WebKitCSSMatrixClassReference/WebKitCSSMatrix/WebKitCSSMatrix.html"&gt;WebKitCSSMatrix&lt;/a&gt; one), you’ll see that you can build very interesting multi-touch experiences in a very simple way. MSCSSMatrix is indeed representing a 4×4 homogeneous matrix that enables Document Object Model (DOM) scripting access to CSS 2-D and 3-D Transforms functionality. But before playing with that, let’s start with the basics. &lt;/p&gt;

&lt;p&gt;The base concept is to &lt;strong&gt;first register to MSPointerDown&lt;/strong&gt;. Then inside the handler taking care of MSPointerDown, you need to &lt;strong&gt;choose&lt;/strong&gt; &lt;strong&gt;which pointers you’d like to send to the MSGesture object&lt;/strong&gt; to let it detect a specific gesture. It will then trigger one of those events: &lt;a href="http://msdn.microsoft.com/en-us/library/hh771901(v=vs.85).aspx"&gt;&lt;strong&gt;MSGestureTap&lt;/strong&gt;&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-us/library/hh771894(v=vs.85).aspx"&gt;&lt;strong&gt;MSGestureHold&lt;/strong&gt;&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-us/library/hh771898(v=vs.85).aspx"&gt;&lt;strong&gt;MSGestureStart&lt;/strong&gt;&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-us/library/hh771887(v=vs.85).aspx"&gt;&lt;strong&gt;MSGestureChange&lt;/strong&gt;&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-us/library/hh771892(v=vs.85).aspx"&gt;&lt;strong&gt;MSGestureEnd&lt;/strong&gt;&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-us/library/hh771906(v=vs.85).aspx"&gt;&lt;strong&gt;MSInertiaStart&lt;/strong&gt;&lt;/a&gt;. The MSGesture object will then take all the pointers submitted as input parameters and will apply a gesture recognizer on top of them to provide some formatted data as output. The only thing you need to do is to choose/filter which pointers you’d like to be part of the gesture (based on their ID, coordinates on the screen, whatever…). The MSGesture object will do all the magic for you after that. &lt;/p&gt;

&lt;h3&gt;Sample 1: handling the hold gesture&lt;/h3&gt;

&lt;p&gt;We’re going to see how to hold an element (a simple DIV containing an image as a background). Once the element will be held, we will add some corners to indicate to the user he has currently selected this element. The corners will be generated by dynamically creating 4 div added on top of each corner of the image. Finally, some CSS tricks will use transformation and linear gradients in a smart way to obtain something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/6840.image_5F00_576B37A6.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5025.image_5F00_thumb_5F00_1D7E856B.png" width="240" height="187" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The sequence will be the following one:&lt;/p&gt;

&lt;p&gt;1 - register to MSPointerDown &amp;amp; &lt;a href="http://msdn.microsoft.com/en-us/library/hh771894(v=vs.85).aspx"&gt;MSPointerHold&lt;/a&gt; events on the HTML element you’re interested in 

  &lt;br /&gt;2 - create a MSGesture object that will target this very same HTML element&amp;#160; &lt;br /&gt;3 - inside the MSPointerDown handler, add to the MSGesture object the various PointerID you’d like to monitor (all of them or a subset of them based on what you’d like to achieve) 

  &lt;br /&gt;4 - inside the MSPointerHold event handler, check in the details if the user has just started the hold gesture (MSGESTURE_FLAG_BEGIN flag). If so, add the corners. If not, remove them. &lt;/p&gt;

&lt;p&gt;This leads to the following code:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;!&lt;/span&gt;&lt;span style="color: maroon"&gt;DOCTYPE &lt;/span&gt;&lt;span style="color: red"&gt;html&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;html&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;head&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;title&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;Touch article sample 5: simple gesture handler&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;title&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;link &lt;/span&gt;&lt;span style="color: red"&gt;rel&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;stylesheet&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;type&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;text/css&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;href&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;toucharticle.css&amp;quot; /&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;script &lt;/span&gt;&lt;span style="color: red"&gt;src&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Corners.js&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;script&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;head&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;body&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;div &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;myGreatPicture&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;class&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;container&amp;quot; /&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;script&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        var &lt;/span&gt;myGreatPic = document.getElementById(&lt;span style="color: maroon"&gt;&amp;quot;myGreatPicture&amp;quot;&lt;/span&gt;);
        &lt;span style="color: #006400"&gt;// Creating a new MSGesture that will monitor the myGreatPic DOM Element
        &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;myGreatPicAssociatedGesture = &lt;span style="color: blue"&gt;new &lt;/span&gt;MSGesture();
        myGreatPicAssociatedGesture.target = myGreatPic;

        &lt;span style="color: #006400"&gt;// You need to first register to MSPointerDown to be able to
        // have access to more complex Gesture events
        &lt;/span&gt;myGreatPic.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;MSPointerDown&amp;quot;&lt;/span&gt;, pointerdown, &lt;span style="color: blue"&gt;false&lt;/span&gt;);
        myGreatPic.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;MSGestureHold&amp;quot;&lt;/span&gt;, holded, &lt;span style="color: blue"&gt;false&lt;/span&gt;);

        &lt;span style="color: #006400"&gt;// Once pointer down raised, we're sending all pointers to the MSGesture object
        &lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;pointerdown(event) {
            myGreatPicAssociatedGesture.addPointer(event.pointerId);
        }

        &lt;span style="color: #006400"&gt;// This event will be triggered by the MSGesture object
        // based on the pointers provided during the MSPointerDown event
        &lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;holded(event) {
            &lt;span style="color: #006400"&gt;// The gesture begins, we're adding the corners
            &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(event.detail === event.MSGESTURE_FLAG_BEGIN) {
                Corners.append(myGreatPic);
            }
            &lt;span style="color: blue"&gt;else &lt;/span&gt;{
                &lt;span style="color: #006400"&gt;// The user has released his finger, the gesture ends
                // We're removing the corners
                &lt;/span&gt;Corners.remove(myGreatPic);
            }
        }

        &lt;span style="color: #006400"&gt;// To avoid having the equivalent of the contextual  
        // &amp;quot;right click&amp;quot; menu being displayed on the MSPointerUp event, 
        // we're preventing the default behavior
        &lt;/span&gt;myGreatPic.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;contextmenu&amp;quot;&lt;/span&gt;, &lt;span style="color: blue"&gt;function &lt;/span&gt;(e) {
            e.preventDefault();    &lt;span style="color: #006400"&gt;// Disables system menu
        &lt;/span&gt;}, &lt;span style="color: blue"&gt;false&lt;/span&gt;);
    &lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;script&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;body&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;html&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;And here is the result:&lt;/p&gt;
&lt;iframe style="border-top: rgb(255,255,255) 0px solid; border-right: rgb(255,255,255) 0px solid; border-bottom: rgb(255,255,255) 0px solid; border-left: rgb(255,255,255) 0px solid" height="400" src="http://david.blob.core.windows.net/html5/touchsample6.html" width="450" scrolling="no"&gt;&lt;/iframe&gt;

&lt;br /&gt;

&lt;br /&gt;

&lt;p&gt;Try to just tap or mouse click the element, nothing occurs. Touch &amp;amp; maintain only 1 finger on the image or do a long mouse click on it, the corners appear. Release your finger, the corners disappear. &lt;/p&gt;

&lt;p&gt;Touch &amp;amp; maintains 2 or more fingers on the image, nothing happens as the Hold gesture is only being triggered only if 1 unique finger is holding the element. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Note:&lt;/u&gt;&lt;/strong&gt; the white border, the corners &amp;amp; the background image are set via CSS defined in &lt;em&gt;toucharticle.css&lt;/em&gt;. &lt;em&gt;Corners.js&lt;/em&gt; simply creates 4 DIVs (with the append function) and places them on top of the main element in each corner with the appropriate CSS classes.&lt;/p&gt;

&lt;p&gt;Still, there is something I’m not happy with in the current result. Once you’re holding the picture, as soon as you’re slightly moving your finger, the MSGESTURE_FLAG_CANCEL flag is raised and caught by the handler which removes the corners. I would rather like to remove the corners only once the user releases his finger anywhere above the picture or as soon as he’s moving his finger out of the box delimited by the picture. To do that, we’re going to remove the corners only on the MSPointerUp or the MSPointerOut. This gives this code instead:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;myGreatPic = document.getElementById(&lt;span style="color: maroon"&gt;&amp;quot;myGreatPicture&amp;quot;&lt;/span&gt;);
&lt;span style="color: #006400"&gt;// Creating a new MSGesture that will monitor the myGreatPic DOM Element
&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;myGreatPicAssociatedGesture = &lt;span style="color: blue"&gt;new &lt;/span&gt;MSGesture();
myGreatPicAssociatedGesture.target = myGreatPic;

&lt;span style="color: #006400"&gt;// You need to first register to MSPointerDown to be able to
// have access to more complex Gesture events
&lt;/span&gt;myGreatPic.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;MSPointerDown&amp;quot;&lt;/span&gt;, pointerdown, &lt;span style="color: blue"&gt;false&lt;/span&gt;);
myGreatPic.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;MSGestureHold&amp;quot;&lt;/span&gt;, holded, &lt;span style="color: blue"&gt;false&lt;/span&gt;);
myGreatPic.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;MSPointerUp&amp;quot;&lt;/span&gt;, removecorners, &lt;span style="color: blue"&gt;false&lt;/span&gt;);
myGreatPic.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;MSPointerOut&amp;quot;&lt;/span&gt;, removecorners, &lt;span style="color: blue"&gt;false&lt;/span&gt;);

&lt;span style="color: #006400"&gt;// Once touched, we're sending all pointers to the MSGesture object
&lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;pointerdown(event) {
    myGreatPicAssociatedGesture.addPointer(event.pointerId);
}

&lt;span style="color: #006400"&gt;// This event will be triggered by the MSGesture object
// based on the pointers provided during the MSPointerDown event
&lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;holded(event) {
    &lt;span style="color: #006400"&gt;// The gesture begins, we're adding the corners
    &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(event.detail === event.MSGESTURE_FLAG_BEGIN) {
        Corners.append(myGreatPic);
    }
}

&lt;span style="color: #006400"&gt;// We're removing the corners on pointer Up or Out
&lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;removecorners(event) {
    Corners.remove(myGreatPic);
}

&lt;span style="color: #006400"&gt;// To avoid having the equivalent of the contextual  
// &amp;quot;right click&amp;quot; menu being displayed on the MSPointerUp event, 
// we're preventing the default behavior
&lt;/span&gt;myGreatPic.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;contextmenu&amp;quot;&lt;/span&gt;, &lt;span style="color: blue"&gt;function &lt;/span&gt;(e) {
    e.preventDefault();    &lt;span style="color: #006400"&gt;// Disables system menu
&lt;/span&gt;}, &lt;span style="color: blue"&gt;false&lt;/span&gt;);&lt;/pre&gt;

&lt;p&gt;which now provides the behavior I was looking for:&lt;/p&gt;

&lt;p&gt;&lt;iframe style="border-top: rgb(255,255,255) 0px solid; border-right: rgb(255,255,255) 0px solid; border-bottom: rgb(255,255,255) 0px solid; border-left: rgb(255,255,255) 0px solid" height="400" src="http://david.blob.core.windows.net/html5/touchsample6b.html" width="450" scrolling="no"&gt;&lt;/iframe&gt;

  &lt;br /&gt;&lt;/p&gt;

&lt;h3&gt;Sample 2: handling scale, translation &amp;amp; rotation&lt;/h3&gt;

&lt;p&gt;Finally, if you want to scale, translate or rotate an element, you simply need to write a very few lines of code. You need to first to register to the &lt;a href="http://msdn.microsoft.com/en-us/library/hh771887(v=vs.85).aspx"&gt;MSGestureChange&lt;/a&gt; event. This event will send you via the various attributes described in the &lt;a href="http://msdn.microsoft.com/en-us/library/hh772076(v=vs.85).aspx"&gt;MSGestureEvent object&lt;/a&gt; documentation like &lt;a href="http://msdn.microsoft.com/en-us/library/hh772363(v=vs.85).aspx"&gt;rotation&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-us/library/hh772082(v=vs.85).aspx"&gt;scale&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-us/library/hh772083(v=vs.85).aspx"&gt;translationX&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-us/library/hh772085(v=vs.85).aspx"&gt;translationY&lt;/a&gt; currently applied to your HTML element.&lt;/p&gt;

&lt;p&gt;Even better, by default, the MSGesture object is providing an inertia algorithm for free. This means that you can take the HTML element and throw it on the screen using your fingers and the animation will be handled for you.&lt;/p&gt;

&lt;p&gt;Lastly, to reflect these changes sent by the MSGesture, you need to move the element accordingly. The easiest way to do that is to apply some CSS Transformation mapping the rotation, scale, translation details matching your fingers gesture. For that, use the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh453593.aspx"&gt;MSCSSMatrix&lt;/a&gt; element. &lt;/p&gt;

&lt;p&gt;In conclusion, if you’d like to handle all this cool gestures to the previous samples, register to the event like that:&lt;/p&gt;

&lt;pre class="code"&gt;myGreatPic.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;MSGestureChange&amp;quot;&lt;/span&gt;, manipulateElement, &lt;span style="color: blue"&gt;false&lt;/span&gt;);&lt;/pre&gt;

&lt;p&gt;And use the following handler:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;manipulateElement(e) {
    &lt;span style="color: #006400"&gt;// Uncomment the following code if you want to disable the built-in inertia 
    // provided by dynamic gesture recognition
    // if (e.detail == e.MSGESTURE_FLAG_INERTIA)
    // return;

    // Get the latest CSS transform on the element
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;m = &lt;span style="color: blue"&gt;new &lt;/span&gt;MSCSSMatrix(e.target.currentStyle.transform); 
    e.target.style.transform = m
    .translate(e.offsetX, e.offsetY) &lt;span style="color: #006400"&gt;// Move the transform origin under the center of the gesture
    &lt;/span&gt;.rotate(e.rotation * 180 / Math.PI) &lt;span style="color: #006400"&gt;// Apply Rotation
    &lt;/span&gt;.scale(e.scale) &lt;span style="color: #006400"&gt;// Apply Scale
    &lt;/span&gt;.translate(e.translationX, e.translationY) &lt;span style="color: #006400"&gt;// Apply Translation
    &lt;/span&gt;.translate(-e.offsetX, -e.offsetY); &lt;span style="color: #006400"&gt;// Move the transform origin back
&lt;/span&gt;}&lt;/pre&gt;

&lt;p&gt;which gives you this final sample:&lt;/p&gt;

&lt;p&gt;&lt;iframe style="border-top: rgb(255,255,255) 0px solid; border-right: rgb(255,255,255) 0px solid; border-bottom: rgb(255,255,255) 0px solid; border-left: rgb(255,255,255) 0px solid" height="500" src="http://david.blob.core.windows.net/html5/touchsample7.html" width="900" scrolling="no"&gt;&lt;/iframe&gt;

  &lt;br /&gt;&lt;/p&gt;

&lt;p&gt;Try to move and throw the image inside the black area with 1 or more fingers. Try also to scale or rotate the element with 2 or more fingers. The result is awesome and the code is very simple as all the complexity is being handled natively by IE10.&lt;/p&gt;

&lt;h2&gt;Video &amp;amp; direct link to all samples&lt;/h2&gt;

&lt;p&gt;If you don’t have a touch screen experience available for IE10 and you’re wondering how these samples works, have a look at this video where I’m describing all samples shared in this article on the Samsung BUILD2011 tablet:&lt;/p&gt;

&lt;div class="video-js-box"&gt;&lt;!-- Using the Video for Everybody Embed Code http://camendesign.com/code/video_for_everybody --&gt;&lt;video id="MSPointerEventsArticleVideo" class="video-js" poster="http://david.blob.core.windows.net/videos/MSPointerEventsArticleVideo.jpg" preload="preload" controls="controls" width="512" height="288"&gt;&lt;source type="video/mp4; codecs=&amp;quot;avc1.42E01E, mp4a.40.2&amp;quot;" src="http://david.blob.core.windows.net/videos/MSPointerEventsArticleVideo.mp4" /&gt;&lt;source type="video/webm; codecs=&amp;quot;vp8, vorbis&amp;quot;" src="http://david.blob.core.windows.net/videos/MSPointerEventsArticleVideo.webm" /&gt;&lt;!-- Flash Fallback. Use any flash video player here. Make sure to keep the vjs-flash-fallback class. --&gt;&lt;object id="flash_fallback_1" class="vjs-flash-fallback" data="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf"
                    width="640" type="application/x-shockwave-flash" height="360"&gt;                     &lt;param name="movie" value="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" /&gt;                     &lt;param name="allowfullscreen" value="true" /&gt;                     &lt;param name="flashvars" value="config={&amp;quot;playlist&amp;quot;:[&amp;quot;http://david.blob.core.windows.net/videos/MSPointerEventsArticleVideo.jpg&amp;quot;, {&amp;quot;url&amp;quot;: &amp;quot;http://david.blob.core.windows.net/videos/MSPointerEventsArticleVideo.mp4&amp;quot;,&amp;quot;autoPlay&amp;quot;:false,&amp;quot;autoBuffering&amp;quot;:true}]}" /&gt;                     &lt;!-- Image Fallback. Typically the same as the poster image. --&gt;                     &lt;img title="No video playback capabilities." alt="Poster Image" src="http://david.blob.core.windows.net/videos/MSPointerEventsArticleVideo.jpg" width="512" height="288" /&gt;                 &lt;/object&gt;&lt;/video&gt;&lt;!-- Download links provided for devices that can't play video in the browser. --&gt;

  &lt;p class="vjs-no-video"&gt;&lt;strong&gt;Download Video:&lt;/strong&gt; &lt;a href="http://david.blob.core.windows.net/videos/MSPointerEventsArticleVideo.mp4"&gt;MP4&lt;/a&gt;, &lt;a href="http://david.blob.core.windows.net/videos/MSPointerEventsArticleVideo.webm"&gt;WebM&lt;/a&gt;, &lt;!-- Support VideoJS by keeping this link. --&gt;&lt;a href="http://videojs.com"&gt;HTML5 Video Player&lt;/a&gt; by VideoJS&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;
  &lt;br /&gt;And you can also have a look to all of them here:&lt;/p&gt;

&lt;p&gt;- &lt;a title="http://david.blob.core.windows.net/html5/touchsample1.htm" href="http://david.blob.core.windows.net/html5/touchsample1.htm"&gt;Simple touch sample 0 with nothing done&lt;/a&gt;&amp;#160; &lt;br /&gt;- &lt;a title="http://david.blob.core.windows.net/html5/touchsample2.htm" href="http://david.blob.core.windows.net/html5/touchsample2.htm"&gt;Simple touch sample 1 with CSS -ms-touch-action&lt;/a&gt;&amp;#160; &lt;br /&gt;- &lt;a title="http://david.blob.core.windows.net/html5/touchsample3.htm" href="http://david.blob.core.windows.net/html5/touchsample3.htm"&gt;Simple touch sample 2a with basic MSPointerMove implementation&lt;/a&gt;&amp;#160; &lt;br /&gt;- &lt;a title="http://david.blob.core.windows.net/html5/touchsample4.htm" href="http://david.blob.core.windows.net/html5/touchsample4.htm"&gt;Simple touch sample 2b with pointerType differentiation&lt;/a&gt;&amp;#160; &lt;br /&gt;- &lt;a title="http://david.blob.core.windows.net/html5/touchsample5.htm" href="http://david.blob.core.windows.net/html5/touchsample5.htm"&gt;Simple touch sample 3 with MSPointers and mouse fallback&lt;/a&gt;&amp;#160; &lt;br /&gt;- &lt;a title="http://david.blob.core.windows.net/html5/touchsample6.html" href="http://david.blob.core.windows.net/html5/touchsample6.html"&gt;MSGesture sample 1: MSGestureHold handler&lt;/a&gt;&amp;#160; &lt;br /&gt;- &lt;a title="http://david.blob.core.windows.net/html5/touchsample6b.html" href="http://david.blob.core.windows.net/html5/touchsample6b.html"&gt;MSGesture sample 1b: MSGestureHold handler&lt;/a&gt;&amp;#160; &lt;br /&gt;- &lt;a title="http://david.blob.core.windows.net/html5/touchsample7.html" href="http://david.blob.core.windows.net/html5/touchsample7.html"&gt;MSGesture sample 2: MSGestureChange&lt;/a&gt;&amp;#160;&lt;/p&gt;

&lt;h2&gt;Associated resources: &lt;/h2&gt;

&lt;p&gt;- &lt;a href="http://www.w3.org/TR/pointerevents/"&gt;W3C Pointer Events Specification&lt;/a&gt; 

  &lt;br /&gt;- &lt;a href="http://blogs.msdn.com/b/ie/archive/2011/10/19/handling-multi-touch-and-mouse-input-in-all-browsers.aspx"&gt;Handling Multi-touch and Mouse Input in All Browsers&lt;/a&gt; : the polyfill library that should help a lot of developers in the future&amp;#160; &lt;br /&gt;- &lt;a href="http://msdn.microsoft.com/en-us/library/hh673557(v=vs.85).aspx"&gt;Pointer and gesture events&lt;/a&gt; 

  &lt;br /&gt;- &lt;a title="http://blogs.msdn.com/b/ie/archive/2012/06/20/go-beyond-pan-zoom-and-tap-using-gesture-events.aspx" href="http://blogs.msdn.com/b/ie/archive/2012/06/20/go-beyond-pan-zoom-and-tap-using-gesture-events.aspx"&gt;Go Beyond Pan, Zoom, and Tap Using Gesture Events&lt;/a&gt; 

  &lt;br /&gt;- &lt;a href="http://ie.microsoft.com/testdrive/Browser/BrowserSurface/"&gt;IE Test Drive Browser Surface&lt;/a&gt; which has greatly inspired lot of the embedded demos 

  &lt;br /&gt;- Try some awesome games in IE10 with Touch: 

  &lt;br /&gt;&amp;#160; - &lt;a href="http://www.contrejour.ie"&gt;Contre Jour&lt;/a&gt; and read a very interesting &lt;a href="http://www.contrejour.ie/BehindTheScenes.html"&gt;Behind The Scenes&lt;/a&gt; article 

  &lt;br /&gt;&amp;#160; - &lt;a href="http://atari.com/arcade"&gt;Atari Arcade Games&lt;/a&gt; and read also this very informative article: &lt;a title="http://atari.com/arcade/developers/building-atari-createjs" href="http://atari.com/arcade/developers/building-atari-createjs"&gt;Building Atari with CreateJS&lt;/a&gt; which details the choice made to support Touch in all platforms. 

  &lt;br /&gt;- Recording of the BUILD session 3-140: &lt;a title="Touchscreen and stylus and mouse, oh my!" href="http://channel9.msdn.com/Events/Build/2012/3-140"&gt;Touchscreen and stylus and mouse, oh my!&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Logically, with all the details shared in this article and associated links to other resources, &lt;strong&gt;you’re now ready to implement the MSPointer Events model in your websites&lt;/strong&gt; &amp;amp; Windows Store applications. You have then the opportunity to easily enhance the experience of your users in Internet Explorer 10.&lt;/p&gt;

&lt;p&gt;David&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10395516" width="1" height="1"&gt;</content><author><name>David Rousset</name><uri>http://blogs.msdn.com/davrous/ProfileUrlRedirect.ashx</uri></author><category term="HTML5" scheme="http://blogs.msdn.com/b/davrous/archive/tags/HTML5/" /><category term="IE10" scheme="http://blogs.msdn.com/b/davrous/archive/tags/IE10/" /><category term="Windows 8" scheme="http://blogs.msdn.com/b/davrous/archive/tags/Windows+8/" /><category term="Touch Events" scheme="http://blogs.msdn.com/b/davrous/archive/tags/Touch+Events/" /><category term="Windows Phone 8" scheme="http://blogs.msdn.com/b/davrous/archive/tags/Windows+Phone+8/" /><category term="Pointer Events" scheme="http://blogs.msdn.com/b/davrous/archive/tags/Pointer+Events/" /></entry><entry><title>Coding4Fun: building a Tetris-like game using CSS Grid Layout &amp; Blend 5</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/davrous/archive/2013/02/12/coding4fun-build-a-tetris-like-game-using-css-grid-layout-amp-blend-5.aspx" /><id>http://blogs.msdn.com/b/davrous/archive/2013/02/12/coding4fun-build-a-tetris-like-game-using-css-grid-layout-amp-blend-5.aspx</id><published>2013-02-12T17:32:27Z</published><updated>2013-02-12T17:32:27Z</updated><content type="html">&lt;!-- Include the VideoJS Library --&gt;&lt;script type="text/javascript" charset="utf-8" src="http://david.blob.core.windows.net/videos/video-js/video.js"&gt;&lt;/script&gt;&lt;script type="text/javascript"&gt;// &lt;![CDATA[
    
	VideoJS.setupAllWhenReady();
  
// ]]&gt;&lt;/script&gt;&lt;link title="Video JS" rel="stylesheet" type="text/css" href="http://david.blob.core.windows.net/videos/video-js/video-js.css" media="screen" /&gt;  &lt;p&gt;I’d like to share with you a mysterious internal secret kept within Microsoft for now a long time. It’s the real story behind the concept of the &lt;a href="http://www.w3.org/TR/css3-grid-layout/"&gt;CSS Grid Layout&lt;/a&gt; imagined by Microsoft for IE10 and Windows Store Apps. Most of you probably think that this specification was designed to help developers having a better layout engine for their websites and applications. But the original motivation was completely different. The very first aim was to be able to create a Tetris-like game in an easy way! But I’m sure you’re not convinced yet. That’s why, I’m going to prove it to you using Blend 5 as a companion. Ok, let’s go!&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Pre-requisites:&lt;/u&gt;&lt;/strong&gt; to follow this tutorial, you need first to:&lt;/p&gt;  &lt;p&gt;1 – Download/buy &amp;amp; install &lt;strong&gt;Windows 8 RTM&lt;/strong&gt; on your machine: &lt;a href="http://msdn.microsoft.com/en-US/windows/apps/br229516.aspx"&gt;http://msdn.microsoft.com/en-US/windows/apps/br229516.aspx&lt;/a&gt;     &lt;br /&gt;2 – Download &amp;amp; install the free edition of &lt;strong&gt;Visual Studio 2012 Express RTM &lt;/strong&gt;for Windows 8: &lt;a href="http://msdn.microsoft.com/en-US/windows/apps/br229516.aspx"&gt;http://msdn.microsoft.com/en-US/windows/apps/br229516.aspx&lt;/a&gt; that includes Expression Blend 5 for Visual Studio or use the higher versions.&lt;/p&gt;  &lt;h2&gt;Step 1: discover the secret behind the CSS Grid Layout thanks to Blend 5&lt;/h2&gt;  &lt;p&gt;Launch Expression Blend 5 and create a new HTML (Windows Store) project of type Blank App. Name it “&lt;em&gt;&lt;strong&gt;TheRealCSSGridStory&lt;/strong&gt;&lt;/em&gt;”:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0447.image_5F00_67473AEA.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/2502.image_5F00_thumb_5F00_00459BE1.png" width="450" height="352" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Replace:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;p&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;Content goes here&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;p&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;By:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;div &lt;/span&gt;&lt;span style="color: red"&gt;class&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;mainGrid&amp;quot;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;div&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Let’s create a grid containing 10 columns and 20 lines whatever the screen’s resolution by using fraction units. For that, add this CSS rule:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: maroon"&gt;.mainGrid &lt;/span&gt;{
    &lt;span style="color: red"&gt;display&lt;/span&gt;: &lt;span style="color: blue"&gt;-ms-grid&lt;/span&gt;;
    &lt;span style="color: red"&gt;width&lt;/span&gt;: &lt;span style="color: blue"&gt;100%&lt;/span&gt;;
    &lt;span style="color: red"&gt;height&lt;/span&gt;: &lt;span style="color: blue"&gt;100%&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-grid-columns&lt;/span&gt;: &lt;span style="color: blue"&gt;(1fr)[10]&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-grid-rows&lt;/span&gt;: &lt;span style="color: blue"&gt;(1fr)[20]&lt;/span&gt;;
}&lt;/pre&gt;

&lt;p&gt;Select in the Live DOM the &lt;em&gt;&amp;lt;div&amp;gt; mainGrid&lt;/em&gt; element and you should obtain this:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4760.image_5F00_085CC836.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/7220.image_5F00_thumb_5F00_1173967B.png" width="640" height="418" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s draw a shape inside this beautiful grid. Add this block of HTML inside the main grid:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;div &lt;/span&gt;&lt;span style="color: red"&gt;class&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;shape1&amp;quot;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;div&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;And insert this CSS associated with it:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: maroon"&gt;.shape1 &lt;/span&gt;{
    &lt;span style="color: red"&gt;-ms-grid-column&lt;/span&gt;: &lt;span style="color: blue"&gt;4&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-grid-row&lt;/span&gt;: &lt;span style="color: blue"&gt;3&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-grid-column-span&lt;/span&gt;: &lt;span style="color: blue"&gt;3&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-grid-row-span&lt;/span&gt;: &lt;span style="color: blue"&gt;2&lt;/span&gt;;
    &lt;span style="color: red"&gt;background-color&lt;/span&gt;: &lt;span style="color: blue"&gt;red&lt;/span&gt;;
}&lt;/pre&gt;

&lt;p&gt;You should now see that in Blend 5:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/1346.image17_5F00_4F5AAA2B.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5556.image17_5F00_thumb_5F00_4CB47F2B.png" width="450" height="276" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Cool, but not yet something that looks like to a Tetris gaming shape. Let’s work on that. Add these 2 DIV inside the shape1:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;div &lt;/span&gt;&lt;span style="color: red"&gt;class&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;line1shape1&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;div&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;div &lt;/span&gt;&lt;span style="color: red"&gt;class&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;line2shape1&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;div&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;and replace the previous &lt;em&gt;.shape1&lt;/em&gt; rule by this block of CSS:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: maroon"&gt;.shape1 &lt;/span&gt;{
    &lt;span style="color: red"&gt;-ms-grid-column&lt;/span&gt;: &lt;span style="color: blue"&gt;4&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-grid-row&lt;/span&gt;: &lt;span style="color: blue"&gt;3&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-grid-column-span&lt;/span&gt;: &lt;span style="color: blue"&gt;3&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-grid-row-span&lt;/span&gt;: &lt;span style="color: blue"&gt;2&lt;/span&gt;;
    &lt;span style="color: red"&gt;display&lt;/span&gt;: &lt;span style="color: blue"&gt;-ms-grid&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-grid-columns&lt;/span&gt;: &lt;span style="color: blue"&gt;1fr 1fr 1fr&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-grid-rows&lt;/span&gt;: &lt;span style="color: blue"&gt;1fr 1fr&lt;/span&gt;;
    &lt;span style="color: red"&gt;width&lt;/span&gt;: &lt;span style="color: blue"&gt;100%&lt;/span&gt;;
    &lt;span style="color: red"&gt;height&lt;/span&gt;: &lt;span style="color: blue"&gt;100%&lt;/span&gt;;
}

&lt;span style="color: maroon"&gt;.line1shape1 &lt;/span&gt;{
    &lt;span style="color: red"&gt;-ms-grid-column-span&lt;/span&gt;: &lt;span style="color: blue"&gt;2&lt;/span&gt;;
    &lt;span style="color: red"&gt;background-color&lt;/span&gt;: &lt;span style="color: blue"&gt;red&lt;/span&gt;;
    
}

&lt;span style="color: maroon"&gt;.line2shape1 &lt;/span&gt;{
    &lt;span style="color: red"&gt;-ms-grid-column&lt;/span&gt;: &lt;span style="color: blue"&gt;2&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-grid-row&lt;/span&gt;: &lt;span style="color: blue"&gt;2&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-grid-column-span&lt;/span&gt;: &lt;span style="color: blue"&gt;2&lt;/span&gt;;
    &lt;span style="color: red"&gt;background-color&lt;/span&gt;: &lt;span style="color: blue"&gt;red&lt;/span&gt;;
}&lt;/pre&gt;

&lt;p&gt;The shape1 is currently spanning on 3 columns and on 2 rows. I’m then creating a new grid inside this area defined by 3 columns and 2 rows in order to have cells having exactly the same size as the cells of the main grid, whatever the resolution will be! &lt;/p&gt;

&lt;p&gt;Once done, I’m creating 2 lines in order to mimic the Z shape of the Tetris game. You should now have this result:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0743.image_5F00_26C7C9CB.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0334.image_5F00_thumb_5F00_520EF183.png" width="450" height="274" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Even better, play with the various views available in the Device tab and you’ll see that our game is already implementing a &lt;a href="http://en.wikipedia.org/wiki/Responsive_web_design"&gt;responsive design&lt;/a&gt;! This is freaking cool, isn’t it? &lt;img class="wlEmoticon wlEmoticon-winkingsmile" style="border-top-style: none; border-left-style: none; border-bottom-style: none; border-right-style: none" alt="Clignement d&amp;#39;œil" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8863.wlEmoticon_2D00_winkingsmile_5F00_41968088.png" /&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Here is for instance the outputs for the snapped view and the portrait view:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5125.image_5F00_7EDD175D.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/1488.image_5F00_thumb_5F00_544E09F5.png" width="550" height="262" /&gt;&lt;/a&gt;&amp;#160;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8420.image_5F00_453C4C7D.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8345.image_5F00_thumb_5F00_119670D0.png" width="325" height="286" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s now resolve another problem. The Tetris grid gaming grid is composed of squares. Our current responsive design is stretching 100% width. Building a Windows 8 application for the Windows Store will most of the time meet widescreen monitors (current tablets are 1366x768 or 1920x1080 and most desktop PC have a 16/9 ratio). Let’s then assume that targeting a widescreen ratio is addressing almost all cases. To compute the proper responsive width, you need to do: 9/16 * 10/20 (the ratio of the main gaming grid) which equals to: &lt;strong&gt;28.125%.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Add then this rule to target the main grid in full screen landscape mode:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;@media &lt;/span&gt;screen and (-ms-view-state: fullscreen-landscape) {
    &lt;span style="color: maroon"&gt;.mainGrid &lt;/span&gt;{
        &lt;span style="color: red"&gt;width&lt;/span&gt;: &lt;span style="color: blue"&gt;28.125%&lt;/span&gt;;
        }
}&lt;/pre&gt;

&lt;p&gt;Let’s now center the gaming grid by using… the CSS Grid Layout again! (And you should now start to believe it really was really designed for Tetris!).&lt;/p&gt;

&lt;p&gt;Switch the &lt;em&gt;body&lt;/em&gt; element to &lt;em&gt;–ms-grid&lt;/em&gt; made of 1 column &amp;amp; 1 row:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: maroon"&gt;body &lt;/span&gt;{
    &lt;span style="color: red"&gt;display&lt;/span&gt;: &lt;span style="color: blue"&gt;-ms-grid&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-grid-columns&lt;/span&gt;: &lt;span style="color: blue"&gt;1fr&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-grid-rows&lt;/span&gt;: &lt;span style="color: blue"&gt;1fr&lt;/span&gt;;
    &lt;span style="color: red"&gt;width&lt;/span&gt;: &lt;span style="color: blue"&gt;100%&lt;/span&gt;;
    &lt;span style="color: red"&gt;height&lt;/span&gt;: &lt;span style="color: blue"&gt;100%&lt;/span&gt;;
}&lt;/pre&gt;

&lt;p&gt;Now simply add this attribute to the CSS associated to the the main grid:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: red"&gt;-ms-grid-column-align&lt;/span&gt;: &lt;span style="color: blue"&gt;center&lt;/span&gt;;&lt;/pre&gt;

&lt;p&gt;And the grid is now centered:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/6170.image_5F00_0EA9E383.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/2553.image_5F00_thumb_5F00_110B1794.png" width="640" height="332" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At this stage, you’re probably already shocked. “&lt;em&gt;How could I have missed this incredible secret?&lt;/em&gt;” you’re wondering to yourself. Take a breath. Now that you now THE secret, let’s continue this tutorial together to discover other awesome possibilities delivered by the CSS specifications combined together. &lt;/p&gt;

&lt;h2&gt;Step 2: moving or rotating a shape&lt;/h2&gt;

&lt;p&gt;My first idea was to try avoiding JS by using as much CSS as possible. I then first tried to use &lt;a href="http://blogs.msdn.com/b/davrous/archive/2011/12/06/introduction-to-css3-animations.aspx"&gt;CSS3 Animations&lt;/a&gt; to move &amp;amp; animate the shape on the various rows/columns. But the bad news is that you can’t change the &lt;em&gt;–ms-grid-column&lt;/em&gt; or &lt;em&gt;–ms-grid-row&lt;/em&gt; values via CSS3 animations. This will then be the job of some JavaScript code. &lt;/p&gt;

&lt;p&gt;I then started to think about how I will rotate the shape. &lt;a href="http://www.w3.org/TR/css3-transforms/"&gt;CSS Transforms&lt;/a&gt; seemed to be perfectly adapted for that. Let’s check that by doing some experiments. Blend 5 is really cool for that as you can directly see in live the outcome of your changes.&lt;/p&gt;

&lt;p&gt;Add a rotation of 90 degrees on &lt;em&gt;shape1&lt;/em&gt; by adding this class to its DIV element:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: maroon"&gt;.shape1rotated &lt;/span&gt;{
    &lt;span style="color: red"&gt;transform&lt;/span&gt;: &lt;span style="color: blue"&gt;rotate(90deg)&lt;/span&gt;;
}&lt;/pre&gt;

&lt;p&gt;I’m sure you weren’t expecting this: &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4087.image_5F00_0A35F177.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4666.image_5F00_thumb_5F00_15CE3F67.png" width="240" height="122" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Problem: it’s not properly aligned to the gaming grid. To align our shape to the grid, we need some small adjustments:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: maroon"&gt;.shape1rotated &lt;/span&gt;{
    &lt;span style="color: red"&gt;transform-origin&lt;/span&gt;: &lt;span style="color: blue"&gt;33% 50%&lt;/span&gt;;
    &lt;span style="color: red"&gt;transform&lt;/span&gt;: &lt;span style="color: blue"&gt;rotate(90deg) translateX(-33%)&lt;/span&gt;;
}&lt;/pre&gt;

&lt;p&gt;And we now have the same rotation as a Tetris-like game. Here are 2 screenshots before/after the rotation:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/3414.image_5F00_22C81F78.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/3005.image_5F00_thumb_5F00_0C08D7EF.png" width="199" height="160" /&gt;&lt;/a&gt;&amp;#160; &lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8272.image_5F00_0E4560AB.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/2425.image_5F00_thumb_5F00_629496AE.png" width="199" height="160" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can even go further than that by using a transition set on shape1 via this:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: red"&gt;transition&lt;/span&gt;: &lt;span style="color: blue"&gt;all 1s ease-out&lt;/span&gt;;&lt;/pre&gt;

&lt;p&gt;And now, removing/adding the &lt;em&gt;.shape1rotated&lt;/em&gt; class on the shape1 DIV will trigger a smooth rotation animation!&lt;/p&gt;

&lt;p&gt;Check out the result inside Blend 5 thanks to this short video:&lt;/p&gt;

&lt;div class="video-js-box"&gt;&lt;!-- Using the Video for Everybody Embed Code http://camendesign.com/code/video_for_everybody --&gt;&lt;video id="MSPointerEventsArticleVideo" class="video-js" poster="http://david.blob.core.windows.net/videos/TheRealCSSGridStoryVideo1.jpg" preload="preload" controls="controls" width="800" height="450"&gt;&lt;source type="video/mp4; codecs=&amp;quot;avc1.42E01E, mp4a.40.2&amp;quot;" src="http://david.blob.core.windows.net/videos/TheRealCSSGridStoryVideo1.mp4" /&gt;&lt;source type="video/webm; codecs=&amp;quot;vp8, vorbis&amp;quot;" src="http://david.blob.core.windows.net/videos/TheRealCSSGridStoryVideo1.webm" /&gt;&lt;!-- Flash Fallback. Use any flash video player here. Make sure to keep the vjs-flash-fallback class. --&gt;&lt;object id="flash_fallback_1" class="vjs-flash-fallback" data="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf"
                    width="800" type="application/x-shockwave-flash" height="450"&gt;                     &lt;param name="movie" value="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" /&gt;                     &lt;param name="allowfullscreen" value="true" /&gt;                     &lt;param name="flashvars" value="config={&amp;quot;playlist&amp;quot;:[&amp;quot;http://david.blob.core.windows.net/videos/TheRealCSSGridStoryVideo1.jpg&amp;quot;, {&amp;quot;url&amp;quot;: &amp;quot;http://david.blob.core.windows.net/videos/TheRealCSSGridStoryVideo1.mp4&amp;quot;,&amp;quot;autoPlay&amp;quot;:false,&amp;quot;autoBuffering&amp;quot;:true}]}" /&gt;                     &lt;!-- Image Fallback. Typically the same as the poster image. --&gt;                     &lt;img title="No video playback capabilities." alt="Poster Image" src="http://david.blob.core.windows.net/videos/TheRealCSSGridStoryVideo1.jpg" width="800" height="450" /&gt;                 &lt;/object&gt;&lt;/video&gt;&lt;!-- Download links provided for devices that can't play video in the browser. --&gt;

  &lt;p class="vjs-no-video"&gt;&lt;strong&gt;Download Video:&lt;/strong&gt; &lt;a href="http://david.blob.core.windows.net/videos/TheRealCSSGridStoryVideo1.mp4"&gt;MP4&lt;/a&gt;, &lt;a href="http://david.blob.core.windows.net/videos/TheRealCSSGridStoryVideo1.webm"&gt;WebM&lt;/a&gt;, &lt;!-- Support VideoJS by keeping this link. --&gt;&lt;a href="http://videojs.com"&gt;HTML5 Video Player&lt;/a&gt; by VideoJS&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;
  &lt;br /&gt;At this stage, we could think that this approach is the good one to build our game. But this is unfortunately not yet the case. Here’s why. Try moving the shape by simply changing its &lt;em&gt;–ms-grid-column&lt;/em&gt; property. Blend 5 will reflect the changes directly. When not rotated, the shape can be moved up to the 8th row:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0118.image_5F00_4D7445B9.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8623.image_5F00_thumb_5F00_0B043434.png" width="350" height="192" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So far so good. But when you’re rotating it by adding the &lt;em&gt;.shape1rotated&lt;/em&gt; class to the DIV:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0525.image_5F00_5A70B67B.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4807.image_5F00_thumb_5F00_43453BFD.png" width="350" height="193" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You see that there is still 1 row available on the right for the shape’s move. If you think we simply need to move it to the 9th row, you’re wrong! Indeed, here is what we’ll obtain on the 9th row:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/1185.image_5F00_27A340B8.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4314.image_5F00_thumb_5F00_349D20C9.png" width="350" height="195" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You probably forgot that we’re currently moving a DIV element displaying a grid layout of 3 columns and 2 rows matching exactly the underlying gaming grid. When moving it, we really have the feeling that this is a block part of the main grid we’re moving. But for this tricks to work, we need at least 3 columns available to contain our shape element. If it’s contained in 2 columns (when set to the 9th column) or less, it will be “compressed” like in the screenshot. &lt;/p&gt;

&lt;p&gt;There is 2 ways to resolve that. &lt;/p&gt;

&lt;p&gt;1 – Stop using CSS Transforms and draw the rotated shape using another grid definition. For instance, using 3 div inside the shape instead of 2. But using such an approach will prevent us to have the nice CSS Animations in place. 
  &lt;br /&gt;2 – Redefined the main grid to work on 12 columns instead of 10 and we’ll use only the columns from 2 to 11 (a sort of clipping area if you wish). This will resolve our “overflow” problem.&lt;/p&gt;

&lt;p&gt;Let’s implement the 2nd solution.&lt;/p&gt;

&lt;p&gt;Redefine the main grid using that:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: maroon"&gt;.mainGrid &lt;/span&gt;{
    &lt;span style="color: red"&gt;display&lt;/span&gt;: &lt;span style="color: blue"&gt;-ms-grid&lt;/span&gt;;
    &lt;font style="background-color: #ffff00"&gt;&lt;span style="color: red"&gt;-ms-grid-columns&lt;/span&gt;: &lt;span style="color: blue"&gt;(1fr)[12]&lt;/span&gt;;&lt;/font&gt;
    &lt;span style="color: red"&gt;-ms-grid-rows&lt;/span&gt;: &lt;span style="color: blue"&gt;(1fr)[20]&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-grid-column-align&lt;/span&gt;: &lt;span style="color: blue"&gt;center&lt;/span&gt;;    
    &lt;span style="color: red"&gt;width&lt;/span&gt;: &lt;span style="color: blue"&gt;100%&lt;/span&gt;;
    &lt;span style="color: red"&gt;height&lt;/span&gt;: &lt;span style="color: blue"&gt;100%&lt;/span&gt;;
}&lt;/pre&gt;

&lt;p&gt;To have also the proper ratio, you need to update the media query associated:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;@media &lt;/span&gt;screen and (-ms-view-state: fullscreen-landscape) {
    &lt;span style="color: maroon"&gt;.mainGrid &lt;/span&gt;{
        &lt;font style="background-color: #ffff00"&gt;&lt;span style="color: red"&gt;width&lt;/span&gt;: &lt;span style="color: blue"&gt;33.75%&lt;/span&gt;;&lt;/font&gt;
        }
}&lt;/pre&gt;

&lt;p&gt;33.75% = 9/16 *12/20&lt;/p&gt;

&lt;p&gt;Let’s also add a “virtual grid” to delimitate the space where we will be able to move the shapes.&amp;#160; Inside the main grid DIV, insert this one:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;div &lt;/span&gt;&lt;span style="color: red"&gt;class&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;virtualGrid&amp;quot;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;div&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Associated with this block of CSS:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: maroon"&gt;.virtualGrid &lt;/span&gt;{
    &lt;span style="color: red"&gt;-ms-grid-column&lt;/span&gt;: &lt;span style="color: blue"&gt;2&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-grid-column-span&lt;/span&gt;: &lt;span style="color: blue"&gt;10&lt;/span&gt;;
    &lt;span style="color: red"&gt;-ms-grid-row-span&lt;/span&gt;: &lt;span style="color: blue"&gt;20&lt;/span&gt;;
    &lt;span style="color: red"&gt;border-right-style&lt;/span&gt;: &lt;span style="color: blue"&gt;dashed&lt;/span&gt;;
    &lt;span style="color: red"&gt;border-left-style&lt;/span&gt;: &lt;span style="color: blue"&gt;dashed&lt;/span&gt;;
    &lt;span style="color: red"&gt;background-color&lt;/span&gt;: &lt;span style="color: blue"&gt;#505A5A&lt;/span&gt;;
}&lt;/pre&gt;

&lt;p&gt;It will help to delimitate the gaming area with a grey background and some dashed border lines. &lt;/p&gt;

&lt;p&gt;Now, if I’m moving the Z shape on column 9, row 2, here is the result:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4544.image_5F00_21CDE152.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8741.image_5F00_thumb_5F00_7C63EDE3.png" width="450" height="126" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If I’m rotating it with CSS Transforms, I can move it correctly on column 10:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4048.image_5F00_07FC3BD4.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4048.image_5F00_thumb_5F00_69B184DD.png" width="450" height="124" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Bonus – handling the Portrait mode:&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you’d like to support the portrait mode (which is even better for the Tetris grid game), add this CSS Media Query definition:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;@media &lt;/span&gt;screen and (-ms-view-state: fullscreen-portrait) {
        &lt;span style="color: maroon"&gt;.mainGrid &lt;/span&gt;{
        &lt;span style="color: red"&gt;width&lt;/span&gt;: &lt;span style="color: blue"&gt;106.66%&lt;/span&gt;;
        }
}&lt;/pre&gt;

&lt;p&gt;As the ratio need to be computed as = 16/9 * 12/20 = 106,66%. &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/1411.image_5F00_32C79A6A.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/1411.image_5F00_thumb_5F00_1B2FECF7.png" width="293" height="480" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;Step 3: adding some code to handle part of the game logic&lt;/h2&gt;

&lt;p&gt;Now that we’ve solved the graphics part of the game using only some pure CSS &amp;amp; HTML code, we need the help of JavaScript to move/rotate the shape in the gaming area. We’re going to re-implement the CSS logic via a JS object that’s going to be defined thanks to &lt;a href="http://msdn.microsoft.com/fr-fr/library/windows/apps/br229776.aspx"&gt;WinJS.Class&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Open the “&lt;em&gt;TheRealCSSGridStory&lt;/em&gt;” in Visual Studio 2012. &lt;/p&gt;

&lt;p&gt;Create a &lt;em&gt;TetrisShapeZ.js&lt;/em&gt; file in the JS directory and copy/paste this code:&lt;/p&gt;

&lt;pre class="code"&gt;(&lt;span style="color: blue"&gt;function &lt;/span&gt;() {
    &lt;span style="color: maroon"&gt;&amp;quot;use strict&amp;quot;&lt;/span&gt;;

    &lt;span style="color: blue"&gt;var &lt;/span&gt;ShapeZ = WinJS.Class.define(
    &lt;span style="color: #006400"&gt;/// Constructor - columnIndex is optional. If provided, will define in which column the shape will start
        &lt;/span&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;(columnIndex) {
            &lt;span style="color: #006400"&gt;// We're creating the equivalent of this HTML block :
            // &amp;lt;div class=&amp;quot;shape1 &amp;quot;&amp;gt;
            //     &amp;lt;div class=&amp;quot;line1shape1&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;
            //     &amp;lt;div class=&amp;quot;line2shape1&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;
            // &amp;lt;/div&amp;gt;
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;._shape1 = document.createElement(&lt;span style="color: maroon"&gt;&amp;quot;div&amp;quot;&lt;/span&gt;);
            &lt;span style="color: blue"&gt;var &lt;/span&gt;line1 = document.createElement(&lt;span style="color: maroon"&gt;&amp;quot;div&amp;quot;&lt;/span&gt;);
            &lt;span style="color: blue"&gt;var &lt;/span&gt;line2 = document.createElement(&lt;span style="color: maroon"&gt;&amp;quot;div&amp;quot;&lt;/span&gt;);
            &lt;span style="color: blue"&gt;this&lt;/span&gt;._shape1.className = &lt;span style="color: maroon"&gt;&amp;quot;shape1&amp;quot;&lt;/span&gt;;
            line1.className = &lt;span style="color: maroon"&gt;&amp;quot;line1shape1&amp;quot;&lt;/span&gt;;
            line2.className = &lt;span style="color: maroon"&gt;&amp;quot;line2shape1&amp;quot;&lt;/span&gt;;
            &lt;span style="color: blue"&gt;this&lt;/span&gt;._shape1.appendChild(line1);
            &lt;span style="color: blue"&gt;this&lt;/span&gt;._shape1.appendChild(line2);
            &lt;span style="color: #006400"&gt;// Boolean to indicate if the shape is in its default orientation mode or not
            // True means not rotated, false means rotated
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;._defaultOrientation = &lt;span style="color: blue"&gt;true&lt;/span&gt;;
            &lt;span style="color: #006400"&gt;// Setting the column position in the main grid
            &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(columnIndex) {
                &lt;span style="color: blue"&gt;this&lt;/span&gt;._currentColPos = columnIndex;
                &lt;span style="color: blue"&gt;this&lt;/span&gt;._shape1.style.msGridColumn = &lt;span style="color: blue"&gt;this&lt;/span&gt;._currentColPos;
            }
            &lt;span style="color: blue"&gt;else &lt;/span&gt;{
                &lt;span style="color: blue"&gt;this&lt;/span&gt;._currentColPos = 1;
            }
            &lt;span style="color: #006400"&gt;// We always start at line 1
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;._currentLinePos = 1;
            &lt;span style="color: #006400"&gt;// Boolean to know if the shape can be move/rotate or not
            // If true, this means we've reached the last line possible
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;._fixed = &lt;span style="color: blue"&gt;false&lt;/span&gt;;
        },
        {
            &lt;span style="color: #006400"&gt;/// Specify in which HTML element displayed in CSS Grid you'd like to work with
            /// width is the number of columns of the grid &amp;amp; height is the number of lines
            &lt;/span&gt;insertIntoGrid: &lt;span style="color: blue"&gt;function &lt;/span&gt;(element, width, height) {
                element.appendChild(&lt;span style="color: blue"&gt;this&lt;/span&gt;._shape1);
                &lt;span style="color: blue"&gt;this&lt;/span&gt;._gridWidth = width;
                &lt;span style="color: blue"&gt;this&lt;/span&gt;._gridHeight = height;
                &lt;span style="color: #006400"&gt;// These are the left &amp;amp; bottom max limit for this shape
                // when displayed in default orientation mode
                &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;._maxLeft = width - 3;
                &lt;span style="color: blue"&gt;this&lt;/span&gt;._maxBottom = height - 1;
            },
            &lt;span style="color: #006400"&gt;/// Rotate the Z shape 90 degrees anti/clockwise using CSS Transforms
            /// by simply removing/adding the shape1rotated class
            &lt;/span&gt;rotate: &lt;span style="color: blue"&gt;function &lt;/span&gt;() {
                &lt;span style="color: blue"&gt;if &lt;/span&gt;(!&lt;span style="color: blue"&gt;this&lt;/span&gt;._fixed &amp;amp;&amp;amp; &lt;span style="color: blue"&gt;this&lt;/span&gt;._defaultOrientation) {
                    &lt;span style="color: #006400"&gt;// rotating 90 degrees clockwise, it will trigger also the CSS Transition
                    &lt;/span&gt;WinJS.Utilities.addClass(&lt;span style="color: blue"&gt;this&lt;/span&gt;._shape1, &lt;span style="color: maroon"&gt;&amp;quot;shape1rotated&amp;quot;&lt;/span&gt;);
                    &lt;span style="color: blue"&gt;this&lt;/span&gt;._defaultOrientation = &lt;span style="color: blue"&gt;false&lt;/span&gt;;
                    &lt;span style="color: #006400"&gt;// the left limit is now +1 vs the default orientation
                    &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;._maxLeft = &lt;span style="color: blue"&gt;this&lt;/span&gt;._gridWidth - 2;
                }
                &lt;span style="color: blue"&gt;else &lt;/span&gt;{
                    &lt;span style="color: blue"&gt;if &lt;/span&gt;(!&lt;span style="color: blue"&gt;this&lt;/span&gt;._fixed &amp;amp;&amp;amp; &lt;span style="color: blue"&gt;this&lt;/span&gt;._currentColPos &amp;lt; &lt;span style="color: blue"&gt;this&lt;/span&gt;._maxLeft) {
                        &lt;span style="color: #006400"&gt;// removing the shape1rotated will automatically reset the shape
                        // to its initial matrix and again the CSS Transition will do the animation for you
                        &lt;/span&gt;WinJS.Utilities.removeClass(&lt;span style="color: blue"&gt;this&lt;/span&gt;._shape1, &lt;span style="color: maroon"&gt;&amp;quot;shape1rotated&amp;quot;&lt;/span&gt;);
                        &lt;span style="color: blue"&gt;this&lt;/span&gt;._defaultOrientation = &lt;span style="color: blue"&gt;true&lt;/span&gt;;
                        &lt;span style="color: blue"&gt;this&lt;/span&gt;._maxLeft = &lt;span style="color: blue"&gt;this&lt;/span&gt;._gridWidth - 3;
                    }
                }
            },
            &lt;span style="color: #006400"&gt;// Internal function called by public moveLeft/moveRight
            &lt;/span&gt;_moveHorizontally: &lt;span style="color: blue"&gt;function &lt;/span&gt;(direction) {
                &lt;span style="color: blue"&gt;if &lt;/span&gt;(!&lt;span style="color: blue"&gt;this&lt;/span&gt;._fixed &amp;amp;&amp;amp; (&lt;span style="color: blue"&gt;this&lt;/span&gt;._currentColPos &amp;lt; &lt;span style="color: blue"&gt;this&lt;/span&gt;._maxLeft || direction === -1) &amp;amp;&amp;amp; (&lt;span style="color: blue"&gt;this&lt;/span&gt;._currentColPos &amp;gt; 2 || direction === 1)) {
                    &lt;span style="color: blue"&gt;this&lt;/span&gt;._currentColPos = &lt;span style="color: blue"&gt;this&lt;/span&gt;._currentColPos + direction;
                    &lt;span style="color: blue"&gt;this&lt;/span&gt;._shape1.style.msGridColumn = &lt;span style="color: blue"&gt;this&lt;/span&gt;._currentColPos;
                }
            },
            &lt;span style="color: #006400"&gt;/// Move the shape on the immediate left column
            /// Test if you've reached the left limit or not
            &lt;/span&gt;moveLeft: &lt;span style="color: blue"&gt;function &lt;/span&gt;() {
                &lt;span style="color: blue"&gt;this&lt;/span&gt;._moveHorizontally(-1);
            },
            &lt;span style="color: #006400"&gt;/// Move the shape on the immediate right column
            /// Test if you've reached the right limit or not
            &lt;/span&gt;moveRight: &lt;span style="color: blue"&gt;function &lt;/span&gt;() {
                &lt;span style="color: blue"&gt;this&lt;/span&gt;._moveHorizontally(1);
            },
            &lt;span style="color: #006400"&gt;/// Move the shape down on the immediate below line
            /// Test if you've reached the bottom limit or not
            &lt;/span&gt;moveDown: &lt;span style="color: blue"&gt;function &lt;/span&gt;() {
                &lt;span style="color: blue"&gt;if &lt;/span&gt;(!&lt;span style="color: blue"&gt;this&lt;/span&gt;._fixed) {
                    &lt;span style="color: blue"&gt;this&lt;/span&gt;._currentLinePos = &lt;span style="color: blue"&gt;this&lt;/span&gt;._currentLinePos + 1;
                    &lt;span style="color: blue"&gt;this&lt;/span&gt;._shape1.style.msGridRow = &lt;span style="color: blue"&gt;this&lt;/span&gt;._currentLinePos;
                    &lt;span style="color: blue"&gt;if &lt;/span&gt;(&lt;span style="color: blue"&gt;this&lt;/span&gt;._currentLinePos === &lt;span style="color: blue"&gt;this&lt;/span&gt;._maxBottom) {
                        &lt;span style="color: blue"&gt;this&lt;/span&gt;._fixed = &lt;span style="color: blue"&gt;true&lt;/span&gt;;
                    }
                }
            }
        }
    );

    WinJS.Namespace.define(&lt;span style="color: maroon"&gt;&amp;quot;CSSTetris&amp;quot;&lt;/span&gt;, { ShapeZ: ShapeZ });
} ());&lt;/pre&gt;

&lt;p&gt;Simply read the code to understand what it’s doing. It should be commented enough to be self-explicit. &lt;/p&gt;

&lt;p&gt;Add a reference to this script file in &lt;em&gt;default.html &lt;/em&gt;and keep only this block of HTML inside the body:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;div &lt;/span&gt;&lt;span style="color: red"&gt;class&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;mainGrid&amp;quot;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;div &lt;/span&gt;&lt;span style="color: red"&gt;class&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;virtualGrid&amp;quot;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;div&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;div&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Jump into &lt;em&gt;default.js&lt;/em&gt;. &lt;/p&gt;

&lt;p&gt;The cool part of having well documented the code is that we now have interesting IntelliSense details like for the &lt;strong&gt;constructor&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0574.image_5F00_3C57958D.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/4606.image_5F00_thumb_5F00_12E3544D.png" width="734" height="73" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;or the &lt;strong&gt;rotate&lt;/strong&gt; function:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/0160.image_5F00_1BD2E68C.png"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/6443.image_5F00_thumb_5F00_696F130C.png" width="458" height="100" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To properly use this code, add this block of JS just after &lt;em&gt;processAll&lt;/em&gt; call:&lt;/p&gt;

&lt;pre class="code"&gt;document.addEventListener(&lt;span style="color: maroon"&gt;&amp;quot;keydown&amp;quot;&lt;/span&gt;, OnKeyDown, &lt;span style="color: blue"&gt;false&lt;/span&gt;);
mainGrid = document.getElementsByClassName(&lt;span style="color: maroon"&gt;&amp;quot;mainGrid&amp;quot;&lt;/span&gt;)[0];
myShape = &lt;span style="color: blue"&gt;new &lt;/span&gt;CSSTetris.ShapeZ(4);
myShape.insertIntoGrid(mainGrid, 12, 20);
init();&lt;/pre&gt;

&lt;p&gt;And add these 2 functions:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;function &lt;/span&gt;init() {
    setInterval(&lt;span style="color: blue"&gt;function &lt;/span&gt;() {
        myShape.moveDown();
    }, 1000);
}

&lt;span style="color: blue"&gt;function &lt;/span&gt;OnKeyDown(event) {
    &lt;span style="color: blue"&gt;switch &lt;/span&gt;(event.keyCode) {
        &lt;span style="color: blue"&gt;case &lt;/span&gt;KEYCODE_X:
            myShape.rotate();
            &lt;span style="color: blue"&gt;break&lt;/span&gt;;
        &lt;span style="color: blue"&gt;case &lt;/span&gt;KEYCODE_LEFT:
            myShape.moveLeft();
            &lt;span style="color: blue"&gt;break&lt;/span&gt;;
        &lt;span style="color: blue"&gt;case &lt;/span&gt;KEYCODE_RIGHT:
            myShape.moveRight();
            &lt;span style="color: blue"&gt;break&lt;/span&gt;;
        &lt;span style="color: blue"&gt;case &lt;/span&gt;KEYCODE_DOWN:
            myShape.moveDown();
            &lt;span style="color: blue"&gt;break&lt;/span&gt;;
    }
}&lt;/pre&gt;

&lt;p&gt;And we’re done! We now have a very basic game using CSS Grid Layout coupled with CSS Transforms &amp;amp; Animations for the graphics part and a couple of JS lines of code to have the beginning of the basics of a Tetris-like game. &lt;/p&gt;

&lt;p&gt;Here is a short video demonstrating the final result:&lt;/p&gt;

&lt;div class="video-js-box"&gt;&lt;!-- Using the Video for Everybody Embed Code http://camendesign.com/code/video_for_everybody --&gt;&lt;video id="MSPointerEventsArticleVideo" class="video-js" poster="http://david.blob.core.windows.net/videos/TheRealCSSGridStoryVideo2.jpg" preload="preload" controls="controls" width="705" height="450"&gt;&lt;source type="video/mp4; codecs=&amp;quot;avc1.42E01E, mp4a.40.2&amp;quot;" src="http://david.blob.core.windows.net/videos/TheRealCSSGridStoryVideo2.mp4" /&gt;&lt;source type="video/webm; codecs=&amp;quot;vp8, vorbis&amp;quot;" src="http://david.blob.core.windows.net/videos/TheRealCSSGridStoryVideo2.webm" /&gt;&lt;!-- Flash Fallback. Use any flash video player here. Make sure to keep the vjs-flash-fallback class. --&gt;&lt;object id="flash_fallback_1" class="vjs-flash-fallback" data="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf"
                width="705" type="application/x-shockwave-flash" height="450"&gt;
                &lt;param name="movie" value="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" /&gt;
                &lt;param name="allowfullscreen" value="true" /&gt;
                &lt;param name="flashvars" value="config={&amp;quot;playlist&amp;quot;:[&amp;quot;http://david.blob.core.windows.net/videos/TheRealCSSGridStoryVideo2.jpg&amp;quot;, {&amp;quot;url&amp;quot;: &amp;quot;http://david.blob.core.windows.net/videos/TheRealCSSGridStoryVideo2.mp4&amp;quot;,&amp;quot;autoPlay&amp;quot;:false,&amp;quot;autoBuffering&amp;quot;:true}]}" /&gt;
                &lt;!-- Image Fallback. Typically the same as the poster image. --&gt;
                &lt;img title="No video playback capabilities." alt="Poster Image" src="http://david.blob.core.windows.net/videos/TheRealCSSGridStoryVideo2.jpg" width="705" height="450" /&gt;
            &lt;/object&gt;&lt;/video&gt;&lt;!-- Download links provided for devices that can't play video in the browser. --&gt;

  &lt;p class="vjs-no-video"&gt;&lt;strong&gt;Download Video:&lt;/strong&gt; &lt;a href="http://david.blob.core.windows.net/videos/TheRealCSSGridStoryVideo2.mp4"&gt;MP4&lt;/a&gt;, &lt;a href="http://david.blob.core.windows.net/videos/TheRealCSSGridStoryVideo2.webm"&gt;WebM&lt;/a&gt;, &lt;!-- Support VideoJS by keeping this link. --&gt;&lt;a href="http://videojs.com"&gt;HTML5 Video Player&lt;/a&gt; by VideoJS&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;
  &lt;br /&gt;You can download the final Visual Studio solution corresponding to the 3 steps of this tutorial here: &lt;a title="http://david.blob.core.windows.net/win8/TheRealCSSGridStory.zip" href="http://david.blob.core.windows.net/win8/TheRealCSSGridStory.zip"&gt;http://david.blob.core.windows.net/win8/TheRealCSSGridStory.zip&lt;/a&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;So, are you now convinced that CSS Grid Layout was made to simplify the creation of Tetris-like games? &lt;img class="wlEmoticon wlEmoticon-winkingsmile" style="border-top-style: none; border-left-style: none; border-bottom-style: none; border-right-style: none" alt="Clignement d&amp;#39;œil" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8863.wlEmoticon_2D00_winkingsmile_5F00_41968088.png" /&gt;&lt;/p&gt;

&lt;p&gt;David&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10393029" width="1" height="1"&gt;</content><author><name>David Rousset</name><uri>http://blogs.msdn.com/davrous/ProfileUrlRedirect.ashx</uri></author></entry><entry><title>Tout savoir sur le parcours Windows 8/Windows Phone 8 des Techdays 2013 !</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/davrous/archive/2012/12/19/tout-savoir-sur-le-parcours-windows-8-windows-phone-8-des-techdays-2013.aspx" /><id>http://blogs.msdn.com/b/davrous/archive/2012/12/19/tout-savoir-sur-le-parcours-windows-8-windows-phone-8-des-techdays-2013.aspx</id><published>2012-12-19T14:25:08Z</published><updated>2012-12-19T14:25:08Z</updated><content type="html">&lt;p&gt;Cette année, comme tous les ans depuis 5 ans maintenant, j’étais responsable du &lt;a href="http://www.microsoft.com/france/mstechdays/programmes/2013/recherche-sessions.aspx#d=b9922383-933f-4e4d-b5d1-4896a8994fbe&amp;amp;Page=1"&gt;parcours Web des Techdays 2013&lt;/a&gt;. Mais j’avais également la chance d’être responsable du parcours Windows 8/Windows Phone 8 avec mes amis &lt;a href="http://blogs.msdn.com/devosaure"&gt;Eric Vernié&lt;/a&gt;, &lt;a href="http://blogs.msdn.com/pierreca"&gt;Pierre Cauchois&lt;/a&gt; et &lt;a href="https://twitter.com/danvy"&gt;Alex Danvy&lt;/a&gt;. Nous avons essayé de créer un parcours qui couvre les sujets qui nous paraissent les plus importants pour notre plateforme mais contenant aussi les sujets que nous savons qui vous tiennent à cœur. Par ailleurs, nous avons essayé d’établir un équilibre sur les langages (XAML/C# et HTML5/JS) et sur les 2 plateformes (Win8 et WP8). Pour finir, il y aura des sessions de découvertes (niveau 100 et 200) et des sessions dites qui « piquent » (niveau 300 et 400). Bref, il devrait y en avoir pour tous les gouts ! &lt;img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-left-style: none; border-bottom-style: none; border-right-style: none" alt="Sourire" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/2022.wlEmoticon_2D00_smile_5F00_38F3247C.png" /&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/5165.logo_5F00_mstechdays_5F00_win8_5F00_wp8_5F00_169E1FB4.jpg"&gt;&lt;img title="logo_mstechdays_win8_wp8" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="logo_mstechdays_win8_wp8" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-10-46-metablogapi/8715.logo_5F00_mstechdays_5F00_win8_5F00_wp8_5F00_thumb_5F00_785368BD.jpg" width="240" height="97" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;En synthèse, nous avons ainsi réfléchit à 3 types de sessions sur le parcours 8 :&lt;/p&gt;  &lt;p&gt;- Des sessions d’&lt;strong&gt;introduction&lt;/strong&gt; aux plateformes     &lt;br /&gt;- Des sessions &lt;strong&gt;communes&lt;/strong&gt; entre Windows 8/Windows Phone 8 vu que les 2 plateformes partagent un cœur commun ainsi que de nombreux concepts     &lt;br /&gt;- Des sessions &lt;strong&gt;spécifiques&lt;/strong&gt; à Windows 8 et Windows Phone 8 contenant du contenu plus avancé&lt;/p&gt;  &lt;p&gt;Je suis assez content du résultat et des orateurs que nous avons retenus. Je vous propose ainsi de découvrir le programme complet qui vous attend du &lt;a href="http://www.mstechdays.fr/"&gt;12 au 14 février 2013 au palais des congres&lt;/a&gt;. Réservez vos agendas !&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Note :&lt;/u&gt;&lt;/strong&gt; le APPxxx entre parenthèse de chaque titre vous donne le niveau de difficulté de 100 (accessible à tous) vers 400 (accrochez-vous au siège). On considère en général qu’une session développeur commence à 200.&amp;#160;&amp;#160; &lt;/p&gt;  &lt;h2&gt;Sessions d’introduction aux plateformes &lt;/h2&gt;  &lt;p&gt;1. &lt;a href="http://www.microsoft.com/france/mstechdays/programmes/2013/fiche-session.aspx?ID=b47a494e-d4f2-46c2-8189-8d03f56ac86a"&gt;Introduction au développement Windows 8 et Windows Phone 8 (APP101)&lt;/a&gt; qui sera animée par &lt;em&gt;Eric Vernié&lt;/em&gt; et &lt;em&gt;Alex Danvy&lt;/em&gt;. La session chapeau de toutes les autres qui faudra donc absolument ne pas manquer !     &lt;br /&gt;2. &lt;a href="http://www.microsoft.com/france/mstechdays/programmes/2013/fiche-session.aspx?ID=9dafebf4-08aa-4a0b-9c5d-1f9728ecf89c"&gt;Introduction au développement Windows 8 avec XAML et .NET 4.5 (APP201)&lt;/a&gt; qui sera animée par &lt;em&gt;Eric Vernié&lt;/em&gt; et &lt;em&gt;Benjamin Baldacci&lt;/em&gt;     &lt;br /&gt;3. &lt;a href="http://www.microsoft.com/france/mstechdays/programmes/2013/fiche-session.aspx?ID=60738dd2-6d50-4360-a285-ed988e49d850"&gt;Introduction au développement Windows 8 ModernUI avec HTML5 et JavaScript (APP203)&lt;/a&gt; qui sera animée par votre humble serviteur     &lt;br /&gt;4. &lt;a href="http://www.microsoft.com/france/mstechdays/programmes/2013/fiche-session.aspx?ID=1c68d061-f567-43f1-a0f9-e48c6e404a59"&gt;Introduction au développement Windows Phone 8 (APP212)&lt;/a&gt; qui sera animée par&lt;em&gt; Jean-Sébastien Dupuy&lt;/em&gt;, le dernier petit nouveau de notre équipe, et par &lt;em&gt;Julien Corioland&lt;/em&gt;     &lt;br /&gt;5. &lt;a href="http://www.microsoft.com/france/mstechdays/programmes/2013/fiche-session.aspx?ID=d923e746-f2cb-4d45-8c8e-c4788800a6f7"&gt;Quels sont les outils pour créer des jeux pour Windows 8 et Windows Phone 8 (APP204)&lt;/a&gt; qui sera animée par &lt;em&gt;David Catuhe&lt;/em&gt; et moi-même. Que vous soyez un passionné, un étudiant ou un professionnel du jeu vidéo, nous vous dresserons un panorama complet des manières de développer un jeu pour Windows 8 et Windows Phone 8.&lt;/p&gt;  &lt;p&gt;Ces sessions sont programmées sur le 1er jour (le 12 février) sauf celle sur les jeux vidéo qui aura lieu le 2eme jour (13 février). Il est indispensable de les suivre pour avoir les bases nécessaires à la compréhension des sessions qui suivent.&lt;/p&gt;  &lt;h2&gt;Sessions communes aux 2 plateformes&lt;/h2&gt;  &lt;p&gt;6. &lt;a href="http://www.microsoft.com/france/mstechdays/programmes/2013/fiche-session.aspx?ID=0b6b8e83-8bc8-4060-be7e-f614e0c507d1"&gt;WinRT et l'accès aux données (APP202)&lt;/a&gt; qui sera animée par &lt;em&gt;Sébastien Pertus&lt;/em&gt; et &lt;em&gt;Benoit Laut&lt;/em&gt;     &lt;br /&gt;7. &lt;a href="http://www.microsoft.com/france/mstechdays/programmes/2013/fiche-session.aspx?ID=96646a53-dec2-4762-8892-fc97ff09ce8d"&gt;Fichier, Nouveau projet… Et après ? (APP213)&lt;/a&gt; qui sera animée par &lt;em&gt;John Thiriet&lt;/em&gt;     &lt;br /&gt;8. &lt;a href="http://www.microsoft.com/france/mstechdays/programmes/2013/fiche-session.aspx?ID=3858ee7f-0e8f-4bd3-9f16-ec3e51680f24"&gt;Cycle de vie d'une application Windows 8 et Windows Phone 8 (APP305)&lt;/a&gt; qui sera animée par &lt;em&gt;Christopher Maneu&lt;/em&gt;     &lt;br /&gt;9. &lt;a href="http://www.microsoft.com/france/mstechdays/programmes/2013/fiche-session.aspx?ID=58172c08-ee35-47eb-af13-409d5d27ea7b"&gt;Bien soumettre et monétiser votre application Windows 8 et Windows Phone 8 (APP208)&lt;/a&gt; qui sera animée par &lt;em&gt;Pierre Lagarde&lt;/em&gt;     &lt;br /&gt;10. &lt;a href="http://www.microsoft.com/france/mstechdays/programmes/2013/fiche-session.aspx?ID=ae16bf65-56c5-493e-bd94-fa52cc8a2b75"&gt;Bonnes pratiques de l'intégration de la publicité dans les applications Windows 8 et WP8 (APP209)&lt;/a&gt; qui sera animée par &lt;em&gt;Nathalie Belval&lt;/em&gt;, &lt;em&gt;Cyril Cathala&lt;/em&gt;, &lt;em&gt;Pierre Lagarde&lt;/em&gt; et &lt;em&gt;Marc Couraud&lt;/em&gt;     &lt;br /&gt;11. &lt;a href="http://www.microsoft.com/france/mstechdays/programmes/2013/fiche-session.aspx?ID=4ee6c409-2b52-41cf-8553-358a144b1cda"&gt;Plus près, plus près… NFC et la communication à proximité dans Windows 8 et Windows Phone 8 (APP220)&lt;/a&gt; qui sera animée par notre superbe&lt;em&gt; Julie Knibbe&lt;/em&gt; et par &lt;em&gt;Marc Gemeto&lt;/em&gt;     &lt;br /&gt;12. &lt;a href="http://www.microsoft.com/france/mstechdays/programmes/2013/fiche-session.aspx?ID=5608f6b0-30fb-48a8-969c-9b3d4719147a"&gt;Créer des applications métier (LOB) pour Windows 8 et Windows Phone 8 (APP206)&lt;/a&gt; qui sera animée par &lt;em&gt;Audrey Petit&lt;/em&gt; et &lt;em&gt;Patrice Lamarche&lt;/em&gt;     &lt;br /&gt;13. &lt;a href="http://www.microsoft.com/france/mstechdays/programmes/2013/fiche-session.aspx?ID=34729826-1d55-443d-a322-4100904ee6de"&gt;Création de jeux en DirectX pour Windows 8 et Windows Phone 8 (APP401)&lt;/a&gt; qui sera animée par &lt;em&gt;Simon Ferquel&lt;/em&gt; et &lt;em&gt;David Catuhe&lt;/em&gt;     &lt;br /&gt;14. &lt;a href="http://www.microsoft.com/france/mstechdays/programmes/2013/fiche-session.aspx?ID=79a3d763-adea-4edd-a4a5-2c2c307d10b6"&gt;Conception applications 3 écrans sur Windows 8/WP8/Xbox 360 (APP210)&lt;/a&gt; qui sera animée par &lt;em&gt;Romuald Boulanger&lt;/em&gt;,&lt;em&gt; Thierry Bouquain&lt;/em&gt; et &lt;em&gt;Pierre Lagarde&lt;/em&gt;&lt;/p&gt;  &lt;h2&gt;Sessions spécifiques Windows 8&lt;/h2&gt;  &lt;p&gt;15. &lt;a href="http://www.microsoft.com/france/mstechdays/programmes/2013/fiche-session.aspx?ID=929dbd16-7e51-48d0-a8e0-4100c417bd23"&gt;Windows 8 : Comment développer des applications efficaces et performantes pour rendre l'expérience utilisateur unique ? (APP211)&lt;/a&gt; : 2 retours d’expériences intéressants qui seront présentés par &lt;em&gt;Benoit Douvernelle&lt;/em&gt; et &lt;em&gt;Guillaume Brout&lt;/em&gt;     &lt;br /&gt;16. &lt;a href="http://www.microsoft.com/france/mstechdays/programmes/2013/fiche-session.aspx?ID=e0a4692b-284d-4c81-8e1c-5335083f6d53"&gt;Conception d'une application pour Windows 8 avec Blend 5 (APP207)&lt;/a&gt; qui sera animée par &lt;em&gt;Eric Ambrosi&lt;/em&gt;     &lt;br /&gt;17. &lt;a href="http://www.microsoft.com/france/mstechdays/programmes/2013/fiche-session.aspx?ID=d1e1171c-eed2-4aaf-9628-cd512df102a6"&gt;Outillage pour Windows 8 XAML (APP217)&lt;/a&gt; qui sera animée par &lt;em&gt;Sébastien Pertus&lt;/em&gt; et &lt;em&gt;Cyprien Autexier&lt;/em&gt;     &lt;br /&gt;18. &lt;a href="http://www.microsoft.com/france/mstechdays/programmes/2013/fiche-session.aspx?ID=9c4e0077-a8dc-4fd6-b03a-8b83676f0614"&gt;Trucs et astuces pour rendre votre application Windows 8 plus visible (APP218)&lt;/a&gt; qui sera animée par &lt;em&gt;Sacha Leroux&lt;/em&gt; et &lt;em&gt;Alex Danvy&lt;/em&gt;     &lt;br /&gt;19. &lt;a href="http://www.microsoft.com/france/mstechdays/programmes/2013/fiche-session.aspx?ID=c326af6f-e670-4a46-bdde-24318e859a90"&gt;10 tips pour améliorer les performances de vos applications Windows 8 (APP301)&lt;/a&gt; qui sera animée par&lt;em&gt; Loic Rebours&lt;/em&gt; et &lt;em&gt;Eric Vernié&lt;/em&gt;     &lt;br /&gt;20. &lt;a href="http://www.microsoft.com/france/mstechdays/programmes/2013/fiche-session.aspx?ID=d7715158-1991-4ddf-a766-37d00bb6e7cb"&gt;Le développement d'un Composant WinRT (APP302)&lt;/a&gt; qui sera animée par &lt;em&gt;Arnaud Auroux&lt;/em&gt; et &lt;em&gt;Eric Vernié&lt;/em&gt;     &lt;br /&gt;21. &lt;a href="http://www.microsoft.com/france/mstechdays/programmes/2013/fiche-session.aspx?ID=3d141ca7-d4a5-458e-ae06-0057406f5c26"&gt;Deep Dive WinJS – Profitez à 100% de son potentiel (APP304)&lt;/a&gt; qui sera animée par&lt;em&gt; Thomas Lebrun&lt;/em&gt; et &lt;em&gt;Jonathan Antoine&lt;/em&gt;     &lt;br /&gt;22. &lt;a href="http://www.microsoft.com/france/mstechdays/programmes/2013/fiche-session.aspx?ID=f721312a-cc92-4599-8795-cfe07d5c0bb4"&gt;Optimisation des applications Windows 8/HTML5/WinJS (APP402)&lt;/a&gt; qui sera animée par &lt;em&gt;Thomas Lebrun&lt;/em&gt; et&lt;em&gt; Jonathan Antoine&lt;/em&gt;&lt;/p&gt;  &lt;h2&gt;Sessions spécifiques Windows Phone 8&lt;/h2&gt;  &lt;p&gt;23. &lt;a href="http://www.microsoft.com/france/mstechdays/programmes/2013/fiche-session.aspx?ID=2d81322e-6ab2-4840-a4b1-568f1bd370f4"&gt;L'histoire d'HTML5 pour les développeurs Windows Phone 8 (APP215)&lt;/a&gt; qui sera animée par &lt;em&gt;David Catuhe&lt;/em&gt; et moi-même     &lt;br /&gt;24. &lt;a href="http://www.microsoft.com/france/mstechdays/programmes/2013/fiche-session.aspx?ID=5a75df47-b08e-4250-bcf6-bcbf1f2421b4"&gt;Outillage pour Windows Phone 8 (APP219)&lt;/a&gt; qui sera animée par &lt;em&gt;Fabien Décret&lt;/em&gt; et&lt;em&gt; Stéphane Sibué&lt;/em&gt;     &lt;br /&gt;25. &lt;a href="http://www.microsoft.com/france/mstechdays/programmes/2013/fiche-session.aspx?ID=781a3bb0-550d-4462-a3ed-275c1acc2470"&gt;Géolocalisation, Speech, Intégration : Tirez parti des nouveautés de Windows Phone 8 (APP221)&lt;/a&gt; qui sera animée par &lt;em&gt;Julie Knibbe&lt;/em&gt;, &lt;em&gt;Samuel Blanchard&lt;/em&gt; et &lt;em&gt;Jean-Sébastien Dupuy&lt;/em&gt;     &lt;br /&gt;26. &lt;a href="http://www.microsoft.com/france/mstechdays/programmes/2013/fiche-session.aspx?ID=8012dd8f-8796-462d-8f22-4beff4575230"&gt;Trucs et astuces pour rendre votre application Windows Phone 8 plus visible (APP222)&lt;/a&gt; qui sera animée par &lt;em&gt;Rudy Huyn&lt;/em&gt; et &lt;em&gt;Alex Danvy&lt;/em&gt;     &lt;br /&gt;27. &lt;a href="http://www.microsoft.com/france/mstechdays/programmes/2013/fiche-session.aspx?ID=171b48a7-3fc3-44fd-acae-25906b708742"&gt;Booster votre application Windows Phone 8 (APP303)&lt;/a&gt; par &lt;em&gt;Jérémy Alles&lt;/em&gt; et &lt;em&gt;Charlotte Chavancy&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;Bref, vous voyez qu’il y a de quoi faire en la matière : &lt;strong&gt;27 sessions animées par 37 experts différents de chez Microsoft et de notre &lt;strong&gt;écosystème &lt;/strong&gt;de partenaires&lt;/strong&gt;! Sans compter le fait que le parcours &lt;a href="http://www.microsoft.com/france/mstechdays/programmes/2013/recherche-sessions.aspx?d=a2faa853-2170-4bc6-9602-084bb0bc6e34"&gt;Design, ergonomie et Interface naturelle&lt;/a&gt; géré par &lt;a href="http://blogs.msdn.com/b/designmichel"&gt;Michel Rousseau&lt;/a&gt; traitera également des applications Windows 8 et Windows Phone 8 et que certains concepts communs aux nouvelles plateformes 8 seront également abordés dans le parcours &lt;a href="http://www.microsoft.com/france/mstechdays/programmes/2013/recherche-sessions.aspx?d=b9922383-933f-4e4d-b5d1-4896a8994fbe"&gt;Developpement WEB&lt;/a&gt; (comme &lt;a href="http://www.microsoft.com/france/mstechdays/programmes/2013/fiche-session.aspx?ID=5bd8f617-2ecb-476a-b0fb-3e2ef58305f1"&gt;la gestion du tactile&lt;/a&gt;, les &lt;a href="http://www.microsoft.com/france/mstechdays/programmes/2013/fiche-session.aspx?ID=3461e694-0d0f-4293-a929-082e346ebf21"&gt;SPA&lt;/a&gt; et les &lt;a href="http://www.microsoft.com/france/mstechdays/programmes/2013/fiche-session.aspx?ID=4a174b26-32b7-4d4c-8523-ad3a3228ef53"&gt;nouveautés d’HTML5 et CSS3&lt;/a&gt;).&lt;/p&gt;  &lt;p&gt;Avec tout cela, vous serez alors parfaitement armés pour concevoir vos applications à destination de ces nouvelles plateformes. &lt;/p&gt;  &lt;p&gt;Je souhaite donc bon courage à tous les speakers que nous avons nommés pour qu’ils nous fassent des sessions d’excellente qualité. Et je vous souhaite à tous d’excellentes fêtes de fin d’année !&lt;/p&gt;  &lt;p&gt;David&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10379435" width="1" height="1"&gt;</content><author><name>David Rousset</name><uri>http://blogs.msdn.com/davrous/ProfileUrlRedirect.ashx</uri></author><category term="Windows 8" scheme="http://blogs.msdn.com/b/davrous/archive/tags/Windows+8/" /><category term="Techdays2013" scheme="http://blogs.msdn.com/b/davrous/archive/tags/Techdays2013/" /><category term="Windows Phone 8" scheme="http://blogs.msdn.com/b/davrous/archive/tags/Windows+Phone+8/" /></entry></feed>