main moved to top and comments added for functions
This commit is contained in:
42
physics.c
42
physics.c
@@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
#include "graphics.h"
|
#include "graphics.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -23,21 +23,14 @@ typedef struct Link {
|
|||||||
} Link;
|
} Link;
|
||||||
|
|
||||||
|
|
||||||
|
void draw_link(Canvas* c, Link* l);
|
||||||
void draw_link(Canvas* c, Link* l){
|
void update_point(Point* p);
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* main
|
||||||
|
*/
|
||||||
int main(){
|
int main(){
|
||||||
char *data = malloc(40*40);
|
char *data = malloc(40*40);
|
||||||
Canvas c = {40, 40, data};
|
Canvas c = {40, 40, data};
|
||||||
@@ -64,9 +57,26 @@ int main(){
|
|||||||
usleep(1000000/FRAMERATE);
|
usleep(1000000/FRAMERATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user