1 /******************************************************************************
2 * Arachnoid Graphics Plugin for Mupen64Plus
3 * http://bitbucket.org/wahrhaft/mupen64plus-video-arachnoid/
5 * Copyright (C) 2007 Kristofer Karlsson, Rickard Niklasson
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *****************************************************************************/
22 #ifndef MATH_LIBRARY_H_
23 #define MATH_LIBRARY_H_
25 #include <cmath> //sqrtf
28 // Formula: a.b = a0*b0 + a1*b1 + a2*b2
29 #define Vec3Dot(a,b) ((a)[0]*(b)[0]+(a)[1]*(b)[1]+(a)[2]*(b)[2])
31 #define Vec3Normalize(v) { \
32 float lenght = (v)[0]*(v)[0]+(v)[1]*(v)[1]+(v)[2]*(v)[2]; \
33 if ( lenght > 0.00001f ) { \
34 lenght = 1.0f / sqrt(lenght); \
42 //-----------------------------------------------------------------------------
44 //-----------------------------------------------------------------------------
46 inline void transformVertex( float* m, float* v, float* out )
51 out[0] = m[0] * x + m[4] * y + m[8] * z + m[12];
52 out[1] = m[1] * x + m[5] * y + m[9] * z + m[13];
53 out[2] = m[2] * x + m[6] * y + m[10] * z + m[14];
54 out[3] = m[3] * x + m[7] * y + m[11] * z + m[15];
57 inline void transformVector( float* m, float* v, float* out )
62 out[0] = m[0] * x + m[4] * y + m[8] * z;
63 out[1] = m[1] * x + m[5] * y + m[9] * z;
64 out[2] = m[2] * x + m[6] * y + m[10] * z;
69 //-----------------------------------------------------------------------------
71 //-----------------------------------------------------------------------------
72 inline float randomFloat(float min, float max)
74 return (float)( min + double(max-min)*rand()/RAND_MAX );
77 inline unsigned int pow2( unsigned int dim )
81 while (i < dim) i <<= 1;
86 inline unsigned int powof( unsigned int dim )