Search code examples
delphiopenglfpcglscene

GlScene Mouse to point on TGLHeightField


I have a GLScene with a TGLHeightField with it points loaded from its OnGetHeight.

What i'm trying to work out is what 3d point on the HeightField the mouse is currently over in the mousemove event.

The hight(y) on the HeightField isn't really needed just the point on the plane (x,z)

ive tried GLSceneViewer1.Buffer.OrthoScreenToWorld(x, y) but thats just a point on the cameras plane.


Solution

  • Check out the hfpick demo (in Demos\Interface). It demonstrates how to do this using PixelRayToWorld.

    Basically, what you do is:

    var
       v: TAffineVector;
    
    ...
          v := GLSceneViewer.Buffer.PixelRayToWorld(x, y)
          v := HeightField.AbsoluteToLocal(v);