1 #include <math.h>
2 #include "Phys_Math.h"
3 
4 
VAdd(vector_3 * a,vector_3 * b)5 vector_3 VAdd( vector_3 *a, vector_3 *b )
6 {
7 	vector_3 c;
8 
9 	c.x = a->x + b->x;
10 	c.y = a->y + b->y;
11 	c.z = a->z + b->z;
12 
13 	return( c );
14 }
15 
VMultScalar(vector_3 * a,float b)16 vector_3 VMultScalar( vector_3 *a, float b )
17 {
18 	vector_3 c;
19 
20 	c.x = a->x * b;
21 	c.y = a->y * b;
22 	c.z = a->z * b;
23 
24 	return( c );
25 }
26 
27 
VDotProduct(vector_3 * a,vector_3 * b)28 float VDotProduct( vector_3 *a, vector_3 *b )
29 {
30 	return ( ( a->x * b->x ) + ( a->y * b->y ) + ( a->z * b->z ) );
31 }
32 
33 
VGetNormal(vector_3 * a)34 vector_3 VGetNormal( vector_3 *a )
35 {
36 	vector_3 c;
37 	const float length = VDotProduct(a, a);
38 	if (length == 0)
39 	{
40 		c.x = 0;
41 		c.y = 0;
42 		c.z = 0;
43 	}
44 	else
45 	{
46 		const float OneOverLength = 1 / sqrt(length);
47 		c.x = OneOverLength * a->x;
48 		c.y = OneOverLength * a->y;
49 		c.z = OneOverLength * a->z;
50 	}
51 	return ( c );
52 }
53