* evtl. an Stoff ziehen\r
*/\r
\r
-\r
-class Point {\r
- constructor(x, y) {\r
- this.x = x;\r
- this.y = y;\r
- }\r
-\r
- add(that) {\r
- return new Point(\r
- this.x + that.x,\r
- this.y + that.y\r
- );\r
- }\r
-\r
- sub(that) {\r
- return new Point(\r
- this.x - that.x,\r
- this.y - that.y\r
- );\r
- }\r
-\r
- dist(that) {\r
- let a = this.x - that.x;\r
- let b = this.y - that.y;\r
- return Math.sqrt(a * a + b * b)\r
- }\r
-}\r
-\r
-\r
/**\r
* setup THREE JS Scene, Camera and Renderer\r
*/\r
document.body.onload = init;\r
\r
function init() {\r
- let mousePos = new Point();\r
+ let mousePos = new THREE.Vector2();\r
let previousClothSimulation;\r
\r
/**\r
const light = new THREE.DirectionalLight( 0xffffff, 0.5 );\r
light.position.set( 0, 1, 0.5 );\r
scene.add( light );\r
+ \r
+ let raycaster = new THREE.Raycaster();\r
\r
/**\r
* function called every frame\r
function animate(dt) {\r
cloth.simulate(dt/1000);\r
\r
+ raycaster.setFromCamera( new THREE.Vector2((mousePos.x / w) * 2 - 1, ((h - mousePos.y) / h) * 2 - 1), camera );\r
+\r
+ const intersects = raycaster.intersectObject( mesh );\r
+\r
+ if ( intersects.length > 0 ) {\r
+ cloth.wind(intersects);\r
+ }\r
setTimeout(() => {\r
animate(frameTime);\r
}, frameTime);\r
renderer.render(scene, camera);\r
}\r
\r
+\r
/** add callback for window resize */\r
let canvas = document.getElementsByTagName("canvas")[0];\r
+ let w = window.innerWidth;\r
+ let h = window.innerHeight - canvasSpace;\r
let resize = function () {\r
- let w = window.innerWidth;\r
- let h = window.innerHeight - 200;\r
+ w = window.innerWidth;\r
+ h = window.innerHeight - canvasSpace;\r
canvas.width = w;\r
canvas.height = h;\r
}\r