istereo

view libs/vmath/vmath.inl @ 29:fb4c9641059f

added more forgotten files
author John Tsiombikas <nuclear@mutantstargoat.com>
date Thu, 08 Sep 2011 08:31:15 +0300
parents
children ff055bff6a15
line source
1 #include <stdlib.h>
3 /** Generates a random number in [0, range) */
4 static inline scalar_t frand(scalar_t range)
5 {
6 return range * (scalar_t)rand() / (scalar_t)RAND_MAX;
7 }
9 /** Generates a random vector on the surface of a sphere */
10 static inline vec3_t sphrand(scalar_t rad)
11 {
12 scalar_t u = (scalar_t)rand() / RAND_MAX;
13 scalar_t v = (scalar_t)rand() / RAND_MAX;
15 scalar_t theta = 2.0 * M_PI * u;
16 scalar_t phi = acos(2.0 * v - 1.0);
18 vec3_t res;
19 res.x = rad * cos(theta) * sin(phi);
20 res.y = rad * sin(theta) * sin(phi);
21 res.z = rad * cos(phi);
22 return res;
23 }
25 /** linear interpolation */
26 static inline scalar_t lerp(scalar_t a, scalar_t b, scalar_t t)
27 {
28 return a + (b - a) * t;
29 }