quaternions done
[gph-cmath] / src / cgmath.h
1 /* C version of the graphene math library */
2 #ifndef CGMATH_H_
3 #define CGMATH_H_
4
5 #include <math.h>
6
7 typedef struct {
8         float x, y, z;
9 } cgm_vec3;
10
11 typedef struct {
12         float x, y, z, w;
13 } cgm_quat;
14
15 /* vectors */
16 static inline void cgm_vzero(cgm_vec3 *v);
17 static inline void cgm_vone(cgm_vec3 *v);
18
19 static inline void cgm_vadd(cgm_vec3 *a, const cgm_vec3 *b);
20 static inline void cgm_vsub(cgm_vec3 *a, const cgm_vec3 *b);
21 static inline void cgm_vmul(cgm_vec3 *a, const cgm_vec3 *b);
22 static inline void cgm_vscale(cgm_vec3 *v, float s);
23
24 static inline float cgm_vdot(const cgm_vec3 *a, const cgm_vec3 *b);
25 static inline void cgm_vcross(cgm_vec3 *res, const cgm_vec3 *a, const cgm_vec3 *b);
26 static inline float cgm_vlength(const cgm_vec3 *v);
27 static inline float cgm_vlength_sq(const cgm_vec3 *v);
28 static inline float cgm_vdist(const cgm_vec3 *a, const cgm_vec3 *b);
29 static inline float cgm_vdist_sq(const cgm_vec3 *a, const cgm_vec3 *b);
30 static inline void cgm_vnormalize(cgm_vec3 *v);
31
32 /* quaternions */
33 static inline void cgm_qident(cgm_quat *q);
34
35 static inline void cgm_qneg(cgm_quat *q);
36 static inline void cgm_qadd(cgm_quat *a, const cgm_quat *b);
37 static inline void cgm_qsub(cgm_quat *a, const cgm_quat *b);
38 static inline void cgm_qmul(cgm_quat *a, const cgm_quat *b);
39
40 static inline float cgm_qlength(const cgm_quat *q);
41 static inline float cgm_qlength_sq(const cgm_quat *q);
42
43 static inline void cgm_qnormalize(cgm_quat *q);
44
45 static inline void cgm_qconjugate(cgm_quat *q);
46 static inline void cgm_qinvert(cgm_quat *q);
47
48 static inline void cgm_qrot_axis(cgm_quat *q, float axis, float x, float y, float z);
49 static inline void cgm_qrot_quat(cgm_quat *q, const cgm_quat *rq);
50
51 static inline void cgm_qmatrix(float *mat, const cgm_quat *q);
52
53 static inline void cgm_qslerp(cgm_quat *res, const cgm_quat *a, const cgm_quat *b, float t);
54
55 #include "cgmath.inl"
56
57 #endif  /* CGMATH_H_ */