载入中...
搜索中...
未找到
Fluid2D.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
5#include <cstdint>
6#include <unordered_map>
7#include <vector>
8
9namespace eve::graphics {
10class Graphics;
11}
12
13namespace eve::physics {
14
20public:
22 explicit Fluid2D(int capacity = 512);
24 ~Fluid2D();
25
26 Fluid2D(const Fluid2D &) = delete;
27 Fluid2D &operator=(const Fluid2D &) = delete;
28
30 void update(float dt);
31
33 void setGravity(float gx, float gy);
35 float getGravityX() const { return gravityX_; }
37 float getGravityY() const { return gravityY_; }
38
40 void setSmoothingRadius(float radius);
42 float getSmoothingRadius() const { return h_; }
43
45 void setRestDensity(float density);
47 float getRestDensity() const { return restDensity_; }
48
50 void setPressureStiffness(float k);
52 float getPressureStiffness() const { return pressureK_; }
53
55 void setNearPressureStiffness(float k);
57 float getNearPressureStiffness() const { return nearPressureK_; }
58
60 void setViscosity(float viscosity);
62 float getViscosity() const { return viscosity_; }
63
65 void setIterations(int iterations);
67 int getIterations() const { return iterations_; }
68
70 void setBounds(float x, float y, float w, float h);
72 void clearBounds();
73
78 int emit(float x, float y, int count, float vx = 0.f, float vy = 0.f);
79
81 void clear();
82
87 void interactAt(float x, float y, float radius, float strength);
88
90 void setColor(float r, float g, float b, float a = 1.f);
92 float getColorR() const { return colorR_; }
94 float getColorG() const { return colorG_; }
96 float getColorB() const { return colorB_; }
98 float getColorA() const { return colorA_; }
99
101 void setParticleSize(float size);
103 float getParticleSize() const { return particleSize_; }
104
106 void draw(graphics::Graphics *gfx);
107
109 int getCapacity() const { return capacity_; }
111 int getParticleCount() const { return static_cast<int>(particles_.size()); }
113 float getParticleX(int index) const;
115 float getParticleY(int index) const;
117 float getParticleVx(int index) const;
119 float getParticleVy(int index) const;
120
122 void destroy();
123
124private:
125 struct Particle {
126 float x = 0.f, y = 0.f;
127 float vx = 0.f, vy = 0.f;
128 float density = 0.f;
129 };
130
131 void rebuildHash();
132 void applyViscosity(float dt);
133 void doubleDensityRelaxation();
134 void collideBounds();
135 bool validIndex(int index) const;
136 int64_t cellKey(int cx, int cy) const;
137
138 int capacity_ = 512;
139 float gravityX_ = 0.f;
140 float gravityY_ = 980.f;
141 float h_ = 18.f;
142 float restDensity_ = 4.f;
143 float pressureK_ = 0.5f;
144 float nearPressureK_ = 0.5f;
145 float viscosity_ = 0.12f;
146 int iterations_ = 3;
147
148 bool hasBounds_ = false;
149 float boundX_ = 0.f, boundY_ = 0.f, boundW_ = 0.f, boundH_ = 0.f;
150
151 float interactX_ = 0.f, interactY_ = 0.f;
152 float interactRadius_ = 0.f;
153 float interactStrength_ = 0.f;
154
155 float colorR_ = 0.25f, colorG_ = 0.55f, colorB_ = 0.95f, colorA_ = 0.85f;
156 float particleSize_ = 5.f;
157
158 bool destroyed_ = false;
159
160 std::vector<Particle> particles_;
161 std::unordered_map<int64_t, std::vector<int>> hash_;
162};
163
164} // namespace eve::physics
float w
Definition AnimClip.cpp:738
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
float cx
Definition CardTypes.cpp:33
float cy
Definition CardTypes.cpp:34
#define EVENGINE_API_WORLD
Definition Export.h:109
tensor::Graph g
Definition GpuGraph.cpp:7
std::uint32_t capacity
double r
int h
void(* destroy)(void *)
MeleePoint3 b
Definition MeleeHit.cpp:41
MeleePoint3 a
Definition MeleeHit.cpp:40
MeshVfxBatchedDraw draw
float radius
std::uint32_t count
int iterations
Definition TreeMesh.cpp:311
float size
Definition TreeMesh.cpp:156
uint32_t index
float vy
float vx
Interactive 2D particle fluid (double-density relaxation) in pixel space. Script-owned; independent o...
Definition Fluid2D.h:19
Fluid2D(const Fluid2D &)=delete
float getNearPressureStiffness() const
Returns the near pressure stiffness.
Definition Fluid2D.h:57
float getGravityY() const
Returns the gravity y.
Definition Fluid2D.h:37
float getColorA() const
Returns the color a.
Definition Fluid2D.h:98
int getIterations() const
Returns the iterations.
Definition Fluid2D.h:67
float getRestDensity() const
Returns the rest density.
Definition Fluid2D.h:47
float getGravityX() const
Returns the gravity x.
Definition Fluid2D.h:35
int getParticleCount() const
Returns the particle count.
Definition Fluid2D.h:111
float getColorR() const
Returns the color r.
Definition Fluid2D.h:92
float getSmoothingRadius() const
Returns the smoothing radius.
Definition Fluid2D.h:42
float getColorG() const
Returns the color g.
Definition Fluid2D.h:94
Fluid2D & operator=(const Fluid2D &)=delete
int getCapacity() const
Returns the capacity.
Definition Fluid2D.h:109
float getColorB() const
Returns the color b.
Definition Fluid2D.h:96
float getParticleSize() const
Returns the particle size.
Definition Fluid2D.h:103
float getViscosity() const
Returns the viscosity.
Definition Fluid2D.h:62
float getPressureStiffness() const
Returns the pressure stiffness.
Definition Fluid2D.h:52
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition Animation.h:25
Optional physics backend for vehicle mobility and body attach.
Definition Climbing.h:36