From f0c64cdbb2ad2e1ae9a110e1d291db57c5b8d85d Mon Sep 17 00:00:00 2001 From: Ramtin Naraghi Date: Sun, 24 Jan 2021 12:29:57 +0100 Subject: [PATCH] Distinguish between right and left mouse click for wind and dragging --- Scripts/cloth.js | 2 +- Scripts/main.js | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Scripts/cloth.js b/Scripts/cloth.js index c873a3d..1ec79d5 100644 --- a/Scripts/cloth.js +++ b/Scripts/cloth.js @@ -99,7 +99,7 @@ export class Cloth { vertexRigidness = []; externalForces = []; - windForce = 0; + windForce = 100; /** * creates a rectangular piece of cloth diff --git a/Scripts/main.js b/Scripts/main.js index c269982..5f6595e 100644 --- a/Scripts/main.js +++ b/Scripts/main.js @@ -91,7 +91,7 @@ function init() { intersects = raycaster.intersectObject( mesh ); - if ( intersects.length > 0 ) { + if ( intersects.length > 0 && rightMousePressed) { cloth.wind(intersects); } setTimeout(() => { @@ -149,12 +149,15 @@ function init() { }; canvas.onmousedown = (evt) => { - if(intersects.length > 0){ + rightMousePressed = evt.button == 2; + + if(intersects.length > 0 && evt.button == 0){ cloth.mousePress(intersects); - } + } } canvas.onmouseup = (evt) => { cloth.mouseRelease(); + rightMousePressed = false; } } \ No newline at end of file -- 2.50.1