This is an old revision of the document!


Picking / Selecting

Selecting a mesh or picking a specific triangle of a mesh are well known everyday challenges. Since v1.1.0.2927 we've fixed and optimized our set of methods.

You can now perform a raycast intersect test or a pick triangle call on a model or mesh and it will also test containing sub-meshes.

MethodDescription
function RayCastIntersect(const ARayPos, ARayDir: TPoint3D; var AIntersection, ANormal: TPoint3D) : Boolean;Perform a ray cast on this mesh. CAUTION: absolute ray position and ray direction expected!
function PickTriangle(const X, Y : Single; var AIntersection, ANormal: TPoint3D; out A, B, C : TPoint3D) : Boolean;Detects an intersected triangle by a screen point. The method converts screen coordinates to 3d coordinates and calls PickTriangle() routine with the corresponding raypos and raydir. If intersection was successful, the method returns the intersection 3D coordinate and the normal vector at this position. Otherwise those values are undefined. If intersection was successful, the method returns the absolute triangle corner coordinates. Otherwise A, B and C are zero.
function PickTriangle(const X, Y : Single; var AResult : TTriangleRayCastResult) : Boolean;Detects an intersected triangle by a screen point. The method converts screen coordinates to 3d coordinates and calls PickTriangle() routine with the corresponding raypos and raydir. If intersection was successful, the method returns the TTriangleRayCastResult structure containing the intersection point, the normal at this position, the 3 corner vertex positions and if a object could be detected the instance those data belongs to. Otherwise this structure is undefined.
function PickTriangle(const ARayPos, ARayDir: TVector3D; var AIntersection, ANormal: TPoint3D; out A, B, C : TPoint3D) : Boolean;Detects an intersected triangle by an absolute raypos and raydir! If intersection was successful, the method returns the intersection 3D coordinate and the normal vector at this position. Otherwise those values are undefined. If intersection was successful, the method returns the absolute triangle corner coordinates. Otherwise A, B and C are zero.
function PickTriangle(const ARayPos, ARayDir: TVector3D; var AResult : TTriangleRayCastResult) : Boolean;Detects an intersected triangle by an absolute raypos and raydir! If intersection was successful, the method returns the TTriangleRayCastResult structure containing the intersection point, the normal at this position, the 3 corner vertex positions and if a object could be detected the instance those data belongs to. Otherwise this structure is undefined.

Use the extended calls with the TTriangleRayCastResult result for detailed information about the picked data.

The TTriangleRayCastResult record has the following structure:

  TTriangleRayCastResult = record
    T            : Single;
    Normal       : TPoint3D;
    Hit          : Boolean;
    Intersection : TPoint3D;
    Instance     : TObject;
    Triangle     : Array[0..2] of TPoint3D;
  end;