Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
1.1.0:picking [2024/04/09 15:45] – admin | 1.1.0:picking [2024/04/09 15:59] (current) – admin | ||
---|---|---|---|
Line 23: | Line 23: | ||
Hit : Boolean; | Hit : Boolean; | ||
Intersection : TPoint3D; | Intersection : TPoint3D; | ||
- | Instance | + | Instance |
Triangle | Triangle | ||
end; | 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]] |