polyadvent

A game engine from scratch in C
git clone git://jb55.com/polyadvent
Log | Files | Refs | README

commit 22d643338dc8db1a5e1f85d91b34cbf2dc78f462
parent 48c9d306969745e809ede5865a1bdd88d2f02f85
Author: William Casarin <jb55@jb55.com>
Date:   Sat,  3 Nov 2018 22:47:00 -0700

vec3 min/max

Diffstat:
Msrc/vec3.c | 23+++++++++++++++++++++++
Msrc/vec3.h | 2++
2 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/src/vec3.c b/src/vec3.c @@ -236,3 +236,26 @@ void vec3_copy(vec3 *a, vec3 *dest) { dest[1] = a[1]; dest[2] = a[2]; } + + +static inline double max(double a, double b) { + return a > b ? a : b; +} + +static inline double min(double a, double b) { + return a < b ? a : b; +} + +vec3 *vec3_min(vec3 *vec, vec3* vec2, vec3 *dest) { + dest[0] = min(vec[0], vec2[0]); + dest[1] = min(vec[1], vec2[1]); + dest[2] = min(vec[2], vec2[2]); + return dest; +} + +vec3 *vec3_max(vec3 *vec, vec3* vec2, vec3 *dest) { + dest[0] = max(vec[0], vec2[0]); + dest[1] = max(vec[1], vec2[1]); + dest[2] = max(vec[2], vec2[2]); + return dest; +} diff --git a/src/vec3.h b/src/vec3.h @@ -12,6 +12,8 @@ vec3 *vec3_cross (vec3 *vec, vec3 *vec2, vec3 *dest); vec3 *vec3_multiply(vec3 *vec, vec3 *vec2, vec3 *dest); vec3 *vec3_scale(vec3 *vec, float val, vec3 *dest); vec3 *vec3_normalize(vec3 *vec, vec3 *dest); +vec3 *vec3_min(vec3 *vec, vec3* vec2, vec3 *dest); +vec3 *vec3_max(vec3 *vec, vec3* vec2, vec3 *dest); float vec3_dist(vec3 *vec, vec3 *vec2); float vec3_distsq(vec3 *vec, vec3 *vec2); float *vec3_set(vec3 *vec, vec3 *dest);