blob: 86192dcb8b28340229947dcc473eb631772bb70b (
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
|
#include "math.h"
#include "../util/assert.h"
#include "../core/mem.h"
void vec2_scale(Vec2* v, float k, Vec2* out) {
ssr_assert(v && out);
out->x = v->x * k;
out->y = v->y * k;
}
void vec2_plus(Vec2* v1, Vec2* v2, Vec2* out) {
ssr_assert(v1 && v2 && out);
out->x = v1->x + v2->x;
out->y = v1->y + v2->y;
}
void vec2_offset(Vec2* v, float offset, Vec2* out) {
ssr_assert(v && out);
out->x = v->x + offset;
out->y = v->y + offset;
}
float vec2_dot(Vec2* v1, Vec2* v2) {
ssr_assert(v1 && v2);
float d = v1->x * v2->x + v1->y * v2->y;
return d;
}
void vec2_tostring(Vec2* v, char buf[]) {
sprintf(buf, "%8.3f %8.3f", v->x, v->y);
}
void vec2_print(Vec2* v) {
vec2_tostring(v, printbuffer);
printf("%s", printbuffer);
}
|