fluidvis
fluid.h
1 #ifndef _FLUID_H_
2 #define _FLUID_H_
3 
4 #include <sx/SX.h>
5 #include <sx/SXCore.h>
6 #include <sx/SXWidget.h>
7 #include <QSpinBox>
8 #include <QDoubleSpinBox>
9 #include <QLabel>
10 #include <QSlider>
11 #include <QDialog>
12 #include <QWidget>
13 #include <QMainWindow>
14 #include <QComboBox>
15 #include <QString>
16 #include <QLayout>
17 #include <QSize>
18 #include <list>
19 #include <string>
20 using namespace std;
21 using namespace sx;
22 
23 namespace fluid {
24 
25  enum GlyphState {
26  STATE_ALIVE,
27  STATE_DEAD,
28  STATE_READY
29  };
30 
31  class Glyph {
32  private:
33  static float maxStateSwitchTime;
34  static float maxRespawnDistance;
35  static float maxKillDistance;
36 
37  int id;
38 
39  GlyphState state;
40  float stateswitchtime;
41  UniformFloat *visibility;
42  Vector slowdownpos;
43  float recordslowdownpos;
44  float slowdowntime;
45 
46  float vorticity;
47 
48  unsigned int groupsize;
49  UniformVector *positions[13];
50  UniformVector *velocities[13];
51  Vector *oldpositions[13];
52  Vector *oldvelocities[13];
53  UniformFloat *glyphsize;
54 
55  Glyph(const Glyph &);
56  Glyph &operator = (const Glyph &);
57 
58  public:
59 
60  static void setMaxStateSwitchTime(float t);
61  static void setMaxRespawnDistance(float d);
62  static void setMaxKillDistance(float d);
63 
64  Glyph(unsigned int id);
65  ~Glyph();
66  unsigned int getID() const;
67 
68  void reset(const Vector &startpos, float *data);
69  const Vector &getMidpoint();
70  void updatePositions(const float *data);
71  void updateVelocities(const float *data);
72  void updateGlyphsize();
73 
74  unsigned int getGroupSize() const;
75  Vector &operator[](unsigned int i);
76 
77  float getVorticity() const;
78 
79  float length() const;
80 
81  float killDistance() const;
82  float respawnDistance() const;
83 
84  void setAlive();
85  void kill();
86  void updateStateSwitchTime(float deltatime);
87  GlyphState getState() const;
88  };
89 
90  bool glyphComparison(Glyph *g1, Glyph *g2);
91 
92  struct GridElement {
93  Glyph *glyph;
94  Vector position;
95  float length;
96  unsigned int x;
97  unsigned int y;
98  };
99 
101  private:
102  unsigned int cells_x;
103  unsigned int cells_y;
104 
105  list<GridElement *> elements;
106  list<GridElement *> **grid;
107 
108  StreamletGrid(const StreamletGrid &);
109  StreamletGrid &operator = (const StreamletGrid &);
110  public:
111  StreamletGrid(unsigned int cells_x, unsigned int cells_y);
112  ~StreamletGrid();
113  void put(Glyph *glyph);
114  void clear();
115  void collide();
116  bool respawnCollide(Glyph *g);
117  };
118 
119  enum ViewOption {
120  VIEW_STANDARD,
121  VIEW_VORTICITY
122  };
123 
125  public:
126  static unsigned int GROUPS;
127  static const unsigned int RESPAWN_WIDTH;
128  static const unsigned int RESPAWN_HEIGHT;
129  private:
130  bool pressed;
131  Vector mousepos;
132 
133  ViewOption view;
134 
135  float stopDrawTime;
136  float drawTime;
137  UniformVector *drawOrigin;
138 
139  bool updateGlyphCount;
140 
141  list<Glyph *> glyphs;
142  list<Glyph *> alive;
143  list<Glyph *> dead;
144  list<Glyph *> ready;
145  unsigned int respawn_pos_x;
146  unsigned int respawn_pos_y;
147 
148  StreamletGrid *grid;
149 
150  Vector getMinRespawnPos();
151  Vector getRespawnArea();
152 
153  FluidListener(const FluidListener &);
154  FluidListener &operator = (const FluidListener &);
155  public:
156  static ShadeX shadeX;
157 
158  void setMaxGlyphs(unsigned int glyphs);
159  void setView(ViewOption view);
160 
161  void setSolidMap(const string &path);
162  void setBackgroundMap(const string &path);
163 
164  FluidListener();
165  ~FluidListener();
166  void create(SXRenderArea &area);
167  void reshape(SXRenderArea &area);
168  void render(SXRenderArea &area);
169  void stop(SXRenderArea &area);
170  };
171 
172  class FloatSlider: public QWidget {
173 
174  Q_OBJECT
175 
176  signals:
177  void valueChanged(double);
178  private slots:
179  void updateSlider();
180  void updateText();
181  private:
182  QSlider *slider;
183  QDoubleSpinBox *text;
184 
185  FloatSlider(const FloatSlider &);
186  FloatSlider &operator = (const FloatSlider &);
187  public:
188  FloatSlider(const string &label, double value, double minVal, double maxVal, QWidget *parent = 0, Qt::WindowFlags f = 0);
189  ~FloatSlider();
190 
191  void setValue(double value);
192  double getValue() const;
193  void setMinimum(double minVal);
194  double getMinimum() const;
195  void setMaximum(double maxVal);
196  double getMaximum() const;
197  void setRange(double minVal, double maxVal);
198  };
199 
200  class IntSlider: public QWidget {
201 
202  Q_OBJECT
203 
204  signals:
205  void valueChanged(int);
206  private slots:
207  void updateSlider();
208  void updateText();
209  private:
210  QSlider *slider;
211  QSpinBox *text;
212 
213  IntSlider(const IntSlider &);
214  IntSlider &operator = (const IntSlider &);
215  public:
216  IntSlider(const string &label, int value, int minVal, int maxVal, QWidget *parent = 0, Qt::WindowFlags f = 0);
217  ~IntSlider();
218 
219  void setValue(int value);
220  int getValue() const;
221  void setMinimum(int minVal);
222  int getMinimum() const;
223  void setMaximum(int maxVal);
224  int getMaximum() const;
225  void setRange(int minVal, int maxVal);
226  };
227 
228  class WarningWidget: public QDialog {
229  Q_OBJECT
230  private:
231  WarningWidget(const WarningWidget &);
232  WarningWidget &operator = (const WarningWidget &);
233  public:
234  WarningWidget(const QString &title, const QString &text, QWidget *w);
235  };
236 
237  class FluidLayout: public QWidget {
238 
239  Q_OBJECT
240 
241  private:
242 
243  FluidLayout(const FluidLayout &);
244  FluidLayout &operator = (const FluidLayout &);
245 
246  public:
247 
248  FluidLayout();
249  QSize sizeHint() const;
250  bool hasHeightForWidth () const;
251  int heightForWidth(int w) const;
252 // bool hasHeightForWidth();
253 // int heightForWidth(int w) const;
254 
255  };
256 
257  class MainWidget: public QMainWindow {
258 
259  Q_OBJECT
260 
261  private:
262  FluidListener *fluidListener;
263 
264  IntSlider *maxGlyphs;
265  FloatSlider *maxStateSwitchTime;
266  FloatSlider *maxRespawnDistance;
267  FloatSlider *maxKillDistance;
268  QComboBox *viewOptions;
269 
270  MainWidget(const MainWidget &);
271  MainWidget &operator = (const MainWidget &);
272  public slots:
273 
274  void updateMaxGlyphs();
275  void updateMaxStateSwitchTime();
276  void updateMaxRespawnDistance();
277  void updateMaxKillDistance();
278  void updateViewOptions();
279  void loadSolid();
280  void loadBackground();
281  void showInfo();
282 
283  public:
284  static const string VIEWOPTION_STANDARD;
285  static const string VIEWOPTION_VORTICITY;
286 
287  MainWidget();
288  ~MainWidget();
289  };
290 
291 }
292 
293 #endif
Definition: SX.h:78
Definition: fluid.h:92
Definition: fluid.h:257
Definition: SX.h:160
Definition: fluid.h:31
Definition: SXMath.h:37
Definition: fluid.h:23
Definition: fluid.h:228
Definition: fluid.h:237
Definition: fluid.h:124
Definition: fluid.h:200
Definition: fluid.h:172
Definition: SXCore.h:1027
Definition: SX.h:522
Definition: SXCore.h:1147
Definition: fluid.h:100
Definition: Exception.h:13