0

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.

Community
  • 1
  • 1
prieston
  • 1,426
  • 2
  • 18
  • 39

1 Answers1

3

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

WestLangley
  • 102,557
  • 10
  • 276
  • 276
  • sorry for the late reply! I was searching to solve my problem but with no result. What i need is to update the trackball controls to detect the mouse position event to a different screen. I managed to make the handleResize() function but the getmousePosition(event) is not working correct. any help how to fix this? – prieston Feb 26 '15 at 09:37
  • 1
    When you have a new question, you need to make a new post. – WestLangley Feb 26 '15 at 17:28