Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OrbitControls: Support frame rate independent autoRotate. #26472

Merged
Merged
16 changes: 12 additions & 4 deletions examples/jsm/controls/OrbitControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class OrbitControls extends EventDispatcher {

const twoPI = 2 * Math.PI;

return function update() {
return function update( deltaTime = null ) {

const position = scope.object.position;

Expand All @@ -190,7 +190,7 @@ class OrbitControls extends EventDispatcher {

if ( scope.autoRotate && state === STATE.NONE ) {

rotateLeft( getAutoRotationAngle() );
rotateLeft( getAutoRotationAngle( deltaTime ) );

}

Expand Down Expand Up @@ -469,9 +469,17 @@ class OrbitControls extends EventDispatcher {
const pointers = [];
const pointerPositions = {};

function getAutoRotationAngle() {
function getAutoRotationAngle( deltaTime ) {

return 2 * Math.PI / 60 / 60 * scope.autoRotateSpeed;
if ( deltaTime !== null ) {

return ( 2 * Math.PI / 60 * scope.autoRotateSpeed ) * deltaTime;

} else {

return 2 * Math.PI / 60 / 60 * scope.autoRotateSpeed;

}

}

Expand Down
10 changes: 6 additions & 4 deletions examples/webgl2_volume_instancing.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@

}

let renderer, scene, camera;
let controls;
let renderer, scene, camera, controls, clock;

init();
animate();
Expand All @@ -61,6 +60,8 @@
controls.autoRotateSpeed = - 1.0;
controls.enableDamping = true;

clock = new THREE.Clock();

// Material

const vertexShader = /* glsl */`
Expand Down Expand Up @@ -234,8 +235,9 @@
function animate() {

requestAnimationFrame( animate );

controls.update();

const delta = clock.getDelta();
controls.update( delta );

renderer.render( scene, camera );

Expand Down