Hello list, I'm currently working on a Gem patch where I have a lot of sphere primitives and I would like to identify the sphere that appears under some particular Gemwin screen coordinates (aka raycasting). I can't find an object that already does this calculation so I ended up finding this SO answer explaining the raycasting principle https://stackoverflow.com/a/19153090. Still, I'm a bit lost and don't know where to start ... I found this informative post for the 3D graphics noob that I am : https://gamedev.stackexchange.com/a/178645 But I can't figure out how to apply this to Gem. Any help would be greatly appreciated. Best, Joseph
Hello again, Fortunately I have a friend who is good at 3D graphics and yesterday he showed me a simple way to achieve what I was after. First I had to determine the world coordinates of the camera (C), and of the mouse on the near plane (M). I kept the default gemwin settings, so the camera is located at C = (0,0,4) and the mouse at M = (x,y,3) with x and y between -1 and 1 when the gemwin is square. We get the ray to cast by doing M - C and normalizing the resulting vector. Then I used the technique described here : https://www.scratchapixel.com/lessons/3d-basic-rendering/minimal-ray-tracer-... This gets us all the spheres pointed at by the mouse. Sorting the spheres by their respective distances to M, we then get the closest one. I didn't go further because this was all I needed. I hope this might help someone in the future. Cheers, Joseph
Le 08/03/2025 à 15:43, Joseph Larralde a écrit :
Hello list, I'm currently working on a Gem patch where I have a lot of sphere primitives and I would like to identify the sphere that appears under some particular Gemwin screen coordinates (aka raycasting). I can't find an object that already does this calculation so I ended up finding this SO answer explaining the raycasting principle https://stackoverflow.com/a/19153090. Still, I'm a bit lost and don't know where to start ... I found this informative post for the 3D graphics noob that I am : https://gamedev.stackexchange.com/a/178645 But I can't figure out how to apply this to Gem. Any help would be greatly appreciated. Best, Joseph