在GLScene中确定与平截头体的交点

时间:2009-12-30 10:39:27

标签: delphi opengl frustum glscene

在delphi中使用GLScene我需要找到一个对象(一条线或一个平面就足够了)和可见空间之间的交集,以确定该对象当前显示的部分。
我尝试了视锥,但我找不到。我正在考虑使用相机的位置,方向和视野,但我怀疑它们在使用MoveAroundTarget或设置目标物体等方法时没有更新。
谢谢,
马可

2 个答案:

答案 0 :(得分:2)

要获得平截头体,您可以使用从TGLScene当前缓冲区中获取的ModelViewMatrix和ProjectionMatrix获得的ModelViewProjection矩阵。要从矩阵中获取平面,请使用ExtractFrustumFromModelViewProjection函数。这是一段代码:

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;

答案 1 :(得分:1)

您可以从相机对象(TGLSceneViewer.Camera属性)中获取平截头体 - 将需要属性NearPlaneDepthOfViewPositionDirection,以及'TGLSceneViewer.FieldOfView'。

TGLCamera还有一个名为RayCastIntersect的方法可能有用。