1 static inline void cgm_vadd(cgm_vec3 *a, const cgm_vec3 *b)
8 static inline void cgm_vsub(cgm_vec3 *a, const cgm_vec3 *b)
15 static inline void cgm_vmul(cgm_vec3 *a, const cgm_vec3 *b)
22 static inline void cgm_vscale(cgm_vec3 *v, float s)
29 static inline float cgm_vdot(const cgm_vec3 *a, const cgm_vec3 *b)
31 return a->x * b->x + a->y * b->y + a->z * b->z;
34 static inline void cgm_vcross(cgm_vec3 *res, const cgm_vec3 *a, const cgm_vec3 *b)
36 res->x = a->y * b->z - a->z * b->y;
37 res->y = a->z * b->x - a->x * b->z;
38 res->z = a->x * b->y - a->y * b->x;
41 static inline float cgm_vlength(const cgm_vec3 *v)
43 return sqrt(v->x * v->x + v->y * v->y + v->z * v->z);
46 static inline float cgm_vlength_sq(const cgm_vec3 *v)
48 return v->x * v->x + v->y * v->y + v->z * v->z;
51 static inline float cgm_vdist(const cgm_vec3 *a, const cgm_vec3 *b)
53 float dx = a->x - b->x;
54 float dy = a->y - b->y;
55 float dz = a->z - b->z;
56 return sqrt(dx * dx + dy * dy + dz * dz);
59 static inline float cgm_vdist_sq(const cgm_vec3 *a, const cgm_vec3 *b)
61 float dx = a->x - b->x;
62 float dy = a->y - b->y;
63 float dz = a->z - b->z;
64 return dx * dx + dy * dy + dz * dz;
67 static inline void cgm_vnormalize(cgm_vec3 *v)
69 float len = cgm_vlength(v);