In this scenario, picture a three.js scene configured with an OrthographicCamera and OrbitControls:
https://i.sstatic.net/rhJnr.png
When the user moves the yellow disc (representing the Sun), it should follow along its corresponding yellow circle. To better visualize this, here's another perspective of the scene showing the complete yellow circle:
https://i.sstatic.net/sRQ3g.png
My challenge lies in figuring out how to identify the point on the circle closest to the current cursor position using an event handler. Just for reference, the yellow circle is a THREE.Mesh object.
I've been trying to use THREE.Raycaster and its intersectObjects()
function to detect mouseover events, but I'm unsure about how to determine the nearest point on a single object with this Raycaster. Perhaps there's some straightforward calculations involved after transforming the mouse coordinates into world coordinates. Can anyone offer guidance on this? Is Three.js's Raycaster suitable for this task? If not, what approach should I take to find the nearest point on this mesh?
If you want to view the entire source code, visit: https://github.com/ccnmtl/astro-interactives/blob/master/sun-motion-simulator/src/HorizonView.jsx. Look for this.sunDeclination
, which represents the Mesh object of the yellow circle.
To see a demo in action, click here:
If you want to understand how the sun should move, check out this link: (Flash required)