-
Notifications
You must be signed in to change notification settings - Fork 0
/
pbd_test.h
103 lines (79 loc) · 2.94 KB
/
pbd_test.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
95
96
97
98
99
100
101
102
#pragma once
#include "obj_model.h"
#include "utils/vec.h"
#include <atomic>
#include <vector>
void unified_pbd_init();
void unified_pbd_deinit();
void unified_pbd_update(float dt);
struct PBDUnifiedSimulation* unified_pbd_get();
void initialize_particle_positions(class SPHSceneObject* o);
class StaticCollisionComponent: public TransformComponent {
int id_ = -1;
struct CollisionWorld* world_ = nullptr;
virtual ~StaticCollisionComponent() {};
static void on_transformed(TransformComponent* );
static const ComponentType type_ = ComponentType::kPBDStaticCollision;
public:
virtual ComponentType GetType() const override { return type_; }
StaticCollisionComponent() {};
static StaticCollisionComponent* Create(const struct PBDUnifiedSimulation*sim, const vec2 &dim);
static void Destroy(StaticCollisionComponent* comp);
virtual void Initialize() override { state_ = kInitialized; }
virtual void Deinitialize() override { state_ = kUninitialized; }
};
class PBDStaticCollisionObj: public GameObject {
struct Tuple {
TransformComponent* tr_;
StaticCollisionComponent* coll_;
};
Tuple Tuple_;
public:
PBDStaticCollisionObj(const PBDUnifiedSimulation* sim, const vec2 &dim);
~PBDStaticCollisionObj();
// IEditorObject
virtual int GetIconID() const override { return 1; }
//
void addToSimulation(PBDUnifiedSimulation* sim);
void removeFromSimulation(PBDUnifiedSimulation* sim);
virtual const char* GetName() const override { return "unified pbd collision"; };
virtual void Update(float dt) override {};
};
class PBDVisComponent : public Component, public IRenderable {
RenderMesh* sphere_mesh_ = nullptr;
HGOSVERTEXDECLARATION vdecl_;
std::vector<HGOSBUFFER> inst_vb_;
mutable int cur_inst_vb_ = 0;
HGOSRENDERMATERIAL mat_;
std::atomic_bool b_initalized_rendering_resources;
public:
virtual IRenderable* getRenderableInterface() override { return this; }
virtual ComponentType GetType() const override { return ComponentType::kPBDVisComponent; }
// IRenderable
virtual void InitRenderResources() override;
virtual void DeinitRenderResources() override;
virtual void AddRenderPackets(struct RenderFrameContext* rfc) const override;
// this will be updated by Init/Deinit Render Resoueces
virtual void Initialize() override {}
virtual void Deinitialize() override {}
};
class PBDTestObject: public GameObject {
public:
typedef struct {
uint32_t contacts: 1;
uint32_t friction: 1;
// rotation of soft body particle
uint32_t sb_part_rot: 1;
uint32_t distance_constraints: 1;
} DDFlags;
DDFlags dbg_flags_;
private:
vec2 sim_dim_;
public:
struct PBDUnifiedSimulation* sim_;
static PBDTestObject* Create();
virtual void Update(float /*dt*/) override;
virtual const char* GetName() const override { return "PBD Scene"; };
virtual ~PBDTestObject();
const DDFlags& getDbgFlags() { return dbg_flags_; }
};