Sophie

Sophie

distrib > Fedora > 14 > x86_64 > media > updates > by-pkgid > 8ffe23af9b6e2265bcac8526648e8186 > files > 138

alleggl-devel-0.4.3-8.fc14.i686.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>AllegroGL: math.c Source File</title>
<link href="alleggl.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.2 -->
<div class="tabs">
  <ul>
    <li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
    <li><a href="modules.html"><span>Modules</span></a></li>
    <li><a href="annotated.html"><span>Data&nbsp;Structures</span></a></li>
    <li class="current"><a href="files.html"><span>Files</span></a></li>
    <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
  </ul>
</div>
<div class="tabs">
  <ul>
    <li><a href="files.html"><span>File&nbsp;List</span></a></li>
    <li><a href="globals.html"><span>Globals</span></a></li>
  </ul>
</div>
<h1>math.c</h1><a href="math_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* This code is (C) AllegroGL contributors, and double licensed under</span>
<a name="l00002"></a>00002 <span class="comment"> * the GPL and zlib licenses. See gpl.txt or zlib.txt for details.</span>
<a name="l00003"></a>00003 <span class="comment"> */</span>
<a name="l00015"></a>00015 <span class="preprocessor">#include &lt;math.h&gt;</span>
<a name="l00016"></a>00016 <span class="preprocessor">#include &lt;allegro.h&gt;</span>
<a name="l00017"></a>00017 <span class="preprocessor">#include "<a class="code" href="alleggl_8h.html" title="Main header file for AllegroGL.">alleggl.h</a>"</span>
<a name="l00018"></a>00018 <span class="preprocessor">#include "allglint.h"</span>
<a name="l00019"></a>00019 
<a name="l00020"></a>00020 
<a name="l00021"></a>00021 <span class="preprocessor">#ifndef M_PI</span>
<a name="l00022"></a><a class="code" href="math_8c.html#e71449b1cc6e6250b91f539153a7a0d3">00022</a> <span class="preprocessor"></span><span class="preprocessor">   #define M_PI   3.14159265358979323846</span>
<a name="l00023"></a>00023 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00024"></a>00024 <span class="preprocessor"></span>
<a name="l00025"></a>00025 
<a name="l00026"></a><a class="code" href="math_8c.html#33706d38f2836132b07580c38541b0ba">00026</a> <span class="preprocessor">#define ALGL_NOCONV(x) x</span>
<a name="l00027"></a>00027 <span class="preprocessor"></span>
<a name="l00028"></a><a class="code" href="math_8c.html#25e8baba5630176200a8cfa8a6fdd1e0">00028</a> <span class="preprocessor">#define TRANSLATE_AL_TO_GL(al_type, gl_type, convertor) \</span>
<a name="l00029"></a>00029 <span class="preprocessor">    void allegro_gl_##al_type##_to_##gl_type (al_type *m, gl_type gl[16]) \</span>
<a name="l00030"></a>00030 <span class="preprocessor">    { \</span>
<a name="l00031"></a>00031 <span class="preprocessor">        int col, row; \</span>
<a name="l00032"></a>00032 <span class="preprocessor">        for (col = 0; col &lt; 3; col++) \</span>
<a name="l00033"></a>00033 <span class="preprocessor">            for (row = 0; row &lt; 3; row++) \</span>
<a name="l00034"></a>00034 <span class="preprocessor">                gl[col*4+row] = convertor (m-&gt;v[col][row]); \</span>
<a name="l00035"></a>00035 <span class="preprocessor">        for (row = 0; row &lt; 3; row++) \</span>
<a name="l00036"></a>00036 <span class="preprocessor">            gl[12+row] = convertor (m-&gt;t[row]); \</span>
<a name="l00037"></a>00037 <span class="preprocessor">        for (col = 0; col &lt; 3; col++) \</span>
<a name="l00038"></a>00038 <span class="preprocessor">            gl[4*col + 3] = 0; \</span>
<a name="l00039"></a>00039 <span class="preprocessor">        gl[15] = 1; \</span>
<a name="l00040"></a>00040 <span class="preprocessor">    }</span>
<a name="l00041"></a>00041 <span class="preprocessor"></span>
<a name="l00042"></a>00042 
<a name="l00043"></a>00043 
<a name="l00066"></a><a class="code" href="group__math.html#g4cf4f453cb3f95a1e7e861a7401b4a8d">00066</a> <a class="code" href="math_8c.html#25e8baba5630176200a8cfa8a6fdd1e0">TRANSLATE_AL_TO_GL</a>(MATRIX, GLfloat, fixtof)
<a name="l00067"></a>00067 
<a name="l00068"></a>00068 
<a name="l00069"></a>00069     
<a name="l00070"></a>00070 
<a name="l00082"></a><a class="code" href="group__math.html#gee6cb48f8e3e70abecc6c282a8ea1edc">00082</a> <a class="code" href="math_8c.html#25e8baba5630176200a8cfa8a6fdd1e0">TRANSLATE_AL_TO_GL</a>(MATRIX, GLdouble, fixtof)
<a name="l00083"></a>00083 
<a name="l00084"></a>00084     
<a name="l00085"></a>00085 
<a name="l00098"></a><a class="code" href="group__math.html#ge8e0ee18b9aeca955402be16de6ca79d">00098</a> <a class="code" href="math_8c.html#25e8baba5630176200a8cfa8a6fdd1e0">TRANSLATE_AL_TO_GL</a>(MATRIX_f, GLfloat, <a class="code" href="math_8c.html#33706d38f2836132b07580c38541b0ba">ALGL_NOCONV</a>)
<a name="l00099"></a>00099 
<a name="l00100"></a>00100 
<a name="l00101"></a>00101 
<a name="l00114"></a><a class="code" href="group__math.html#gb93f3588ea08b048f418023aa76cb3fc">00114</a> <a class="code" href="math_8c.html#25e8baba5630176200a8cfa8a6fdd1e0">TRANSLATE_AL_TO_GL</a>(MATRIX_f, GLdouble, <a class="code" href="math_8c.html#33706d38f2836132b07580c38541b0ba">ALGL_NOCONV</a>)
<a name="l00115"></a>00115 
<a name="l00116"></a>00116 
<a name="l00117"></a>00117     
<a name="l00118"></a><a class="code" href="math_8c.html#69497b942cb028426171b3ca81bf2598">00118</a> <span class="preprocessor">#define TRANSLATE_GL_TO_AL(gl_type, al_type, convertor) \</span>
<a name="l00119"></a>00119 <span class="preprocessor">    void allegro_gl_##gl_type##_to_##al_type (gl_type gl[16], al_type *m) \</span>
<a name="l00120"></a>00120 <span class="preprocessor">    { \</span>
<a name="l00121"></a>00121 <span class="preprocessor">        int col, row; \</span>
<a name="l00122"></a>00122 <span class="preprocessor">        for (col = 0; col &lt; 3; col++) \</span>
<a name="l00123"></a>00123 <span class="preprocessor">            for (row = 0; row &lt; 3; row++) \</span>
<a name="l00124"></a>00124 <span class="preprocessor">                m-&gt;v[col][row] = convertor (gl[col*4+row]); \</span>
<a name="l00125"></a>00125 <span class="preprocessor">        for (row = 0; row &lt; 3; row++) \</span>
<a name="l00126"></a>00126 <span class="preprocessor">            m-&gt;t[row] = convertor (gl[12+row]); \</span>
<a name="l00127"></a>00127 <span class="preprocessor">    }</span>
<a name="l00128"></a>00128 <span class="preprocessor"></span>
<a name="l00129"></a>00129 
<a name="l00130"></a>00130 
<a name="l00143"></a><a class="code" href="group__math.html#g468e83ca4de52ed839978d48f5dbe111">00143</a> <a class="code" href="math_8c.html#69497b942cb028426171b3ca81bf2598">TRANSLATE_GL_TO_AL</a>(GLfloat, MATRIX, ftofix)
<a name="l00144"></a>00144 
<a name="l00145"></a>00145 
<a name="l00146"></a>00146 
<a name="l00147"></a>00147 
<a name="l00159"></a><a class="code" href="group__math.html#g68e2e0e9dcdba42004070a5f8f547994">00159</a> <a class="code" href="math_8c.html#69497b942cb028426171b3ca81bf2598">TRANSLATE_GL_TO_AL</a>(GLdouble, MATRIX, ftofix)
<a name="l00160"></a>00160 
<a name="l00161"></a>00161 
<a name="l00162"></a>00162 
<a name="l00175"></a><a class="code" href="group__math.html#g08692466ae37d7888bbd5f5ee5aa9268">00175</a> <a class="code" href="math_8c.html#69497b942cb028426171b3ca81bf2598">TRANSLATE_GL_TO_AL</a>(GLfloat, MATRIX_f, <a class="code" href="math_8c.html#33706d38f2836132b07580c38541b0ba">ALGL_NOCONV</a>)
<a name="l00176"></a>00176 
<a name="l00177"></a>00177     
<a name="l00178"></a>00178 
<a name="l00192"></a><a class="code" href="group__math.html#ga6b729a9e93e249a8a76e078e94a2b44">00192</a> <a class="code" href="math_8c.html#69497b942cb028426171b3ca81bf2598">TRANSLATE_GL_TO_AL</a>(GLdouble, MATRIX_f, <a class="code" href="math_8c.html#33706d38f2836132b07580c38541b0ba">ALGL_NOCONV</a>)
<a name="l00193"></a>00193 
<a name="l00194"></a>00194 
<a name="l00195"></a>00195 <span class="preprocessor">#undef ALGL_NOCONV</span>
<a name="l00196"></a>00196 <span class="preprocessor"></span>
<a name="l00197"></a>00197 
<a name="l00198"></a>00198 <span class="preprocessor">#ifndef RAD_2_DEG</span>
<a name="l00199"></a><a class="code" href="math_8c.html#779175036d19925ff6aa6469c2926b00">00199</a> <span class="preprocessor"></span><span class="preprocessor">    #define RAD_2_DEG(a) ((a) * 180 / M_PI)</span>
<a name="l00200"></a>00200 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00201"></a>00201 <span class="preprocessor"></span>
<a name="l00202"></a>00202     
<a name="l00203"></a>00203 
<a name="l00204"></a>00204 <span class="comment">/* void allegro_gl_apply_quat(QUAT *q) */</span>
<a name="l00222"></a><a class="code" href="group__math.html#ga83a678516d8a7a5503a2b0c9014cb64">00222</a> <span class="keywordtype">void</span> <a class="code" href="group__math.html#ga83a678516d8a7a5503a2b0c9014cb64" title="Multiplies the Quaternion to the current transformation matrix, by converting it...">allegro_gl_apply_quat</a>(QUAT *q) {
<a name="l00223"></a>00223 
<a name="l00224"></a>00224     <span class="keywordtype">float</span> theta;
<a name="l00225"></a>00225     ASSERT(q);
<a name="l00226"></a>00226     ASSERT(<a class="code" href="alleggl_8c.html#1cf577416af8a45cce479746114d7acb">__allegro_gl_valid_context</a>);
<a name="l00227"></a>00227 
<a name="l00228"></a>00228     theta = <a class="code" href="math_8c.html#779175036d19925ff6aa6469c2926b00">RAD_2_DEG</a>(2 * acos(q-&gt;w));
<a name="l00229"></a>00229     <span class="keywordflow">if</span> (q-&gt;w &lt; 1.0f &amp;&amp; q-&gt;w &gt; -1.0f) 
<a name="l00230"></a>00230         glRotatef(theta, q-&gt;x, q-&gt;y, q-&gt;z); 
<a name="l00231"></a>00231 
<a name="l00232"></a>00232     <span class="keywordflow">return</span>;
<a name="l00233"></a>00233 }
<a name="l00234"></a>00234 
<a name="l00235"></a>00235 
<a name="l00236"></a>00236 
<a name="l00237"></a>00237 <span class="comment">/* void allegro_gl_quat_to_glrotatef(QUAT *q, float *angle, float *x, float *y, float *z) */</span>
<a name="l00258"></a><a class="code" href="group__math.html#gb00b667363181a8f0853121170bebaca">00258</a> <span class="keywordtype">void</span> <a class="code" href="group__math.html#gb00b667363181a8f0853121170bebaca" title="Converts a quaternion to a vector/angle, which can be used with glRotate*().">allegro_gl_quat_to_glrotatef</a>(QUAT *q, <span class="keywordtype">float</span> *angle, <span class="keywordtype">float</span> *x, <span class="keywordtype">float</span> *y, <span class="keywordtype">float</span> *z) {
<a name="l00259"></a>00259 
<a name="l00260"></a>00260     ASSERT(q);
<a name="l00261"></a>00261     ASSERT(angle);
<a name="l00262"></a>00262     ASSERT(x);
<a name="l00263"></a>00263     ASSERT(y);
<a name="l00264"></a>00264     ASSERT(z);
<a name="l00265"></a>00265 
<a name="l00266"></a>00266     *angle = <a class="code" href="math_8c.html#779175036d19925ff6aa6469c2926b00">RAD_2_DEG</a>(2 * acos(q-&gt;w));
<a name="l00267"></a>00267     *x = q-&gt;x;
<a name="l00268"></a>00268     *y = q-&gt;y;
<a name="l00269"></a>00269     *z = q-&gt;z;
<a name="l00270"></a>00270 
<a name="l00271"></a>00271     <span class="keywordflow">return</span>;
<a name="l00272"></a>00272 }
<a name="l00273"></a>00273 
<a name="l00274"></a>00274 
<a name="l00275"></a>00275 
<a name="l00276"></a>00276 <span class="comment">/* void allegro_gl_quat_to_glrotated(QUAT *q, double *angle, double *x, double *y, double *z) */</span>
<a name="l00290"></a><a class="code" href="group__math.html#g956160418e1c0c37143dd3cee54477ce">00290</a> <span class="keywordtype">void</span> <a class="code" href="group__math.html#g956160418e1c0c37143dd3cee54477ce" title="Converts a quaternion to a vector/angle, which can be used with glRotate*().">allegro_gl_quat_to_glrotated</a>(QUAT *q, <span class="keywordtype">double</span> *angle, <span class="keywordtype">double</span> *x, <span class="keywordtype">double</span> *y, <span class="keywordtype">double</span> *z) {
<a name="l00291"></a>00291 
<a name="l00292"></a>00292     ASSERT(q);
<a name="l00293"></a>00293     ASSERT(angle);
<a name="l00294"></a>00294     ASSERT(x);
<a name="l00295"></a>00295     ASSERT(y);
<a name="l00296"></a>00296     ASSERT(z);
<a name="l00297"></a>00297 
<a name="l00298"></a>00298     *angle = <a class="code" href="math_8c.html#779175036d19925ff6aa6469c2926b00">RAD_2_DEG</a>(2 * acos(q-&gt;w));
<a name="l00299"></a>00299     *x = q-&gt;x;
<a name="l00300"></a>00300     *y = q-&gt;y;
<a name="l00301"></a>00301     *z = q-&gt;z;
<a name="l00302"></a>00302 
<a name="l00303"></a>00303     <span class="keywordflow">return</span>;
<a name="l00304"></a>00304 }
<a name="l00305"></a>00305 
</pre></div><hr size="1"><address style="text-align: right;"><small>Generated on Mon Nov 12 11:05:31 2007 for AllegroGL by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.2 </small></address>
</body>
</html>