Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
964 - 1
#include "vector.h"
2
#include <math.h>
3
 
4
void vector_cross(const vector *a, const vector *b, vector *out)
5
{
6
        out->x = a->y * b->z - a->z * b->y;
7
        out->y = a->z * b->x - a->x * b->z;
8
        out->z = a->x * b->y - a->y * b->x;
9
}
10
 
11
float vector_dot(const vector *a, const vector *b)
12
{
13
  return a->x * b->x + a->y * b->y + a->z * b->z;
14
}
15
 
16
void vector_normalize(vector *a)
17
{
18
        float mag = sqrt(vector_dot(a, a));
19
        a->x /= mag;
20
        a->y /= mag;
21
        a->z /= mag;
22
}
23
 
24
float vector_magnitude(const vector *a)
25
{
26
        return sqrt(pow(a->x,2.0) + pow(a->y,2.0) + pow(a->z,2.0));
27
}