【问题标题】:Create a 3d plane with three points用三个点创建一个 3d 平面
【发布时间】:2015-11-08 20:55:49
【问题描述】:

我们知道 3D 平面是由 3 个点构成的。 现在在德尔福我使用 GLScene 有一个平面,你看不到任何任意点来创建一个平面。我的问题是如何通过 3 个给定点设置平面。 根据 SO 规则,我编写了我的 TGLPlane 源代码。

  TGLPlane = class(TGLSceneObject)
  private
    { Private Declarations }
    FXOffset, FYOffset: TGLFloat;
    FXScope, FYScope: TGLFloat;
    FWidth, FHeight: TGLFloat;
    FXTiles, FYTiles: Cardinal;
    FStyle: TGLPlaneStyles;
    FMesh: array of array of TVertexRec;
  protected
    { Protected Declarations }
    procedure SetHeight(const aValue: Single);
    procedure SetWidth(const aValue: Single);
    procedure SetXOffset(const Value: TGLFloat);
    procedure SetXScope(const Value: TGLFloat);
    function StoreXScope: Boolean;
    procedure SetXTiles(const Value: Cardinal);
    procedure SetYOffset(const Value: TGLFloat);
    procedure SetYScope(const Value: TGLFloat);
    function StoreYScope: Boolean;
    procedure SetYTiles(const Value: Cardinal);
    procedure SetStyle(const val: TGLPlaneStyles);

  public
    { Public Declarations }
    constructor Create(AOwner: TComponent); override;

    procedure Assign(Source: TPersistent); override;

    procedure BuildList(var rci: TRenderContextInfo); override;
    function GenerateSilhouette(const silhouetteParameters
      : TGLSilhouetteParameters): TGLSilhouette; override;

    function AxisAlignedDimensionsUnscaled: TVector; override;
    function RayCastIntersect(const rayStart, rayVector: TVector;
      intersectPoint: PVector = nil; intersectNormal: PVector = nil)
      : Boolean; override;
    { : Computes the screen coordinates of the smallest rectangle encompassing the plane.<p>
      Returned extents are NOT limited to any physical screen extents. }
    function ScreenRect(aBuffer: TGLSceneBuffer): TGLRect;

    { : Computes the signed distance to the point.<p>
      Point coordinates are expected in absolute coordinates. }
    function PointDistance(const aPoint: TVector): Single;

  published
    { Public Declarations }
    property Height: TGLFloat read FHeight write SetHeight;
    property Width: TGLFloat read FWidth write SetWidth;
    property XOffset: TGLFloat read FXOffset write SetXOffset;
    property XScope: TGLFloat read FXScope write SetXScope stored StoreXScope;
    property XTiles: Cardinal read FXTiles write SetXTiles default 1;
    property YOffset: TGLFloat read FYOffset write SetYOffset;
    property YScope: TGLFloat read FYScope write SetYScope stored StoreYScope;
    property YTiles: Cardinal read FYTiles write SetYTiles default 1;
    property Style: TGLPlaneStyles read FStyle write SetStyle
      default [psSingleQuad, psTileTexture];
  end;

【问题讨论】:

  • 您是否阅读过文档?甚至是源代码。请不要告诉我们你没有。我希望如果你这样做,你会找到一个接受三个点的平面对象的构造函数。
  • 请不要使用答案来评论其他 cmets。这不是 SO 的工作方式(有关更多信息,请参阅 help。也就是说,@DavidHeffernan 的评论是完全有效的。如果您显示的源代码是 TGLPlane 的全部内容,那么您寻找的答案是显而易见的。
  • 我找到文档的 GLScene 平面对象有一个构造函数,它接受平面中的三个点(顶点)。 akser 提供的 Delphi 类没有。我不知道为什么不。
  • 我试图复制代码,但这是一个限制词。
  • 请删除您的反对票。

标签: delphi 3d plane glscene


【解决方案1】:

在 GLScene 中,平面由其位置和方向决定,而不是直接由三个点决定。

让我们标记点 A、B 和 C。选择 A 作为位置。矢量 AB 和 AC 的叉积将为您提供法线矢量。使用这些结果设置平面的 AbsolutePositionAbsoluteDirection 属性。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-11
    • 1970-01-01
    • 2011-04-13
    • 1970-01-01
    • 1970-01-01
    • 2018-11-05
    • 2017-07-12
    相关资源
    最近更新 更多