istereo2

annotate libs/vmath/vmath.inl @ 7:a3c4fcc9f8f3

- started a goatkit UI theme - font rendering with drawtext and shaders - asset manager (only used by drawtext for now, will replace respath eventually)
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 24 Sep 2015 06:49:25 +0300
parents
children
rev   line source
nuclear@2 1 /*
nuclear@2 2 libvmath - a vector math library
nuclear@2 3 Copyright (C) 2004-2011 John Tsiombikas <nuclear@member.fsf.org>
nuclear@2 4
nuclear@2 5 This program is free software: you can redistribute it and/or modify
nuclear@2 6 it under the terms of the GNU Lesser General Public License as published
nuclear@2 7 by the Free Software Foundation, either version 3 of the License, or
nuclear@2 8 (at your option) any later version.
nuclear@2 9
nuclear@2 10 This program is distributed in the hope that it will be useful,
nuclear@2 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
nuclear@2 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
nuclear@2 13 GNU Lesser General Public License for more details.
nuclear@2 14
nuclear@2 15 You should have received a copy of the GNU Lesser General Public License
nuclear@2 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
nuclear@2 17 */
nuclear@2 18
nuclear@2 19 #include <stdlib.h>
nuclear@2 20
nuclear@2 21 /** Generates a random number in [0, range) */
nuclear@2 22 static inline scalar_t frand(scalar_t range)
nuclear@2 23 {
nuclear@2 24 return range * (scalar_t)rand() / (scalar_t)RAND_MAX;
nuclear@2 25 }
nuclear@2 26
nuclear@2 27 /** Generates a random vector on the surface of a sphere */
nuclear@2 28 static inline vec3_t sphrand(scalar_t rad)
nuclear@2 29 {
nuclear@2 30 scalar_t u = (scalar_t)rand() / RAND_MAX;
nuclear@2 31 scalar_t v = (scalar_t)rand() / RAND_MAX;
nuclear@2 32
nuclear@2 33 scalar_t theta = 2.0 * M_PI * u;
nuclear@2 34 scalar_t phi = acos(2.0 * v - 1.0);
nuclear@2 35
nuclear@2 36 vec3_t res;
nuclear@2 37 res.x = rad * cos(theta) * sin(phi);
nuclear@2 38 res.y = rad * sin(theta) * sin(phi);
nuclear@2 39 res.z = rad * cos(phi);
nuclear@2 40 return res;
nuclear@2 41 }
nuclear@2 42
nuclear@2 43 /** linear interpolation */
nuclear@2 44 static inline scalar_t lerp(scalar_t a, scalar_t b, scalar_t t)
nuclear@2 45 {
nuclear@2 46 return a + (b - a) * t;
nuclear@2 47 }