Question

using GLScene in delphi I need to find the intersection between an object (a line or plane is enough) and the visible space, to determine what part of this object is currently showing.
I tried getting the view frustum but I couldn't find how. I was thinking of using camera's position, direction and field of view, but I suspect they are not updated when using methods like MoveAroundTarget or setting the target object.
Thanks,
Marco

Was it helpful?

Solution

To get the frustum you can use the ModelViewProjection matrix obtained multipying the ModelViewMatrix and the ProjectionMatrix from TGLScene's current buffer. To get the planes from the matrix use the ExtractFrustumFromModelViewProjection function. Here is a code snippet:

var
  matMVP: TMatrix;
  frustum : TFrustum;
  intersectPoint : TVector;
begin
  // get the ModelViewProjection matrix
  matMVP:=MatrixMultiply(GLScene1.CurrentBuffer.ModelViewMatrix, GLScene1.CurrentBuffer.ProjectionMatrix);
  // extract frustum
  frustum:=ExtractFrustumFromModelViewProjection(matMVP);
  // calculate intersection between left plane and line passing through GLArrowLineX object
  if (IntersectLinePlane(GLArrowLineX.Position.AsVector,GLArrowLineX.Direction.AsVector, frustum.pLeft, @intersectPoint)=1)
  then begin
    // do something with intersectPoint
  end else begin
    // no intersection point (parallel or inside plane)
  end;
end;

OTHER TIPS

You can get the frustum out of the camera object (TGLSceneViewer.Camera property) -- the properties NearPlane, DepthOfView, Position, Direction will be needed, as well as 'TGLSceneViewer.FieldOfView'.

The TGLCamera has also a method called RayCastIntersect that may prove useful.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top