Quellcode durchsuchen

Add start and end events triggered on mouse/wheel/touch down/up for trackball control

The start and end events can be used to start or stop an animation loop, for example, so that the animation loop does not have to run continuously.
Jason Grout vor 12 Jahren
Ursprung
Commit
50186868ce
1 geänderte Dateien mit 10 neuen und 0 gelöschten Zeilen
  1. 10 0
      examples/js/controls/TrackballControls.js

+ 10 - 0
examples/js/controls/TrackballControls.js

@@ -65,6 +65,8 @@ THREE.TrackballControls = function ( object, domElement ) {
 	// events
 
 	var changeEvent = { type: 'change' };
+	var startEvent = { type: 'start'};
+	var endEvent = { type: 'end'};
 
 
 	// methods
@@ -389,6 +391,8 @@ THREE.TrackballControls = function ( object, domElement ) {
 
 		document.addEventListener( 'mousemove', mousemove, false );
 		document.addEventListener( 'mouseup', mouseup, false );
+		_this.dispatchEvent( startEvent );
+
 
 	}
 
@@ -426,6 +430,7 @@ THREE.TrackballControls = function ( object, domElement ) {
 
 		document.removeEventListener( 'mousemove', mousemove );
 		document.removeEventListener( 'mouseup', mouseup );
+		_this.dispatchEvent( endEvent );
 
 	}
 
@@ -449,6 +454,8 @@ THREE.TrackballControls = function ( object, domElement ) {
 		}
 
 		_zoomStart.y += delta * 0.01;
+		_this.dispatchEvent( startEvent );
+		_this.dispatchEvent( endEvent );
 
 	}
 
@@ -479,6 +486,8 @@ THREE.TrackballControls = function ( object, domElement ) {
 				_state = STATE.NONE;
 
 		}
+		_this.dispatchEvent( startEvent );
+
 
 	}
 
@@ -533,6 +542,7 @@ THREE.TrackballControls = function ( object, domElement ) {
 		}
 
 		_state = STATE.NONE;
+		_this.dispatchEvent( endEvent );
 
 	}