viewing source for "vector.c"

last commit

commit 2fcfc3b2e8e18bd4ab667b82d939cc2ba9b6a5d3 Author: Andrew Rader <andrew.r.rader@gmail.com> Date: Sun Jan 13 09:25:46 2008 -0800
Initial Commit

source code

01: #include <math.h>
02: #include "vector.h"
03: 
04: void vect_add( vector *a, vector *b ) {
05:     a->x += b->x;
06:     a->y += b->y;
07:     a->z += b->z;
08: }
09: 
10: void vect_addf( vector *a, float f ) {
11:     a->x += f;
12:     a->y += f;
13:     a->z += f;
14: }
15: 
16: void vect_sub( vector *a, vector *b ) {
17:     a->x -= b->x;
18:     a->y -= b->y;
19:     a->z -= b->z;
20: }
21: 
22: void vect_subf( vector *a, float f ) {
23:     a->x -= f;
24:     a->y -= f;
25:     a->z -= f;
26: }
27: 
28: void vect_mult( vector *a, vector *b ) {
29:     a->x *= b->x;
30:     a->y *= b->y;
31:     a->z *= b->z;
32: }
33: 
34: void vect_multf( vector *a, float f ) {
35:     a->x *= f;
36:     a->y *= f;
37:     a->z *= f;
38: }
39: 
40: float vect_length( vector *v ) {
41:     return sqrtf( v->x*v->x + v->y*v->y + v->z*v->z );
42: }
43: 
44: void vect_normalize( vector *v ) {
45:     float length = 0.0f;
46:     float tmp = 0.0f;
47: 
48:     length = sqrtf( v->x * v->x + v->y * v->y + v->z * v->z );
49:     tmp = 1.0f / length;
50: 
51:     v->x *= tmp;
52:     v->y *= tmp;
53:     v->z *= tmp;
54: }
55: 
56: float vect_dot( vector *a, vector *b ) {
57:     return( a->x * b->x + a->y * b->y + a->z * b->z );
58: }
59: 
60: inline void vect_copy( vector *dest, vector *src ) {
61:     dest->x = src->x;
62:     dest->y = src->y;
63:     dest->z = src->z;
64: }