-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrigidbody.h
94 lines (80 loc) · 2.43 KB
/
rigidbody.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#pragma once
#include <glm/trigonometric.hpp>
#include <Box2D/Box2D.h>
#include <Vortex2D/Vortex2D.h>
class Box2DSolver : public Vortex2D::Fluid::RigidBodySolver
{
public:
Box2DSolver(b2World& world);
void Step(float delta) override;
private:
b2World& mWorld;
};
class Box2DRigidbody : public Vortex2D::Fluid::RigidBody
{
public:
Box2DRigidbody(const Vortex2D::Renderer::Device& device,
const glm::ivec2& size,
Vortex2D::Renderer::Drawable& drawable,
Vortex2D::Fluid::RigidBody::Type type,
b2Body* body);
private:
void ApplyForces();
void ApplyVelocities();
b2Body* mBody;
};
class Rigidbody
{
public:
virtual ~Rigidbody() {}
void SetTransform(const glm::vec2& pos, float angle);
std::unique_ptr<Box2DRigidbody> mRigidbody;
b2Body* mBody;
};
class PolygonRigidbody : public Rigidbody
{
public:
PolygonRigidbody(const Vortex2D::Renderer::Device& device,
const glm::ivec2& size,
b2World& rWorld,
b2BodyType rType,
Vortex2D::Fluid::RigidBody::Type type,
const std::vector<glm::vec2>& points,
float density = 1.0f);
Vortex2D::Fluid::Polygon mPolygon;
};
class RectangleRigidbody : public PolygonRigidbody
{
public:
RectangleRigidbody(const Vortex2D::Renderer::Device& device,
const glm::ivec2& size,
b2World& rWorld,
b2BodyType rType,
Vortex2D::Fluid::RigidBody::Type type,
const glm::vec2& halfSize,
float density = 1.0f)
: PolygonRigidbody(device,
size,
rWorld,
rType,
type,
{{-halfSize.x, -halfSize.y},
{halfSize.x, -halfSize.y},
{halfSize.x, halfSize.y},
{-halfSize.x, halfSize.y}},
density)
{
}
};
class CircleRigidbody : public Rigidbody
{
public:
CircleRigidbody(const Vortex2D::Renderer::Device& device,
const glm::ivec2& size,
b2World& rWorld,
b2BodyType rType,
Vortex2D::Fluid::RigidBody::Type type,
const float radius,
float density = 1.0f);
Vortex2D::Fluid::Circle mCircle;
};