disable the unrecognized nls and x flags
[AROS-Contrib.git] / Games / XInvaders3D / mat4x4.c
blobc3074507c03863356338fd6f3ce45effa8517e7b
1 /*------------------------------------------------------------------
2 mat4x4.c:
4 XINVADERS 3D - 3d Shoot'em up
5 Copyright (C) 2000 Don Llopis
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 ------------------------------------------------------------------*/
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <memory.h>
25 #include <math.h>
26 #include <string.h>
28 #include "mat4x4.h"
31 /*================================================================*/
33 void Matrix_id ( MATRIX4 a )
35 memset ( a, 0, sizeof ( MATRIX4 ) );
36 a[0][0] = a[1][1] = a[2][2] = a[3][3] = 1.0f;
39 /*================================================================*/
41 void Matrix_zero ( MATRIX4 a )
43 memset ( a, 0, sizeof (MATRIX4 ) );
46 /*================================================================*/
48 void Matrix_copy ( MATRIX4 a, MATRIX4 b )
50 memcpy ( b, a, sizeof ( MATRIX4 ) );
53 /*================================================================*/
55 void Matrix_print ( MATRIX4 a )
57 int i, j;
59 for ( i=0; i<4; i++ )
61 for (j=0; j<4; j++ )
62 fprintf ( stderr, "%5.5f ", a[i][j] );
64 fprintf ( stderr, "\n" );
68 /*================================================================*/
70 void Matrix_mult ( MATRIX4 a, MATRIX4 b, MATRIX4 c )
72 int i;
74 for ( i=0; i<4; i++ )
76 c[i][0] = ( a[i][0] * b[0][0] ) +
77 ( a[i][1] * b[1][0] ) +
78 ( a[i][2] * b[2][0] ) +
79 ( a[i][3] * b[3][0] );
81 c[i][1] = ( a[i][0] * b[0][1] ) +
82 ( a[i][1] * b[1][1] ) +
83 ( a[i][2] * b[2][1] ) +
84 ( a[i][3] * b[3][1] );
86 c[i][2] = ( a[i][0] * b[0][2] ) +
87 ( a[i][1] * b[1][2] ) +
88 ( a[i][2] * b[2][2] ) +
89 ( a[i][3] * b[3][2] );
91 c[i][3] = ( a[i][0] * b[0][3] ) +
92 ( a[i][1] * b[1][3] ) +
93 ( a[i][2] * b[2][3] ) +
94 ( a[i][3] * b[3][3] );
98 /*================================================================*/
100 void Matrix_transpose ( MATRIX4 a, MATRIX4 b )
102 b[0][0] = a[0][0];
103 b[0][1] = a[1][0];
104 b[0][2] = a[2][0];
105 b[0][3] = b[3][0];
107 b[1][0] = a[0][1];
108 b[1][1] = a[1][1];
109 b[1][2] = a[2][1];
110 b[1][3] = b[3][1];
112 b[2][0] = a[0][2];
113 b[2][1] = a[1][2];
114 b[2][2] = a[2][2];
115 b[2][3] = b[3][2];
117 b[3][0] = a[0][3];
118 b[3][1] = a[1][3];
119 b[3][2] = a[2][3];
120 b[3][3] = b[3][3];
123 /*================================================================*/
125 void Matrix_vec_mult ( MATRIX4 a, VECTOR4 b, VECTOR4 c )
127 c[0] = ( a[0][0] * b[0] ) +
128 ( a[0][1] * b[1] ) +
129 ( a[0][2] * b[2] ) +
130 ( a[0][3] * b[3] );
132 c[1] = ( a[1][0] * b[0] ) +
133 ( a[1][1] * b[1] ) +
134 ( a[1][2] * b[2] ) +
135 ( a[1][3] * b[3] );
137 c[2] = ( a[2][0] * b[0] ) +
138 ( a[2][1] * b[1] ) +
139 ( a[2][2] * b[2] ) +
140 ( a[2][3] * b[3] );
142 c[3] = ( a[3][0] * b[0] ) +
143 ( a[3][1] * b[1] ) +
144 ( a[3][2] * b[2] ) +
145 ( a[3][3] * b[3] );
148 /*================================================================*/
150 void Matrix_vec_multn ( MATRIX4 a, VECTOR4 b[], VECTOR4 c[], int num )
152 int i;
154 for ( i=0; i<num; i++ )
156 c[i][0] = ( a[0][0] * b[i][0] ) +
157 ( a[0][1] * b[i][1] ) +
158 ( a[0][2] * b[i][2] ) +
159 ( a[0][3] * b[i][3] );
161 c[i][1] = ( a[1][0] * b[i][0] ) +
162 ( a[1][1] * b[i][1] ) +
163 ( a[1][2] * b[i][2] ) +
164 ( a[1][3] * b[i][3] );
166 c[i][2] = ( a[2][0] * b[i][0] ) +
167 ( a[2][1] * b[i][1] ) +
168 ( a[2][2] * b[i][2] ) +
169 ( a[2][3] * b[i][3] );
171 c[i][3] = ( a[3][0] * b[i][0] ) +
172 ( a[3][1] * b[i][1] ) +
173 ( a[3][2] * b[i][2] ) +
174 ( a[3][3] * b[i][3] );
178 /*================================================================*/
180 void Matrix_x_rot ( MATRIX4 a, float rad )
182 float sine, cosine;
184 sine = (float) sin ( rad );
185 cosine = (float) cos ( rad );
187 Matrix_id ( a );
188 a[1][1] = cosine; a[1][2] = -sine;
189 a[2][1] = sine; a[2][2] = cosine;
192 /*================================================================*/
194 void Matrix_y_rot ( MATRIX4 a, float rad )
196 float sine, cosine;
198 sine = (float) sin ( rad );
199 cosine = (float) cos ( rad );
201 Matrix_id ( a );
202 a[0][0] = cosine; a[0][2] = sine;
203 a[2][0] = -sine; a[2][2] = cosine;
206 /*================================================================*/
208 void Matrix_z_rot ( MATRIX4 a, float rad )
210 float sine, cosine;
212 sine = sin ( rad );
213 cosine = cos ( rad );
215 Matrix_id ( a );
216 a[0][0] = cosine; a[0][1] = -sine;
217 a[1][0] = sine; a[1][1] = cosine;
220 /*================================================================*/
222 void Matrix_set_xrow ( MATRIX4 a, VECTOR4 b )
224 a[0][0] = b[0];
225 a[0][1] = b[1];
226 a[0][2] = b[2];
229 /*================================================================*/
231 void Matrix_set_yrow ( MATRIX4 a, VECTOR4 b )
233 a[1][0] = b[0];
234 a[1][1] = b[1];
235 a[1][2] = b[2];
238 /*================================================================*/
240 void Matrix_set_zrow ( MATRIX4 a, VECTOR4 b )
242 a[2][0] = b[0];
243 a[2][1] = b[1];
244 a[2][2] = b[2];
247 /*================================================================*/
249 void Matrix_set_xcol ( MATRIX4 a, VECTOR4 b )
251 a[0][0] = b[0];
252 a[1][0] = b[1];
253 a[2][0] = b[2];
256 /*================================================================*/
258 void Matrix_set_ycol ( MATRIX4 a, VECTOR4 b )
260 a[0][1] = b[0];
261 a[1][1] = b[1];
262 a[2][1] = b[2];
265 /*================================================================*/
267 void Matrix_set_zcol ( MATRIX4 a, VECTOR4 b )
269 a[0][2] = b[0];
270 a[1][2] = b[1];
271 a[2][2] = b[2];
274 /*================================================================*/
276 void Matrix_set_trans ( MATRIX4 a, VECTOR4 b )
278 a[0][3] = b[0];
279 a[1][3] = b[1];
280 a[2][3] = b[2];
283 /*================================================================*/