diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2019-05-06 20:33:48 -0700 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2019-05-06 20:33:48 -0700 |
commit | f62314fba6050d14e14d70e8556d77b35c36b3c6 (patch) | |
tree | cbdb6eb6b34fe9288756a8883a047b15fbdad971 | |
parent | 8d621db560e44be9cc40ae51956f91992fa71ff6 (diff) |
v3f: add random vector within range: v3f_rand()
-rw-r--r-- | v3f.h | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -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 |