提交 64d61686 编写于 作者: M Mr.doob

Made PonterlockControls example frame independent.

上级 caa2dc2b
...@@ -23,6 +23,8 @@ THREE.PointerLockControls = function ( camera ) { ...@@ -23,6 +23,8 @@ THREE.PointerLockControls = function ( camera ) {
var isOnObject = false; var isOnObject = false;
var canJump = false; var canJump = false;
var prevTime = performance.now();
var velocity = new THREE.Vector3(); var velocity = new THREE.Vector3();
var PI_2 = Math.PI / 2; var PI_2 = Math.PI / 2;
...@@ -65,7 +67,7 @@ THREE.PointerLockControls = function ( camera ) { ...@@ -65,7 +67,7 @@ THREE.PointerLockControls = function ( camera ) {
break; break;
case 32: // space case 32: // space
if ( canJump === true ) velocity.y += 10; if ( canJump === true ) velocity.y += 350;
canJump = false; canJump = false;
break; break;
...@@ -139,22 +141,23 @@ THREE.PointerLockControls = function ( camera ) { ...@@ -139,22 +141,23 @@ THREE.PointerLockControls = function ( camera ) {
}(); }();
this.update = function ( delta ) { this.update = function () {
if ( scope.enabled === false ) return; if ( scope.enabled === false ) return;
delta *= 0.1; var time = performance.now();
var delta = ( time - prevTime ) / 1000;
velocity.x += ( - velocity.x ) * 0.08 * delta; velocity.x -= velocity.x * 10.0 * delta;
velocity.z += ( - velocity.z ) * 0.08 * delta; velocity.z -= velocity.z * 10.0 * delta;
velocity.y -= 0.25 * delta; velocity.y -= 9.8 * 100.0 * delta; // 100.0 = mass
if ( moveForward ) velocity.z -= 0.12 * delta; if ( moveForward ) velocity.z -= 400.0 * delta;
if ( moveBackward ) velocity.z += 0.12 * delta; if ( moveBackward ) velocity.z += 400.0 * delta;
if ( moveLeft ) velocity.x -= 0.12 * delta; if ( moveLeft ) velocity.x -= 400.0 * delta;
if ( moveRight ) velocity.x += 0.12 * delta; if ( moveRight ) velocity.x += 400.0 * delta;
if ( isOnObject === true ) { if ( isOnObject === true ) {
...@@ -162,9 +165,9 @@ THREE.PointerLockControls = function ( camera ) { ...@@ -162,9 +165,9 @@ THREE.PointerLockControls = function ( camera ) {
} }
yawObject.translateX( velocity.x ); yawObject.translateX( velocity.x * delta );
yawObject.translateY( velocity.y ); yawObject.translateY( velocity.y * delta );
yawObject.translateZ( velocity.z ); yawObject.translateZ( velocity.z * delta );
if ( yawObject.position.y < 10 ) { if ( yawObject.position.y < 10 ) {
...@@ -175,6 +178,8 @@ THREE.PointerLockControls = function ( camera ) { ...@@ -175,6 +178,8 @@ THREE.PointerLockControls = function ( camera ) {
} }
prevTime = time;
}; };
}; };
...@@ -75,7 +75,7 @@ ...@@ -75,7 +75,7 @@
var camera, scene, renderer; var camera, scene, renderer;
var geometry, material, mesh; var geometry, material, mesh;
var controls,time = Date.now(); var controls;
var objects = []; var objects = [];
...@@ -279,8 +279,6 @@ ...@@ -279,8 +279,6 @@
requestAnimationFrame( animate ); requestAnimationFrame( animate );
//
controls.isOnObject( false ); controls.isOnObject( false );
ray.ray.origin.copy( controls.getObject().position ); ray.ray.origin.copy( controls.getObject().position );
...@@ -300,12 +298,10 @@ ...@@ -300,12 +298,10 @@
} }
controls.update( Date.now() - time ); controls.update();
renderer.render( scene, camera ); renderer.render( scene, camera );
time = Date.now();
} }
</script> </script>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册