diff options
Diffstat (limited to 'v3f.h')
-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 |