From f62314fba6050d14e14d70e8556d77b35c36b3c6 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Mon, 6 May 2019 20:33:48 -0700 Subject: v3f: add random vector within range: v3f_rand() --- v3f.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'v3f.h') diff --git a/v3f.h b/v3f.h index 68f06c7..3011182 100644 --- a/v3f.h +++ b/v3f.h @@ -283,4 +283,23 @@ static inline v3f_t * v3f_cross(v3f_t *res, const v3f_t *a, const v3f_t *b) } +static inline v3f_t _v3f_rand(const v3f_t *min, const v3f_t *max) +{ + return (v3f_t){ + .x = min->x + (float)rand() * (1.f/RAND_MAX) * (max->x - min->x), + .y = min->y + (float)rand() * (1.f/RAND_MAX) * (max->y - min->y), + .z = min->z + (float)rand() * (1.f/RAND_MAX) * (max->z - min->z), + }; +} + + +static inline v3f_t * v3f_rand(v3f_t *res, const v3f_t *min, const v3f_t *max) +{ + if (_v3f_allocated(&res)) + *res = _v3f_rand(min, max); + + return res; +} + + #endif -- cgit v1.2.3