2006-02-10 22:01:20 +00:00
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
======================================================================
|
|
|
|
vecmath.c
|
2006-02-10 22:01:20 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Basic vector and matrix functions.
|
2006-02-10 22:01:20 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Ernie Wright 17 Sep 00
|
|
|
|
====================================================================== */
|
2006-02-10 22:01:20 +00:00
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
float dot( float a[], float b[] ){
|
|
|
|
return a[ 0 ] * b[ 0 ] + a[ 1 ] * b[ 1 ] + a[ 2 ] * b[ 2 ];
|
2006-02-10 22:01:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void cross( float a[], float b[], float c[] ){
|
|
|
|
c[ 0 ] = a[ 1 ] * b[ 2 ] - a[ 2 ] * b[ 1 ];
|
|
|
|
c[ 1 ] = a[ 2 ] * b[ 0 ] - a[ 0 ] * b[ 2 ];
|
|
|
|
c[ 2 ] = a[ 0 ] * b[ 1 ] - a[ 1 ] * b[ 0 ];
|
2006-02-10 22:01:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void normalize( float v[] ){
|
|
|
|
float r;
|
2006-02-10 22:01:20 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
r = ( float ) sqrt( dot( v, v ) );
|
|
|
|
if ( r > 0 ) {
|
|
|
|
v[ 0 ] /= r;
|
|
|
|
v[ 1 ] /= r;
|
|
|
|
v[ 2 ] /= r;
|
|
|
|
}
|
2006-02-10 22:01:20 +00:00
|
|
|
}
|