|
@@ -131,48 +131,42 @@
|
|
|
|
|
|
} );
|
|
|
|
|
|
- window.addEventListener( 'mousedown', function () {
|
|
|
+ window.addEventListener( 'pointerdown', function () {
|
|
|
|
|
|
moved = false;
|
|
|
|
|
|
}, false );
|
|
|
|
|
|
- window.addEventListener( 'mouseup', function () {
|
|
|
+ window.addEventListener( 'pointerup', function ( event ) {
|
|
|
|
|
|
- checkIntersection();
|
|
|
- if ( ! moved && intersection.intersects ) shoot();
|
|
|
+ if ( moved === false ) {
|
|
|
|
|
|
- } );
|
|
|
+ checkIntersection( event.clientX, event.clientY );
|
|
|
|
|
|
- window.addEventListener( 'mousemove', onTouchMove );
|
|
|
- window.addEventListener( 'touchmove', onTouchMove );
|
|
|
+ if ( intersection.intersects ) shoot();
|
|
|
|
|
|
- function onTouchMove( event ) {
|
|
|
+ }
|
|
|
|
|
|
- var x, y;
|
|
|
+ } );
|
|
|
|
|
|
- if ( event.changedTouches ) {
|
|
|
+ window.addEventListener( 'pointermove', onPointerMove );
|
|
|
|
|
|
- x = event.changedTouches[ 0 ].pageX;
|
|
|
- y = event.changedTouches[ 0 ].pageY;
|
|
|
+ function onPointerMove( event ) {
|
|
|
|
|
|
- } else {
|
|
|
+ if ( event.isPrimary ) {
|
|
|
|
|
|
- x = event.clientX;
|
|
|
- y = event.clientY;
|
|
|
+ checkIntersection( event.clientX, event.clientY );
|
|
|
|
|
|
}
|
|
|
|
|
|
- mouse.x = ( x / window.innerWidth ) * 2 - 1;
|
|
|
- mouse.y = - ( y / window.innerHeight ) * 2 + 1;
|
|
|
-
|
|
|
- checkIntersection();
|
|
|
-
|
|
|
}
|
|
|
|
|
|
- function checkIntersection() {
|
|
|
+ function checkIntersection( x, y ) {
|
|
|
+
|
|
|
+ if ( mesh === undefined ) return;
|
|
|
|
|
|
- if ( ! mesh ) return;
|
|
|
+ mouse.x = ( x / window.innerWidth ) * 2 - 1;
|
|
|
+ mouse.y = - ( y / window.innerHeight ) * 2 + 1;
|
|
|
|
|
|
raycaster.setFromCamera( mouse, camera );
|
|
|
raycaster.intersectObject( mesh, false, intersects );
|