I found some code for ray-triangle intersection but it's hard to understand. I can't tell what it's doing to the vectors or anything.
These are the bits confusing me:
Start is the origin of the ray, Points.at(i).at(j) is the first corner of the current triangle. E1 and E2 are the edges of the current triangle and E3 is the direction of the ray, not normalized. (Should it be normalized?)Code:a = Dot(Cross(E1, E2), E3); //I managed to simplify this bit k = ((Start.x-Points.at(i).at(j).x)*E2.y*E3.z +E2.x*E3.y*(Start.z-Points.at(i).at(j).z) +(Start.y-Points.at(i).at(j).y)*E2.z*E3.x -E3.x*E2.y*(Start.z-Points.at(i).at(j).z) -E3.y*E2.z*(Start.x-Points.at(i).at(j).x) -E2.x*(Start.y-Points.at(i).at(j).y)*E3.z)/a; l = (E1.x*(Start.y-Points.at(i).at(j).y)*E3.z +(Start.x-Points.at(i).at(j).x)*E3.y*E1.z +E1.y*(Start.z-Points.at(i).at(j).z)*E3.x -E3.x*(Start.y-Points.at(i).at(j).y)*E1.z -E3.y*(Start.z-Points.at(i).at(j).z)*E1.x -(Start.x-Points.at(i).at(j).x)*E1.y*E3.z)/a;
Wasn't exactly sure where to post this so sorry if it's in the wrong place.


LinkBack URL
About LinkBacks