istereo2

view libs/vmath/vmath.inl @ 27:f0da8b2b61ec

removed iOS cpu restriction and bumped build number to 3 implemented android JNI calls to show/hide ads (untested)
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 05 Oct 2015 17:15:02 +0300
parents
children
line source
1 /*
2 libvmath - a vector math library
3 Copyright (C) 2004-2011 John Tsiombikas <nuclear@member.fsf.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published
7 by the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
19 #include <stdlib.h>
21 /** Generates a random number in [0, range) */
22 static inline scalar_t frand(scalar_t range)
23 {
24 return range * (scalar_t)rand() / (scalar_t)RAND_MAX;
25 }
27 /** Generates a random vector on the surface of a sphere */
28 static inline vec3_t sphrand(scalar_t rad)
29 {
30 scalar_t u = (scalar_t)rand() / RAND_MAX;
31 scalar_t v = (scalar_t)rand() / RAND_MAX;
33 scalar_t theta = 2.0 * M_PI * u;
34 scalar_t phi = acos(2.0 * v - 1.0);
36 vec3_t res;
37 res.x = rad * cos(theta) * sin(phi);
38 res.y = rad * sin(theta) * sin(phi);
39 res.z = rad * cos(phi);
40 return res;
41 }
43 /** linear interpolation */
44 static inline scalar_t lerp(scalar_t a, scalar_t b, scalar_t t)
45 {
46 return a + (b - a) * t;
47 }