delphi - 在 GLScene 中确定与视锥体的交集

标签 delphi opengl frustum glscene

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

最佳答案

要获得截锥体,您可以使用通过将 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;

关于delphi - 在 GLScene 中确定与视锥体的交集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1979511/

相关文章:

multithreading - 如何编写和执行线程

delphi - 需要有关 TIdCmdTCPServer 基本使用的帮助

c# - 使用 mono 中的 freepascal 库 (.dylib)

c++ - 投影矩阵产生不正确的结果

c++ - 在 OpenGL 中每帧绘制新的全屏图像的最快方法是什么?

cocoa - 最简单、简约、opengl 3.2 cocoa项目

javascript - 如何计算在给定坐标处相机可见的矩形的大小?

c++ - 优化视锥剔除

delphi - 在此过程中,Delete 是否做了任何事情?

android - Android 上 OpenGL ES 2.0 中的 frustumM/setLookAtM