2 * Copyright (C) 2003 Robert Kooima
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.
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.
20 #define V_PI 3.1415927f
22 #define V_RAD(d) (d * V_PI / 180.f)
23 #define V_DEG(r) (r * 180.f / V_PI)
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 fasinf(a) ((float) asin((double) a))
31 #define facosf(a) ((float) acos((double) a))
32 #define fmodf(x,y) ((float) fmod((double) x, (double) y))
33 #define fatan2f(x, y) ((float) atan2((double) x, (double) y))
35 /*---------------------------------------------------------------------------*/
37 #define v_dot(u, v) ((u)[0] * (v)[0] + (u)[1] * (v)[1] + (u)[2] * (v)[2])
38 #define v_len(u) fsqrtf(v_dot(u, u))
40 #define v_cpy(u, v) do { \
46 #define v_inv(u, v) do { \
52 #define v_scl(u, v, k) do { \
53 (u)[0] = (v)[0] * (k); \
54 (u)[1] = (v)[1] * (k); \
55 (u)[2] = (v)[2] * (k); \
58 #define v_add(u, v, w) do { \
59 (u)[0] = (v)[0] + (w)[0]; \
60 (u)[1] = (v)[1] + (w)[1]; \
61 (u)[2] = (v)[2] + (w)[2]; \
64 #define v_sub(u, v, w) do { \
65 (u)[0] = (v)[0] - (w)[0]; \
66 (u)[1] = (v)[1] - (w)[1]; \
67 (u)[2] = (v)[2] - (w)[2]; \
70 #define v_mid(u, v, w) do { \
71 (u)[0] = ((v)[0] + (w)[0]) / 2.f; \
72 (u)[1] = ((v)[1] + (w)[1]) / 2.f; \
73 (u)[2] = ((v)[2] + (w)[2]) / 2.f; \
76 #define v_mad(u, p, v, t) do { \
77 (u)[0] = (p)[0] + (v)[0] * (t); \
78 (u)[1] = (p)[1] + (v)[1] * (t); \
79 (u)[2] = (p)[2] + (v)[2] * (t); \
82 /*---------------------------------------------------------------------------*/
85 void v_nrm(float *, const float *);
86 void v_crs(float *, const float *, const float *);
88 void m_cpy(float *, const float *);
89 void m_xps(float *, const float *);
90 int m_inv(float *, const float *);
92 void m_ident(float *);
93 void m_basis(float *, const float *,
96 void m_xlt(float *, const float *);
97 void m_scl(float *, const float *);
98 void m_rot(float *, const float *, float);
100 void m_mult(float *, const float *, const float *);
101 void m_pxfm(float *, const float *, const float *);
102 void m_vxfm(float *, const float *, const float *);
104 void m_view(float *, const float *,
108 /*---------------------------------------------------------------------------*/
110 #define q_dot(q, r) ((q)[0] * (r)[0] + v_dot((q) + 1, (r) + 1))
111 #define q_len(q) fsqrtf(q_dot((q), (q)))
113 #define q_cpy(q, r) do { \
120 #define q_conj(q, r) do { \
127 void q_as_axisangle(const float q[4], float u[3], float *a);
128 void q_by_axisangle(float q[4], const float u[3], float a);
130 void q_nrm(float q[4], const float r[4]);
131 void q_mul(float q[4], const float a[4], const float b[4]);
132 void q_rot(float v[3], const float r[4], const float w[3]);
134 void q_euler(float v[3], const float q[4]);
135 void q_slerp(float q[4], const float a[4], const float b[4], float t);