1 #pragma once 2 3 #include "misc.h" 4 5 struct Circle 6 { 7 vec2 pos; 8 float r; CircleCircle9 Circle(vec2 _pos,float _r) : pos(_pos), r(_r) {} 10 }; 11 12 struct Line 13 { 14 vec2 p1,p2; LineLine15 Line(vec2 _p1,vec2 _p2) : p1(_p1), p2(_p2) {} 16 }; 17 18 // axis aligned bounding box 19 struct AABB 20 { 21 float x1,x2,y1,y2; 22 AABB(); 23 AABB(float _x1,float _x2,float _y1,float _y2); 24 AABB(vec2_ary_t const& verts); // compute from array of vertices 25 26 bool contains_point(const vec2 p); 27 28 void draw(void); 29 }; 30 31 // 2d oriented bounding box class for fast collisions, adapted from flipcode code-dump 32 class OBB { 33 vec2 corner[4]; 34 vec2 axis[2]; 35 double origin[2]; 36 37 bool overlaps1Way(const OBB& other) const; 38 void computeAxes(void); 39 40 public: 41 OBB(const AABB& aabb); // takes AABB and rotates it with current modelview matrix 42 43 bool overlaps(const OBB& other) const; 44 bool overlaps(const Circle& other) const; 45 46 void draw(bool highlight=false) const; // for debugging collisions 47 }; 48 49 bool CircleLineIntersect(const Circle& circle, const Line& line); 50