Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stationary Ball option in GUI #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions clothphysics.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 ++ ){
Expand Down