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@8
|
47 enum MeshType {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@0
|
52 virtual ~Mesh();
|
rt300@0
|
53
|
rt300@0
|
54 void draw();
|
rt300@0
|
55
|
rt300@0
|
56 // INTERACTIONS
|
rt300@0
|
57 void resetAll();
|
rt300@0
|
58 void resetPositions();
|
rt300@0
|
59 void resetVelocities();
|
rt300@0
|
60 void resetEverything();
|
rt300@0
|
61
|
rt300@0
|
62 // excite via position, velocity force
|
rt300@0
|
63 // using shapes : noise, hamming, sine,
|
rt300@0
|
64 void hit(double dax,double day,int velocity = 100, GlobalForces::excitationTypes aEType = GlobalForces::POSITION,
|
rt300@0
|
65 GlobalForces::excitationShapes aEShape = GlobalForces::NOISE);
|
rt300@0
|
66 void spatialHarmonic(int aharm1 = 1, int aharm2 = 0);
|
rt300@0
|
67 void damp();
|
rt300@0
|
68 void forceField(double dax,double day,double strength);
|
rt300@0
|
69 void averagingFilter(double amt);
|
rt300@0
|
70
|
rt300@0
|
71 void grab(double x, double y, int touchID);
|
rt300@0
|
72 void drag(double ax,double ay, int touchID);
|
rt300@0
|
73 void unGrab(int touchID);
|
rt300@0
|
74
|
rt300@0
|
75 virtual void constrain(double x, double y, constrainMode aMode); // diff meshes will have diff edges
|
rt300@0
|
76 void unconstrain();
|
rt300@0
|
77 void unconstrain(double x, double y, constrainMode aMode);
|
rt300@0
|
78
|
rt300@0
|
79
|
rt300@0
|
80 // PARAMETER SETTINGS
|
rt300@0
|
81 void toggleSyrup();
|
rt300@0
|
82 void toggleSyrup(bool on);
|
rt300@0
|
83 void toggleSpringForces();
|
rt300@0
|
84 void toggleSpringForces(bool on);
|
rt300@0
|
85 void toggleGravity();
|
rt300@0
|
86 void toggleGravity(bool on);
|
rt300@0
|
87 void toggleHome(bool on);
|
rt300@0
|
88
|
rt300@0
|
89 void setRestLength();
|
rt300@0
|
90 void zeroRestLength();
|
rt300@0
|
91
|
rt300@0
|
92 void setPropagationSpeed(double aSpeed); // sets k and m to give a certain speed
|
rt300@0
|
93 void decreasePropagationSpeed();
|
rt300@0
|
94 void increasePropagationSpeed();
|
rt300@0
|
95 void setSpringConstant(double aK);
|
rt300@0
|
96 void setMass(double aM);
|
rt300@0
|
97 void setFriction(double aF);
|
rt300@0
|
98
|
rt300@0
|
99 // create varying constants
|
rt300@0
|
100 void setSpringConstantAsym(double aAsym);
|
rt300@0
|
101 void setMassAsym(double aAsym);
|
rt300@0
|
102 void setFrictionAsym(double aAsym);
|
rt300@0
|
103 void setZeroAudioLine();
|
rt300@0
|
104
|
rt300@0
|
105 // only for mouse cursor
|
rt300@0
|
106 void checkHover(double x, double y);
|
rt300@0
|
107
|
rt300@0
|
108 // SCANPATH STUFF
|
rt300@0
|
109 void clearScanPath();
|
rt300@0
|
110 void disconnectDraw(); // enables you to draw scanpths anywhere
|
rt300@0
|
111 int inscribeScanPath(double ax, double ay);
|
rt300@8
|
112
|
rt300@8
|
113 // inscribeScanPathFromJson
|
rt300@8
|
114
|
rt300@0
|
115 // called by scanpath.update wavetables
|
rt300@0
|
116 double getNextSample();
|
rt300@0
|
117
|
rt300@0
|
118 virtual void update();
|
rt300@8
|
119
|
rt300@8
|
120 // save stuff
|
rt300@8
|
121 Json::Value convertToJsonForSaving();
|
rt300@8
|
122
|
rt300@0
|
123 protected:
|
rt300@0
|
124
|
rt300@0
|
125 int prevLump;
|
rt300@0
|
126
|
rt300@0
|
127 // specific mesh shapes override these:
|
rt300@0
|
128
|
rt300@0
|
129 virtual void makeComponents(int adimension1, int adimension2);
|
rt300@0
|
130 virtual void setLumpPositions();
|
rt300@0
|
131 virtual void makeConnections();
|
rt300@0
|
132 virtual void makeDefaultScanPath();
|
rt300@0
|
133
|
rt300@0
|
134 // UTILS
|
rt300@0
|
135 TwoVector calculateCentre();
|
rt300@0
|
136 void connect(int springnum,int lumpnum);
|
rt300@0
|
137 void connect(int springnum,int lumpnum,int alumpnum2);
|
rt300@0
|
138 int getNearestLump(double ax,double ay);
|
rt300@0
|
139
|
rt300@0
|
140 };
|
rt300@0
|
141 //---------------------------------------------------------
|
rt300@0
|
142 class SpiderMesh : public Mesh{
|
rt300@0
|
143 public:
|
rt300@0
|
144 int numSpokes, numRings;
|
rt300@0
|
145
|
rt300@0
|
146 SpiderMesh(int aNumSpokes,int aNumRings);
|
rt300@0
|
147
|
rt300@0
|
148 virtual void constrain(double x, double y, constrainMode aMode);
|
rt300@0
|
149 virtual void makeComponents(int adimension1, int adimension2);
|
rt300@0
|
150 virtual void setLumpPositions();
|
rt300@0
|
151 virtual void makeConnections();
|
rt300@0
|
152 virtual void makeDefaultScanPath();
|
rt300@0
|
153 };
|
rt300@0
|
154 //---------------------------------------------------------
|
rt300@0
|
155 class HoledSpiderMesh : public Mesh{
|
rt300@0
|
156 public:
|
rt300@0
|
157 int numSpokes, numRings;
|
rt300@0
|
158
|
rt300@0
|
159 HoledSpiderMesh(int aNumSpokes,int aNumRings);
|
rt300@0
|
160 void constrain(double x, double y, constrainMode aMode);
|
rt300@0
|
161 void makeComponents(int adimension1, int adimension2);
|
rt300@0
|
162 void setLumpPositions();
|
rt300@0
|
163 void makeConnections();
|
rt300@0
|
164 void makeDefaultScanPath();
|
rt300@0
|
165 };
|
rt300@0
|
166 //---------------------------------------------------------
|
rt300@0
|
167 class SpiderCrossMesh : public Mesh{
|
rt300@0
|
168 public:
|
rt300@0
|
169 int numSpokes, numRings;
|
rt300@0
|
170
|
rt300@0
|
171 SpiderCrossMesh(int aNumSpokes,int aNumRings);
|
rt300@0
|
172
|
rt300@0
|
173 void constrain(double x, double y, constrainMode aMode);
|
rt300@0
|
174 void makeComponents(int adimension1, int adimension2); // override
|
rt300@0
|
175 void setLumpPositions(); // same
|
rt300@0
|
176 void makeConnections(); // overrride
|
rt300@0
|
177 void makeDefaultScanPath(); // same
|
rt300@0
|
178 };
|
rt300@0
|
179 //---------------------------------------------------------
|
rt300@0
|
180 // square grid with all diagonals connected
|
rt300@0
|
181 class SquareCrossMesh : public Mesh{
|
rt300@0
|
182 public:
|
rt300@0
|
183 // square specific
|
rt300@0
|
184 int height;
|
rt300@0
|
185 int width;
|
rt300@0
|
186
|
rt300@0
|
187 SquareCrossMesh(int height, int width);
|
rt300@0
|
188 ~SquareCrossMesh();
|
rt300@0
|
189 void constrain(double x, double y, constrainMode aMode);
|
rt300@0
|
190 void makeComponents(int adimension1, int adimension2);
|
rt300@0
|
191 void setLumpPositions();
|
rt300@0
|
192 void makeConnections();
|
rt300@0
|
193 void makeDefaultScanPath();
|
rt300@0
|
194 };
|
rt300@0
|
195 //---------------------------------------------------------
|
rt300@0
|
196 // simple 1d line
|
rt300@0
|
197 class LineMesh : public Mesh{
|
rt300@0
|
198 public:
|
rt300@0
|
199 // square specific
|
rt300@0
|
200 int numSegments;
|
rt300@0
|
201
|
rt300@0
|
202 LineMesh(int aNumSegments);
|
rt300@0
|
203 void constrain(double x, double y, constrainMode aMode);
|
rt300@0
|
204 void makeComponents(int adimension1, int adimension2);
|
rt300@0
|
205 void setLumpPositions();
|
rt300@0
|
206 void makeConnections();
|
rt300@0
|
207 void makeDefaultScanPath();
|
rt300@0
|
208 };
|
rt300@0
|
209 //---------------------------------------------------------
|
rt300@0
|
210 // simple 1d line attached to 'ground' (constrained lumps) by other springs...
|
rt300@0
|
211 class GroundedLineMesh : public Mesh{
|
rt300@0
|
212 public:
|
rt300@0
|
213 int numSegments;
|
rt300@0
|
214
|
rt300@0
|
215 GroundedLineMesh(int aNumSegments);
|
rt300@0
|
216 void constrain(double x, double y, constrainMode aMode);
|
rt300@0
|
217 void makeComponents(int adimension1, int adimension2);
|
rt300@0
|
218 void setLumpPositions();
|
rt300@0
|
219 void makeConnections();
|
rt300@0
|
220 void makeDefaultScanPath();
|
rt300@0
|
221 };
|
rt300@0
|
222
|
rt300@0
|
223 //----------------------------------------------------------
|
rt300@0
|
224 //---------------------------------------------------------
|
rt300@0
|
225 // circular spring with internal pressure
|
rt300@0
|
226 class DropletMesh : public Mesh{
|
rt300@0
|
227 public:
|
rt300@0
|
228 // specific
|
rt300@0
|
229 int numSegments;
|
rt300@0
|
230 double restArea;
|
rt300@0
|
231
|
rt300@0
|
232 DropletMesh(int aNumSegments);
|
rt300@0
|
233 void constrain(double x, double y, constrainMode aMode);
|
rt300@0
|
234 void makeComponents(int adimension1, int adimension2);
|
rt300@0
|
235 void setLumpPositions();
|
rt300@0
|
236 void makeConnections();
|
rt300@0
|
237 void makeDefaultScanPath();
|
rt300@0
|
238 double calculatePressure();
|
rt300@0
|
239 double calculateArea();
|
rt300@0
|
240 void update();
|
rt300@0
|
241 };
|
rt300@0
|
242 //---------------------------------------------------------
|
rt300@0
|
243 // trangular mesh
|
rt300@0
|
244 class TriangleMesh : public Mesh{
|
rt300@0
|
245 public:
|
rt300@0
|
246 // square specific
|
rt300@0
|
247 int height;
|
rt300@0
|
248 int width;
|
rt300@0
|
249
|
rt300@0
|
250 TriangleMesh(int height, int width);
|
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 };
|
rt300@0
|
257 //----------------------------------------------------------
|
rt300@0
|
258
|
rt300@0
|
259 #endif
|