Skip to content

Commit

Permalink
Docs: Improve Raycaster page. (#23132)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mugen87 authored Jan 1, 2022
1 parent 484f9e2 commit 61a4d5c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
16 changes: 8 additions & 8 deletions docs/api/en/core/Raycaster.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ <h1>[name]</h1>
<h2>Code Example</h2>
<code>
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

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() {

// 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
const intersects = raycaster.intersectObjects( scene.children );
Expand All @@ -48,7 +48,7 @@ <h2>Code Example</h2>

}

window.addEventListener( 'mousemove', onMouseMove, false );
window.addEventListener( 'pointermove', onPointerMove );

window.requestAnimationFrame(render);

Expand Down
16 changes: 8 additions & 8 deletions docs/api/ko/core/Raycaster.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ <h1>[name]</h1>
<h2>코드 예제</h2>
<code>
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

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() {

// 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
const intersects = raycaster.intersectObjects( scene.children );
Expand All @@ -47,7 +47,7 @@ <h2>코드 예제</h2>

}

window.addEventListener( 'mousemove', onMouseMove, false );
window.addEventListener( 'pointermove', onPointerMove );

window.requestAnimationFrame(render);

Expand Down
12 changes: 6 additions & 6 deletions docs/api/zh/core/Raycaster.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ <h1>光线投射[name]</h1>
<h2>代码示例</h2>
<code>
const raycaster = new THREE.Raycaster();
const mouse = new THREE.Vector2();
const pointer = new THREE.Vector2();

function onMouseMove( event ) {
function onPointerMove( event ) {

// 将鼠标位置归一化为设备坐标。x 和 y 方向的取值范围是 (-1 to +1)

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() {

// 通过摄像机和鼠标位置更新射线
raycaster.setFromCamera( mouse, camera );
raycaster.setFromCamera( pointer, camera );

// 计算物体和射线的焦点
const intersects = raycaster.intersectObjects( scene.children );
Expand All @@ -46,7 +46,7 @@ <h2>代码示例</h2>

}

window.addEventListener( 'mousemove', onMouseMove, false );
window.addEventListener( 'pointermove', onPointerMove );

window.requestAnimationFrame(render);

Expand Down

0 comments on commit 61a4d5c

Please sign in to comment.