Browse Source

Improved webvr_daydream physics performance.

Mr.doob 7 years ago
parent
commit
960ce5a573
1 changed files with 7 additions and 5 deletions
  1. 7 5
      examples/webvr_daydream.html

+ 7 - 5
examples/webvr_daydream.html

@@ -19,7 +19,7 @@
 				overflow: hidden;
 			}
 			a {
-				color: #f00;
+				color: #48f;
 			}
 		</style>
 	</head>
@@ -206,18 +206,20 @@
 
 						normal.copy( cube.position ).sub( cube2.position );
 
-						if ( normal.length() < 2 * radius ) {
+						var distance = normal.length();
+
+						if ( distance < 2 * radius ) {
+
+							normal.multiplyScalar( 0.5 * distance - radius );
 
-							normal.multiplyScalar( 0.5 * normal.length() - radius );
 							cube.position.sub( normal );
 							cube2.position.add( normal );
 
 							normal.normalize();
 
 							relativeVelocity.copy( cube.userData.velocity ).sub( cube2.userData.velocity );
-							var dot = relativeVelocity.dot( normal );
 
-							normal = normal.multiplyScalar( dot );
+							normal = normal.multiplyScalar( relativeVelocity.dot( normal ) );
 
 							cube.userData.velocity.sub( normal );
 							cube2.userData.velocity.add( normal );