1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 2<HTML> 3<HEAD> 4<META http-equiv="Content-Type" content="text/html; charset=windows-1252"> 5<META name="GENERATOR" content="Microsoft FrontPage 5.0"> 6<META http-equiv="Content-Style-Type" content="text/css"> 7<LINK rel="stylesheet" type="text/css" href="../../CSS/revolution.css"> 8<TITLE>Mtx, MtxPtr</TITLE> 9</HEAD> 10<BODY> 11<H1>Mtx, MtxPtr</H1> 12 13<H2>Syntax</H2> 14<dl><dd><pre class="construction"> 15#include <revolution/mtx/GeoTypes.h> 16 17typedef f32 Mtx[3][4]; 18typedef f32 (*MtxPtr)[4]; 19 20#define MTX_PTR_OFFSET 3 21</pre></dd></dl> 22 23<H2>Description</H2> 24<P><strong>Mtx</strong> is a 3-row, 4-column two-dimensional array of 12 floating point values. It is used by the matrix library as a 3x4 transformation matrix. In this notation, it has an implied fourth row of (<CODE>0,0,0,1</CODE>). 3x4 matrices are used by all <EM><STRONG><code>MTX</code></STRONG></EM>-prefixed functions except those involving projection. The <a href="../Projection/MTXFrustum.html"><code>MTXFrustum</code></a>, <a href="../Projection/MTXPerspective.html"><code>MTXPerspective</code></a>, and <a href="../Projection/MTXOrtho.html"><code>MTXOrtho</code></a> functions all require a true 4x4 matrix (see <a href="../Structures/Mtx44_Mtx44Ptr.html"><CODE>Mtx44</CODE> and <CODE>Mtx44Ptr</CODE></a>).</P> 25<P>Matrices are stored and dereferenced C-style in row-major format. The table below summarizes the three ways of looking at a matrix: in memory, from a mathematical viewpoint, and as a C-style array.</P> 26<DIV align="center"> 27<TABLE border="1" cellspacing="1" cellpadding="7" width="400"> 28 <TBODY> 29 <TR> 30 <TD width="29%" bgcolor="#ffffff">Address</TD> 31 <TD width="31%" bgcolor="#ffffff">Mathematical</TD> 32 <TD width="40%" bgcolor="#ffffff">C arrays</TD> 33 </TR> 34 <TR> 35 <TD width="29%">0x80200080</TD> 36 <TD width="31%"><I>m<SUB>00</SUB></I></TD> 37 <TD width="40%">m[0][0]</TD> 38 </TR> 39 <TR> 40 <TD width="29%">0x80200084</TD> 41 <TD width="31%"><I>m<SUB>01</SUB></I></TD> 42 <TD width="40%">m[0][1]</TD> 43 </TR> 44 <TR> 45 <TD width="29%">0x80200088</TD> 46 <TD width="31%"><I>m<SUB>02</SUB></I></TD> 47 <TD width="40%">m[0][2]</TD> 48 </TR> 49 <TR> 50 <TD width="29%">0x8020008c</TD> 51 <TD width="31%"><I>m<SUB>03</SUB></I></TD> 52 <TD width="40%">m[0][3]</TD> 53 </TR> 54 <TR> 55 <TD width="29%">0x80200090</TD> 56 <TD width="31%"><I>m<SUB>10</SUB></I></TD> 57 <TD width="40%">m[1][0]</TD> 58 </TR> 59 <TR> 60 <TD width="29%">0x80200094</TD> 61 <TD width="31%"><I>m<SUB>11</SUB></I></TD> 62 <TD width="40%">m[1][1]</TD> 63 </TR> 64 <TR> 65 <TD width="29%">0x80200098</TD> 66 <TD width="31%"><I>m<SUB>12</SUB></I></TD> 67 <TD width="40%">m[1][2]</TD> 68 </TR> 69 <TR> 70 <TD width="29%">0x8020009c</TD> 71 <TD width="31%"><I>m<SUB>13</SUB></I></TD> 72 <TD width="40%">m[1][3]</TD> 73 </TR> 74 <TR> 75 <TD width="29%">0x802000a0</TD> 76 <TD width="31%"><I>m<SUB>20</SUB></I></TD> 77 <TD width="40%">m[2][0]</TD> 78 </TR> 79 <TR> 80 <TD width="29%">0x802000a4</TD> 81 <TD width="31%"><I>m<SUB>21</SUB></I></TD> 82 <TD width="40%">m[2][1]</TD> 83 </TR> 84 <TR> 85 <TD width="29%">0x802000a8</TD> 86 <TD width="31%"><I>m<SUB>22</SUB></I></TD> 87 <TD width="40%">m[2][2]</TD> 88 </TR> 89 <TR> 90 <TD width="29%">0x802000ac</TD> 91 <TD width="31%"><I>m<SUB>23</SUB></I></TD> 92 <TD width="40%">m[2][3]</TD> 93 </TR> 94 </TBODY> 95</TABLE> 96</DIV> 97 98<P><B>Note:</B> Storage format is transparent to the programmer if matrices are set and manipulated exclusively by <EM><STRONG><code>MTX</code></STRONG></EM> functions, but it is relevant if matrix elements are set individually. To insulate code from future changes to the storage format, do not set matrix values by hand, and do not initialize matrices when they are first declared. Instead, use the <a href="../General/MTXRowCol.html"><code>MTXRowCol(m,row,col)</code></a> macro defined in <code>mtx.h</code>.</P> 99<P>An <STRONG>Mtx</STRONG> is row-major for computational purposes. For example, to apply a rotation <STRONG><EM><CODE>mR</CODE></EM></STRONG> followed by a translation <STRONG><EM><CODE>mT</CODE></EM></STRONG> to a point <EM><CODE><STRONG>pOld</STRONG></CODE></EM>, <CODE><STRONG><EM>pNew</EM></STRONG> = <STRONG><EM>mT</EM></STRONG> x <STRONG><EM>mR</EM></STRONG> x <STRONG><EM>pOld</EM></STRONG></CODE>. If programmed, this appears as shown below.</P> 100<dl><dd><pre class="construction"> 101MTXConcat( mT, mR, mFinal ); 102MTXMultVec( mFinal, &pOld, &pNew ); 103</pre></dd></dl> 104<P>A <STRONG>MtxPtr</STRONG> is a pointer to an array of four floating point values. <STRONG>MtxPtr</STRONG> is also a pointer to <STRONG>Mtx</STRONG> and can replace <STRONG>Mtx</STRONG> as a function argument. It is even possible to use sub-scripts just as with <STRONG>Mtx</STRONG>. However, it is really a pointer to an array of four floats. This has two implications. First, a <STRONG>MtxPtr</STRONG> is assigned to a <STRONG>Mtx</STRONG> without the use of the <CODE>&</CODE> operator. For example:</P> 105<dl><dd><pre class="construction"> 106void foo( Mtx m1, Mtx m2 ) 107{ 108 MtxPtr mPtr; 109 110 if( condition ) 111 mPtr = m1; // note that the & operator is not required. 112 else 113 mPtr = m2; 114 115 MTXIdentity( mPtr ); 116} 117</pre></dd></dl> 118<P>Second, you cannot just increment and decrement a <STRONG>MtxPtr</STRONG>, because its size is 16, not 48. Therefore, we have defined a constant in <CODE>mtx.h</CODE> which provides the correct multiplier to offset a <STRONG>MtxPtr</STRONG> by the size of one matrix.</P> 119<dl><dd><pre class="construction"> 120#define MTX_PTR_OFFSET 3 121</pre></dd></dl> 122<P><CODE>MTX_PTR_OFFSET</CODE> can be used whenever you need to increment a <STRONG>MtxPtr</STRONG> to the next matrix of an array. This will insulate your code from future changes to the <STRONG>Mtx</STRONG> storage format. For example:</P> 123<dl><dd><pre class="construction"> 124Mtx mArray[2]; 125MtxPtr mPtr; 126 127mPtr = (MtxPtr)mArray; // mPtr points to mArray[0] 128 129MTXIdentity( mPtr ); // set mArray[0] to an identity matrix 130 131mPtr += MTX_PTR_OFFSET // mPtr now points to mArray[1] 132 133MTXTrans( mPtr, 3.0, 4.0, 5.0 ); // set mArray[1] to a translation matrix 134</pre></dd></dl> 135<P>A function cannot return a pointer to a two-dimensional array, but it can return a <STRONG>MtxPtr</STRONG>. This makes <STRONG>MtxPtr</STRONG> especially useful for functions that need to return a matrix. For example, the following type of matrix stack function.</P> 136<dl><dd><pre class="construction"> 137MtxPtr mPtr; 138MtxStack stack; 139 140Point3d pt = { 3.0, 4.0, 5.0 }; 141 142// + some code to initialize stack 143mPtr = GetStackPtr( &stack ); 144 145MTXMultVec( mPtr, &pt, &pt ); 146</pre></dd></dl> 147 148<H2>See Also</H2> 149<P class="reference"> 150<A href="Mtx44_Mtx44Ptr.html">Mtx44, Mtx44Ptr</A>, 151<A href="../stack/MTXAllocStack.html">MTXAllocStack</A>, 152<A href="../general/MTXConcat.html">MTXConcat</A>, 153<A href="../general/MTXCopy.html">MTXCopy</A>, 154<A href="../stack/MTXFreeStack.html">MTXFreeStack</A>, 155<A href="../stack/MTXGetStackPtr.html">MTXGetStackPtr</A>, 156<A href="../general/MTXIdentity.html">MTXIdentity</A>, 157<A href="../stack/MTXInitStack.html">MTXInitStack</A>, 158<A href="../general/MTXInverse.html">MTXInverse</A>, 159<A href="../view/MTXLookAt.html">MTXLookAt</A>, 160<A href="../general/MTXMultVec.html">MTXMultVec</A>, 161<A href="../general/MTXMultVecArray.html">MTXMultVecArray</A>, 162<A href="../stack/MTXPop.html">MTXPop</A>, 163<A href="../stack/MTXPush.html">MTXPush</A>, 164<A href="../stack/MTXPushFwd.html">MTXPushFwd</A>, 165<A href="../stack/MTXPushInv.html">MTXPushInv</A>, 166<A href="../stack/MTXPushInvXpose.html">MTXPushInvXpose</A>, 167<A href="../model/MTXQuat.html">MTXQuat</A>, 168<A href="../model/MTXRotAxisRad.html">MTXRotAxisRad</A>, 169<A href="../model/MTXRotDeg.html">MTXRotDeg</A>, 170<A href="../model/MTXRotTrig.html">MTXRotTrig</A>, 171<A href="../general/MTXRowCol.html">MTXRowCol</A>, 172<A href="../model/MTXScale.html">MTXScale</A>, 173<A href="../model/MTXTrans.html">MTXTrans</A>, 174<A href="../general/MTXTranspose.html">MTXTranspose</A> 175</P> 176 177<H2>Revision History</H2> 178<P> 1792006/03/01 Initial version.<br> 180</p> 181 182<hr><p>CONFIDENTIAL</p></body> 183</HTML>