Dura2D  v0.1.0
An educational 2D game physics library
Loading...
Searching...
No Matches
d2Shape.h
Go to the documentation of this file.
1#ifndef SHAPE_H
2#define SHAPE_H
3
4#include "d2api.h"
5#include "d2Math.h"
6#include <vector>
7
9
11{
14 BOX
15};
16
18{
19 virtual ~d2Shape() = default;
20
21 virtual d2ShapeType GetType() const = 0;
22
23 // clone with block allocator as parameter
24 virtual d2Shape *Clone() const = 0;
25
26 virtual void UpdateVertices(const d2Transform &transform) = 0;
27
28 virtual real GetMomentOfInertia() const = 0;
29};
30
32{
34
35 d2CircleShape(const real radius);
36
37 virtual ~d2CircleShape();
38
39 d2ShapeType GetType() const override;
40
41 d2Shape *Clone() const override;
42
43 void UpdateVertices(const d2Transform &transform) override { (void)transform; };
44
45 real GetMomentOfInertia() const override;
46};
47
49{
52
54
57
58 d2PolygonShape() = default;
59
60 d2PolygonShape(const d2Vec2* vertices, int vertexCount);
61
62 virtual ~d2PolygonShape();
63
64 d2ShapeType GetType() const override;
65
66 d2Shape *Clone() const override;
67
68 d2Vec2 EdgeAt(int index) const;
69
70 real FindMinSeparation(const d2PolygonShape *other, int &indexReferenceEdge, d2Vec2 &supportPoint) const;
71
72 int FindIncidentEdge(const d2Vec2 &normal) const;
73
74 int ClipSegmentToLine(const std::vector<d2Vec2> &contactsIn,
75 std::vector<d2Vec2> &contactsOut,
76 const d2Vec2 &c0,
77 const d2Vec2 &c1) const;
78
80
82
83 real GetMomentOfInertia() const override;
84
85 void UpdateVertices(const d2Transform &transform) override;
86
87 friend class d2World;
88};
89
91{
92 d2BoxShape(real width, real height);
93
94 virtual ~d2BoxShape();
95
96 d2ShapeType GetType() const override;
97
98 d2Shape *Clone() const override;
99
100 real GetMomentOfInertia() const override;
101};
102
103#endif
Represents a 2D physics world.
Definition d2World.h:22
CIRCLE
Definition d2Shape.h:12
enum D2_API d2ShapeType
Definition d2Shape.h:11
POLYGON
Definition d2Shape.h:13
float real
Definition d2Types.h:10
#define D2_API
Definition d2api.h:27
Definition d2Shape.h:91
d2BoxShape(real width, real height)
d2ShapeType GetType() const override
real GetMomentOfInertia() const override
d2Shape * Clone() const override
virtual ~d2BoxShape()
Definition d2Shape.h:32
real GetMomentOfInertia() const override
d2CircleShape(const real radius)
d2ShapeType GetType() const override
d2Shape * Clone() const override
real radius
Definition d2Shape.h:33
void UpdateVertices(const d2Transform &transform) override
Definition d2Shape.h:43
virtual ~d2CircleShape()
Definition d2Shape.h:49
virtual ~d2PolygonShape()
int FindIncidentEdge(const d2Vec2 &normal) const
real GetMomentOfInertia() const override
real FindMinSeparation(const d2PolygonShape *other, int &indexReferenceEdge, d2Vec2 &supportPoint) const
d2PolygonShape(const d2Vec2 *vertices, int vertexCount)
void UpdateVertices(const d2Transform &transform) override
d2Vec2 * localVertices
Definition d2Shape.h:55
d2Vec2 * worldVertices
Definition d2Shape.h:56
d2Vec2 PolygonCentroid() const
int m_vertexCount
Definition d2Shape.h:53
real PolygonArea() const
d2ShapeType GetType() const override
d2PolygonShape()=default
real height
Definition d2Shape.h:51
int ClipSegmentToLine(const std::vector< d2Vec2 > &contactsIn, std::vector< d2Vec2 > &contactsOut, const d2Vec2 &c0, const d2Vec2 &c1) const
real width
Definition d2Shape.h:50
d2Vec2 EdgeAt(int index) const
d2Shape * Clone() const override
Definition d2Shape.h:18
virtual real GetMomentOfInertia() const =0
virtual d2ShapeType GetType() const =0
virtual d2Shape * Clone() const =0
virtual ~d2Shape()=default
virtual void UpdateVertices(const d2Transform &transform)=0
Represents a transformation in 2D space.
Definition d2Math.h:309
Represents a 2D vector.
Definition d2Math.h:22