summaryrefslogtreecommitdiff
path: root/src/entity.h
blob: 25ac435a4077ef91fdd88360b2a02a87c2433ac2 (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
#ifndef ENTITY_H
#define ENTITY_H

#include <stdbool.h>
#include <stdint.h>

#ifndef M_PI
#define M_PI 3.141592f
#endif

struct Vec2d
{
    union
    {
        struct
        {
            float x;
            float y;
        };
        struct
        {
            float w;
            float h;
        };
        float xy[2];
        float d[2];
    };
};

struct Entity
{
    float mass;
    float size;
    struct Vec2d position;
    struct Vec2d velocity;
    uint32_t color;
};

void entity_accelerate(struct Entity *e, struct Vec2d *v);
struct Vec2d vec2d_add(struct Vec2d v0, struct Vec2d v1);
struct Vec2d vec2d_add_c(float x0, float y0, float x1, float y1);
struct Vec2d vec2d_al_to_xy(struct Vec2d v);
float vec2d_get_angle(float x, float y);
bool vec2d_equal(struct Vec2d v0, struct Vec2d v1);
float vec2d_get_length(float x, float y);
struct Vec2d vec2d_negate(struct Vec2d v);
struct Vec2d vec2d_normalize(float x, float y);
struct Vec2d vec2d_scale(struct Vec2d v, float s);
struct Vec2d vec2d_scale_c(float x, float y, float s);
struct Vec2d vec2d_xy_to_al(struct Vec2d v);

#endif