From 4a5e31b59fef016c9132516daeb9003c2670278b Mon Sep 17 00:00:00 2001 From: "Mr.doob" Date: Fri, 18 Mar 2016 16:32:07 +0000 Subject: [PATCH] Interactive-er webvr_cubes. --- examples/webvr_cubes.html | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/examples/webvr_cubes.html b/examples/webvr_cubes.html index c933884c12..f95a23d975 100644 --- a/examples/webvr_cubes.html +++ b/examples/webvr_cubes.html @@ -107,9 +107,9 @@ object.scale.z = Math.random() + 0.5; object.userData.velocity = new THREE.Vector3(); - object.userData.velocity.x = Math.random() * 0.4 - 0.2; - object.userData.velocity.y = Math.random() * 0.4 - 0.2; - object.userData.velocity.z = Math.random() * 0.4 - 0.2; + object.userData.velocity.x = Math.random() - 0.5; + object.userData.velocity.y = Math.random() - 0.5; + object.userData.velocity.z = Math.random() - 0.5; scene.add( object ); cubes.push( object ); @@ -134,6 +134,17 @@ } + renderer.domElement.addEventListener( 'click', function ( event ) { + + if ( INTERSECTED ) { + + var object = INTERSECTED; + object.userData.velocity.subVectors( object.position, camera.position ).normalize(); + + } + + } ); + // window.addEventListener( 'resize', onWindowResize, false ); @@ -182,7 +193,7 @@ if ( INTERSECTED ) INTERSECTED.material.emissive.setHex( INTERSECTED.currentHex ); - INTERSECTED = null; + INTERSECTED = undefined; } @@ -192,6 +203,8 @@ var cube = cubes[ i ]; + cube.userData.velocity.multiplyScalar( 0.999 ); + cube.position.add( cube.userData.velocity ); if ( cube.position.x < - 100 || cube.position.x > 100 ) { -- GitLab