在delphi中使用GLScene时,我需要找到一个对象(一条直线或一个平面就足够了)和可视空间之间的交点,以确定该对象当前显示的部分。
我试着获得视锥,但我找不到方法。我在考虑使用相机的位置、方向和视野,但我怀疑它们在使用MoveAroundTarget或设置目标对象等方法时不会更新。
谢谢,
马可
发布于 2010-01-08 18:51:22
要获得平截体,可以使用从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;发布于 2009-12-31 06:38:43
您可以从camera对象(TGLSceneViewer.Camera属性)中获取截锥--需要属性NearPlane、DepthOfView、Position、Direction以及'TGLSceneViewer.FieldOfView‘。
TGLCamera还有一个名为RayCastIntersect的方法,它可能会被证明是有用的。
https://stackoverflow.com/questions/1979511
复制相似问题