function intersectObjects({ locationX, locationY }, objects) { const { width, height } = Dimensions.get('window'); pointerVector.set( locationX / width * 2 - 1, -(locationY / height * 2) + 1 ); ray.setFromCamera(pointerVector, camera); var intersections = ray.intersectObjects(objects, true); return intersections[0] ? intersections[0] : false; }
useCallback(event => { if (event.clientX !== void 0) { let x = event.clientX; let y = event.clientY; // #101: https://github.com/react-spring/react-three-fiber/issues/101 // The offset parent isn't taken into account by the resize observer if (event.target && event.target.offsetParent) { x -= event.target.offsetParent.offsetLeft; y -= event.target.offsetParent.offsetTop; } const left = state.current.size.left || 0; const right = left + state.current.size.width || 0; const top = size.top || 0; const bottom = top + state.current.size.height || 0; mouse.set((x - left) / (right - left) * 2 - 1, -((y - top) / (bottom - top)) * 2 + 1); defaultRaycaster.setFromCamera(mouse, state.current.camera); } }, [])
function handleMouseMoveDolly(event) { //console.log( 'handleMouseMoveDolly' ); dollyEnd.set(event.clientX, event.clientY); dollyDelta.subVectors(dollyEnd, dollyStart); if (dollyDelta.y > 0) { dollyIn(getZoomScale()); } else if (dollyDelta.y < 0) { dollyOut(getZoomScale()); } dollyStart.copy(dollyEnd); scope.update(); }
function handleTouchMoveRotate(event) { //console.log( 'handleTouchMoveRotate' ); rotateEnd.set(event.touches[0].pageX, event.touches[0].pageY); rotateDelta.subVectors(rotateEnd, rotateStart); // rotating across whole screen goes 360 degrees around rotateLeft( ((2 * Math.PI * rotateDelta.x) / scope.clientWidth) * scope.rotateSpeed ); // rotating up and down along whole screen attempts to go 360, but limited to 180 rotateUp( ((2 * Math.PI * rotateDelta.y) / scope.clientHeight) * scope.rotateSpeed ); rotateStart.copy(rotateEnd); scope.update(); }
function handleMouseMoveRotate(event) { //console.log( 'handleMouseMoveRotate' ); rotateEnd.set(event.clientX, event.clientY); rotateDelta.subVectors(rotateEnd, rotateStart); // rotating across whole screen goes 360 degrees around rotateLeft( ((2 * Math.PI * rotateDelta.x) / scope.clientWidth) * scope.rotateSpeed ); // rotating up and down along whole screen attempts to go 360, but limited to 180 rotateUp( ((2 * Math.PI * rotateDelta.y) / scope.clientHeight) * scope.rotateSpeed ); rotateStart.copy(rotateEnd); scope.update(); }
function handleTouchMoveDolly(event) { //console.log( 'handleTouchMoveDolly' ); var dx = event.touches[0].pageX - event.touches[1].pageX; var dy = event.touches[0].pageY - event.touches[1].pageY; var distance = Math.sqrt(dx * dx + dy * dy); dollyEnd.set(0, distance); dollyDelta.subVectors(dollyEnd, dollyStart); if (dollyDelta.y > 0) { dollyOut(getZoomScale()); } else if (dollyDelta.y < 0) { dollyIn(getZoomScale()); } dollyStart.copy(dollyEnd); scope.update(); }