From ce9436892fcc16f6707937d9b4dfcfb5069ac27d Mon Sep 17 00:00:00 2001 From: mi-creative Date: Wed, 8 Apr 2020 21:58:48 +0200 Subject: [PATCH] few modifications to examples --- .../DynamicTopologyMods.pde | 22 +- .../WayCoolerWreckingBall/BuildPyramid.pde | 2 +- examples/2_Audio/BeamModel/BeamModel.pde | 8 +- .../2_Audio/MetalPlate3D/MetalPlate3D.pde | 8 +- examples/2_Audio/WobbleBeam/GenerateTopo.pde | 143 ---------- examples/2_Audio/WobbleBeam/WobbleBeam.pde | 118 +++++--- examples/2_Audio/WobbleBeam/phyUGen.pde | 258 +++++++++--------- src/miPhysics/Engine/Driver3D.java | 2 +- src/miPhysics/Engine/Interaction.java | 4 + 9 files changed, 248 insertions(+), 317 deletions(-) diff --git a/examples/1_Visuals/DynamicTopologyMods/DynamicTopologyMods.pde b/examples/1_Visuals/DynamicTopologyMods/DynamicTopologyMods.pde index 6ab89cc..c0681d6 100644 --- a/examples/1_Visuals/DynamicTopologyMods/DynamicTopologyMods.pde +++ b/examples/1_Visuals/DynamicTopologyMods/DynamicTopologyMods.pde @@ -38,6 +38,7 @@ float fric = 0.001; Driver3D d; +boolean showInstructions = true; // SETUP: THIS IS WHERE WE SETUP AND INITIALISE OUR MODEL @@ -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){ @@ -149,6 +150,8 @@ void keyPressed() { phys.init(); } break; + case 'h': + showInstructions = ! showInstructions; default: break; } @@ -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); + +} diff --git a/examples/1_Visuals/WayCoolerWreckingBall/BuildPyramid.pde b/examples/1_Visuals/WayCoolerWreckingBall/BuildPyramid.pde index 3cf9710..2b9401c 100644 --- a/examples/1_Visuals/WayCoolerWreckingBall/BuildPyramid.pde +++ b/examples/1_Visuals/WayCoolerWreckingBall/BuildPyramid.pde @@ -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 ! diff --git a/examples/2_Audio/BeamModel/BeamModel.pde b/examples/2_Audio/BeamModel/BeamModel.pde index 55d783c..2250b04 100644 --- a/examples/2_Audio/BeamModel/BeamModel.pde +++ b/examples/2_Audio/BeamModel/BeamModel.pde @@ -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); @@ -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(); @@ -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 @@ -77,6 +78,7 @@ void setup() void draw() { + noCursor(); background(0, 0, 25); directionalLight(126, 126, 126, 100, 0, -1); ambientLight(182, 182, 182); diff --git a/examples/2_Audio/MetalPlate3D/MetalPlate3D.pde b/examples/2_Audio/MetalPlate3D/MetalPlate3D.pde index 3fa8fd6..55d497a 100644 --- a/examples/2_Audio/MetalPlate3D/MetalPlate3D.pde +++ b/examples/2_Audio/MetalPlate3D/MetalPlate3D.pde @@ -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); @@ -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); @@ -68,8 +70,10 @@ 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(); @@ -77,7 +81,7 @@ void draw() renderer.setZoomVector(1, 1, 0.1 * zZoom); pushMatrix(); - translate(xOffset, yOffset, 0.); + translate(xOffset + 20, yOffset + 20, 0.); renderer.renderScene(phys); popMatrix(); diff --git a/examples/2_Audio/WobbleBeam/GenerateTopo.pde b/examples/2_Audio/WobbleBeam/GenerateTopo.pde index 096414b..8b13789 100644 --- a/examples/2_Audio/WobbleBeam/GenerateTopo.pde +++ b/examples/2_Audio/WobbleBeam/GenerateTopo.pde @@ -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); - } - } - } -} diff --git a/examples/2_Audio/WobbleBeam/WobbleBeam.pde b/examples/2_Audio/WobbleBeam/WobbleBeam.pde index 043403c..3f6edc5 100644 --- a/examples/2_Audio/WobbleBeam/WobbleBeam.pde +++ b/examples/2_Audio/WobbleBeam/WobbleBeam.pde @@ -1,15 +1,11 @@ -/* -NOTE: Haven't ported this example yet! -TODO: port with same logic as PinScreenCube example -*/ - - - -import ddf.minim.*; -import ddf.minim.ugens.*; import peasy.*; -import miPhysics.ModelRenderer.*; +import miPhysics.Renderer.*; +import miPhysics.Engine.*; +import miPhysics.Engine.Sound.*; + +import java.math.RoundingMode; +import java.text.DecimalFormat; int baseFrameRate = 60; @@ -17,12 +13,17 @@ PeasyCam cam; // Audio Output Variables Init float currAudio = 0; -Minim minim; -PhyUGen simUGen; -Gain gain; -AudioOutput out; + +PhysicsContext phys; + +Observer3D listener; +PosInput3D input; +miTopoCreator beam; ModelRenderer renderer; +miPhyAudioClient audioStreamHandler; + +boolean showInstructions = true; /////////////////////////////////////// @@ -30,28 +31,39 @@ ModelRenderer renderer; void setup() { //size(1000, 700, P3D); // Fullscreen option - fullScreen(P3D); // Or window option + fullScreen(P3D, 2); // Or window option cam = new PeasyCam(this, 100); cam.setMinimumDistance(50); cam.setMaximumDistance(5000); - minim = new Minim(this); + phys = new PhysicsContext(44100); + phys.setGlobalFriction(0.0000003); + + PhyModel perc = new PhyModel("pluck", phys.getGlobalMedium()); + input = perc.addMass("input", new PosInput3D(40, new Vect3D(3, -4, 0), 100)); + phys.mdl().addPhyModel(perc); - // use the getLineOut method of the Minim object to get an AudioOutput object - out = minim.getLineOut(); + beam = new miTopoCreator("topo", phys.getGlobalMedium()); + beam.setDim(4, 50, 1, 1); + beam.setGeometry(10, 10); + beam.setParams(1,0.3,0.0001); + beam.setMassRadius(4); + beam.set2DPlane(true); + beam.addBoundaryCondition(Bound.Y_LEFT); + //beam.addBoundaryCondition(Bound.X_RIGHT); + beam.generate(); + beam.translate(0, 0, 0); - // start the Gain at 0 dB, which means no change in amplitude - gain = new Gain(0); + listener = beam.addInOut("listener1", new Observer3D(filterType.HIGH_PASS), "m_2_30_0"); + beam.addInOut("listener2", new Observer3D(filterType.HIGH_PASS), "m_1_22_0"); - // create a physicalModel UGEN - simUGen = new PhyUGen(44100); - // patch the Oscil to the output - simUGen.patch(gain).patch(out); + phys.mdl().addPhyModel(beam); + phys.colEngine().addCollision(beam, perc,0.1, 0.01); + + phys.init(); renderer = new ModelRenderer(this); - - renderer.setZoomVector(100,100,100); - + renderer.displayMasses(true); renderer.setColor(massType.MASS2DPLANE, 120, 0, 140); renderer.setColor(massType.GROUND3D, 30, 100, 100); @@ -62,26 +74,60 @@ void setup() cam.setDistance(500); // distance from looked-at point + audioStreamHandler = miPhyAudioClient.miPhyClassic(44100, 128, 0, 2, phys); + audioStreamHandler.setListenerAxis(listenerAxis.Y); + audioStreamHandler.setGain(0.05); + audioStreamHandler.start(); + frameRate(baseFrameRate); } void draw() { - background(255,255,255); - - directionalLight(126, 126, 126, 100, 0, -1); + noCursor(); + background(0, 0, 25); + directionalLight(126, 126, 126, 100, 1, 0); ambientLight(182, 182, 182); + + float x = 2000 * (float)mouseX / width - 1000; + float y = 1500 * (float)mouseY / height - 750; + input.drivePosition(new Vect3D(x, y, 0)); + + if(showInstructions) + displayModelInstructions(); + + renderer.renderScene(phys); +} + + +void keyPressed(){ + switch(key){ + case 'o': + renderer.toggleObjectVolumesDisplay(); + break; + case 'v': + renderer.toggleIntersectionVolumesDisplay(); + break; + case 'h': + showInstructions = !showInstructions; - renderer.renderModel(simUGen.mdl); + } +} + +void displayModelInstructions(){ cam.beginHUD(); - stroke(125,125,255); - strokeWeight(2); - fill(0,0,60, 220); - rect(0,0, 250, 50); + textMode(MODEL); textSize(16); fill(255, 255, 255); - text("Curr Audio: " + currAudio, 10, 30); + text("Use the mouse to pluck the string with the red Position Input module", 10, 30); + text("Press 'o' to toggle object volumes display", 10, 55); + text("Press 'v' to toggle intersection volumes display", 10, 80); + text("Press 'h' to hide help", 10, 105); + text("FrameRate : " + frameRate, 10, 130); + DecimalFormat df = new DecimalFormat("#.####"); + df.setRoundingMode(RoundingMode.CEILING); + text("Curr Audio: " + df.format(listener.observePos().y), 10, 155); cam.endHUD(); } diff --git a/examples/2_Audio/WobbleBeam/phyUGen.pde b/examples/2_Audio/WobbleBeam/phyUGen.pde index b18eaf5..a766cd1 100644 --- a/examples/2_Audio/WobbleBeam/phyUGen.pde +++ b/examples/2_Audio/WobbleBeam/phyUGen.pde @@ -1,134 +1,134 @@ -import java.util.Arrays; -import ddf.minim.UGen; - -import miPhysics.Engine.*; - -/* Phyiscal parameters for the model */ -/* The general approach her is to use general/homogeneus parameters for mass (m), stifness (k), internal viscosity (z) -/* dist is the value defining the distance between to mass modules when generating the structure -/* fric is the global external viscoty -/* l0 is the resting lenght for all interaction modules -/* grav is a general parameters of gravity -/* c_dist, c_gnd, c_k and c_z are the parameters of the interaction model and mass - */ -float m, k, z, dist, fric, l0, grav, c_k, c_z; - -public class PhyUGen extends UGen -{ - private float oneOverSampleRate; - float audioOut; - PhysicalModel mdl; - PosInput3D input; - Observer3D listener; - private String listeningPoint; - int smoothing = 100; - - public PhyUGen(int sampleRate) - { - super(); - - this.mdl = new PhysicalModel(sampleRate, (int)baseFrameRate); - mdl.setGlobalGravity(0,0,grav); - mdl.setGlobalFriction(fric); - - audioOut = 0; - - - // Just a good old beam - m = 1.0; - k = 0.3; - z = 0.0001; - dist = 0.24; - fric = 0.00003; - l0 = 0.3; - grav = 0.; - c_k = 0.03; - c_z = 0.01; - generateVolume(this.mdl, 3, 30, 1, "mass", "spring", m, 0.05, dist, dist, k, z); - listeningPoint = "mass20"; - - // Metal Hurlant / - //m = 1.0; k = 0.35; z = 0.01; dist = 0.4; fric = 0.0003; l0 = 0.2; grav = 0.; c_dist = 1.8; c_gnd = 0.65; c_k = 0.07; c_z = -0.04; - //generateVolume(this.mdl, 3, 40, 1, "mass", "spring", m, 0.05, dist, dist, k, z); - //listeningPoint = "mass30"; - - // Fat Woden Stick / - // m = 1.0; k = 0.35; z = 0.1; dist = 1.; fric = 0.0003; l0 = 0.2; grav = 0.; c_dist = .9; c_gnd = 0.65; c_k = 0.07; c_z = 0.04; - // generateVolume(this.mdl, 3, 40, 1, "mass", "spring", m, 0.05, dist, dist, k, z); - // listeningPoint = "mass30"; - - // Udu - //m = 1.0; k = 0.39; z = 0.02; dist = 1.; fric = 0.0003; l0 = 0.2; grav = 0.; c_dist = 1.9; c_gnd = 0.65; c_k = 0.07; c_z = 0.04; - //generateVolume(this.mdl, 2, 10, 1, "mass", "spring", m, 0.05, dist, dist, k, z); - //listeningPoint = "mass10"; - - // Balafon - //m = 1.0; k = 0.39; z = 0.02; dist = 1.; fric = 0.0003; l0 = 0.2; grav = 0.; c_dist = 1.9; c_gnd = 0.65; c_k = 0.07; c_z = 0.04; - //generateVolume(this.mdl, 3, 10, 1, "mass", "spring", m, 0.05, dist, dist, k, z); - //listeningPoint = "mass20"; - - // Tabla - //m = 1.0; k = 0.39; z = 0.01; dist = 1.; fric = 0.0003; l0 = 0.2; grav = 0.; c_dist = 1.9; c_gnd = 0.65; c_k = 0.07; c_z = 0.04; - //generateVolume(this.mdl, 5, 20, 1, "mass", "spring", m, 1, dist, dist, k, z); - //listeningPoint = "mass20"; - - // Tiberian Crotals - //m = 1.0; k = 0.39; z = 0.0001; dist = 1.; fric = 0.00003; l0 = 0.2; grav = 0.; c_dist = 1.9; c_gnd = 0.65; c_k = 0.07; c_z = 0.04; - //generateVolume(this.mdl, 20, 5, 1, "mass", "spring", m, 0.05, dist, dist, k, z); - //listeningPoint = "mass30"; - - // Cow Bell - //m = 1.0; k = 0.35; z = 0.001; dist = 1.; fric = 0.003; l0 = 0.2; grav = 0.; c_dist = 1.9; c_gnd = 0.65; c_k = 0.07; c_z = 0.04; - //generateVolume(this.mdl, 5, 20, 1, "mass", "spring", m, 0.05, dist, dist, k, z); - //listeningPoint = "mass30"; - - // Screaming Bitch - //m = 1.0; k = 0.1; z = 0.00001; dist = 1.; fric = 0.000003; l0 = 0.2; grav = 0.; c_dist = 4.9; c_gnd = 0.65; c_k = 0.07; c_z = 0.04; - //generateVolume(this.mdl, 20, 5, 1, "mass", "spring", m, 0.05, dist, dist, k, z); - //listeningPoint = "mass30"; - - // Try and make it scream - //m = 1.0; k = 0.35; z = 0.00001; dist = 1.; fric = 0.0003; l0 = 0.2; grav = 0.; c_dist = 6.9; c_gnd = 0.65; c_k = 0.07; c_z = 0.04; - //generateVolume(this.mdl, 2, 2, 1, "mass", "spring", m, 0.05, dist, dist, k, z); - //listeningPoint = "mass3"; - - input = this.mdl.addMass("percMass", new PosInput3D(1., new Vect3D(3, -4, 0.), smoothing)); +//import java.util.Arrays; +//import ddf.minim.UGen; + +//import miPhysics.Engine.*; + +///* Phyiscal parameters for the model */ +///* The general approach her is to use general/homogeneus parameters for mass (m), stifness (k), internal viscosity (z) +///* dist is the value defining the distance between to mass modules when generating the structure +///* fric is the global external viscoty +///* l0 is the resting lenght for all interaction modules +///* grav is a general parameters of gravity +///* c_dist, c_gnd, c_k and c_z are the parameters of the interaction model and mass +// */ +//float m, k, z, dist, fric, l0, grav, c_k, c_z; + +//public class PhyUGen extends UGen +//{ +// private float oneOverSampleRate; +// float audioOut; +// PhysicalModel mdl; +// PosInput3D input; +// Observer3D listener; +// private String listeningPoint; +// int smoothing = 100; + +// public PhyUGen(int sampleRate) +// { +// super(); + +// this.mdl = new PhysicalModel(sampleRate, (int)baseFrameRate); +// mdl.setGlobalGravity(0,0,grav); +// mdl.setGlobalFriction(fric); + +// audioOut = 0; + + +// // Just a good old beam +// m = 1.0; +// k = 0.3; +// z = 0.0001; +// dist = 0.24; +// fric = 0.00003; +// l0 = 0.3; +// grav = 0.; +// c_k = 0.03; +// c_z = 0.01; +// generateVolume(this.mdl, 3, 30, 1, "mass", "spring", m, 0.05, dist, dist, k, z); +// listeningPoint = "mass20"; + +// // Metal Hurlant / +// //m = 1.0; k = 0.35; z = 0.01; dist = 0.4; fric = 0.0003; l0 = 0.2; grav = 0.; c_dist = 1.8; c_gnd = 0.65; c_k = 0.07; c_z = -0.04; +// //generateVolume(this.mdl, 3, 40, 1, "mass", "spring", m, 0.05, dist, dist, k, z); +// //listeningPoint = "mass30"; + +// // Fat Woden Stick / +// // m = 1.0; k = 0.35; z = 0.1; dist = 1.; fric = 0.0003; l0 = 0.2; grav = 0.; c_dist = .9; c_gnd = 0.65; c_k = 0.07; c_z = 0.04; +// // generateVolume(this.mdl, 3, 40, 1, "mass", "spring", m, 0.05, dist, dist, k, z); +// // listeningPoint = "mass30"; + +// // Udu +// //m = 1.0; k = 0.39; z = 0.02; dist = 1.; fric = 0.0003; l0 = 0.2; grav = 0.; c_dist = 1.9; c_gnd = 0.65; c_k = 0.07; c_z = 0.04; +// //generateVolume(this.mdl, 2, 10, 1, "mass", "spring", m, 0.05, dist, dist, k, z); +// //listeningPoint = "mass10"; + +// // Balafon +// //m = 1.0; k = 0.39; z = 0.02; dist = 1.; fric = 0.0003; l0 = 0.2; grav = 0.; c_dist = 1.9; c_gnd = 0.65; c_k = 0.07; c_z = 0.04; +// //generateVolume(this.mdl, 3, 10, 1, "mass", "spring", m, 0.05, dist, dist, k, z); +// //listeningPoint = "mass20"; + +// // Tabla +// //m = 1.0; k = 0.39; z = 0.01; dist = 1.; fric = 0.0003; l0 = 0.2; grav = 0.; c_dist = 1.9; c_gnd = 0.65; c_k = 0.07; c_z = 0.04; +// //generateVolume(this.mdl, 5, 20, 1, "mass", "spring", m, 1, dist, dist, k, z); +// //listeningPoint = "mass20"; + +// // Tiberian Crotals +// //m = 1.0; k = 0.39; z = 0.0001; dist = 1.; fric = 0.00003; l0 = 0.2; grav = 0.; c_dist = 1.9; c_gnd = 0.65; c_k = 0.07; c_z = 0.04; +// //generateVolume(this.mdl, 20, 5, 1, "mass", "spring", m, 0.05, dist, dist, k, z); +// //listeningPoint = "mass30"; + +// // Cow Bell +// //m = 1.0; k = 0.35; z = 0.001; dist = 1.; fric = 0.003; l0 = 0.2; grav = 0.; c_dist = 1.9; c_gnd = 0.65; c_k = 0.07; c_z = 0.04; +// //generateVolume(this.mdl, 5, 20, 1, "mass", "spring", m, 0.05, dist, dist, k, z); +// //listeningPoint = "mass30"; + +// // Screaming Bitch +// //m = 1.0; k = 0.1; z = 0.00001; dist = 1.; fric = 0.000003; l0 = 0.2; grav = 0.; c_dist = 4.9; c_gnd = 0.65; c_k = 0.07; c_z = 0.04; +// //generateVolume(this.mdl, 20, 5, 1, "mass", "spring", m, 0.05, dist, dist, k, z); +// //listeningPoint = "mass30"; + +// // Try and make it scream +// //m = 1.0; k = 0.35; z = 0.00001; dist = 1.; fric = 0.0003; l0 = 0.2; grav = 0.; c_dist = 6.9; c_gnd = 0.65; c_k = 0.07; c_z = 0.04; +// //generateVolume(this.mdl, 2, 2, 1, "mass", "spring", m, 0.05, dist, dist, k, z); +// //listeningPoint = "mass3"; + +// input = this.mdl.addMass("percMass", new PosInput3D(1., new Vect3D(3, -4, 0.), smoothing)); - // it is also possible to set interactions by using module references directly and not names - for (int i = 0; i< mdl.getNumberOfMasses()-1; i++) - this.mdl.addInteraction("col"+i, new Contact3D(c_k, c_z), input, mdl.getMassList().get(i)); +// // it is also possible to set interactions by using module references directly and not names +// for (int i = 0; i< mdl.getNumberOfMasses()-1; i++) +// this.mdl.addInteraction("col"+i, new Contact3D(c_k, c_z), input, mdl.getMassList().get(i)); - this.listener = this.mdl.addInOut("obs1", new Observer3D(filterType.HIGH_PASS), listeningPoint); - - - this.mdl.init(); - } - - /* - * This routine will be called any time the sample rate changes. - */ - protected void sampleRateChanged() - { - oneOverSampleRate = 1 / sampleRate(); - this.mdl.setSimRate((int)sampleRate()); - } - - // Some variable dealing with mouse movement smoothing - float smooth = 0.01; - float x_avg=0, y_avg=0; - - @Override - protected void uGenerate(float[] channels) - { - float x = 30 * (float)mouseX / width - 15; - float y = 30 * (float)mouseY / height - 15; - input.drivePosition(new Vect3D(x, y, 0)); +// this.listener = this.mdl.addInOut("obs1", new Observer3D(filterType.HIGH_PASS), listeningPoint); + + +// this.mdl.init(); +// } + +// /* +// * This routine will be called any time the sample rate changes. +// */ +// protected void sampleRateChanged() +// { +// oneOverSampleRate = 1 / sampleRate(); +// this.mdl.setSimRate((int)sampleRate()); +// } + +// // Some variable dealing with mouse movement smoothing +// float smooth = 0.01; +// float x_avg=0, y_avg=0; + +// @Override +// protected void uGenerate(float[] channels) +// { +// float x = 30 * (float)mouseX / width - 15; +// float y = 30 * (float)mouseY / height - 15; +// input.drivePosition(new Vect3D(x, y, 0)); - this.mdl.computeSingleStep(); +// this.mdl.computeSingleStep(); - audioOut = (float)listener.observePos().y * 1.4; - Arrays.fill( channels, audioOut ); - currAudio = audioOut; - } -} +// audioOut = (float)listener.observePos().y * 1.4; +// Arrays.fill( channels, audioOut ); +// currAudio = audioOut; +// } +//} diff --git a/src/miPhysics/Engine/Driver3D.java b/src/miPhysics/Engine/Driver3D.java index 38719bf..ed83dbb 100644 --- a/src/miPhysics/Engine/Driver3D.java +++ b/src/miPhysics/Engine/Driver3D.java @@ -52,7 +52,7 @@ public void applyFrc(Vect3D frc){ public void applyFrc(double x, double y, double z){ Vect3D newFrc = new Vect3D(x,y,z); - this.applyPos(newFrc); + this.applyFrc(newFrc); } /** diff --git a/src/miPhysics/Engine/Interaction.java b/src/miPhysics/Engine/Interaction.java index 8d7bfa1..1fb7ed0 100644 --- a/src/miPhysics/Engine/Interaction.java +++ b/src/miPhysics/Engine/Interaction.java @@ -93,6 +93,10 @@ protected void initDistances() { m_dist = Math.sqrt(m_distSquared); } + public void init(){ + this.initDistances(); + } + /** * Calculate the euclidian distance between both Mats connected to this Interaction. * @return