rt300@0
|
1 /*
|
rt300@0
|
2 * mesh.h
|
rt300@0
|
3 * springstructure
|
rt300@0
|
4 *
|
rt300@0
|
5 * Created by Robert Tubb on 07/06/2011.
|
rt300@0
|
6 * Copyright 2011 __MyCompanyName__. All rights reserved.
|
rt300@0
|
7 *
|
rt300@0
|
8 */
|
rt300@0
|
9
|
rt300@0
|
10 #ifndef _MESHH
|
rt300@0
|
11 #define _MESHH
|
rt300@0
|
12
|
rt300@0
|
13 #include <iostream>
|
rt300@0
|
14 #include "lump.h"
|
rt300@0
|
15 #include "scanpath.h"
|
rt300@0
|
16 #include "globalForces.h"
|
rt300@8
|
17 #include "json.h"
|
rt300@0
|
18
|
rt300@0
|
19 class Mesh{
|
rt300@0
|
20 public:
|
rt300@8
|
21 int dim1, dim2;
|
rt300@8
|
22
|
rt300@0
|
23 bool radial; // tells us if mesh is radial or not
|
rt300@0
|
24 // toggles
|
rt300@0
|
25 bool syrup;
|
rt300@0
|
26 bool home;
|
rt300@0
|
27
|
rt300@0
|
28 double propagationSpeed;
|
rt300@0
|
29
|
rt300@0
|
30 double k,m,f; // for stability check and asym
|
rt300@0
|
31
|
rt300@0
|
32 int numLumps;
|
rt300@0
|
33 int numSprings;
|
rt300@0
|
34
|
rt300@4
|
35 //Lump *lumps;
|
rt300@4
|
36 vector<Lump> lumps;
|
rt300@3
|
37 vector<Spring> springs;
|
rt300@3
|
38 //Spring *springs;
|
rt300@0
|
39
|
rt300@0
|
40 TwoVector centre;
|
rt300@0
|
41
|
rt300@0
|
42
|
rt300@0
|
43 // modes
|
rt300@0
|
44 enum constrainMode { CONSTRAIN_CORNERS, CONSTRAIN_EDGES,CONSTRAIN_EDGES_XY, CONSTRAIN_SINGLE_POINT, CONSTRAIN_SINGLE_POINT_X, CONSTRAIN_SINGLE_POINT_Y, CONSTRAIN_GRAB_REGION,CONSTRAIN_GRAB_REGION_X,CONSTRAIN_GRAB_REGION_Y, CONSTRAIN_ALL_X, CONSTRAIN_ALL_Y};
|
rt300@0
|
45 double GRAB_RANGE;
|
rt300@0
|
46
|
rt300@9
|
47 enum MeshType {SQUARE_MESH, SQUARE_CROSS_MESH, SPIDER_MESH, SPIDER_CROSS_MESH, DROPLET_MESH, LINE_MESH, TRIANGLE_MESH, GROUNDED_LINE_MESH, HOLED_SPIDER_MESH};
|
rt300@8
|
48 MeshType meshType;
|
rt300@0
|
49
|
rt300@0
|
50 // MEMBER FUNCTIONS
|
rt300@0
|
51 Mesh();
|
rt300@9
|
52 Mesh(Json::Value& savedMesh); // contructor using saved mesh
|
rt300@9
|
53
|
rt300@0
|
54 virtual ~Mesh();
|
rt300@0
|
55
|
rt300@0
|
56 void draw();
|
rt300@0
|
57
|
rt300@0
|
58 // INTERACTIONS
|
rt300@0
|
59 void resetAll();
|
rt300@0
|
60 void resetPositions();
|
rt300@0
|
61 void resetVelocities();
|
rt300@0
|
62 void resetEverything();
|
rt300@0
|
63
|
rt300@0
|
64 // excite via position, velocity force
|
rt300@0
|
65 // using shapes : noise, hamming, sine,
|
rt300@0
|
66 void hit(double dax,double day,int velocity = 100, GlobalForces::excitationTypes aEType = GlobalForces::POSITION,
|
rt300@0
|
67 GlobalForces::excitationShapes aEShape = GlobalForces::NOISE);
|
rt300@0
|
68 void spatialHarmonic(int aharm1 = 1, int aharm2 = 0);
|
rt300@0
|
69 void damp();
|
rt300@0
|
70 void forceField(double dax,double day,double strength);
|
rt300@0
|
71 void averagingFilter(double amt);
|
rt300@0
|
72
|
rt300@0
|
73 void grab(double x, double y, int touchID);
|
rt300@0
|
74 void drag(double ax,double ay, int touchID);
|
rt300@0
|
75 void unGrab(int touchID);
|
rt300@0
|
76
|
rt300@0
|
77 virtual void constrain(double x, double y, constrainMode aMode); // diff meshes will have diff edges
|
rt300@0
|
78 void unconstrain();
|
rt300@0
|
79 void unconstrain(double x, double y, constrainMode aMode);
|
rt300@0
|
80
|
rt300@0
|
81
|
rt300@0
|
82 // PARAMETER SETTINGS
|
rt300@0
|
83 void toggleSyrup();
|
rt300@0
|
84 void toggleSyrup(bool on);
|
rt300@0
|
85 void toggleSpringForces();
|
rt300@0
|
86 void toggleSpringForces(bool on);
|
rt300@0
|
87 void toggleGravity();
|
rt300@0
|
88 void toggleGravity(bool on);
|
rt300@0
|
89 void toggleHome(bool on);
|
rt300@0
|
90
|
rt300@0
|
91 void setRestLength();
|
rt300@0
|
92 void zeroRestLength();
|
rt300@0
|
93
|
rt300@0
|
94 void setPropagationSpeed(double aSpeed); // sets k and m to give a certain speed
|
rt300@0
|
95 void decreasePropagationSpeed();
|
rt300@0
|
96 void increasePropagationSpeed();
|
rt300@0
|
97 void setSpringConstant(double aK);
|
rt300@0
|
98 void setMass(double aM);
|
rt300@0
|
99 void setFriction(double aF);
|
rt300@0
|
100
|
rt300@0
|
101 // create varying constants
|
rt300@0
|
102 void setSpringConstantAsym(double aAsym);
|
rt300@0
|
103 void setMassAsym(double aAsym);
|
rt300@0
|
104 void setFrictionAsym(double aAsym);
|
rt300@0
|
105 void setZeroAudioLine();
|
rt300@0
|
106
|
rt300@0
|
107 // only for mouse cursor
|
rt300@0
|
108 void checkHover(double x, double y);
|
rt300@0
|
109
|
rt300@0
|
110 // SCANPATH STUFF
|
rt300@0
|
111 void clearScanPath();
|
rt300@0
|
112 void disconnectDraw(); // enables you to draw scanpths anywhere
|
rt300@0
|
113 int inscribeScanPath(double ax, double ay);
|
rt300@8
|
114
|
rt300@8
|
115 // inscribeScanPathFromJson
|
rt300@8
|
116
|
rt300@0
|
117 // called by scanpath.update wavetables
|
rt300@0
|
118 double getNextSample();
|
rt300@0
|
119
|
rt300@0
|
120 virtual void update();
|
rt300@8
|
121
|
rt300@8
|
122 // save stuff
|
rt300@8
|
123 Json::Value convertToJsonForSaving();
|
rt300@9
|
124 Json::Value saveConnectionsAsJson();
|
rt300@0
|
125 protected:
|
rt300@0
|
126
|
rt300@0
|
127 int prevLump;
|
rt300@0
|
128
|
rt300@0
|
129 // specific mesh shapes override these:
|
rt300@0
|
130
|
rt300@0
|
131 virtual void makeComponents(int adimension1, int adimension2);
|
rt300@0
|
132 virtual void setLumpPositions();
|
rt300@0
|
133 virtual void makeConnections();
|
rt300@0
|
134 virtual void makeDefaultScanPath();
|
rt300@9
|
135
|
rt300@9
|
136 // alternatively get from saved:
|
rt300@9
|
137
|
rt300@9
|
138 void setLumpPositionsFromJson(Json::Value lumpPositions);
|
rt300@9
|
139 void makeConnectionsFromJson(Json::Value connections);
|
rt300@9
|
140 void makeScanPathFromJson(Json::Value scanPathElements);
|
rt300@9
|
141 void constrainFromJson(Json::Value constrainedLumps);
|
rt300@0
|
142 // UTILS
|
rt300@0
|
143 TwoVector calculateCentre();
|
rt300@0
|
144 void connect(int springnum,int lumpnum);
|
rt300@0
|
145 void connect(int springnum,int lumpnum,int alumpnum2);
|
rt300@0
|
146 int getNearestLump(double ax,double ay);
|
rt300@0
|
147
|
rt300@0
|
148 };
|
rt300@0
|
149 //---------------------------------------------------------
|
rt300@0
|
150 class SpiderMesh : public Mesh{
|
rt300@0
|
151 public:
|
rt300@0
|
152 int numSpokes, numRings;
|
rt300@0
|
153
|
rt300@0
|
154 SpiderMesh(int aNumSpokes,int aNumRings);
|
rt300@0
|
155
|
rt300@0
|
156 virtual void constrain(double x, double y, constrainMode aMode);
|
rt300@0
|
157 virtual void makeComponents(int adimension1, int adimension2);
|
rt300@0
|
158 virtual void setLumpPositions();
|
rt300@0
|
159 virtual void makeConnections();
|
rt300@0
|
160 virtual void makeDefaultScanPath();
|
rt300@0
|
161 };
|
rt300@0
|
162 //---------------------------------------------------------
|
rt300@0
|
163 class HoledSpiderMesh : public Mesh{
|
rt300@0
|
164 public:
|
rt300@0
|
165 int numSpokes, numRings;
|
rt300@0
|
166
|
rt300@0
|
167 HoledSpiderMesh(int aNumSpokes,int aNumRings);
|
rt300@0
|
168 void constrain(double x, double y, constrainMode aMode);
|
rt300@0
|
169 void makeComponents(int adimension1, int adimension2);
|
rt300@0
|
170 void setLumpPositions();
|
rt300@0
|
171 void makeConnections();
|
rt300@0
|
172 void makeDefaultScanPath();
|
rt300@0
|
173 };
|
rt300@0
|
174 //---------------------------------------------------------
|
rt300@0
|
175 class SpiderCrossMesh : public Mesh{
|
rt300@0
|
176 public:
|
rt300@0
|
177 int numSpokes, numRings;
|
rt300@0
|
178
|
rt300@0
|
179 SpiderCrossMesh(int aNumSpokes,int aNumRings);
|
rt300@0
|
180
|
rt300@0
|
181 void constrain(double x, double y, constrainMode aMode);
|
rt300@0
|
182 void makeComponents(int adimension1, int adimension2); // override
|
rt300@0
|
183 void setLumpPositions(); // same
|
rt300@0
|
184 void makeConnections(); // overrride
|
rt300@0
|
185 void makeDefaultScanPath(); // same
|
rt300@0
|
186 };
|
rt300@0
|
187 //---------------------------------------------------------
|
rt300@9
|
188 // square grid
|
rt300@9
|
189 class SquareMesh : public Mesh{
|
rt300@0
|
190 public:
|
rt300@0
|
191 // square specific
|
rt300@0
|
192 int height;
|
rt300@0
|
193 int width;
|
rt300@9
|
194 SquareMesh();
|
rt300@9
|
195 SquareMesh(int height, int width);
|
rt300@9
|
196 ~SquareMesh();
|
rt300@9
|
197 void constrain(double x, double y, constrainMode aMode);
|
rt300@9
|
198 void makeComponents(int adimension1, int adimension2);
|
rt300@9
|
199 void setLumpPositions();
|
rt300@9
|
200 void makeConnections();
|
rt300@9
|
201 void makeDefaultScanPath();
|
rt300@9
|
202 };
|
rt300@9
|
203 //---------------------------------------------------------
|
rt300@9
|
204 // square grid with all diagonals connected i.e. we override makeConnections
|
rt300@9
|
205 class SquareCrossMesh : public SquareMesh{
|
rt300@9
|
206 public:
|
rt300@9
|
207 SquareCrossMesh(){};
|
rt300@9
|
208 SquareCrossMesh(int height, int width);
|
rt300@0
|
209 ~SquareCrossMesh();
|
rt300@0
|
210 void makeConnections();
|
rt300@9
|
211
|
rt300@0
|
212 };
|
rt300@0
|
213 //---------------------------------------------------------
|
rt300@0
|
214 // simple 1d line
|
rt300@0
|
215 class LineMesh : public Mesh{
|
rt300@0
|
216 public:
|
rt300@0
|
217 // square specific
|
rt300@0
|
218 int numSegments;
|
rt300@0
|
219
|
rt300@0
|
220 LineMesh(int aNumSegments);
|
rt300@0
|
221 void constrain(double x, double y, constrainMode aMode);
|
rt300@0
|
222 void makeComponents(int adimension1, int adimension2);
|
rt300@0
|
223 void setLumpPositions();
|
rt300@0
|
224 void makeConnections();
|
rt300@0
|
225 void makeDefaultScanPath();
|
rt300@0
|
226 };
|
rt300@0
|
227 //---------------------------------------------------------
|
rt300@0
|
228 // simple 1d line attached to 'ground' (constrained lumps) by other springs...
|
rt300@0
|
229 class GroundedLineMesh : public Mesh{
|
rt300@0
|
230 public:
|
rt300@0
|
231 int numSegments;
|
rt300@0
|
232
|
rt300@0
|
233 GroundedLineMesh(int aNumSegments);
|
rt300@0
|
234 void constrain(double x, double y, constrainMode aMode);
|
rt300@0
|
235 void makeComponents(int adimension1, int adimension2);
|
rt300@0
|
236 void setLumpPositions();
|
rt300@0
|
237 void makeConnections();
|
rt300@0
|
238 void makeDefaultScanPath();
|
rt300@0
|
239 };
|
rt300@0
|
240
|
rt300@0
|
241 //----------------------------------------------------------
|
rt300@0
|
242 //---------------------------------------------------------
|
rt300@0
|
243 // circular spring with internal pressure
|
rt300@0
|
244 class DropletMesh : public Mesh{
|
rt300@0
|
245 public:
|
rt300@0
|
246 // specific
|
rt300@0
|
247 int numSegments;
|
rt300@0
|
248 double restArea;
|
rt300@0
|
249
|
rt300@0
|
250 DropletMesh(int aNumSegments);
|
rt300@0
|
251 void constrain(double x, double y, constrainMode aMode);
|
rt300@0
|
252 void makeComponents(int adimension1, int adimension2);
|
rt300@0
|
253 void setLumpPositions();
|
rt300@0
|
254 void makeConnections();
|
rt300@0
|
255 void makeDefaultScanPath();
|
rt300@0
|
256 double calculatePressure();
|
rt300@0
|
257 double calculateArea();
|
rt300@0
|
258 void update();
|
rt300@0
|
259 };
|
rt300@0
|
260 //---------------------------------------------------------
|
rt300@0
|
261 // trangular mesh
|
rt300@0
|
262 class TriangleMesh : public Mesh{
|
rt300@0
|
263 public:
|
rt300@0
|
264 // square specific
|
rt300@0
|
265 int height;
|
rt300@0
|
266 int width;
|
rt300@0
|
267
|
rt300@0
|
268 TriangleMesh(int height, int width);
|
rt300@0
|
269 void constrain(double x, double y, constrainMode aMode);
|
rt300@0
|
270 void makeComponents(int adimension1, int adimension2);
|
rt300@0
|
271 void setLumpPositions();
|
rt300@0
|
272 void makeConnections();
|
rt300@0
|
273 void makeDefaultScanPath();
|
rt300@0
|
274 };
|
rt300@0
|
275 //----------------------------------------------------------
|
rt300@0
|
276
|
rt300@0
|
277 #endif
|