Skip to content

Commit

Permalink
few modifications to examples
Browse files Browse the repository at this point in the history
  • Loading branch information
jameslnrd committed Apr 8, 2020
1 parent 5e1c3d5 commit ce94368
Show file tree
Hide file tree
Showing 9 changed files with 248 additions and 317 deletions.
22 changes: 20 additions & 2 deletions examples/1_Visuals/DynamicTopologyMods/DynamicTopologyMods.pde
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ float fric = 0.001;

Driver3D d;

boolean showInstructions = true;

// SETUP: THIS IS WHERE WE SETUP AND INITIALISE OUR MODEL

Expand Down Expand Up @@ -92,8 +93,8 @@ void draw() {
fill(255);
textSize(13);

text("Friction: " + phys.getGlobalFriction(), 50, 50, 50);
text("Zoom: " + zZoom, 50, 100, 50);
if(showInstructions)
displayModelInstructions();


if (mouseDragged == 1){
Expand Down Expand Up @@ -149,6 +150,8 @@ void keyPressed() {
phys.init();
}
break;
case 'h':
showInstructions = ! showInstructions;
default:
break;
}
Expand Down Expand Up @@ -177,3 +180,18 @@ void keyPressed() {
break;
}
}

void displayModelInstructions(){
textMode(MODEL);
textSize(20);
fill(255, 255, 255);
text("Press left-click and move around to excite mesh", 10, 30);
text("Press right-click to chisel (remove) masses and interactions", 10, 55);
text("LEFT and RIGHT to change Zoom", 10, 80);
text("UP and DOWN to change friction", 10, 105);
text("Press 'r' to reset the model", 10, 130);
text("Friction: " + fric, 10, 155);
text("FrameRate: " + frameRate, 10, 180);
text("Press 'h' to hide instructions", 10, 210);

}
2 changes: 1 addition & 1 deletion examples/1_Visuals/WayCoolerWreckingBall/BuildPyramid.pde
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ PhyModel buildPyramid(String name, Medium med, int baseSize, double baseDist, in
}
int cpt = 0;
for(Mass m : model.getMassList()){
model.addInteraction("plane" + cpt++, new PlaneContact3D(0.1, 0.1, 2, 0), m);
model.addInteraction("plane" + cpt++, new PlaneContact3D(0.1, 0.01, 2, 0), m);
}

// Brute force collision algorithms between elements... very expensive to compute !
Expand Down
8 changes: 5 additions & 3 deletions examples/2_Audio/BeamModel/BeamModel.pde
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ boolean showInstructions = true;
void setup()
{
//size(1000, 700, P3D);
fullScreen(P3D,1);
fullScreen(P3D,2);
cam = new PeasyCam(this, 100);
cam.setMinimumDistance(50);
cam.setMaximumDistance(5500);
Expand All @@ -50,7 +50,8 @@ void setup()

driver = beam.addInOut("driver", new Driver3D(), "m_8_0_0");
listener = beam.addInOut("listener1", new Observer3D(filterType.HIGH_PASS), "m_15_1_0");

beam.addInOut("listener2", new Observer3D(filterType.HIGH_PASS), "m_40_0_0");

phys.mdl().addPhyModel(beam);

phys.init();
Expand All @@ -67,7 +68,7 @@ void setup()

audioStreamHandler = miPhyAudioClient.miPhyClassic(44100, 128, 0, 2, phys);
audioStreamHandler.setListenerAxis(listenerAxis.Y);
audioStreamHandler.setGain(0.02);
audioStreamHandler.setGain(0.03);
audioStreamHandler.start();

cam.setDistance(500); // distance from looked-at point
Expand All @@ -77,6 +78,7 @@ void setup()

void draw()
{
noCursor();
background(0, 0, 25);
directionalLight(126, 126, 126, 100, 0, -1);
ambientLight(182, 182, 182);
Expand Down
8 changes: 6 additions & 2 deletions examples/2_Audio/MetalPlate3D/MetalPlate3D.pde
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ void setup()
mesh = createMesh(dimX, dimY, "osc", "spring", 1., gridSpacing, 0.12, 0.1);
driver = mesh.addInOut("driver", new Driver3D(), "osc0_0");
mesh.addInOut("listener", new Observer3D(), "osc5_5");
mesh.addInOut("listener2", new Observer3D(), "osc19_10");

phys.mdl().addPhyModel(mesh);

Expand All @@ -53,6 +54,7 @@ void setup()
renderer = new ModelRenderer(this);

renderer.displayMasses(true);
renderer.setColor(massType.MASS3D, 105, 100, 250);
renderer.setColor(interType.SPRINGDAMPER3D, 155, 50, 50, 70);
renderer.setStrainGradient(interType.SPRINGDAMPER3D, true, 20);
renderer.setStrainColor(interType.SPRINGDAMPER3D, 255, 250, 255, 255);
Expand All @@ -68,16 +70,18 @@ void draw()
{
camera(width/2.0, height/2.0, (height/2.0) / tan(PI*30.0 / 180.0), width/2, height/2.0, 0, 0, 1, 0);

background(0);
background(0, 0, 25);

directionalLight(126, 126, 126, 100, 0, -1);
ambientLight(182, 182, 182);
if (showInstructions)
displayModelInstructions();


renderer.setZoomVector(1, 1, 0.1 * zZoom);

pushMatrix();
translate(xOffset, yOffset, 0.);
translate(xOffset + 20, yOffset + 20, 0.);
renderer.renderScene(phys);
popMatrix();

Expand Down
143 changes: 0 additions & 143 deletions examples/2_Audio/WobbleBeam/GenerateTopo.pde
Original file line number Diff line number Diff line change
@@ -1,144 +1 @@
void generateVolume(PhysicalModel mdl, int dimX, int dimY, int dimZ, String mName, String lName, float masValue, float radius, float l0, float dist, float K, float Z) {

String masName;
Vect3D X0, V0;

for (int k = 0; k < dimZ; k++) {
for (int i = 0; i < dimY; i++) {
for (int j = 1; j <= dimX; j++) {
masName = mName +(j+i*dimX+k*dimX*dimY);
println(masName);
masValue = 1.0;
X0 = new Vect3D(j*dist-(dimX/2*dist), i*dist, k*dist);
V0 = new Vect3D(0., 0., 0.);
if(i==0)
mdl.addMass(masName, new Ground3D(radius, X0));
else
mdl.addMass(masName, new Mass3D(masValue, radius, X0, V0));
}
}
}

// add the spring to the model: length, stiffness, connected mats
String masName1, masName2;

for (int k = 0; k < dimZ; k++) {
for (int i = 0; i < dimY; i++) {
for (int j = 1; j < dimX; j++) {
masName1 = mName +(j+i*dimX+k*(dimX*dimY));
masName2 = mName +(j+i*dimX+k*(dimX*dimY)+1);
//println("X " +masName1+masName2);

String name = lName + "1_" +i+"_"+j+"_"+k;
mdl.addInteraction(name, new SpringDamper3D(l0, K, Z), masName1, masName2);
}
}
}

for (int k = 0; k < dimZ; k++) {
for (int i = 1; i < dimX+1; i++) {
for (int j = 0; j < dimY-1; j++) {
masName1 = mName +(i+j*dimX+k*(dimX*dimY));
masName2 = mName +(i+(j+1)*dimX+k*(dimX*dimY));
//println("Y "+masName1+masName2);

String name = lName + "2_" +i+"_"+j+"_"+k;
mdl.addInteraction(name, new SpringDamper3D(l0, K, Z), masName1, masName2);
}
}
}

for (int i = 1; i < dimX+1; i++) {
for (int j = 0; j < dimY; j++) {
for (int k = 0; k < dimZ-1; k++) {
masName1 = mName +(i+j*dimX+k*(dimX*dimY));
masName2 = mName +(i+j*dimX+(k+1)*(dimX*dimY));
//println("Z "+masName1+masName2);

String name = lName + "3_" +i+"_"+j+"_"+k;
mdl.addInteraction(name, new SpringDamper3D(l0, K, Z), masName1, masName2);
}
}
}

// Create cross links (for structural integrity) here!
double h1 = sqrt(2)*dist;
double h2 = sqrt(3)*dist;

for (int i = 1; i < dimX; i++) {
for (int j = 0; j < dimY-1; j++) {
for (int k = 0; k < dimZ; k++) {
masName1 = mName +(i+j*dimX+k*(dimX*dimY));
masName2 = mName +(i+1+(j+1)*dimX+k*(dimX*dimY));

String name = lName + "4_" +i+"_"+j+"_"+k;
mdl.addInteraction(name, new SpringDamper3D(h1, K, Z), masName1, masName2);

masName1 = mName +(i+(j+1)*dimX+k*(dimX*dimY));
masName2 = mName +(i+1+(j)*dimX+k*(dimX*dimY));

name = lName + "5_" +i+"_"+j+"_"+k;
mdl.addInteraction(name, new SpringDamper3D(h1, K, Z), masName1, masName2);
}
}
}
for (int i = 1; i < dimX; i++) {
for (int j = 0; j < dimY; j++) {
for (int k = 0; k < dimZ-1; k++) {
masName1 = mName +(i+j*dimX+k*(dimX*dimY));
masName2 = mName +(i+1+(j)*dimX+(k+1)*(dimX*dimY));

String name = lName + "6_" +i+"_"+j+"_"+k;
mdl.addInteraction(name, new SpringDamper3D(h1, K, Z), masName1, masName2);


masName1 = mName +(i+(j)*dimX+(k+1)*(dimX*dimY));
masName2 = mName +(i+1+(j)*dimX+k*(dimX*dimY));
name = lName + "7_" +i+"_"+j+"_"+k;
mdl.addInteraction(name, new SpringDamper3D(h1, K, Z), masName1, masName2);
}
}
}
for (int i = 1; i < dimX+1; i++) {
for (int j = 0; j < dimY-1; j++) {
for (int k = 0; k < dimZ-1; k++) {
masName1 = mName +(i+j*dimX+k*(dimX*dimY));
masName2 = mName +(i+(j+1)*dimX+(k+1)*((dimX)*(dimY)));

String name = lName + "8_" +i+"_"+j+"_"+k;
mdl.addInteraction(name, new SpringDamper3D(h1, K, Z), masName1, masName2);

masName1 = mName +(i+j*dimX+(k+1)*(dimX*dimY));
masName2 = mName +(i+(j+1)*dimX+(k)*((dimX)*(dimY)));
name = lName + "9_" +i+"_"+j+"_"+k;
mdl.addInteraction(name, new SpringDamper3D(h1, K, Z), masName1, masName2);
}
}
}
for (int i = 1; i < dimX; i++) {
for (int j = 0; j < dimY-1; j++) {
for (int k = 0; k < dimZ-1; k++) {
masName1 = mName +(i+j*dimX+k*(dimX*dimY));
masName2 = mName +(i+1+(j+1)*dimX+(k+1)*((dimX)*(dimY)));

String name = lName + "10_" +i+"_"+j+"_"+k;
mdl.addInteraction(name, new SpringDamper3D(h2, K, Z), masName1, masName2);

masName1 = mName +(i+(j+1)*dimX+(k+1)*(dimX*dimY));
masName2 = mName +(i+1+(j)*dimX+(k)*((dimX)*(dimY)));
name = lName + "11_" +i+"_"+j+"_"+k;
mdl.addInteraction(name, new SpringDamper3D(h2, K, Z), masName1, masName2);

masName1 = mName +(i+1+(j+1)*dimX+(k)*(dimX*dimY));
masName2 = mName +(i+(j)*dimX+(k+1)*((dimX)*(dimY)));
name = lName + "11_" +i+"_"+j+"_"+k;
mdl.addInteraction(name, new SpringDamper3D(h2, K, Z), masName1, masName2);

masName1 = mName +(i+1+(j)*dimX+(k+1)*(dimX*dimY));
masName2 = mName +(i+(j+1)*dimX+(k)*((dimX)*(dimY)));
name = lName + "12_" +i+"_"+j+"_"+k;
mdl.addInteraction(name, new SpringDamper3D(h2, K, Z), masName1, masName2);
}
}
}
}
Loading

0 comments on commit ce94368

Please sign in to comment.