在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/