prieston
prieston

Reputation: 1506

How to update Trackball controls at three js

I have a project at three.js where i need to update the trackball controls on window resize.. I need to do that updating the whole controls calling the function with new input variables. Recreating the controls causes crash and i dont want to delete the controls and create new one cause of the garbage this might cause. I have a similar question How to update createControls's function input variables at javascript? but i think this is more complete question.

Upvotes: 0

Views: 1236

Answers (1)

WestLangley
WestLangley

Reputation: 104763

If you want to update TrackballControls when you resize the window, you can use this pattern:

window.addEventListener( 'resize', onWindowResize, false );

function onWindowResize() {

    camera.aspect = window.innerWidth / window.innerHeight;
    camera.updateProjectionMatrix();

    renderer.setSize( window.innerWidth, window.innerHeight );

    controls.handleResize(); // for TrackballControls

    render();

}

You will have to modify this pattern depending on how your canvas is sized.

See http://threejs.org/examples/misc_controls_trackball.html.

three.js r.70

Upvotes: 3

Related Questions