diff --git a/CameraSpinControls.js b/CameraSpinControls.js index f9a70b1..f668b18 100644 --- a/CameraSpinControls.js +++ b/CameraSpinControls.js @@ -28,14 +28,20 @@ CameraSpinControls = function ( camera, domElement ) { // Set to false to disable this control this.enabled = true; + this.distanceFromPivot = 500; + this.object = camera; // "target" sets the location of focus, where the object orbits around this.targetObj = new THREE.Object3D(); - this.targetObj.lookAt(camera.position); this.target = this.targetObj.position; - this.distanceFromPivot = this.target.distanceTo( camera.position ); + + if ( camera.position.length() < EPS ) { + camera.position.set(0, 0, 1); + } + + this.targetObj.lookAt(camera.position); - this.isTargetOffCenter = false; + this.isTargetOffCenter = true; this.trackballToObject = new THREE.Matrix4(); this.targetObj.updateWorldMatrix(true, false); @@ -43,10 +49,9 @@ CameraSpinControls = function ( camera, domElement ) { transformTo(this.trackballToObject, this.targetObj.matrixWorld, this.object.matrixWorld); // How far you can dolly in and out ( PerspectiveCamera only ) - // If isTargetOffCenter === true, will cause jumps if target is closer or further than limits + // Will cause jumps if target is moved closer or further than limits this.minDistance = 0; this.maxDistance = Infinity; - // TODO If rotate or pan with intersection, ignore rotation distance clamps // How far you can zoom in and out ( OrthographicCamera only ) this.minZoom = 0; @@ -166,7 +171,6 @@ CameraSpinControls = function ( camera, domElement ) { scope.object.matrix.copy( scope.targetObj.matrixWorld ); scope.object.matrix.multiply(scope.trackballToObject); - } else { scope.distanceFromPivot *= scale; @@ -891,7 +895,8 @@ CameraSpinControls = function ( camera, domElement ) { scope.spinControl.enabled = true; scope.spinControl.handleTouchStart( event ); - } else { + } else if( event.touches.length === 0 ) { + // } else { state = STATE.NONE; endEvent.state = state; @@ -934,19 +939,6 @@ CameraSpinControls = function ( camera, domElement ) { scope.dispatchEvent( changeEvent ); } ); - - scope.spinControl.addEventListener( 'start', function ( event ) { - - scope.dispatchEvent( startEvent ); - - } ); - - scope.spinControl.addEventListener( 'end', function ( event ) { - - endEvent.state = state; - scope.dispatchEvent( endEvent ); - - } ); // Starts touch interfaces off right this.ajustTrackballRadius(); diff --git a/SpinControls.js b/SpinControls.js index 1e48aa8..02ca771 100644 --- a/SpinControls.js +++ b/SpinControls.js @@ -592,7 +592,7 @@ var SpinControls = function ( object, trackBallRadius, camera, domElement ) { } function onTouchMove( event ) { - + if ( _this.enabled === false || !_isPointerDown ) return; event.preventDefault(); @@ -604,7 +604,7 @@ var SpinControls = function ( object, trackBallRadius, camera, domElement ) { function onTouchEnd( event ) { - if( _this.enabled === false || !_isPointerDown ) return; + if( _this.enabled === false ) return; if( !_this.hasPointerMovedThisFrame ) { @@ -616,6 +616,11 @@ var SpinControls = function ( object, trackBallRadius, camera, domElement ) { _this.handlePointerUp( event ); + // override handlePointerUp if finger still down + if( event.touches.length > 0 ) { + _isPointerDown = true; + } + } this.dispose = function () { diff --git a/example_camera_spin.html b/example_camera_spin.html index 2b4b53c..e7c3d6e 100644 --- a/example_camera_spin.html +++ b/example_camera_spin.html @@ -54,8 +54,9 @@ camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 1, 10000 ); + camera.position.set(0, 0, 500); + cameraSpinControl = new CameraSpinControls( camera, renderer.domElement ); - cameraSpinControl.distanceFromPivot = 500; // Uncomment for third person view of CameraSpinControls // And comment out CameraSpinControls above diff --git a/index.html b/index.html index 7286353..7d4fbae 100644 --- a/index.html +++ b/index.html @@ -188,7 +188,7 @@

SpinControls

window.addEventListener( 'wheel', onMouseWheel, true ); window.addEventListener( 'wheel', onMouseWheelOff, false ); - renderer.domElement.addEventListener( 'touchstart', onTouchStart, false ); + renderer.domElement.addEventListener( 'touchstart', onTouchStart, true ); // catch down to enable camera control window.addEventListener( 'touchend', onTouchEnd, false ); // get event last, so false on capture // Spheres to spin