The same to you! Thanks. BTW I can't get the ray intersect triangle function to work (works sometimes), any Idea? I'm using the rit() function by elias_t, a mod of the original by sswift who converted it from a Tomas Moller Here's the original, but I'd rather find an other one than to fix this, I tried for hours. So, just if you have a working, reliable RIT() function somewhere.
;-------------------------------------------------------------------------
;A function that finds out if a line segment and a triangle intersect
;and calculates the intersection point in the array picked(2)
;where picked(0)=pickedx,..1=y,..2=z
;
;This actually the function posted by sswift and originally made by Tomas Moller.
;Only here we get also the intersection point !
;
;mod by elias_t
;
;-------------------------------------------------------------------------
;stores the picked location
;Dim picked#(2)
Function rit(Px#,Py#,Pz#, Dx#,Dy#,Dz#, V0x#,V0y#,V0z#, V1x#,V1y#,V1z#, V2x#,V2y#,V2z#, Extend_To_Infinity=1, Cull_Backfaces=0)
;-
E1x# = V2x# - V0x#
E1y# = V2y# - V0y#
E1z# = V2z# - V0z#
;-
E2x# = V1x# - V0x#
E2y# = V1y# - V0y#
E2z# = V1z# - V0z#
; Hxyz = Crossproduct(Dxyz, E2xyz)
Hx# = (Dy# * E2z#) - (E2y# * Dz#)
Hy# = (Dz# * E2x#) - (E2z# * Dx#)
Hz# = (Dx# * E2y#) - (E2x# * Dy#)
; Calculate the dot product of the above vector and the vector between point 0 and point 2.
A# = (E1x# * Hx#) + (E1y# * Hy#) + (E1z# * Hz#)
;cull
If (Cull_Backfaces = 1) And (A# >= 0) Then Return 0
;parralel
If (A# > -0.00001) And (A# < 0.00001) Then Return 0
;Inverse Determinant
F# = 1.0 / A#
;-
Sx# = Px# - V0x#
Sy# = Py# - V0y#
Sz# = Pz# - V0z#
; U# = F# * (DotProduct(Sxyz, Hxyz))
U# = F# * ((Sx# * Hx#) + (Sy# * Hy#) + (Sz# * Hz#))
;check u
If (U# < 0.0) Or (U# > 1.0) Return 0
; Qxyz = CrossProduct(Sxyz, E1xyz)
Qx# = (Sy# * E1z#) - (E1y# * Sz#)
Qy# = (Sz# * E1x#) - (E1z# * Sx#)
Qz# = (Sx# * E1y#) - (E1x# * Sy#)
; V# = F# * DotProduct(Dxyz, Qxyz)
V# = F# * ((Dx# * Qx#) + (Dy# * Qy#) + (Dz# * Qz#))
;check v
If (V# < 0.0) Or ((U# + V#) > 1.0) Return 0
T# = F#*((E2x#*Qx#)+(E2y#*Qy#)+(E2z#*Qz#))
; If T#<0 Return 0; orig
If T#<=0 Return 0
If Extend_To_Infinity=0 And T#>1 Return 0
pickU=U
pickV=V
;-------------------------------------------------
;Calculate intersection point
nx#=(E1y*E2z)-(E1z*E2y)
ny#=(E1z*E2x)-(E1x*E2z)
nz#=(E1x*E2y)-(E1y*E2x)
d# = - nx*V0x - ny*V0y - nz*V0z
denom# = nx*Dx + ny*Dy + nz*Dz
mu# = - (d + nx*Px + ny*Py + nz*Pz) / denom
picked(0) = Px + mu * DX
picked(1) = Py + mu * Dy
picked(2) = Pz + mu * Dz
;-------------------------------------------------
;intersects
Return 1
End Function