3D Collision Detection |
In the last project, Condenado, the people ask
me about the collision detection. Now Sorgo I.D. makes a universal function
to all programming language. In this document I explaining to your. All 3D objects are made by triangles, in this easy function your need input the triangles vertex and the vector origin and direction, the function returns the collision coordinates. Firs your need define on the function head the parameters that not are define in the body function, the parameters are: |
. | |
To input
VO.x, VO.y, VO.z -Origin Vector Coordinates. VD.x, VD.y, VD.z -Direction Vector Coordinates. VE1.x, VE1.y, VE1.z -Triangle vertex coordinate.
To output
|
![]() |
. |
. | . |
![]() |
The vector is only a infinite line section, is possible that the vector orientation across 2 or more triangles if your have multiple objects .The function only return the last coordinate intersection. |
. | . |
The body function: R1,R2,R3,L1,L2,L3,LR,NL,TL // Define this variables to type FLOAT, for better Precision. R1=((VE2.y
- VE1.y)*(VE3.z - VE1.z)) – ((VE2.z - VE1.z)*(VE3.y – VE1.y))
L1=(VD.x
– VO.x)
LR=(R1*L1)
– (R2*L2) + (R3*L3)
TL=(-1*NL)/LR ve11.x=VO.x
+ TL*(L1)
I hope you like this function . by Necro
|