summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2019-05-06 20:33:48 -0700
committerVito Caputo <vcaputo@pengaru.com>2019-05-06 20:33:48 -0700
commitf62314fba6050d14e14d70e8556d77b35c36b3c6 (patch)
treecbdb6eb6b34fe9288756a8883a047b15fbdad971
parent8d621db560e44be9cc40ae51956f91992fa71ff6 (diff)
v3f: add random vector within range: v3f_rand()
-rw-r--r--v3f.h19
1 files changed, 19 insertions, 0 deletions
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
© All Rights Reserved