istereo

diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/libs/vmath/vmath.inl	Thu Sep 08 08:31:15 2011 +0300
     1.3 @@ -0,0 +1,29 @@
     1.4 +#include <stdlib.h>
     1.5 +
     1.6 +/** Generates a random number in [0, range) */
     1.7 +static inline scalar_t frand(scalar_t range)
     1.8 +{
     1.9 +	return range * (scalar_t)rand() / (scalar_t)RAND_MAX;
    1.10 +}
    1.11 +
    1.12 +/** Generates a random vector on the surface of a sphere */
    1.13 +static inline vec3_t sphrand(scalar_t rad)
    1.14 +{
    1.15 +	scalar_t u = (scalar_t)rand() / RAND_MAX;
    1.16 +	scalar_t v = (scalar_t)rand() / RAND_MAX;
    1.17 +
    1.18 +	scalar_t theta = 2.0 * M_PI * u;
    1.19 +	scalar_t phi = acos(2.0 * v - 1.0);
    1.20 +
    1.21 +	vec3_t res;
    1.22 +	res.x = rad * cos(theta) * sin(phi);
    1.23 +	res.y = rad * sin(theta) * sin(phi);
    1.24 +	res.z = rad * cos(phi);
    1.25 +	return res;
    1.26 +}
    1.27 +
    1.28 +/** linear interpolation */
    1.29 +static inline scalar_t lerp(scalar_t a, scalar_t b, scalar_t t)
    1.30 +{
    1.31 +	return a + (b - a) * t;
    1.32 +}