|
@@ -18,22 +18,22 @@
|
|
<h2>Code Example</h2>
|
|
<h2>Code Example</h2>
|
|
<code>
|
|
<code>
|
|
const raycaster = new THREE.Raycaster();
|
|
const raycaster = new THREE.Raycaster();
|
|
- const mouse = new THREE.Vector2();
|
|
|
|
|
|
+ const pointer = new THREE.Vector2();
|
|
|
|
|
|
- function onMouseMove( event ) {
|
|
|
|
|
|
+ function onPointerMove( event ) {
|
|
|
|
|
|
- // calculate mouse position in normalized device coordinates
|
|
|
|
|
|
+ // calculate pointer position in normalized device coordinates
|
|
// (-1 to +1) for both components
|
|
// (-1 to +1) for both components
|
|
|
|
|
|
- mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
|
|
|
|
- mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
|
|
|
|
|
|
+ pointer.x = ( event.clientX / window.innerWidth ) * 2 - 1;
|
|
|
|
+ pointer.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
function render() {
|
|
function render() {
|
|
|
|
|
|
- // update the picking ray with the camera and mouse position
|
|
|
|
- raycaster.setFromCamera( mouse, camera );
|
|
|
|
|
|
+ // update the picking ray with the camera and pointer position
|
|
|
|
+ raycaster.setFromCamera( pointer, camera );
|
|
|
|
|
|
// calculate objects intersecting the picking ray
|
|
// calculate objects intersecting the picking ray
|
|
const intersects = raycaster.intersectObjects( scene.children );
|
|
const intersects = raycaster.intersectObjects( scene.children );
|
|
@@ -48,7 +48,7 @@
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- window.addEventListener( 'mousemove', onMouseMove, false );
|
|
|
|
|
|
+ window.addEventListener( 'pointermove', onPointerMove );
|
|
|
|
|
|
window.requestAnimationFrame(render);
|
|
window.requestAnimationFrame(render);
|
|
|
|
|