Chipmunk++
 All Classes Functions Variables Pages
space.hpp
1 #pragma once
2 
3 #include "shape.hpp"
4 #include "vect.hpp"
5 #include "memory.hpp"
6 
7 #include <vector>
8 
9 #pragma GCC visibility push(default)
10 namespace cp {
11  typedef std::function<void(std::shared_ptr<Shape>, Float, Vect)> SegmentQueryFunc;
12 
13  class Body;
14 
16  class Space {
17  public:
18  Space();
19  ~Space();
20  operator cpSpace*();
21  void add(std::shared_ptr<Shape>);
22  void add(std::shared_ptr<Body>);
23  void remove(std::shared_ptr<Shape>);
24  void remove(std::shared_ptr<Body>);
25 
28  Vect getGravity() const;
29  void setGravity(const Vect&);
30 
31  void step(Float);
32  void segmentQuery(Vect a, Vect b, Layers, Group, SegmentQueryFunc) const;
33  std::shared_ptr<Shape> segmentQueryFirst(Vect a, Vect b, Layers, Group, SegmentQueryInfo* = nullptr) const;
34  std::shared_ptr<Shape> pointQueryFirst(Vect p, Layers, Group) const;
35  private:
36  Space(const Space&);
37  const Space& operator=(const Space&);
38  static void segmentQueryFunc(cpShape*, cpFloat, cpVect, void*);
39  std::shared_ptr<Shape> findPtr(cpShape*) const;
40 
41  cpSpace* space;
42  std::vector<std::shared_ptr<Shape>> shapes;
43  std::vector<std::shared_ptr<Body>> bodies;
44 
45  struct SegmentQueryData {
46  const Space* const self;
47  SegmentQueryFunc& func;
48  };
49  public:
50  std::shared_ptr<Body> staticBody;
51  };
52 }
53 #pragma GCC visibility pop