Hi,
you can download sample code for ray-triangle intersection in the attachement.
It uses newly introduced function enabled types to produce easy to follow code.
Thanks to this, the main code can be very short:
Uses "Console"
#INCLUDE Once "tTriangle.tBasicU"
#INCLUDE Once "tVector3D.tBasicU"
#INCLUDE Once "tRay.tBasicU"
Function TBMain()
Dim triangle As tTriangle
triangle.Init(-1, -1, 0, ' -- A
1, -1, 0, ' -- B
0, 1, 0) ' -- C
Dim ray As tRay
ray.Init(0, 0, 1, ' -- Point
0, 0,-1) ' -- Direction
Dim collisionPoint As tVector3D
PrintL "Ray : " + ray.ToString()
PrintL "Triangle: " + triangle.ToString()
PrintL "-----"
If ray.IntersectsTriangle(triangle, collisionPoint) Then
PrintL "Intersection found at " + collisionPoint.ToString()
Else
PrintL "No intersection found"
End If
WaitKey
End Function
Petr
Bookmarks