1 /*------------------------------------------------------------------
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 ------------------------------------------------------------------*/
30 /*================================================================*/
32 void Vector_init ( VECTOR4 a
)
34 a
[0] = a
[1] = a
[2] = 0.0f
;
38 /*================================================================*/
40 void Vector_set ( VECTOR4 a
, float x
, float y
, float z
)
48 /*================================================================*/
50 void Vector_copy ( VECTOR4 a
, VECTOR4 b
)
52 memcpy ( b
, a
, sizeof ( VECTOR4
) );
55 /*================================================================*/
57 void Vector_print ( VECTOR4 a
)
59 fprintf ( stderr
, "%5.5f %5.5f %5.5f\n", a
[0], a
[1], a
[2] );
62 /*================================================================*/
64 void Vector_negate ( VECTOR4 a
)
71 /*================================================================*/
73 void Vector_add ( VECTOR4 a
, VECTOR4 b
, VECTOR4 c
)
80 void Vector_addd ( VECTOR4 a
, VECTOR4 b
)
87 /*================================================================*/
89 void Vector_sub ( VECTOR4 a
, VECTOR4 b
, VECTOR4 c
)
96 void Vector_subb ( VECTOR4 a
, VECTOR4 b
)
103 /*================================================================*/
105 void Vector_cross ( VECTOR4 a
, VECTOR4 b
, VECTOR4 c
)
107 c
[0] = ( a
[1] * b
[2] ) - ( a
[2] * b
[1] );
108 c
[1] = ( a
[2] * b
[0] ) - ( a
[0] * b
[2] );
109 c
[2] = ( a
[0] * b
[1] ) - ( a
[1] * b
[0] );
112 /*================================================================*/
114 float Vector_mag ( VECTOR4 a
)
116 return (float) sqrt ( ( a
[0] * a
[0] + a
[1] * a
[1] + a
[2] * a
[2] ) );
119 float Vector_mag_squared ( VECTOR4 a
)
121 return ( a
[0] * a
[0] + a
[1] * a
[1] + a
[2] * a
[2] );
125 /*================================================================*/
127 float Vector_dist ( VECTOR4 a
, VECTOR4 b
)
135 return (float) sqrt ( (x
*x
) + (y
*y
) + (z
*z
) );
138 /*================================================================*/
140 float Vector_dist_squared ( VECTOR4 a
, VECTOR4 b
)
148 return ( (x
*x
) + (y
*y
) + (z
*z
) );
151 /*================================================================*/
153 float Vector_dot ( VECTOR4 a
, VECTOR4 b
)
155 return ( (a
[0] * b
[0]) + (a
[1] * b
[1]) + (a
[2] * b
[2]) );
158 /*================================================================*/
160 void Vector_norm ( VECTOR4 a
)
164 len
= (float) sqrt ( (a
[0] * a
[0]) + (a
[1] * a
[1]) + (a
[2] * a
[2]) );
171 /*================================================================*/
173 void Vector_scale ( VECTOR4 a
, float s
)
180 /*================================================================*/