views:

310

answers:

2

Hello,
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

+1  A: 

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.

Kornel Kisielewicz
Direction doesn't change e.g. when I use TGLCamera.MoveAroundTarget I'm now experimenting with the projection and modelview matrices mat:=MatrixMultiply(GLScene1.CurrentBuffer.ProjectionMatrix,GLScene1.CurrentBuffer.ModelViewMatrix);
mabi
the correct matrix is MatrixMultiply(GLScene1.CurrentBuffer.ModelViewMatrix ,GLScene1.CurrentBuffer.ProjectionMatrix);I will post some delphi code when I clean up my test
mabi
A: 

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;
mabi