Skip to content

Commit abb4bc2

Browse files
committed
More improvements to webvr_cubes example.
1 parent e9e4b80 commit abb4bc2

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

examples/webvr_cubes.html

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@
6767
scene.add( camera );
6868

6969
crosshair = new THREE.Mesh(
70-
new THREE.RingGeometry( 0.5, 1, 32 ),
70+
new THREE.RingGeometry( 0.02, 0.04, 32 ),
7171
new THREE.MeshBasicMaterial( {
7272
color: 0xffffff,
7373
opacity: 0.5,
7474
transparent: true
7575
} )
7676
);
77-
crosshair.position.z = - 40;
77+
crosshair.position.z = - 2;
7878
camera.add( crosshair );
7979

8080
var mesh = new THREE.Mesh(
@@ -89,15 +89,15 @@
8989
light.position.set( 1, 1, 1 ).normalize();
9090
scene.add( light );
9191

92-
var geometry = new THREE.BoxGeometry( 3, 3, 3 );
92+
var geometry = new THREE.BoxGeometry( 5, 5, 5 );
9393

9494
for ( var i = 0; i < 200; i ++ ) {
9595

9696
var object = new THREE.Mesh( geometry, new THREE.MeshLambertMaterial( { color: Math.random() * 0xffffff } ) );
9797

98-
object.position.x = Math.random() * 100 - 50;
99-
object.position.y = Math.random() * 100 - 50;
100-
object.position.z = Math.random() * 100 - 50;
98+
object.position.x = Math.random() * 200 - 100;
99+
object.position.y = Math.random() * 200 - 100;
100+
object.position.z = Math.random() * 200 - 100;
101101

102102
object.rotation.x = Math.random() * 2 * Math.PI;
103103
object.rotation.y = Math.random() * 2 * Math.PI;
@@ -202,13 +202,23 @@
202202

203203
cube.position.add( cube.userData.velocity );
204204

205-
if ( cube.position.x < 100 ) cube.position.x += 200;
206-
if ( cube.position.y < 100 ) cube.position.y += 200;
207-
if ( cube.position.z < 100 ) cube.position.z += 200;
205+
if ( cube.position.x < - 100 || cube.position.x > 100 ) {
208206

209-
if ( cube.position.x > 100 ) cube.position.x -= 200;
210-
if ( cube.position.y > 100 ) cube.position.y -= 200;
211-
if ( cube.position.z > 100 ) cube.position.z -= 200;
207+
cube.userData.velocity.x = - cube.userData.velocity.x;
208+
209+
}
210+
211+
if ( cube.position.y < - 100 || cube.position.y > 100 ) {
212+
213+
cube.userData.velocity.y = - cube.userData.velocity.y;
214+
215+
}
216+
217+
if ( cube.position.z < - 100 || cube.position.z > 100 ) {
218+
219+
cube.userData.velocity.z = - cube.userData.velocity.z;
220+
221+
}
212222

213223
cube.rotation.x += 0.01;
214224

0 commit comments

Comments
 (0)