]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - libs/picomodel/lwo/vecmath.c
Merge branch 'master' into divVerent/farplanedist-sky-fix
[xonotic/netradiant.git] / libs / picomodel / lwo / vecmath.c
1 /*
2    ======================================================================
3    vecmath.c
4
5    Basic vector and matrix functions.
6
7    Ernie Wright  17 Sep 00
8    ====================================================================== */
9
10 #include <math.h>
11
12
13 float dot( float a[], float b[] ){
14         return a[ 0 ] * b[ 0 ] + a[ 1 ] * b[ 1 ] + a[ 2 ] * b[ 2 ];
15 }
16
17
18 void cross( float a[], float b[], float c[] ){
19         c[ 0 ] = a[ 1 ] * b[ 2 ] - a[ 2 ] * b[ 1 ];
20         c[ 1 ] = a[ 2 ] * b[ 0 ] - a[ 0 ] * b[ 2 ];
21         c[ 2 ] = a[ 0 ] * b[ 1 ] - a[ 1 ] * b[ 0 ];
22 }
23
24
25 void normalize( float v[] ){
26         float r;
27
28         r = ( float ) sqrt( dot( v, v ) );
29         if ( r > 0 ) {
30                 v[ 0 ] /= r;
31                 v[ 1 ] /= r;
32                 v[ 2 ] /= r;
33         }
34 }