From ab7c7251e63ce22c8820cd6a49e4ab852c67a296 Mon Sep 17 00:00:00 2001 From: "Mr.doob" Date: Tue, 21 Feb 2012 16:30:15 +0100 Subject: [PATCH] TrackballControls: Caching event. --- src/extras/controls/TrackballControls.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/extras/controls/TrackballControls.js b/src/extras/controls/TrackballControls.js index 018aea5762..d62392aab2 100644 --- a/src/extras/controls/TrackballControls.js +++ b/src/extras/controls/TrackballControls.js @@ -55,6 +55,10 @@ THREE.TrackballControls = function ( object, domElement ) { _panStart = new THREE.Vector2(), _panEnd = new THREE.Vector2(); + // events + + var changeEvent = { type: 'change' }; + // methods @@ -68,7 +72,7 @@ THREE.TrackballControls = function ( object, domElement ) { }; - this.getMouseOnScreen = function( clientX, clientY ) { + this.getMouseOnScreen = function ( clientX, clientY ) { return new THREE.Vector2( ( clientX - _this.screen.offsetLeft ) / _this.radius * 0.5, @@ -77,7 +81,7 @@ THREE.TrackballControls = function ( object, domElement ) { }; - this.getMouseProjectionOnBall = function( clientX, clientY ) { + this.getMouseProjectionOnBall = function ( clientX, clientY ) { var mouseOnBall = new THREE.Vector3( ( clientX - _this.screen.width * 0.5 - _this.screen.offsetLeft ) / _this.radius, @@ -107,7 +111,7 @@ THREE.TrackballControls = function ( object, domElement ) { }; - this.rotateCamera = function() { + this.rotateCamera = function () { var angle = Math.acos( _rotateStart.dot( _rotateEnd ) / _rotateStart.length() / _rotateEnd.length() ); @@ -140,7 +144,7 @@ THREE.TrackballControls = function ( object, domElement ) { }; - this.zoomCamera = function() { + this.zoomCamera = function () { var factor = 1.0 + ( _zoomEnd.y - _zoomStart.y ) * _this.zoomSpeed; @@ -162,7 +166,7 @@ THREE.TrackballControls = function ( object, domElement ) { }; - this.panCamera = function() { + this.panCamera = function () { var mouseChange = _panEnd.clone().subSelf( _panStart ); @@ -190,7 +194,7 @@ THREE.TrackballControls = function ( object, domElement ) { }; - this.checkDistances = function() { + this.checkDistances = function () { if ( !_this.noZoom || !_this.noPan ) { @@ -210,7 +214,7 @@ THREE.TrackballControls = function ( object, domElement ) { }; - this.update = function() { + this.update = function () { _eye.copy( _this.object.position ).subSelf( _this.target ); @@ -240,7 +244,7 @@ THREE.TrackballControls = function ( object, domElement ) { if ( lastPosition.distanceTo( _this.object.position ) > 0 ) { - _this.dispatchEvent( { type: 'change' } ); + _this.dispatchEvent( changeEvent ); lastPosition.copy( _this.object.position ); -- GitLab