istereo
annotate 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 |
rev | line source |
---|---|
nuclear@29 | 1 #include <stdlib.h> |
nuclear@29 | 2 |
nuclear@29 | 3 /** Generates a random number in [0, range) */ |
nuclear@29 | 4 static inline scalar_t frand(scalar_t range) |
nuclear@29 | 5 { |
nuclear@29 | 6 return range * (scalar_t)rand() / (scalar_t)RAND_MAX; |
nuclear@29 | 7 } |
nuclear@29 | 8 |
nuclear@29 | 9 /** Generates a random vector on the surface of a sphere */ |
nuclear@29 | 10 static inline vec3_t sphrand(scalar_t rad) |
nuclear@29 | 11 { |
nuclear@29 | 12 scalar_t u = (scalar_t)rand() / RAND_MAX; |
nuclear@29 | 13 scalar_t v = (scalar_t)rand() / RAND_MAX; |
nuclear@29 | 14 |
nuclear@29 | 15 scalar_t theta = 2.0 * M_PI * u; |
nuclear@29 | 16 scalar_t phi = acos(2.0 * v - 1.0); |
nuclear@29 | 17 |
nuclear@29 | 18 vec3_t res; |
nuclear@29 | 19 res.x = rad * cos(theta) * sin(phi); |
nuclear@29 | 20 res.y = rad * sin(theta) * sin(phi); |
nuclear@29 | 21 res.z = rad * cos(phi); |
nuclear@29 | 22 return res; |
nuclear@29 | 23 } |
nuclear@29 | 24 |
nuclear@29 | 25 /** linear interpolation */ |
nuclear@29 | 26 static inline scalar_t lerp(scalar_t a, scalar_t b, scalar_t t) |
nuclear@29 | 27 { |
nuclear@29 | 28 return a + (b - a) * t; |
nuclear@29 | 29 } |