blob: 5a3e29d63340a5e37fd2cd03a84b0cc2c434cf66 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
#include "vector2f.h"
#include <SDL2/SDL.h>
vec2_t vec2_create(GLfloat x, GLfloat y)
{
vec2_t a = {x, y};
return a;
}
vec2_t vec2_add(const vec2_t* a, const vec2_t* b)
{
vec2_t c;
c.x = a->x + b->x;
c.y = a->y + b->y;
return c;
}
vec2_t vec2_sub(const vec2_t* a, const vec2_t* b)
{
vec2_t c;
c.x = a->x - b->x;
c.y = a->y - b->y;
return c;
}
vec2_t vec2_scalar_mul(const vec2_t* a, GLfloat scalar)
{
vec2_t c;
c.x = a->x * scalar;
c.y = a->y * scalar;
return c;
}
GLfloat vec2_dot_mul(const vec2_t* a, const vec2_t* b)
{
return ( (a->x * b->x) + (a->y * b->y) );
}
vec2_t vec2_cross_mul(const vec2_t* a, const vec2_t* b)
{
vec2_t c;
c.x = (a->x * b->y) - (a->y * b->x);
c.y = (a->y * b->x) - (a->x * b->y);
return c;
}
GLfloat vec2_length(vec2_t* a)
{
return SDL_sqrtf(SDL_pow(a->x, 2.0f) + SDL_pow(a->y, 2.0f) );
}
vec2_t vec2_normalize(vec2_t* a)
{
vec2_t b;
GLfloat length = vec2_length(a);
b.x = a->x / length;
b.y = a->y / length;
return b;
}
|