diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2024-09-19 20:11:32 -0400 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2024-09-19 20:11:32 -0400 |
| commit | d439ed77546a00929ddd55bf44d65b448d9d520c (patch) | |
| tree | cf1070d32e766c0fe5d753aebee840f0be67756f /vec.c | |
| parent | 8944ad075c6b12bbda1273ec31efade801892c19 (diff) | |
| download | balls-d439ed77546a00929ddd55bf44d65b448d9d520c.zip | |
pretty good collisions
Diffstat (limited to 'vec.c')
| -rw-r--r-- | vec.c | 16 |
1 files changed, 10 insertions, 6 deletions
@@ -6,23 +6,23 @@ vsub(Vec v1, Vec v2) { } Vec -vmuls(Vec v, int a) { +vmuls(Vec v, double a) { return V(v.x*a, v.y*a); } Vec -vdivs(Vec v, int a) { +vdivs(Vec v, double a) { if (a == 0) return V(0, 0); return V(v.x/a, v.y/a); } -int +double vdot(Vec v1, Vec v2) { return v1.x*v2.x + v1.y*v2.y; } -int +double vlen(Vec v) { return sqrt(v.x*v.x + v.y*v.y); } @@ -40,12 +40,16 @@ ptaddv(Point p, Vec v) { } Vec -V(int x, int y) { +V(double x, double y) { Vec v = {x, y}; return v; } Vec Vpt(Point p, Point q) { - return V(p.x-q.x, p.y-q.y); + double dx, dy; + + dx = (double) q.x - (double) p.x; + dy = (double) q.y - (double) p.y; + return V(dx, dy); } |