Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
1.1.0:picking [2024/04/09 15:42] – created admin | 1.1.0:picking [2024/04/09 15:59] (current) – admin | ||
---|---|---|---|
Line 12: | Line 12: | ||
|function PickTriangle(const ARayPos, ARayDir: TVector3D; var AIntersection, | |function PickTriangle(const ARayPos, ARayDir: TVector3D; var AIntersection, | ||
|function PickTriangle(const ARayPos, ARayDir: TVector3D; var AResult : TTriangleRayCastResult) : Boolean; | |function PickTriangle(const ARayPos, ARayDir: TVector3D; var AResult : TTriangleRayCastResult) : Boolean; | ||
+ | |||
+ | Use the extended calls with the **TTriangleRayCastResult** result for detailed information about the picked data. | ||
+ | |||
+ | The TTriangleRayCastResult record has the following structure: | ||
+ | |||
+ | <file Pascal> | ||
+ | TTriangleRayCastResult = record | ||
+ | T : Single; | ||
+ | Normal | ||
+ | Hit : Boolean; | ||
+ | Intersection : TPoint3D; | ||
+ | Instance | ||
+ | Triangle | ||
+ | end; | ||
+ | </ | ||
+ | |||
+ | As example, you can register an OnMouseUp event on your specific mesh/model or sub-mesh. | ||
+ | Within your OnMouseUp event you can then perform the raycasting or triangle picking: | ||
+ | |||
+ | <file Pascal> | ||
+ | procedure TForm1.MyMeshMouseUp(Sender: | ||
+ | Shift: TShiftState; | ||
+ | var LAbsRayPos, LAbsRayDir : TVector3D; | ||
+ | LIntersect, LNormal : TPoint3D; | ||
+ | LMesh : TGorillaMesh; | ||
+ | LTriResult | ||
+ | begin | ||
+ | LMesh := Sender as TGorillaMesh; | ||
+ | |||
+ | if not Assigned(LMesh) then | ||
+ | Exit; | ||
+ | |||
+ | // Convert from local vector to absolute, because we're currently in object space | ||
+ | LAbsRayPos := LMesh.LocalToAbsoluteVector(ARayPos); | ||
+ | LAbsRayDir := LMesh.LocalToAbsoluteDirection(ARayDir); | ||
+ | |||
+ | // Perform a raycast intersection test and if it hits the mesh, show a message | ||
+ | if LMesh.RayCastIntersect(LAbsRayPos, | ||
+ | ShowMessage(Format(' | ||
+ | | ||
+ | // Or perform a triangle pick and output the triangle points and the instance pointer too | ||
+ | if LMesh.PickTriangle(LAbsRayPos, | ||
+ | ShowMessage(Format(' | ||
+ | [ | ||
+ | NativeUInt(LTriResult.Instance), | ||
+ | LTriResult.Intersection.X, | ||
+ | | ||
+ | LTriResult.Triangle[0].X, | ||
+ | LTriResult.Triangle[1].X, | ||
+ | LTriResult.Triangle[2].X, | ||
+ | ])); | ||
+ | end; | ||
+ | </ | ||
+ | |||
+ | Next step: [[charactercontrolling|CharacterControlling]] |