aboutsummaryrefslogtreecommitdiff
path: root/src/1-5-unit-vec.c
blob: 1f3acbbec79146482e595855835b4303e50d2336 (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 <stdbool.h>
#include <vectorlib.c>

#include <SDL2/SDL.h>
#include <SDL2/SDL_video.h>

#define PROJECT_NAME "vectors-unit vec"
#define obj_n 1

typedef struct {
    Point pos;
} OBJECT_INER;

typedef struct OBJECT {
    OBJECT_INER *objs[obj_n];
} OBJECT;

#include <init.h>

void constructor(int w, int h, OBJECT_INER *obj){
    obj->pos.x = (float)w/2;
    obj->pos.y = (float)h/2;
}

void init_stuffs(int w, int h, OBJECT_INER *objs, STUFFS *stuff){
    constructor(w,h,&objs[0]);
}

void normalize(Point *p){
    point_set_mag(p, 1);
}

void draw(SDL_Renderer* renderer,SDL_Window* window, STUFFS *stuff){
    SDL_SetRenderDrawColor(renderer,0,0,0,255);
    SDL_RenderClear(renderer);

    Point pos = { 300,300 };
    Point mouse = {stuff->mx, stuff->my};

    Point v = {
        mouse.x - pos.x,
        mouse.y - pos.y,
    };

    //float mag = magnitude(v.x, v.y);
    //point_div(&v,&(Point){mag,mag});

    //normalize(&v);

    //point_mul(&v,&(Point){50,50});

    point_set_mag(&v, 50);

    SDL_SetRenderDrawColor(renderer,150,50,255,255);
    SDL_RenderDrawLine(renderer,stuff->width/2,stuff->height/2,v.x + (float)stuff->width/2,v.y + (float)stuff->height/2);

	SDL_RenderPresent(renderer);
}

#include <init.c>