the Möller–Trumbore intersection algorithm
これは実装です:
bool EngineItem::checkIntersection(glm::vec3& rayOrigin, glm::vec3& rayVector, Face& face, glm::vec3& point) {
const float EPSILON = 0.0000001;
glm::vec3 vertex0 = face.v1;
glm::vec3 vertex1 = face.v2;
glm::vec3 vertex2 = face.v3;
glm::vec3 edge1, edge2, h, s, q;
float a, f, u, v;
edge1 = vertex1 - vertex0;
edge2 = vertex2 - vertex0;
h = glm::cross(rayVector, edge2);
a = glm::dot(edge1, h);
if (a > -EPSILON && a < EPSILON)
return false;
f = 1/a;
s = rayOrigin - vertex0;
u = f * glm::dot(s, h);
if (u < 0.0 || u > 1.0)
return false;
q = glm::cross(s, edge1);
v = f * glm::dot(rayVector, q);
if (v < 0.0 || u + v > 1.0)
return false;
float t = f * glm::dot(edge2, q);
if (t > EPSILON) {
glm::vec3 plus = glm::normalize(rayVector) * (t * glm::length(rayVector));
point = rayOrigin + plus;
return true;
} else
return false;
}
は標準線三角形の交差を実行しますか? – BDL
あなたの答えは質問ではなく答えとして投稿してください –