blob: 69adde96a4335b078263f521132a9418a14ef4f7 (
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
35
36
37
|
#include <u.h>
#include <libc.h>
#include <stdio.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);
void collideball(Ball *b1, const Ball *b2);
void collidewall(Ball *b, Rectangle wall);
|