summaryrefslogtreecommitdiffstats
path: root/balls.h
blob: 8e66ae0862154f306f729e3aefcefc0c285ab09b (plain) (blame)
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
#include <u.h>
#include <libc.h>
#include <draw.h>
#include <cursor.h>

enum {
	RADIUS = 20,
};

typedef struct {
	double x, y;
} Vec;

typedef struct {
	Point p1, p2;
} Line;

typedef struct {
	Point p; /* position */
	Vec v; /* velocity */
	double m; /* mass */
} Ball;

Vec vsub(Vec v1, Vec v2);
Vec vmuls(Vec v, double a);
Vec vdivs(Vec v, double a);
double vdot(Vec v1, Vec v2);
double vlen(Vec v);
Vec unitnorm(Vec v);
Point ptaddv(Point p, Vec v);
Vec V(double x, double y);
Vec Vpt(Point p, Point q);

int iscollision(Point p, Point q);