diff --git a/physics.c b/physics.c index 5336df2..bc2eff3 100644 --- a/physics.c +++ b/physics.c @@ -1,5 +1,5 @@ - +#include #include "graphics.h" #include #include @@ -23,21 +23,14 @@ typedef struct Link { } Link; - -void draw_link(Canvas* c, Link* l){ - line(c, l->a->x, l->a->y, l->b->x, l->b->y); -} - -void update_point(Point* p){ - uint tempx = p->x; - uint tempy = p->y; - p->x += (p->x - p->px) + p->fx; - p->y += (p->y - p->py) + p->fy; - p->px = tempx; - p->py = tempy; -} +void draw_link(Canvas* c, Link* l); +void update_point(Point* p); + +/* + * main + */ int main(){ char *data = malloc(40*40); Canvas c = {40, 40, data}; @@ -64,9 +57,26 @@ int main(){ usleep(1000000/FRAMERATE); } - - return 0; } +/* + * Draws a line between linked points + */ +void draw_link(Canvas* c, Link* l){ + line(c, l->a->x, l->a->y, l->b->x, l->b->y); +} + +/* + * Updates the position of a point + * the update is based on its position, its position in the previous frame (px, py) and the forces acting upon it (fx,fy) + */ +void update_point(Point* p){ + uint tempx = p->x; + uint tempy = p->y; + p->x += (p->x - p->px) + p->fx; + p->y += (p->y - p->py) + p->fy; + p->px = tempx; + p->py = tempy; +}