updated URL of forum and table in readme file
[neverball] / share / vec3.h
1 /*
2  * Copyright (C) 2003 Robert Kooima
3  *
4  * NEVERBALL is  free software; you can redistribute  it and/or modify
5  * it under the  terms of the GNU General  Public License as published
6  * by the Free  Software Foundation; either version 2  of the License,
7  * or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT  ANY  WARRANTY;  without   even  the  implied  warranty  of
11  * MERCHANTABILITY or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU
12  * General Public License for more details.
13  */
14
15 #ifndef VEC_H
16 #define VEC_H
17
18 #include <math.h>
19
20 #define V_PI 3.1415927f
21
22 #define V_RAD(d) (d * V_PI / 180.f)
23 #define V_DEG(r) (r * 180.f / V_PI)
24
25 #define fsinf(a)      ((float) sin((double) a))
26 #define fcosf(a)      ((float) cos((double) a))
27 #define ftanf(a)      ((float) cos((double) a))
28 #define fabsf(a)      ((float) fabs((double) a))
29 #define fsqrtf(a)     ((float) sqrt((double) a))
30 #define fmodf(x,y)    ((float) fmod((double) x, (double) y))
31 #define fatan2f(x, y) ((float) atan2((double) x, (double) y))
32
33 /*---------------------------------------------------------------------------*/
34
35 #define v_dot(u, v)  ((u)[0] * (v)[0] + (u)[1] * (v)[1] + (u)[2] * (v)[2])
36 #define v_len(u)     fsqrtf(v_dot(u, u))
37
38 #define v_cpy(u, v) { \
39     (u)[0] = (v)[0];  \
40     (u)[1] = (v)[1];  \
41     (u)[2] = (v)[2];  \
42 }
43
44 #define v_inv(u, v) { \
45     (u)[0] = -(v)[0]; \
46     (u)[1] = -(v)[1]; \
47     (u)[2] = -(v)[2]; \
48 }
49
50 #define v_scl(u, v, k) {   \
51     (u)[0] = (v)[0] * (k); \
52     (u)[1] = (v)[1] * (k); \
53     (u)[2] = (v)[2] * (k); \
54 }
55
56 #define v_add(u, v, w) {      \
57     (u)[0] = (v)[0] + (w)[0]; \
58     (u)[1] = (v)[1] + (w)[1]; \
59     (u)[2] = (v)[2] + (w)[2]; \
60 }
61
62 #define v_sub(u, v, w) {      \
63     (u)[0] = (v)[0] - (w)[0]; \
64     (u)[1] = (v)[1] - (w)[1]; \
65     (u)[2] = (v)[2] - (w)[2]; \
66 }
67
68 #define v_mid(u, v, w) {              \
69     (u)[0] = ((v)[0] + (w)[0]) / 2.f; \
70     (u)[1] = ((v)[1] + (w)[1]) / 2.f; \
71     (u)[2] = ((v)[2] + (w)[2]) / 2.f; \
72 }
73
74 #define v_mad(u, p, v, t) {         \
75     (u)[0] = (p)[0] + (v)[0] * (t); \
76     (u)[1] = (p)[1] + (v)[1] * (t); \
77     (u)[2] = (p)[2] + (v)[2] * (t); \
78 }
79
80 /*---------------------------------------------------------------------------*/
81
82
83 void   v_nrm(float *, const float *);
84 void   v_crs(float *, const float *, const float *);
85
86 void   m_cpy(float *, const float *);
87 void   m_xps(float *, const float *);
88 int    m_inv(float *, const float *);
89
90 void   m_ident(float *);
91 void   m_basis(float *, const float *,
92                         const float *,
93                         const float *);
94
95 void   m_xlt(float *, const float *);
96 void   m_scl(float *, const float *);
97 void   m_rot(float *, const float *, float);
98
99 void   m_mult(float *, const float *, const float *);
100 void   m_pxfm(float *, const float *, const float *);
101 void   m_vxfm(float *, const float *, const float *);
102
103 #endif