UGDK  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
convexpolygon.h
Go to the documentation of this file.
1 #ifndef PYRAMIDWORKS_GEOMETRY_CONVEXPOLYGON_H_
2 #define PYRAMIDWORKS_GEOMETRY_CONVEXPOLYGON_H_
3 
5 #include <vector>
6 
7 namespace pyramidworks {
8 namespace geometry {
9 
11 class ConvexPolygon : public GeometricShape {
12  public:
16  ConvexPolygon(const std::vector<ugdk::math::Vector2D>& vertices);
17 
18  void set_vertices(const std::vector<ugdk::math::Vector2D>& vertices) { vertices_ = vertices; this->CalculateSize(); }
19 
20  bool Intersects(const ugdk::math::Vector2D& this_pos, const GeometricShape *obj, const ugdk::math::Vector2D& that_pos) const;
21  bool Intersects(const ugdk::math::Vector2D& this_pos, const Rect *obj, const ugdk::math::Vector2D& that_pos) const;
22  bool Intersects(const ugdk::math::Vector2D& this_pos, const Circle *obj, const ugdk::math::Vector2D& that_pos) const;
23  bool Intersects(const ugdk::math::Vector2D& this_pos, const ConvexPolygon *obj, const ugdk::math::Vector2D& that_pos) const;
25 
26  double bbox_width() { return bbox_half_width_*2; }
27  double bbox_height() { return bbox_half_height_*2; }
28 
29  private:
30  void CalculateSize();
31 
34 
41  bool CheckAxisSeparation(const std::vector<ugdk::math::Vector2D>& obj1, const ugdk::math::Vector2D& obj1pos,
42  const std::vector<ugdk::math::Vector2D>& obj2, const ugdk::math::Vector2D& obj2pos) const;
43  bool AxisSeparationTest(const ugdk::math::Vector2D& p1, const ugdk::math::Vector2D& p2, const ugdk::math::Vector2D& ref,
44  const std::vector<ugdk::math::Vector2D>& obj, const ugdk::math::Vector2D& obj2pos) const;
45  bool InsideSameSpace(const ugdk::math::Vector2D& line, const ugdk::math::Vector2D& point) const;
46 
47  std::vector<ugdk::math::Vector2D> vertices_;
48  double bbox_half_width_, bbox_half_height_;
49 };
50 
51 } // namespace geometry
52 } // namespace pyramidworks
53 
54 
55 #endif /* PYRAMIDWORKS_GEOMETRY_CONVEXPOLYGON_H_ */
Definition: vector2D.h:18
void set_vertices(const std::vector< ugdk::math::Vector2D > &vertices)
Definition: convexpolygon.h:18
Definition: collisionclass.h:13
ConvexPolygon(const std::vector< ugdk::math::Vector2D > &vertices)
bool Intersects(const ugdk::math::Vector2D &this_pos, const GeometricShape *obj, const ugdk::math::Vector2D &that_pos) const
Checks if this shape intersects another shape.
Definition: circle.h:11
ugdk::structure::Box< 2 > GetBoundingBox(const ugdk::math::Vector2D &position) const
Returns a bounding box for this shape.
Definition: geometricshape.h:13
A convex polygon, one type of GeometricShape. This determines a polygon conposed by at least 3 vertic...
Definition: convexpolygon.h:11
double bbox_width()
Definition: convexpolygon.h:26
double bbox_height()
Definition: convexpolygon.h:27
Definition: rect.h:11