File: math_8c_source.html

package info (click to toggle)
allegro4.4 2%3A4.4.2-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 19,920 kB
  • ctags: 39,951
  • sloc: ansic: 164,225; asm: 17,620; cpp: 3,848; objc: 1,687; sh: 1,131; python: 676; pascal: 179; makefile: 48; perl: 29; lisp: 1
file content (214 lines) | stat: -rw-r--r-- 11,680 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>AllegroGL: math.c Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript">
$(document).ready(initResizable);
</script>
<link href="alleggl.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.7.3 -->
<div id="top">
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">AllegroGL&#160;<span id="projectnumber">0.4.4</span></div>
  </td>
 </tr>
 </tbody>
</table>
</div>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('math_8c.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<h1>math.c</h1>  </div>
</div>
<div class="contents">
<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 &quot;alleggl.h&quot;</span>
<a name="l00018"></a>00018 <span class="preprocessor">#include &quot;allglint.h&quot;</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>00022 <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>00026 <span class="preprocessor">#define ALGL_NOCONV(x) x</span>
<a name="l00027"></a>00027 <span class="preprocessor"></span>
<a name="l00028"></a>00028 <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#ga4cf4f453cb3f95a1e7e861a7401b4a8d">00066</a> TRANSLATE_AL_TO_GL(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#gaee6cb48f8e3e70abecc6c282a8ea1edc">00082</a> TRANSLATE_AL_TO_GL(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#gae8e0ee18b9aeca955402be16de6ca79d">00098</a> TRANSLATE_AL_TO_GL(MATRIX_f, GLfloat, ALGL_NOCONV)
<a name="l00099"></a>00099 
<a name="l00100"></a>00100 
<a name="l00101"></a>00101 
<a name="l00114"></a>00114 TRANSLATE_AL_TO_GL(MATRIX_f, GLdouble, ALGL_NOCONV)
<a name="l00115"></a>00115 
<a name="l00116"></a>00116 
<a name="l00117"></a>00117     
<a name="l00118"></a>00118 <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>00143 TRANSLATE_GL_TO_AL(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>00159 TRANSLATE_GL_TO_AL(GLdouble, MATRIX, ftofix)
<a name="l00160"></a>00160 
<a name="l00161"></a>00161 
<a name="l00162"></a>00162 
<a name="l00175"></a>00175 TRANSLATE_GL_TO_AL(GLfloat, MATRIX_f, ALGL_NOCONV)
<a name="l00176"></a>00176 
<a name="l00177"></a>00177     
<a name="l00178"></a>00178 
<a name="l00192"></a>00192 TRANSLATE_GL_TO_AL(GLdouble, MATRIX_f, ALGL_NOCONV)
<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>00199 <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>00222 <span class="keywordtype">void</span> allegro_gl_apply_quat(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(__allegro_gl_valid_context);
<a name="l00227"></a>00227 
<a name="l00228"></a>00228     theta = RAD_2_DEG(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>00258 <span class="keywordtype">void</span> allegro_gl_quat_to_glrotatef(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 = RAD_2_DEG(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>00290 <span class="keywordtype">void</span> allegro_gl_quat_to_glrotated(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 = RAD_2_DEG(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></div>
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="math_8c.html">math.c</a>      </li>
      <li class="footer">Generated on Thu May 19 2011 23:20:20 for AllegroGL by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.3 </li>
    </ul>
  </div>

</body>
</html>