Created
April 28, 2015 18:24
-
-
Save zeux/762bea2bd7e8582e5ac3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void rayTriangle(RayResult& result, const btVector3& raySource, const btVector3& rayDir, const btVector3& v0, const btVector3& v1, const btVector3& v2, unsigned int tri) const | |
{ | |
btVector3 edge1 = v1 - v0; | |
btVector3 edge2 = v2 - v0; | |
btVector3 P = rayDir.cross(edge2); | |
float det = edge1.dot(P); | |
if (det <= 0) | |
return; | |
btVector3 T = raySource - v0; | |
float u = T.dot(P); | |
if (u < 0 || u > det) | |
return; | |
btVector3 Q = T.cross(edge1); | |
float v = rayDir.dot(Q); | |
if (v < 0 || u + v > det) | |
return; | |
float t = edge2.dot(Q) / det; | |
if (t < 0 || t >= result.fraction) | |
return; | |
result = RayResult(t, this, tri); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment