Gamedev Framework (gf)  0.12.0
A C++14 framework for 2D games
PhysicsGeometry.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016-2019 Julien Bernard
4  *
5  * This software is provided 'as-is', without any express or implied
6  * warranty. In no event will the authors be held liable for any damages
7  * arising from the use of this software.
8  *
9  * Permission is granted to anyone to use this software for any purpose,
10  * including commercial applications, and to alter it and redistribute it
11  * freely, subject to the following restrictions:
12  *
13  * 1. The origin of this software must not be misrepresented; you must not
14  * claim that you wrote the original software. If you use this software
15  * in a product, an acknowledgment in the product documentation would be
16  * appreciated but is not required.
17  * 2. Altered source versions must be plainly marked as such, and must not be
18  * misrepresented as being the original software.
19  * 3. This notice may not be removed or altered from any source distribution.
20  */
21 #ifndef GF_PHYSICS_GEOMETRY_H
22 #define GF_PHYSICS_GEOMETRY_H
23 
24 #include "Circ.h"
25 #include "Polygon.h"
26 #include "Rect.h"
27 #include "Vector.h"
28 #include "Matrix.h"
29 
30 namespace gf {
31 #ifndef DOXYGEN_SHOULD_SKIP_THIS
32 inline namespace v1 {
33 #endif
34 
35  struct RenderStates;
36  class RenderTarget;
37 
46  class GF_API PhysicsGeometry {
47  public:
51  enum class Type {
52  Circle,
53  Polygon,
54  };
55 
62  : m_type(type)
63  {
64 
65  }
66 
70  virtual ~PhysicsGeometry();
71 
75  Type getType() const {
76  return m_type;
77  }
78 
84  virtual float getArea() const = 0;
85 
93  virtual CircF getBoundingCircle() const = 0;
94 
103  virtual void renderAt(RenderTarget& target, const RenderStates& states, Vector2f position, float angle) const = 0;
104 
105  private:
106  Type m_type;
107  };
108 
112  class GF_API CircleGeometry : public PhysicsGeometry {
113  public:
121  CircleGeometry(float radius);
122 
128  CircleGeometry(CircF circle);
129 
135  const CircF& get() const;
136 
137  virtual float getArea() const override;
138  virtual CircF getBoundingCircle() const override;
139  virtual void renderAt(RenderTarget& target, const RenderStates& states, Vector2f position, float angle) const override;
140 
141  private:
142  CircF m_circle;
143  };
144 
150  class GF_API PolygonGeometry : public PhysicsGeometry {
151  public:
157  PolygonGeometry(Polygon polygon);
158 
167 
173  PolygonGeometry(RectF rectangle);
174 
180  const Polygon& get() const;
181 
182  virtual float getArea() const override;
183  virtual CircF getBoundingCircle() const override;
184  virtual void renderAt(RenderTarget& target, const RenderStates& states, Vector2f position, float angle) const override;
185 
186  private:
187  void computeBoundingCircle();
188 
189  private:
190  Polygon m_polygon;
191  CircF m_boundingCircle;
192  };
193 
194 #ifndef DOXYGEN_SHOULD_SKIP_THIS
195 }
196 #endif
197 }
198 
199 #endif // GF_PHYSICS_GEOMETRY_H
Type
The type of geometry.
Definition: PhysicsGeometry.h:51
Base class for all render targets (window, texture, ...)
Definition: RenderTarget.h:66
A circle physics geometry.
Definition: PhysicsGeometry.h:112
Define the states used for drawing to a RenderTarget.
Definition: RenderStates.h:82
A polygon physics geometry.
Definition: PhysicsGeometry.h:150
PhysicsGeometry(Type type)
Constructor.
Definition: PhysicsGeometry.h:61
Type getType() const
Get the type of the geometry.
Definition: PhysicsGeometry.h:75
The namespace for gf classes.
Definition: Action.h:35
float angle(Direction direction)
Get an angle from a direction.
A convex polygon.
Definition: Polygon.h:46
The geometry of a physics body.
Definition: PhysicsGeometry.h:46