annotate mesh.h @ 3:d346ddc50f70

Vectorised a few things. Fiddled with new mesh creator... not solved much.
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Fri, 07 Dec 2012 19:20:57 +0000
parents c667dfe12d47
children 79c7cf39a0a0
rev   line source
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@0 17
rt300@0 18
rt300@0 19 class Mesh{
rt300@0 20 public:
rt300@0 21
rt300@0 22 bool radial; // tells us if mesh is radial or not
rt300@0 23 // toggles
rt300@0 24 bool syrup;
rt300@0 25 bool home;
rt300@0 26
rt300@0 27 double propagationSpeed;
rt300@0 28
rt300@0 29 double k,m,f; // for stability check and asym
rt300@0 30
rt300@0 31 int numLumps;
rt300@0 32 int numSprings;
rt300@0 33
rt300@0 34 Lump *lumps;
rt300@3 35
rt300@3 36 vector<Spring> springs;
rt300@3 37 //Spring *springs;
rt300@0 38
rt300@0 39 TwoVector centre;
rt300@0 40
rt300@0 41
rt300@0 42 // modes
rt300@0 43 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 44 double GRAB_RANGE;
rt300@0 45
rt300@0 46
rt300@0 47
rt300@0 48 // MEMBER FUNCTIONS
rt300@0 49 Mesh();
rt300@0 50 virtual ~Mesh();
rt300@0 51
rt300@0 52 void draw();
rt300@0 53
rt300@0 54 // INTERACTIONS
rt300@0 55 void resetAll();
rt300@0 56 void resetPositions();
rt300@0 57 void resetVelocities();
rt300@0 58 void resetEverything();
rt300@0 59
rt300@0 60 // excite via position, velocity force
rt300@0 61 // using shapes : noise, hamming, sine,
rt300@0 62 void hit(double dax,double day,int velocity = 100, GlobalForces::excitationTypes aEType = GlobalForces::POSITION,
rt300@0 63 GlobalForces::excitationShapes aEShape = GlobalForces::NOISE);
rt300@0 64 void spatialHarmonic(int aharm1 = 1, int aharm2 = 0);
rt300@0 65 void damp();
rt300@0 66 void forceField(double dax,double day,double strength);
rt300@0 67 void averagingFilter(double amt);
rt300@0 68
rt300@0 69 void grab(double x, double y, int touchID);
rt300@0 70 void drag(double ax,double ay, int touchID);
rt300@0 71 void unGrab(int touchID);
rt300@0 72
rt300@0 73 virtual void constrain(double x, double y, constrainMode aMode); // diff meshes will have diff edges
rt300@0 74 void unconstrain();
rt300@0 75 void unconstrain(double x, double y, constrainMode aMode);
rt300@0 76
rt300@0 77
rt300@0 78 // PARAMETER SETTINGS
rt300@0 79 void toggleSyrup();
rt300@0 80 void toggleSyrup(bool on);
rt300@0 81 void toggleSpringForces();
rt300@0 82 void toggleSpringForces(bool on);
rt300@0 83 void toggleGravity();
rt300@0 84 void toggleGravity(bool on);
rt300@0 85 void toggleHome(bool on);
rt300@0 86
rt300@0 87 void setRestLength();
rt300@0 88 void zeroRestLength();
rt300@0 89
rt300@0 90 void setPropagationSpeed(double aSpeed); // sets k and m to give a certain speed
rt300@0 91 void decreasePropagationSpeed();
rt300@0 92 void increasePropagationSpeed();
rt300@0 93 void setSpringConstant(double aK);
rt300@0 94 void setMass(double aM);
rt300@0 95 void setFriction(double aF);
rt300@0 96
rt300@0 97 // create varying constants
rt300@0 98 void setSpringConstantAsym(double aAsym);
rt300@0 99 void setMassAsym(double aAsym);
rt300@0 100 void setFrictionAsym(double aAsym);
rt300@0 101 void setZeroAudioLine();
rt300@0 102
rt300@0 103 // only for mouse cursor
rt300@0 104 void checkHover(double x, double y);
rt300@0 105
rt300@0 106 // SCANPATH STUFF
rt300@0 107 void clearScanPath();
rt300@0 108 void disconnectDraw(); // enables you to draw scanpths anywhere
rt300@0 109 int inscribeScanPath(double ax, double ay);
rt300@0 110 // called by scanpath.update wavetables
rt300@0 111 double getNextSample();
rt300@0 112
rt300@0 113 virtual void update();
rt300@0 114
rt300@0 115 protected:
rt300@0 116
rt300@0 117 int prevLump;
rt300@0 118
rt300@0 119 // specific mesh shapes override these:
rt300@0 120
rt300@0 121 virtual void makeComponents(int adimension1, int adimension2);
rt300@0 122 virtual void setLumpPositions();
rt300@0 123 virtual void makeConnections();
rt300@0 124 virtual void makeDefaultScanPath();
rt300@0 125
rt300@0 126 // UTILS
rt300@0 127 TwoVector calculateCentre();
rt300@0 128 void connect(int springnum,int lumpnum);
rt300@0 129 void connect(int springnum,int lumpnum,int alumpnum2);
rt300@0 130 int getNearestLump(double ax,double ay);
rt300@0 131
rt300@0 132 };
rt300@0 133 //---------------------------------------------------------
rt300@0 134 class SpiderMesh : public Mesh{
rt300@0 135 public:
rt300@0 136 int numSpokes, numRings;
rt300@0 137
rt300@0 138 SpiderMesh(int aNumSpokes,int aNumRings);
rt300@0 139
rt300@0 140 virtual void constrain(double x, double y, constrainMode aMode);
rt300@0 141 virtual void makeComponents(int adimension1, int adimension2);
rt300@0 142 virtual void setLumpPositions();
rt300@0 143 virtual void makeConnections();
rt300@0 144 virtual void makeDefaultScanPath();
rt300@0 145 };
rt300@0 146 //---------------------------------------------------------
rt300@0 147 class HoledSpiderMesh : public Mesh{
rt300@0 148 public:
rt300@0 149 int numSpokes, numRings;
rt300@0 150
rt300@0 151 HoledSpiderMesh(int aNumSpokes,int aNumRings);
rt300@0 152 void constrain(double x, double y, constrainMode aMode);
rt300@0 153 void makeComponents(int adimension1, int adimension2);
rt300@0 154 void setLumpPositions();
rt300@0 155 void makeConnections();
rt300@0 156 void makeDefaultScanPath();
rt300@0 157 };
rt300@0 158 //---------------------------------------------------------
rt300@0 159 class SpiderCrossMesh : public Mesh{
rt300@0 160 public:
rt300@0 161 int numSpokes, numRings;
rt300@0 162
rt300@0 163 SpiderCrossMesh(int aNumSpokes,int aNumRings);
rt300@0 164
rt300@0 165 void constrain(double x, double y, constrainMode aMode);
rt300@0 166 void makeComponents(int adimension1, int adimension2); // override
rt300@0 167 void setLumpPositions(); // same
rt300@0 168 void makeConnections(); // overrride
rt300@0 169 void makeDefaultScanPath(); // same
rt300@0 170 };
rt300@0 171 //---------------------------------------------------------
rt300@0 172 // square grid with all diagonals connected
rt300@0 173 class SquareCrossMesh : public Mesh{
rt300@0 174 public:
rt300@0 175 // square specific
rt300@0 176 int height;
rt300@0 177 int width;
rt300@0 178
rt300@0 179 SquareCrossMesh(int height, int width);
rt300@0 180 ~SquareCrossMesh();
rt300@0 181 void constrain(double x, double y, constrainMode aMode);
rt300@0 182 void makeComponents(int adimension1, int adimension2);
rt300@0 183 void setLumpPositions();
rt300@0 184 void makeConnections();
rt300@0 185 void makeDefaultScanPath();
rt300@0 186 };
rt300@0 187 //---------------------------------------------------------
rt300@0 188 // simple 1d line
rt300@0 189 class LineMesh : public Mesh{
rt300@0 190 public:
rt300@0 191 // square specific
rt300@0 192 int numSegments;
rt300@0 193
rt300@0 194 LineMesh(int aNumSegments);
rt300@0 195 void constrain(double x, double y, constrainMode aMode);
rt300@0 196 void makeComponents(int adimension1, int adimension2);
rt300@0 197 void setLumpPositions();
rt300@0 198 void makeConnections();
rt300@0 199 void makeDefaultScanPath();
rt300@0 200 };
rt300@0 201 //---------------------------------------------------------
rt300@0 202 // simple 1d line attached to 'ground' (constrained lumps) by other springs...
rt300@0 203 class GroundedLineMesh : public Mesh{
rt300@0 204 public:
rt300@0 205 int numSegments;
rt300@0 206
rt300@0 207 GroundedLineMesh(int aNumSegments);
rt300@0 208 void constrain(double x, double y, constrainMode aMode);
rt300@0 209 void makeComponents(int adimension1, int adimension2);
rt300@0 210 void setLumpPositions();
rt300@0 211 void makeConnections();
rt300@0 212 void makeDefaultScanPath();
rt300@0 213 };
rt300@0 214
rt300@0 215 //----------------------------------------------------------
rt300@0 216 //---------------------------------------------------------
rt300@0 217 // circular spring with internal pressure
rt300@0 218 class DropletMesh : public Mesh{
rt300@0 219 public:
rt300@0 220 // specific
rt300@0 221 int numSegments;
rt300@0 222 double restArea;
rt300@0 223
rt300@0 224 DropletMesh(int aNumSegments);
rt300@0 225 void constrain(double x, double y, constrainMode aMode);
rt300@0 226 void makeComponents(int adimension1, int adimension2);
rt300@0 227 void setLumpPositions();
rt300@0 228 void makeConnections();
rt300@0 229 void makeDefaultScanPath();
rt300@0 230 double calculatePressure();
rt300@0 231 double calculateArea();
rt300@0 232 void update();
rt300@0 233 };
rt300@0 234 //---------------------------------------------------------
rt300@0 235 // trangular mesh
rt300@0 236 class TriangleMesh : public Mesh{
rt300@0 237 public:
rt300@0 238 // square specific
rt300@0 239 int height;
rt300@0 240 int width;
rt300@0 241
rt300@0 242 TriangleMesh(int height, int width);
rt300@0 243 void constrain(double x, double y, constrainMode aMode);
rt300@0 244 void makeComponents(int adimension1, int adimension2);
rt300@0 245 void setLumpPositions();
rt300@0 246 void makeConnections();
rt300@0 247 void makeDefaultScanPath();
rt300@0 248 };
rt300@0 249 //----------------------------------------------------------
rt300@0 250
rt300@0 251 #endif