<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>MikePelton's WebLog : DirectX</title><link>http://blogs.msdn.com/mikepelton/archive/tags/DirectX/default.aspx</link><description>Tags: DirectX</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>DirectX Matrix Multiply</title><link>http://blogs.msdn.com/mikepelton/archive/2005/08/06/448513.aspx</link><pubDate>Sat, 06 Aug 2005 17:11:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:448513</guid><dc:creator>MikePelton</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/mikepelton/comments/448513.aspx</comments><wfw:commentRss>http://blogs.msdn.com/mikepelton/commentrss.aspx?PostID=448513</wfw:commentRss><description>&lt;P&gt;&lt;FONT face=Arial&gt;Just in case it's driving you nuts too, I've just rediscovered something. I'd be happy to be proved wrong, but I've been drawing pictures of axes for an hour now (sad, I know), and I'm satisfied I'm right.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;You might imagine that...&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;Matrix m1 = ...&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;Matrix m2 = ...&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;Matrix m3 = m1 * m2;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;...(I should add in C#) would give you a matrix m3 which represents the results of m1's operations&amp;nbsp;FOLLOWED BY m2's. But no; it's the OPPOSITE, m2 followed by m1. &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;To say this is counter-intuitive is a massive understatement, and of course if it gets changed 3D worlds everywhere will turn inside out or disintegrate, so live with it we must. I say rediscovered because I remember falling down this same hole a couple of years ago.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Arial&gt;There's probably a reasoned argument as to why it's done this way. and I seem to recall GDI+'s matrices do the same thing. Equally I also seem to recall that quaternions in C++ do the opposite; q1 * q2 is q1 followed by q2. So my top tip is next time things look wrong after a matrix calculation, flip the multiplication order and maybe all will be well without you having to write "X", "Y" and "Z" on&amp;nbsp;the edges of a&amp;nbsp;CD cover and invest an hour of your day experiencing the feeling that you may be&amp;nbsp;going mad!&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=448513" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/mikepelton/archive/tags/DirectX/default.aspx">DirectX</category></item><item><title>Games Programmers - While Away These Long Winter Nights</title><link>http://blogs.msdn.com/mikepelton/archive/2005/01/28/362401.aspx</link><pubDate>Fri, 28 Jan 2005 22:49:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:362401</guid><dc:creator>MikePelton</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/mikepelton/comments/362401.aspx</comments><wfw:commentRss>http://blogs.msdn.com/mikepelton/commentrss.aspx?PostID=362401</wfw:commentRss><description>&lt;p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"&gt;I've been out of the blogosphere for a little while, partly because I've had my nose buried in some very good books. At the European Games Developers’ Conference last September I realised how little I knew about some of the key areas of gaming technology, and resolved to address the issue not only by buying books (my normal strategy) but also by reading them too.&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"&gt;After an excellent&amp;nbsp;session about AI in games, I went to the exhibition book stall and invested in a copy of Nils Nilsson's "Artificial Intelligence: A New Synthesis", (Morgan Kaufmann, ISBN 1 55860 535 5) which I thoroughly enjoyed reading (back then when we still had sunshine). In conversation at the event, I realised I was some kind of alien – fancy not knowing what an A-Star search is – but now I do know and can spout forth at the slightest provocation, which may explain why my social life has dwindled. If anyone can point me to other digestible books about AI I’d be very grateful to hear, besides which life as a hermit quite suits me.&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"&gt;In games, as they say, vehicles are the new &lt;?xml:namespace prefix = st2 ns = "schemas-contoso-com/contoso" /&gt;&lt;st2:color w:st="on"&gt;black&lt;/st2:color&gt;. What do we need to make vehicles fun? Good physics engines. I read Engineering at university 25 years ago, and hence can still work out what will happen when two identical inextensible snooker balls collide elastically in a perfect straight line. Tragically the applicability of this crucial calculation is diminished in an Unreal world where I expect to be able to bounce and skid a jeep over a rough snow-covered field at speed, so again I decided that a little revision was in order.&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"&gt;My first foray into game physics was via David Bourg’s “Physics for Games Developers” (O’Reilly, ISBN 0 596 00006 5) which is a superb introduction to the principles and maths, and is very well written too.&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"&gt;Further research led me to The Book – one of the reviewers said that no games programmer today would use more than 25% of the principles it outlined, so clearly this had to appear on my shelf as well. It’s David Eberly’s “Game Physics” (Morgan Kaufmann, ISBN 1 55860 740 4). My feedback to David would be that it’s a little light on jokes, but it more than makes up for that with its extraordinarily well- and tightly-woven descriptions, equations and code. It’s a superb piece of work, backed up by very portable C++ examples that run over DirectX and OpenGL (putting an abstraction layer over the two of them incidentally – now there’s an idea for a Standards committee to get hold of!) as well as a living web site with yet more descriptive text and code.&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"&gt;Suffice to say, I now feel equipped to write code for a world where some objects aren’t round and travelling solely in one dimension.&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"&gt;I’m a Microsoft employee, and therefore should tread very carefully around anything that could be construed as a recommendation, particularly where software’s concerned, so I must stress that what I’m about to write in no way constitues a recommendation by the Microsoft corporate body, it doesn’t point to any commercial or other relationship with or endorsement of the vendor, it doesn’t suggest that other vendors and Microsoft are or aren’t doing this stuff… you get the idea – this is purely personal, okay? I just liked it. Right, here we go. If you’ve any doubt that physics is going to be very big in gaming (and I suspect all other UI too) you need to take a look at Novodex’s Rocket demo (http://www.novodex.com/). Top tips – you can pick up pretty much anything with the right mouse key (including the rocket) and the space bar fires balls. For all their simplicity, the Jenga games are enormously satisfying!&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"&gt;Coming full circle, and with all the same caveats, if you’re interested in AI, the demo’s and &lt;st2:color w:st="on"&gt;white&lt;/st2:color&gt; papers on Kynogon’s site (&lt;a href="http://www.kynogon.com/"&gt;http://www.kynogon.com/&lt;/a&gt;) are very thought-provoking.&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"&gt;So. Books. Inevitably, I did weaken and buy some graphics texts too. One was the second in editor Wolfgang Engel’s Shader X series – “Shader X2, Shader Programming Tips and Tricks with DirectX 9” (Wordware, ISBN 1 55622 988 7). Excellent reading and inspirational, it draws together a series of articles that show how to do jolly clever things with the High Level Shader Language, amongst them an article by Microsoft’s own &lt;?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /&gt;&lt;st1:PersonName w:st="on"&gt;Peter-Pike Sloan&lt;/st1:PersonName&gt;. I mention Peter-Pike particularly because he presented (very well I should add) at the GDC and made an impression on me for two reasons: one was that he almost certainly has the best job in the world, pushing the boundaries of graphics; the second was that if I ever fall prey to the suspicion that I may be remotely intelligent I think of him and am immediately grounded and reminded of my relative status – picture a unicellular organism and Isaac Newton and guess which one’s me.&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"&gt;My final purchase was a book that caught my eye as one of the authors is Joseph Laviola, Jr. of &lt;st1:place w:st="on"&gt;&lt;st1:PlaceName w:st="on"&gt;&lt;st2:color w:st="on"&gt;Brown&lt;/st2:color&gt;&lt;/st1:PlaceName&gt; &lt;st1:PlaceType w:st="on"&gt;University&lt;/st1:PlaceType&gt;&lt;/st1:place&gt;. Joseph very kindly gave us permission to use some of his code to demonstrate Tablet PC a while ago – he’d written an interactive pen-based tool for teaching maths, which amongst other things takes equations and graphs them. It can interpret a hand-written equation of surprising complexity, and really shows how pen-based input could change the way we work with computers.&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"&gt;I digress! The book itself is “3D User Interfaces” by Doug Bowman, Ernst Kruiff, Ivan Poupyrev and Joseph Laviola (Addison Wesley, ISBN 0 201 75867 9). I’ve always been interested in stereo vision and 3D, so it’s great to have a book that outlines the state of the art and weighs up the pro’s and con’s of many different approaches to working with three dimensions. I cling on (sometimes in desperation) to the belief that mainstream computing will eventually wake up to the huge value that sophisticated graphics could add even to traditional applications – every day I see people struggling with two-dimensional spreadsheets, trying to get a grip on multi-dimensional data – when a simple walk-through visualisation could highlight any issues hiding in the data immediately. I’m searching for a pithy phrase along the lines of “A mesh can paint a thousand spreadsheets” – if you’re feeling creative (and/or pithy) do help me out.&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"&gt;So is this all I’ve read since September? Actually no – there’s one more technical book I want to rave about, but that’s on a different theme, so more of that later!&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=362401" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/mikepelton/archive/tags/DirectX/default.aspx">DirectX</category></item><item><title>Matrix Mysteries II: The XYZ Matrix</title><link>http://blogs.msdn.com/mikepelton/archive/2004/11/15/257492.aspx</link><pubDate>Mon, 15 Nov 2004 20:14:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:257492</guid><dc:creator>MikePelton</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/mikepelton/comments/257492.aspx</comments><wfw:commentRss>http://blogs.msdn.com/mikepelton/commentrss.aspx?PostID=257492</wfw:commentRss><description>&lt;table width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div style="FONT-SIZE: 10px; COLOR: black; FONT-FAMILY: Verdana, Arial, sans-serif" align="left"&gt;&lt;br /&gt;&lt;font size="3"&gt;I know I promised not to be so dull in future, but enough people seem to share my curiosity about what goes on inside DirectX matrices for it to be worth publishing the details of DX's other pre-defined matrix form, the XYZ matrix.&lt;/font&gt;&lt;/div&gt; &lt;div style="FONT-SIZE: 10px; COLOR: black; FONT-FAMILY: Verdana, Arial, sans-serif" align="left"&gt;&lt;font size="3"&gt;&lt;/font&gt;&amp;nbsp;&lt;/div&gt; &lt;div style="FONT-SIZE: 10px; COLOR: black; FONT-FAMILY: Verdana, Arial, sans-serif" align="left"&gt;&lt;font size="3"&gt;So, if I create rotation matrices for a rotation about X by x radians (and call it Rx), about Y by y, and about Z by z, and multiply them together Rx * Ry * Rz, I wind up with the following:&lt;/font&gt;&lt;/div&gt; &lt;div style="FONT-SIZE: 10px; COLOR: black; FONT-FAMILY: Verdana, Arial, sans-serif" align="left"&gt; &lt;table cellpadding="30"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;Cos(y).Cos(z)&lt;/td&gt; &lt;td&gt;Cos(y).Sin(z) &lt;/td&gt; &lt;td&gt;-Sin(y)&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Sin(x).Sin(y).Cos(z) + Cos(x).-Sin(z) &lt;/td&gt; &lt;td&gt;Sin(x).Sin(y).Sin(z) + Cos(x).Cos(z)&lt;/td&gt; &lt;td&gt;Sin(x).Cos(y) &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Cos(x).Sin(y).Cos(z) + Sin(x).Sin(z)&lt;/td&gt; &lt;td&gt;Cos(x).Sin(y).Sin(z) + -Sin(x).Cos(z)&lt;/td&gt; &lt;td&gt;Cos(x).Cos(y)&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt; &lt;div style="FONT-SIZE: 10px; COLOR: black; FONT-FAMILY: Verdana, Arial, sans-serif" align="left"&gt;&lt;font size="3"&gt;....and if, as before, I want to look at a matrix and work out what single set of x, y, z rotations would get me to the same orientation, the code below will do the trick.&lt;/font&gt;&lt;/div&gt; &lt;div style="FONT-SIZE: 10px; COLOR: black; FONT-FAMILY: Verdana, Arial, sans-serif" align="left"&gt;&lt;font size="3"&gt;&lt;/font&gt;&amp;nbsp;&lt;/div&gt; &lt;div style="FONT-SIZE: 10px; COLOR: black; FONT-FAMILY: Verdana, Arial, sans-serif" align="left"&gt;&lt;font size="3"&gt;Like the roll-pitch-yaw case, the numbers go loopy when the rotation about Y is an odd multiple of ninety degrees, so there's a crude test in there to spot that happening and go to a plan B.&lt;/font&gt;&lt;/div&gt; &lt;div style="FONT-SIZE: 10px; COLOR: black; FONT-FAMILY: Verdana, Arial, sans-serif" align="left"&gt;&lt;font size="3"&gt;&lt;/font&gt;&amp;nbsp;&lt;/div&gt; &lt;div style="FONT-SIZE: 10px; COLOR: black; FONT-FAMILY: Verdana, Arial, sans-serif" align="left"&gt;&lt;font size="3"&gt;(Same disqualifier too - if you're concerned for numerical stability and being able to guarantee getting the same matrix back that you started with, there is a more reliable route which avoids the setting of the angle about z to being zero ["gimbal lock"] and again I'd point you to &lt;/font&gt;&lt;a href="http://www.plunk.org/~hatch/rightway.php"&gt;&lt;font color="#0000ff" size="3"&gt;The Right Way to Calculate Stuff&lt;/font&gt;&lt;/a&gt;&lt;font size="3"&gt; by Don Hatch).&lt;/font&gt;&lt;/div&gt; &lt;div style="FONT-SIZE: 10px; COLOR: black; FONT-FAMILY: Verdana, Arial, sans-serif" align="left"&gt;&lt;font size="3"&gt;&lt;/font&gt;&amp;nbsp;&lt;/div&gt; &lt;div style="FONT-SIZE: 10px; COLOR: black; FONT-FAMILY: Verdana, Arial, sans-serif" align="left"&gt;&lt;font size="3"&gt;&lt;/font&gt;&amp;nbsp;&lt;/div&gt; &lt;div style="FONT-SIZE: 10px; COLOR: black; FONT-FAMILY: Verdana, Arial, sans-serif" align="left"&gt;&lt;font size="3"&gt;static public void DecomposeXYZRotationMatrix(Matrix mx, out double rx, out double ry, out double rz)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;ry = Math.Asin(-mx.M13);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;double threshold = 0.001;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;if(Math.Cos(ry) &amp;gt; threshold)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rx = Math.Atan2(mx.M23, mx.M33);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rz = Math.Atan2(mx.M12, mx.M11);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;else&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rx = Math.Atan2(mx.M21, mx.M22);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rz = 0.0;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;}&lt;/font&gt;&lt;/div&gt; &lt;div style="FONT-SIZE: 10px; COLOR: black; FONT-FAMILY: Verdana, Arial, sans-serif" align="left"&gt;&lt;font size="3"&gt;&lt;/font&gt;&amp;nbsp;&lt;/div&gt; &lt;div style="FONT-SIZE: 10px; COLOR: black; FONT-FAMILY: Verdana, Arial, sans-serif" align="left"&gt;&lt;font size="3"&gt;My next blog will be about Managed DirectX and the Effects framework, so if you think that's dull too, apologies!!&lt;/font&gt;&lt;/div&gt; &lt;div style="FONT-SIZE: 10px; COLOR: black; FONT-FAMILY: Verdana, Arial, sans-serif" align="left"&gt;&amp;nbsp;&lt;/div&gt; &lt;div style="FONT-SIZE: 10px; COLOR: black; FONT-FAMILY: Verdana, Arial, sans-serif" align="left"&gt;&lt;br /&gt;&amp;nbsp;&lt;/div&gt; &lt;div style="FONT-SIZE: 10px; COLOR: black; FONT-FAMILY: Verdana, Arial, sans-serif" align="left"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=257492" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/mikepelton/archive/tags/DirectX/default.aspx">DirectX</category></item><item><title>The Mysteries of the DirectX Roll Pitch Yaw Matrix</title><link>http://blogs.msdn.com/mikepelton/archive/2004/10/29/249501.aspx</link><pubDate>Fri, 29 Oct 2004 13:32:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:249501</guid><dc:creator>MikePelton</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/mikepelton/comments/249501.aspx</comments><wfw:commentRss>http://blogs.msdn.com/mikepelton/commentrss.aspx?PostID=249501</wfw:commentRss><description>I know, I know - it' s been keeping you awake too... I've no desire to enhance my well-deserved reputation for being interested in things that could induce narcolepsy in an insomniac, but it took me a fair few hours to get to the bottom of how DirectX manages matrices internally, so in case it's bothering you too, below are the fruits of my labour. Why, you may ask, do I care? Imagine you have an application that allows the user to manipulate objects in 3D, for example applying rotations to them. In your interface, you want to display the current state of play. Your user has applied a number of rotations one after another, perhaps by setting rotations about X, Y &amp;amp; Z, and you want to echo the accumulated effect - you need to be able to turn multiple concatenated rotations into a single set of three rotations about those three axes. In short, you want to unpick the resultant matrix - if I do all these X, Y, Z rotations one after another, what one X,Y,Z rotation would have got me to the same place? Managed DirectX gives us a RollPitchYaw matrix, which, it turns out, builds a matrix which could be represented as Rotation(Z) * Rotation(X) * Rotation(Y). The geometry you remember from school (yeh, right) will remind you that Rotation about X by x radians is: &lt;table cellpadding="20"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;1&lt;/td&gt; &lt;td&gt;0&lt;/td&gt; &lt;td&gt;0&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;0&lt;/td&gt; &lt;td&gt;Cos(x) &lt;/td&gt; &lt;td&gt;Sin(x) &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;0&lt;/td&gt; &lt;td&gt;-Sin(x)&lt;/td&gt; &lt;td&gt;Cos(x)&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;while rotation about Y is &lt;table cellpadding="20"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;Cos(y) &lt;/td&gt; &lt;td&gt;0 &lt;/td&gt; &lt;td&gt;-Sin(y)&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;0&lt;/td&gt; &lt;td&gt;1&lt;/td&gt; &lt;td&gt;0&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Sin(y)&lt;/td&gt; &lt;td&gt;0&lt;/td&gt; &lt;td&gt;Cos(y)&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;and about Z: &lt;table cellpadding="20"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;Cos(z) &lt;/td&gt; &lt;td&gt;Sin(z) &lt;/td&gt; &lt;td&gt;0&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;-Sin(z)&lt;/td&gt; &lt;td&gt;Cos(z)&lt;/td&gt; &lt;td&gt;0&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;0&lt;/td&gt; &lt;td&gt;0&lt;/td&gt; &lt;td&gt;1&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;so the DirectX Yaw Pitch Roll calculation (z * x * y) looks like this: &lt;table cellpadding="30"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;Cos(z).Cos(y) + Sin(z).Sin(x).Sin(y)&lt;/td&gt; &lt;td&gt;Sin(z).Cos(x)&lt;/td&gt; &lt;td&gt;Cos(z).-Sin(y) + Sin(z).Sin(x).Cos(y)&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;-Sin(z).Cos(y) + Cos(z).Sin(x).Sin(y)&lt;/td&gt; &lt;td&gt;Cos(z).Cos(x)&lt;/td&gt; &lt;td&gt;Sin(z).Sin(y) + Cos(z).Sin(x).Cos(y)&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Cos(x).Sin(y)&lt;/td&gt; &lt;td&gt;-Sin(x)&lt;/td&gt; &lt;td&gt;Cos(x).Cos(y)&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;p&gt;Hence the C# code below for Managed DirectX will allow us to look at a rotation matrix and get back to one set of YawPitchRoll angles that would give rise to it. The DirectX Matrix structure exposes elements called M&lt;i&gt;ij&lt;/i&gt; (e.g. M32, M21 etc.) where the first digit is the row, and the second the column (remember "Rock Cakes" for &lt;b&gt;r&lt;/b&gt;ow followed by &lt;b&gt;c&lt;/b&gt;olumn). This being maths there are gotcha's - when the cosine of the pitch angle gets small, (for a pitch of 90-ish degrees, say) numerically things go bananas, so you can take an arbitrary decision about the yaw angle (here I've set it to zero) and deduce a roll. This is okay except where numerical consistency is important (flying jet fighters. guiding satellites and so on) where you can't just swizzle your object in space to make the sums work. If you're looking for the "proper" way to do this, I can recommend a piece I stumbled on called &lt;a href="http://www.plunk.org/~hatch/rightway.php"&gt;The Right Way to Calculate Stuff&lt;/a&gt; by Don Hatch. If you want the code and layout for the XYZ equivalent, holler - I'll be interested to see whether anyone out there got this far before sleep overwhelmed them. &lt;/p&gt; &lt;p&gt;static public void DecomposeRollPitchYawZXYMatrix(Matrix mx, out double xPitch, out double yYaw, out double zRoll) &lt;/p&gt; &lt;p&gt;{ &lt;/p&gt; &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;xPitch = Math.Asin(-mx.M32); &lt;/p&gt; &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;double threshold = 0.001; // Hardcoded constant - burn him, he's a witch&lt;/p&gt; &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;double test = Math.Cos(xPitch); &lt;/p&gt; &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;if(test &amp;gt; threshold) { &lt;/p&gt; &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;zRoll = Math.Atan2(mx.M12, mx.M22);&lt;/p&gt; &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;yYaw = Math.Atan2(mx.M31, mx.M33); &lt;/p&gt; &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;} &lt;/p&gt; &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;else { &lt;/p&gt; &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;zRoll = Math.Atan2(-mx.M21, mx.M11); &lt;/p&gt; &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;yYaw = 0.0; &lt;/p&gt; &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;} &lt;/p&gt; &lt;p&gt;} &lt;/p&gt; &lt;p&gt;Thanks for your patience, O blogosphere - will try to be less turgid in future. &lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=249501" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/mikepelton/archive/tags/DirectX/default.aspx">DirectX</category></item></channel></rss>