]> icculus.org git repositories - taylor/freespace2.git/blob - include/vecmat.h
added copyright header
[taylor/freespace2.git] / include / vecmat.h
1 /*
2  * Copyright (C) Volition, Inc. 1999.  All rights reserved.
3  *
4  * All source code herein is the property of Volition, Inc. You may not sell 
5  * or otherwise commercially exploit the source or things you created based on
6  * the source.
7  */
8
9 /*
10  * $Logfile: /Freespace2/code/Math/VecMat.h $
11  * $Revision$
12  * $Date$
13  * $Author$
14  *
15  * Header file for functions that manipulate vectors and matricies
16  *
17  * $Log$
18  * Revision 1.2  2002/06/09 04:41:15  relnev
19  * added copyright header
20  *
21  * Revision 1.1.1.1  2002/05/03 03:28:12  root
22  * Initial import.
23  *
24  * 
25  * 6     6/18/99 5:16p Dave
26  * Added real beam weapon lighting. Fixed beam weapon sounds. Added MOTD
27  * dialog to PXO screen.
28  * 
29  * 5     4/28/99 11:13p Dave
30  * Temporary checkin of artillery code.
31  * 
32  * 4     1/24/99 11:37p Dave
33  * First full rev of beam weapons. Very customizable. Removed some bogus
34  * Int3()'s in low level net code.
35  * 
36  * 3     1/12/99 12:53a Dave
37  * More work on beam weapons - made collision detection very efficient -
38  * collide against all object types properly - made 3 movement types
39  * smooth. Put in test code to check for possible non-darkening pixels on
40  * object textures.
41  * 
42  * 2     10/07/98 10:53a Dave
43  * Initial checkin.
44  * 
45  * 1     10/07/98 10:49a Dave
46  * 
47  * 43    9/11/98 10:10a Andsager
48  * Optimize and rename matrix_decomp to vm_matrix_to_rot_axis_and_angle,
49  * rename quatern_rot to vm_quaternion_rotate
50  * 
51  * 42    3/09/98 3:51p Mike
52  * More error checking.
53  * 
54  * 41    12/17/97 5:44p Andsager
55  * Change vm_matrix_interpolate so that it does not overshoot if optional
56  * last parameter is 1
57  * 
58  * 40    9/30/97 8:03p Lawrance
59  * add missing semi-colon to function prototype
60  * 
61  * 39    9/30/97 5:04p Andsager
62  * add vm_estimate_next_orientation
63  * 
64  * 38    9/28/97 2:17p Andsager
65  * added vm_project_point_onto_plane
66  * 
67  * 37    9/25/97 5:57p Andsager
68  * improved function description for matrix interpolate
69  * 
70  * 36    9/09/97 10:15p Andsager
71  * added vm_rotate_vec_to_body() and vm_rotate_vec_to_world()
72  * 
73  * 35    8/20/97 5:33p Andsager
74  * added vm_vec_projection_parallel and vm_vec_projection_onto_surface
75  * 
76  * 34    8/19/97 11:42p Lawrance
77  * use atan2_safe() instead of atan2()
78  * 
79  * 33    8/18/97 4:46p Hoffoss
80  * Added global default axis vector constants.
81  * 
82  * 32    8/03/97 3:54p Lawrance
83  * added vm_find_bounding_sphere()
84  * 
85  * 31    7/30/97 2:20p Dan
86  * from allender: fixed vm_is_vec_nan to work properly with address-of
87  * operator by adding parens around macro variables
88  * 
89  * 30    7/29/97 2:48p Hoffoss
90  * Added vm_is_vec_nan().
91  * 
92  * 29    7/28/97 2:21p John
93  * changed vecmat functions to not return src.  Started putting in code
94  * for inline vector math.    Fixed some bugs with optimizer.
95  * 
96  * 28    7/28/97 3:25p Andsager
97  * 
98  * 27    7/28/97 2:41p Mike
99  * Replace vm_forward_interpolate().
100  * 
101  * 26    7/28/97 1:18p Andsager
102  * implement vm_fvec_matrix_interpolate(), which interpolates matrices on
103  * xy and then z
104  * 
105  * 25    7/24/97 5:24p Andsager
106  * implement forward vector interpolation
107  * 
108  * 24    7/02/97 4:25p Mike
109  * Add matrix_interpolate(), but don't call it.
110  * 
111  * 23    7/01/97 3:27p Mike
112  * Improve skill level support.
113  * 
114  * 22    6/25/97 12:27p Hoffoss
115  * Added some functions I needed for Fred.
116  * 
117  * 21    5/21/97 8:49a Lawrance
118  * added vm_vec_same()
119  * 
120  * 20    4/15/97 4:00p Mike
121  * Intermediate checkin caused by getting other files.  Working on camera
122  * slewing system.
123  * 
124  * 19    3/17/97 1:55p Hoffoss
125  * Added function for error checking matrices.
126  * 
127  * 18    3/06/97 10:56a Mike
128  * Write error checking version of vm_vec_normalize().
129  * Fix resultant problems.
130  * 
131  * 17    3/04/97 3:30p John
132  * added function to interpolate an angle.
133  * 
134  * 16    2/25/97 5:12p John
135  * Added functions to see if two matrices or vectors are close.
136  * 
137  * 15    2/03/97 1:30p John
138  * Put a clearer comment in for vm_vec_unrotate
139  * 
140  * 14    2/03/97 1:14p John
141  * Added vm_vec_unrotate function
142  * 
143  * 13    1/27/97 11:57a John
144  * added a function to rotate a point around an arbritary line.
145  * 
146  * 12    11/26/96 12:18p Hoffoss
147  * Added the vm_vec_dist_squared() function.
148  * 
149  * 11    11/16/96 2:38p Mike
150  * Waypoint code, under construction and a painful mess.
151  * 
152  * 10    11/05/96 3:42p Mike
153  * Make AI use accuracy parameter, though not yet specified in ships.tbl
154  * or *.fsm.
155  * 
156  * Add vm_vec_rand_vec_quick.
157  * 
158  * Add frand() which returns a rand in 0.0..1.0.
159  * 
160  * 9     10/30/96 2:35p Mike
161  * Docking behavior.
162  * Changed quick versions of vecmat routines to not return 1/mag.  They
163  * return mag, just like non-quick versions.
164  * 
165  * 8     10/24/96 10:17a Hoffoss
166  * Moved function 'compute_point_on_plane()' to vecmat.
167  * 
168  * 7     10/23/96 10:32p Lawrance
169  * added function vm_vect_mag_squared()
170  *
171  * $NoKeywords: $
172  *
173 */
174
175 #ifndef _VECMAT_H
176 #define _VECMAT_H
177
178 #include <float.h>
179 #include "pstypes.h"
180
181 //#define _INLINE_VECMAT
182
183 #define vm_is_vec_nan(v) (_isnan((v)->x) || _isnan((v)->y) || _isnan((v)->z))
184
185 //Macros/functions to fill in fields of structures
186
187 //macro to check if vector is zero
188 #define IS_VEC_NULL(v) (((v)->x == (float)0.0) && ((v)->y == (float)0.0) && ((v)->z == (float)0.0))
189
190 //macro to set a vector to zero.  we could do this with an in-line assembly
191 //macro, but it's probably better to let the compiler optimize it.
192 //Note: NO RETURN VALUE
193 #define vm_vec_zero(v) (v)->x=(v)->y=(v)->z=(float)0.0
194
195 /*
196 //macro set set a matrix to the identity. Note: NO RETURN VALUE
197 #define vm_set_identity(m) do {m->rvec.x = m->uvec.y = m->fvec.z = (float)1.0;  \
198                                                                                 m->rvec.y = m->rvec.z = \
199                                                                                 m->uvec.x = m->uvec.z = \
200                                                                                 m->fvec.x = m->fvec.y = (float)0.0;} while (0)
201 */
202 extern void vm_set_identity(matrix *m);
203
204 #define vm_vec_make(v,_x,_y,_z) (((v)->x=(_x), (v)->y=(_y), (v)->z=(_z)), (v))
205
206 //Global constants
207
208 extern vector vmd_zero_vector;
209 extern vector vmd_x_vector;
210 extern vector vmd_y_vector;
211 extern vector vmd_z_vector;
212 extern matrix vmd_identity_matrix;
213
214 //Here's a handy constant
215
216 #define ZERO_VECTOR {(float)0.0,(float)0.0,(float)0.0}
217 #define IDENTITY_MATRIX {(float)1.0,(float)0.0,(float)0.0,      \
218                          (float)0.0,(float)1.0,(float)0.0,      \
219                          (float)0.0,(float)0.0,(float)1.0 }
220
221 //fills in fields of an angle vector
222 #define vm_angvec_make(v,_p,_b,_h) (((v)->p=(_p), (v)->b=(_b), (v)->h=(_h)), (v))
223
224 //negate a vector
225 #define vm_vec_negate(v) do {(v)->x = - (v)->x; (v)->y = - (v)->y; (v)->z = - (v)->z;} while (0);
226
227 typedef struct plane {
228         float   A, B, C, D;
229 } plane;
230
231 //Functions in library
232
233 //adds two vectors, fills in dest, returns ptr to dest
234 //ok for dest to equal either source, but should use vm_vec_add2() if so
235 #ifdef _INLINE_VECMAT
236 #define vm_vec_add( dst, src0, src1 ) do {      \
237         (dst)->x = (src0)->x + (src1)->x;                                       \
238         (dst)->y = (src0)->y + (src1)->y;                                       \
239         (dst)->z = (src0)->z + (src1)->z;                                       \
240 } while(0) 
241 #else
242 void vm_vec_add(vector *dest,vector *src0,vector *src1);
243 #endif
244
245 //adds src onto dest vector, returns ptr to dest
246 #ifdef _INLINE_VECMAT
247 #define vm_vec_add2( dst, src ) do {    \
248         (dst)->x += (src)->x;                                   \
249         (dst)->y += (src)->y;                                   \
250         (dst)->z += (src)->z;                                   \
251 } while(0) 
252 #else
253 void vm_vec_add2(vector *dest,vector *src);
254 #endif
255
256
257 //scales a vector and subs from to another
258 //dest -= k * src
259 #ifdef _INLINE_VECMAT
260 #define vm_vec_scale_sub2( dst, src, k ) do {   \
261         float tmp_k = (k);                                                              \
262         (dst)->x -= (src)->x*tmp_k;                                     \
263         (dst)->y -= (src)->y*tmp_k;                                     \
264         (dst)->z -= (src)->z*tmp_k;                                     \
265 } while(0) 
266 #else
267 void vm_vec_scale_sub2(vector *dest,vector *src, float k);
268 #endif
269
270 //subs two vectors, fills in dest, returns ptr to dest
271 //ok for dest to equal either source, but should use vm_vec_sub2() if so
272 #ifdef _INLINE_VECMAT
273 #define vm_vec_sub( dst, src0, src1 ) do {      \
274         (dst)->x = (src0)->x - (src1)->x;                                       \
275         (dst)->y = (src0)->y - (src1)->y;                                       \
276         (dst)->z = (src0)->z - (src1)->z;                                       \
277 } while(0) 
278 #else
279 void vm_vec_sub(vector *dest,vector *src0,vector *src1);
280 #endif
281
282
283 //subs one vector from another, returns ptr to dest
284 //dest can equal source
285 #ifdef _INLINE_VECMAT
286 #define vm_vec_sub2( dst, src ) do {    \
287         (dst)->x -= (src)->x;                                   \
288         (dst)->y -= (src)->y;                                   \
289         (dst)->z -= (src)->z;                                   \
290 } while(0) 
291 #else
292 void vm_vec_sub2(vector *dest,vector *src);
293 #endif
294
295
296 //averages two vectors. returns ptr to dest
297 //dest can equal either source
298 vector *vm_vec_avg(vector *dest,vector *src0,vector *src1);
299
300 //averages four vectors. returns ptr to dest
301 //dest can equal any source
302 vector *vm_vec_avg4(vector *dest,vector *src0,vector *src1,vector *src2,vector *src3);
303
304 //scales a vector in place.  returns ptr to vector
305 #ifdef _INLINE_VECMAT
306 #define vm_vec_scale( dst, k ) do {     \
307         float tmp_k = (k);                                                              \
308         (dst)->x *= tmp_k;                                      \
309         (dst)->y *= tmp_k;                                      \
310         (dst)->z *= tmp_k;                                      \
311 } while(0) 
312 #else
313 void vm_vec_scale(vector *dest,float s);
314 #endif
315
316 //scales and copies a vector.  returns ptr to dest
317 #ifdef _INLINE_VECMAT
318 #define vm_vec_copy_scale( dst, src, k ) do {   \
319         float tmp_k = (k);                                                              \
320         (dst)->x = (src)->x * tmp_k;                                    \
321         (dst)->y = (src)->y * tmp_k;                                    \
322         (dst)->z = (src)->z * tmp_k;                                    \
323 } while(0) 
324 #else
325 void vm_vec_copy_scale(vector *dest,vector *src,float s);
326 #endif
327
328 //scales a vector, adds it to another, and stores in a 3rd vector
329 //dest = src1 + k * src2
330 #ifdef _INLINE_VECMAT
331 #define vm_vec_scale_add( dst, src1, src2, k ) do {     \
332         float tmp_k = (k);                                                              \
333         (dst)->x = (src1)->x + (src2)->x * tmp_k;                                       \
334         (dst)->y = (src1)->y + (src2)->y * tmp_k;                                       \
335         (dst)->z = (src1)->z + (src2)->z * tmp_k;                                       \
336 } while(0) 
337 #else
338 void vm_vec_scale_add(vector *dest,vector *src1,vector *src2,float k);
339 #endif
340
341
342 //scales a vector and adds it to another
343 //dest += k * src
344 #ifdef _INLINE_VECMAT
345 #define vm_vec_scale_add2( dst, src, k ) do {   \
346         float tmp_k = (k);                                                              \
347         (dst)->x += (src)->x * tmp_k;                                   \
348         (dst)->y += (src)->y * tmp_k;                                   \
349         (dst)->z += (src)->z * tmp_k;                                   \
350 } while(0) 
351 #else
352 void vm_vec_scale_add2(vector *dest,vector *src,float k);
353 #endif
354
355 //scales a vector in place, taking n/d for scale.  returns ptr to vector
356 //dest *= n/d
357 #ifdef _INLINE_VECMAT
358 #define vm_vec_scale2( dst, n, d ) do { \
359         float tmp_k = (n)/(d);                                                          \
360         (dst)->x *= tmp_k;                                      \
361         (dst)->y *= tmp_k;                                      \
362         (dst)->z *= tmp_k;                                      \
363 } while(0) 
364 #else
365 void vm_vec_scale2(vector *dest,float n,float d);
366 #endif
367
368 // finds the projection of source vector along a unit vector
369 // returns the magnitude of the component
370 float vm_vec_projection_parallel (vector *component, vector *src, vector *unit_vector);
371
372 // finds the projection of source vector onto a surface given by surface normal
373 void vm_vec_projection_onto_plane (vector *projection, vector *src, vector *normal);
374
375 //returns magnitude of a vector
376 float vm_vec_mag(vector *v);
377
378 // returns the square of the magnitude of a vector (useful if comparing distances)
379 float vm_vec_mag_squared(vector* v);
380
381 // returns the square of the distance between two points (fast and exact)
382 float vm_vec_dist_squared(vector *v0, vector *v1);
383
384 //computes the distance between two points. (does sub and mag)
385 float vm_vec_dist(vector *v0,vector *v1);
386
387 //computes an approximation of the magnitude of the vector
388 //uses dist = largest + next_largest*3/8 + smallest*3/16
389 float vm_vec_mag_quick(vector *v);
390
391 //computes an approximation of the distance between two points.
392 //uses dist = largest + next_largest*3/8 + smallest*3/16
393 float vm_vec_dist_quick(vector *v0,vector *v1);
394
395
396 //normalize a vector. returns mag of source vec
397 float vm_vec_copy_normalize(vector *dest,vector *src);
398 float vm_vec_normalize(vector *v);
399
400 //      This version of vector normalize checks for the null vector before normalization.
401 //      If it is detected, it generates a Warning() and returns the vector 1, 0, 0.
402 float vm_vec_normalize_safe(vector *v);
403
404 //normalize a vector. returns mag of source vec. uses approx mag
405 float vm_vec_copy_normalize_quick(vector *dest,vector *src);
406 float vm_vec_normalize_quick(vector *v);
407
408 //normalize a vector. returns mag of source vec. uses approx mag
409 float vm_vec_copy_normalize_quick_mag(vector *dest,vector *src);
410 float vm_vec_normalize_quick_mag(vector *v);
411
412 //return the normalized direction vector between two points
413 //dest = normalized(end - start).  Returns mag of direction vector
414 //NOTE: the order of the parameters matches the vector subtraction
415 float vm_vec_normalized_dir(vector *dest,vector *end,vector *start);
416 float vm_vec_normalized_dir_quick_mag(vector *dest,vector *end,vector *start);
417 // Returns mag of direction vector
418 float vm_vec_normalized_dir_quick(vector *dest,vector *end,vector *start);
419
420 ////returns dot product of two vectors
421 #ifdef _INLINE_VECMAT
422 #define vm_vec_dotprod( v0, v1 ) (((v1)->x*(v0)->x)+((v1)->y*(v0)->y)+((v1)->z*(v0)->z))
423 #define vm_vec_dot( v0, v1 ) (((v1)->x*(v0)->x)+((v1)->y*(v0)->y)+((v1)->z*(v0)->z))
424 #else
425 float vm_vec_dotprod(vector *v0,vector *v1);
426 #define vm_vec_dot vm_vec_dotprod
427 #endif
428
429 #ifdef _INLINE_VECMAT
430 #define vm_vec_dot3( x1, y1, z1, v ) (((x1)*(v)->x)+((y1)*(v)->y)+((z1)*(v)->z))
431 #else
432 float vm_vec_dot3(float x,float y,float z,vector *v);
433 #endif
434
435 //computes cross product of two vectors. returns ptr to dest
436 //dest CANNOT equal either source
437 vector *vm_vec_crossprod(vector *dest,vector *src0,vector *src1);
438 #define vm_vec_cross vm_vec_crossprod
439
440 // test if 2 vectors are parallel or not.
441 int vm_test_parallel(vector *src0, vector *src1);
442
443 //computes surface normal from three points. result is normalized
444 //returns ptr to dest
445 //dest CANNOT equal either source
446 vector *vm_vec_normal(vector *dest,vector *p0,vector *p1,vector *p2);
447
448 //computes non-normalized surface normal from three points.
449 //returns ptr to dest
450 //dest CANNOT equal either source
451 vector *vm_vec_perp(vector *dest,vector *p0,vector *p1,vector *p2);
452
453 //computes the delta angle between two vectors.
454 //vectors need not be normalized. if they are, call vm_vec_delta_ang_norm()
455 //the forward vector (third parameter) can be NULL, in which case the absolute
456 //value of the angle in returned.  Otherwise the angle around that vector is
457 //returned.
458 float vm_vec_delta_ang(vector *v0,vector *v1,vector *fvec);
459
460 //computes the delta angle between two normalized vectors.
461 float vm_vec_delta_ang_norm(vector *v0,vector *v1,vector *fvec);
462
463 //computes a matrix from a set of three angles.  returns ptr to matrix
464 matrix *vm_angles_2_matrix(matrix *m,angles *a);
465
466 //      Computes a matrix from a single angle.
467 //      angle_index = 0,1,2 for p,b,h
468 matrix *vm_angle_2_matrix(matrix *m, float a, int angle_index);
469
470 //computes a matrix from a forward vector and an angle
471 matrix *vm_vec_ang_2_matrix(matrix *m,vector *v,float a);
472
473 //computes a matrix from one or more vectors. The forward vector is required,
474 //with the other two being optional.  If both up & right vectors are passed,
475 //the up vector is used.  If only the forward vector is passed, a bank of
476 //zero is assumed
477 //returns ptr to matrix
478 matrix *vm_vector_2_matrix(matrix *m,vector *fvec,vector *uvec,vector *rvec);
479
480 //this version of vector_2_matrix requires that the vectors be more-or-less
481 //normalized and close to perpendicular
482 matrix *vm_vector_2_matrix_norm(matrix *m,vector *fvec,vector *uvec,vector *rvec);
483
484 //rotates a vector through a matrix. returns ptr to dest vector
485 //dest CANNOT equal either source
486 vector *vm_vec_rotate(vector *dest,vector *src,matrix *m);
487
488 //rotates a vector through the transpose of the given matrix. 
489 //returns ptr to dest vector
490 //dest CANNOT equal source
491 // This is a faster replacement for this common code sequence:
492 //    vm_copy_transpose_matrix(&tempm,src_matrix);
493 //    vm_vec_rotate(dst_vec,src_vect,&tempm);
494 // Replace with:
495 //    vm_vec_unrotate(dst_vec,src_vect, src_matrix)
496 //
497 // THIS DOES NOT ACTUALLY TRANSPOSE THE SOURCE MATRIX!!! So if
498 // you need it transposed later on, you should use the 
499 // vm_vec_transpose() / vm_vec_rotate() technique.
500 vector *vm_vec_unrotate(vector *dest,vector *src,matrix *m);
501
502 //transpose a matrix in place. returns ptr to matrix
503 matrix *vm_transpose_matrix(matrix *m);
504 #define vm_transpose(m) vm_transpose_matrix(m)
505
506 //copy and transpose a matrix. returns ptr to matrix
507 //dest CANNOT equal source. use vm_transpose_matrix() if this is the case
508 matrix *vm_copy_transpose_matrix(matrix *dest,matrix *src);
509 #define vm_copy_transpose(dest,src) vm_copy_transpose_matrix((dest),(src))
510
511 //mulitply 2 matrices, fill in dest.  returns ptr to dest
512 //dest CANNOT equal either source
513 matrix *vm_matrix_x_matrix(matrix *dest,matrix *src0,matrix *src1);
514
515 //extract angles from a matrix
516 angles *vm_extract_angles_matrix(angles *a,matrix *m);
517
518 //extract heading and pitch from a vector, assuming bank==0
519 angles *vm_extract_angles_vector(angles *a,vector *v);
520
521 //make sure matrix is orthogonal
522 void vm_orthogonalize_matrix(matrix *m_src);
523
524 // like vm_orthogonalize_matrix(), except that zero vectors can exist within the
525 // matrix without causing problems.  Valid vectors will be created where needed.
526 void vm_fix_matrix(matrix *m);
527
528 //Rotates the orient matrix by the angles in tangles and then
529 //makes sure that the matrix is orthogonal.
530 void vm_rotate_matrix_by_angles( matrix *orient, angles *tangles );
531
532 //compute the distance from a point to a plane.  takes the normalized normal
533 //of the plane (ebx), a point on the plane (edi), and the point to check (esi).
534 //returns distance in eax
535 //distance is signed, so negative dist is on the back of the plane
536 float vm_dist_to_plane(vector *checkp,vector *norm,vector *planep);
537
538 // Given mouse movement in dx, dy, returns a 3x3 rotation matrix in RotMat.
539 // Taken from Graphics Gems III, page 51, "The Rolling Ball"
540 // Example:
541 //if ( (Mouse.dx!=0) || (Mouse.dy!=0) ) {
542 //   vm_trackball( Mouse.dx, Mouse.dy, &MouseRotMat );
543 //   vm_matrix_x_matrix(&tempm,&LargeView.ev_matrix,&MouseRotMat);
544 //   LargeView.ev_matrix = tempm;
545 //}
546 void vm_trackball( int idx, int idy, matrix * RotMat );
547
548 //      Find the point on the line between p0 and p1 that is nearest to int_pnt.
549 //      Stuff result in nearest_point.
550 //      Return value indicated where on the line *nearest_point lies.  Between 0.0f and 1.0f means it's
551 //      in the line segment.  Positive means beyond *p1, negative means before *p0.  2.0f means it's
552 //      beyond *p1 by 2x.
553 float find_nearest_point_on_line(vector *nearest_point, vector *p0, vector *p1, vector *int_pnt);
554
555 float vm_vec_dot_to_point(vector *dir, vector *p1, vector *p2);
556
557 void compute_point_on_plane(vector *q, plane *planep, vector *p);
558
559 // ----------------------------------------------------------------------------
560 // computes the point on a plane closest to a given point (which may be on the plane)
561 // 
562 //              inputs:         new_point               =>              point on the plane [result]
563 //                                              point                           =>              point to compute closest plane point
564 //                                              plane_normal    =>              plane normal
565 //                                              plane_point             =>              plane point
566 void vm_project_point_onto_plane(vector *new_point, vector *point, vector *plane_normal, vector *plane_point);
567
568
569 //      Returns fairly random vector, "quick" normalized
570 void vm_vec_rand_vec_quick(vector *rvec);
571
572 // Given an point "in" rotate it by "angle" around an
573 // arbritary line defined by a point on the line "line_point" 
574 // and the normalized line direction, "line_dir"
575 // Returns the rotated point in "out".
576 void vm_rot_point_around_line(vector *out, vector *in, float angle, vector *line_point, vector *line_dir);
577
578 // Given two position vectors, return 0 if the same, else non-zero.
579 int vm_vec_cmp( vector * a, vector * b );
580
581 // Given two orientation matrices, return 0 if the same, else non-zero.
582 int vm_matrix_cmp( matrix * a, matrix * b );
583
584 // Moves angle 'h' towards 'desired_angle', taking the shortest
585 // route possible.   It will move a maximum of 'step_size' radians
586 // each call.   All angles in radians.
587 void vm_interp_angle( float *h, float desired_angle, float step_size );
588
589 // check a matrix for zero rows and columns
590 int vm_check_matrix_for_zeros(matrix *m);
591
592 // see if two vectors are identical
593 int vm_vec_same(vector *v1, vector *v2);
594
595 //      Interpolate from a start matrix toward a goal matrix, minimizing time between orientations.
596 // Moves at maximum rotational acceleration toward the goal when far and then max deceleration when close.
597 // Subject to constaints on rotational velocity and angular accleleration.
598 // Returns next_orientation valid at time delta_t.
599 void vm_matrix_interpolate(matrix *goal_orient, matrix *start_orient, vector *rotvel_in, float delta_t, 
600                 matrix *next_orient, vector *rotvel_out, vector *rotvel_limit, vector *acc_limit, int no_overshoot=0);
601
602 //      Interpolate from a start forward vec toward a goal forward vec, minimizing time between orientations.
603 // Moves at maximum rotational acceleration toward the goal when far and then max deceleration when close.
604 // Subject to constaints on rotational velocity and angular accleleration.
605 // Returns next forward vec valid at time delta_t.
606 void vm_forward_interpolate(vector *goal_fvec, matrix *orient, vector *rotvel_in, float delta_t, float delta_bank,
607                 matrix *next_orient, vector *rotvel_out, vector *vel_limit, vector *acc_limit, int no_overshoot=0);
608
609 // Find the bounding sphere for a set of points (center and radius are output parameters)
610 void vm_find_bounding_sphere(vector *pnts, int num_pnts, vector *center, float *radius);
611
612 // Version of atan2() that is safe for optimized builds
613 float atan2_safe(float x, float y);
614
615 // Translates from world coordinates to body coordinates
616 vector* vm_rotate_vec_to_body(vector *body_vec, vector *world_vec, matrix *orient);
617
618 // Translates from body coordinates to world coordiantes
619 vector* vm_rotate_vec_to_world(vector *world_vec, vector *body_vec, matrix *orient);
620
621 // estimate next orientation matrix as extrapolation of last and current
622 void vm_estimate_next_orientation(matrix *last_orient, matrix *current_orient, matrix *next_orient);
623
624 //      Return true if all elements of *vec are legal, that is, not a NAN.
625 int is_valid_vec(vector *vec);
626
627 //      Return true if all elements of *m are legal, that is, not a NAN.
628 int is_valid_matrix(matrix *m);
629
630 // Finds the rotation matrix corresponding to a rotation of theta about axis u
631 void vm_quaternion_rotate(matrix *m, float theta, vector *u);
632
633 // Takes a rotation matrix and returns the axis and angle needed to generate it
634 void vm_matrix_to_rot_axis_and_angle(matrix *m, float *theta, vector *rot_axis);
635
636 // interpolate between 2 vectors. t goes from 0.0 to 1.0. at
637 void vm_vec_interp_constant(vector *out, vector *v1, vector *v2, float t);
638
639 // randomly perturb a vector around a given (normalized vector) or optional orientation matrix
640 void vm_vec_random_cone(vector *out, vector *in, float max_angle, matrix *orient = NULL);
641
642 // given a start vector, an orientation and a radius, give a point on the plane of the circle
643 // if on_edge is 1, the point is on the very edge of the circle
644 void vm_vec_random_in_circle(vector *out, vector *in, matrix *orient, float radius, int on_edge);
645
646 // find the nearest point on the line to p. if dist is non-NULL, it is filled in
647 // returns 0 if the point is inside the line segment, -1 if "before" the line segment and 1 ir "after" the line segment
648 int vm_vec_dist_to_line(vector *p, vector *l0, vector *l1, vector *nearest, float *dist);
649
650 #endif
651