| 1 | # Detect Scene Hits |
| 2 | |
| 3 | Detect what is the `TCastleScene` under mouse / touch position. |
| 4 | |
| 5 | Uses `TCastleViewport.TransformUnderMouse` to detect clicks on a particular scene. |
| 6 | |
| 7 | Note that you could also look at `TCastleViewport.TriangleHit` for details of the triangle under mouse. You can also look at each scene properties: |
| 8 | |
| 9 | - `TCastleScene.PointingDeviceOverItem: PTriangle;` |
| 10 | - `TCastleScene.PointingDeviceOverPoint: TVector3;` |
| 11 | - `TCastleScene.PointingDeviceActive: Boolean;` |
| 12 | |
| 13 | You can also take a look at `TCastleViewport.MouseRayHit`, which contains all information. The `TCastleViewport.TransformUnderMouse` and `TCastleViewport.TriangleHit` and in fact just comfortable shortcuts that access `TCastleViewport.MouseRayHit` underneath. |
| 14 | |
| 15 | Alternative way to capture clicks is to use `TouchSensor` X3D node (not shown in this example). |
| 16 | |
| 17 | Using [Castle Game Engine](https://castle-engine.io/). |
| 18 | |
| 19 | ## Building |
| 20 | |
| 21 | Compile by: |
| 22 | |
| 23 | - [CGE editor](https://castle-engine.io/editor). Just use menu items _"Compile"_ or _"Compile And Run"_. |
| 24 | |
| 25 | - Or use [CGE command-line build tool](https://castle-engine.io/build_tool). Run `castle-engine compile` in this directory. |
| 26 | |
| 27 | - Or use [Lazarus](https://www.lazarus-ide.org/). Open in Lazarus `detect_scene_hit_standalone.lpi` file and compile / run from Lazarus. Make sure to first register [CGE Lazarus packages](https://castle-engine.io/lazarus). |
| 28 | |
| 29 | - Or use [Delphi](https://www.embarcadero.com/products/Delphi). Open in Delphi `detect_scene_hit_standalone.dproj` file and compile / run from Delphi. See [CGE and Delphi](https://castle-engine.io/delphi) documentation for details. |