Last active
March 16, 2021 20:17
-
-
Save BABAK0T0/1546d3fa4033b84941a60793e1294848 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Default Amplitude Adjustment [0, 1] | |
| * DOM coord [0, 0] is located in left top corner | |
| * Three.js coord [0, 0] is located in center of the screen | |
| * | |
| * | |
| * Position.y axis being positive when going upward in Three.js | |
| * But the clientY axis being positive when going downward in the webpage. | |
| * You can simply invert the cursor.y while updating it by adding a minus (-) | |
| **/ | |
| const cursor = { | |
| x: 0, | |
| y: 0 | |
| } | |
| // Amplitude [-0.5 , 0.5] | |
| window.addEventListener('mousemove', (event) => | |
| { | |
| cursor.x = event.clientX / sizes.width - 0.5 | |
| cursor.y = - (event.clientY / sizes.height - 0.5) | |
| }) | |
| // Amplitude [-1, 1] | |
| window.addEventListener('mousemove', (event) => | |
| { | |
| cursor.x = event.clientX / sizes.width * 2 - 1 | |
| cursor.y = - (event.clientY / sizes.height) * 2 + 1 | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment