three.js 在手机端移动转向 可做场景漫游

先把几个函数发上来,完整代码等解耦后再完善
单手指点击屏幕前进,双手指点击后退 左右滑动专向

this.onTouchStart=function( event ) {

				isUserInteracting = true;
				var clientX = event.clientX || event.touches[ 0 ].clientX;
				var clientY = event.clientY || event.touches[ 0 ].clientY;
				onMouseDownMouseX = clientX;
				onMouseDownMouseY = clientY;
				onMouseDownLon = lon;
				onMouseDownLat = lat;

		
		if ( this.domElement !== document ) {

			this.domElement.focus();

		}

		event.preventDefault();   //防止违约
		event.stopPropagation();   //停止传播


		if ( this.activeLook ) {
					var touch = event.targetTouches[0];
					touchstartY=touch.pageX;

				switch ( event.touches.length ) {

			case 1:	
			 this.moveForward = true;
				
				break;

			case 2:	
				this.moveBackward = true; 
				break;

			default:	

		}
			}
		

		this.mouseDragOn = true;    //鼠标拖动


	console.log("touchstart");

	
	}

	this.onTouchEnd=function( event ) {

				console.log("touchend");

			isUserInteracting = false;

			
			
		//console.log(event.touches.length);

				 this.moveForward = false; 
				 this.moveBackward = false; 

		this.mouseDragOn = false;
	}


	this.onTouchMove=function( event ) {

		console.log("touchmove");

			if ( isUserInteracting === true ) {
					var clientX = event.clientX || event.touches[ 0 ].clientX;
					var clientY = event.clientY || event.touches[ 0 ].clientY;
					lon = ( onMouseDownMouseX - clientX ) * 0.1 + onMouseDownLon;
					lat = ( clientY - onMouseDownMouseY ) * 0.1 + onMouseDownLat;
				}

	}
		
	

你可能感兴趣的:(THREE)