Do not reject 1.5 format SOLs
[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) tan((double) a))
28 #define fabsf(a)      ((float) fabs((double) a))
29 #define fsqrtf(a)     ((float) sqrt((double) a))
30 #define facosf(a)     ((float) acos((double) a))
31 #define fmodf(x,y)    ((float) fmod((double) x, (double) y))
32 #define fatan2f(x, y) ((float) atan2((double) x, (double) y))
33
34 /*---------------------------------------------------------------------------*/
35
36 #define v_dot(u, v)  ((u)[0] * (v)[0] + (u)[1] * (v)[1] + (u)[2] * (v)[2])
37 #define v_len(u)     fsqrtf(v_dot(u, u))
38
39 #define v_cpy(u, v) do { \
40     (u)[0] = (v)[0];     \
41     (u)[1] = (v)[1];     \
42     (u)[2] = (v)[2];     \
43 } while (0)
44
45 #define v_inv(u, v) do { \
46     (u)[0] = -(v)[0];    \
47     (u)[1] = -(v)[1];    \
48     (u)[2] = -(v)[2];    \
49 } while (0)
50
51 #define v_scl(u, v, k) do { \
52     (u)[0] = (v)[0] * (k);  \
53     (u)[1] = (v)[1] * (k);  \
54     (u)[2] = (v)[2] * (k);  \
55 } while (0)
56
57 #define v_add(u, v, w) do {   \
58     (u)[0] = (v)[0] + (w)[0]; \
59     (u)[1] = (v)[1] + (w)[1]; \
60     (u)[2] = (v)[2] + (w)[2]; \
61 } while (0)
62
63 #define v_sub(u, v, w) do {   \
64     (u)[0] = (v)[0] - (w)[0]; \
65     (u)[1] = (v)[1] - (w)[1]; \
66     (u)[2] = (v)[2] - (w)[2]; \
67 } while (0)
68
69 #define v_mid(u, v, w) do {           \
70     (u)[0] = ((v)[0] + (w)[0]) / 2.f; \
71     (u)[1] = ((v)[1] + (w)[1]) / 2.f; \
72     (u)[2] = ((v)[2] + (w)[2]) / 2.f; \
73 } while (0)
74
75 #define v_mad(u, p, v, t) do {      \
76     (u)[0] = (p)[0] + (v)[0] * (t); \
77     (u)[1] = (p)[1] + (v)[1] * (t); \
78     (u)[2] = (p)[2] + (v)[2] * (t); \
79 } while (0)
80
81 /*---------------------------------------------------------------------------*/
82
83
84 void   v_nrm(float *, const float *);
85 void   v_crs(float *, const float *, const float *);
86
87 void   m_cpy(float *, const float *);
88 void   m_xps(float *, const float *);
89 int    m_inv(float *, const float *);
90
91 void   m_ident(float *);
92 void   m_basis(float *, const float *,
93                         const float *,
94                         const float *);
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 void   m_view(float *, const float *,
104                        const float *,
105                        const float *);
106
107 /*---------------------------------------------------------------------------*/
108
109 #define q_cpy(q, p) do { \
110     (q)[0] = (p)[0];     \
111     (q)[1] = (p)[1];     \
112     (q)[2] = (p)[2];     \
113     (q)[3] = (p)[3];     \
114 } while (0)
115
116 void q_axisangle(const float *q, float *u, float *a);
117
118 #endif