From 159bbcf8df63b36d2df0810947c2e91dcf619ae4 Mon Sep 17 00:00:00 2001 From: demifang21 Date: Mon, 23 May 2016 19:33:28 -0400 Subject: [PATCH] Stationary Ball option in GUI Aatish, after working on p5 to make sure it ran OK, I just copy/pasted my new p5 code into this "Edit file" field-- is that how it works? Hope you can see the changes I made. If not, I introduced "isBallMoving" boolean variable and made a Stationary Ball option in the drop-down menu for interactions. The one thing I couldn't figure out is in line 212-- currently, when you select Stationary Ball, the new stationary ball takes on the position of the Moving Ball before it stopped. I think it'd be better to have the position be reset to the center, but I wasn't sure how to go about doing that. Alternatively, maybe it'd be nicer to have a checkbox for "moving" when the "Ball" option is selected from the dropdown menu-- in this scenario, I wouldn't mind the stationary ball taking on the old position. However, I wasn't sure how to code the GUI so that the checkbox would only be activated when a certain dropdown option is selected. Let me know what you think! --- clothphysics.js | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/clothphysics.js b/clothphysics.js index 4c6ab67..a24c450 100644 --- a/clothphysics.js +++ b/clothphysics.js @@ -31,7 +31,8 @@ var windForce = new THREE.Vector3( 0, 0, 0 ); var rotate = false; var pinned = 'Corners'; -var thing = 'Ball'; +var thing = 'Moving Ball'; +var ballIsMoving = true; var cornersPinned, oneEdgePinned, twoEdgesPinned, fourEdgesPinned, randomEdgesPinned; @@ -80,7 +81,7 @@ if(guiEnabled){ f4.add(guiControls, 'rotate').name('auto rotate').onChange(function(value){rotate = value;}); f4.add(guiControls, 'wind').name('wind').onChange(function(value){wind = value;}); - f4.add(guiControls, 'thing', ['None', 'Ball', 'Table']).name('object').onChange(function(value){createThing(value);}); + f4.add(guiControls, 'thing', ['None', 'Stationary Ball', 'Moving Ball', 'Table']).name('object').onChange(function(value){createThing(value);}); f4.add(guiControls, 'pinned', ['None','Corners', 'OneEdge', 'TwoEdges','FourEdges']).name('pinned').onChange(function(value){pinCloth(value);}); var f1 = gui.addFolder('Behavior'); @@ -204,11 +205,21 @@ function pinCloth(choice){ function createThing(thing){ - if(thing == 'Ball' || thing == 'ball'){ + if(thing == 'Stationary Ball' || thing == 'stationary ball'){ sphere.visible = true; table.visible = false; + ballIsMoving = false; + // currently ball takes last Moving Ball position-- how to reset position? restartCloth(); } + + if(thing == 'Moving Ball' || thing == 'moving ball'){ + sphere.visible = true; + table.visible = false; + ballIsMoving = true; + restartCloth(); + } + else if(thing == 'Table' || thing == 'table'){ // these variables are used in the table collision detection @@ -538,12 +549,13 @@ function simulate( time ) { satisifyConstrains( constrain[ 0 ], constrain[ 1 ], constrain[ 2 ], constrain[ 3] ); } - - prevBallPosition.copy(ballPosition); - ballPosition.y = 50*Math.sin(Date.now()/600); - ballPosition.x = 50*Math.sin(Date.now()/600); - ballPosition.z = 50*Math.cos(Date.now()/600); - sphere.position.copy( ballPosition ); //maybe remove this since it's also in render() + if (ballIsMoving == true){ + prevBallPosition.copy(ballPosition); + ballPosition.y = 50*Math.sin(Date.now()/600); + ballPosition.x = 50*Math.sin(Date.now()/600); + ballPosition.z = 50*Math.cos(Date.now()/600); + sphere.position.copy( ballPosition ); //maybe remove this since it's also in render() + } if(avoidClothSelfIntersection){ for ( i = 0; i < particles.length; i ++ ){