PowerBlocks SDK
 
Loading...
Searching...
No Matches
vec2.h
Go to the documentation of this file.
1
11
12#pragma once
13
14#include <math.h>
15#include <stdint.h>
16
17typedef struct {
18 int x;
19 int y;
20} vec2i;
21
22typedef struct {
23 int16_t x;
24 int16_t y;
25} vec2s16;
26
27typedef struct {
28 float x;
29 float y;
30} vec2;
31
32#define vec2i_new(x, y) ((vec2i){x, y})
33#define vec2s16_new(x, y) ((vec2s16){x, y})
34#define vec2_new(x, y) ((vec2){x, y})
35
36#define vec2_add(a, b) ((vec2){(a).x+(b).x, (a).y+(b).y})
37#define vec2_sub(a, b) ((vec2){(a).x-(b).x, (a).y-(b).y})
38#define vec2_dot(a, b) ((a).x * (b).x + (a).y * (b).y)
39#define vec2_magnitude_sq(a) vec2_dot(a, a)
40#define vec2_magnitude(a) (sqrtf(vec2_magnitude_sq(a)))
41#define vec2_muls(a, s) ((vec2){(a).x*s, (a).y*s})
42#define vec2_divs(a, s) ((vec2){(a).x/s, (a).y/s})
43
44#define vec2i_add(a, b) ((vec2i){(a).x+(b).x, (a).y+(b).y})
45#define vec2i_sub(a, b) ((vec2i){(a).x-(b).x, (a).y-(b).y})
46#define vec2i_dot(a, b) ((a).x * (b).x + (a).y * (b).y)
47#define vec2i_magnitude_sq(a) vec2_dot(a, a)
48#define vec2i_magnitude(a) (sqrtf(vec2_magnitude_sq(a)))
49#define vec2i_muls(a, s) ((vec2i){(a).x*s, (a).y*s})
50#define vec2i_divs(a, s) ((vec2i){(a).x/s, (a).y/s})
51
52#define vec2s16_add(a, b) ((vec2s16){(a).x+(b).x, (a).y+(b).y})
53#define vec2s16_sub(a, b) ((vec2s16){(a).x-(b).x, (a).y-(b).y})
54#define vec2s16_dot(a, b) ((a).x * (b).x + (a).y * (b).y)
55#define vec2s16_magnitude_sq(a) vec2_dot(a, a)
56#define vec2s16_magnitude(a) (sqrtf(vec2_magnitude_sq(a)))
57#define vec2s16_muls(a, s) ((vec2s16){(a).x*s, (a).y*s})
58#define vec2s16_divs(a, s) ((vec2s16){(a).x/s, (a).y/s})
Definition vec2.h:27
Definition vec2.h:17
Definition vec2.h:22