فهرست منبع

TrackballControls: Caching event.

Mr.doob 13 سال پیش
والد
کامیت
ab7c7251e6
1فایلهای تغییر یافته به همراه12 افزوده شده و 8 حذف شده
  1. 12 8
      src/extras/controls/TrackballControls.js

+ 12 - 8
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 );