I try to write an method bool intersect(const Ray& ray, Intersection& intersection)
that returns true, when the Intersection is inside the Triangle.
What i've done so far , is check if there are Points on the Plane, that is created by 2 Vectors of the Triangle.
The Problem is now to check, if the Point is inside the Triangle.I use barycentric Coordinates
Vec3 AB = b_-a_;
Vec3 AC = c_-a_;
double areaABC = vec_normal_triangle.dot(AB.cross(AC));
Vec3 PB = b_-intersection.pos;
Vec3 PC = c_-intersection.pos;
double alpha = vec_normal_triangle.dot(PB.cross(PC));
Vec3 PA = a_-position.pos;
double beta = vec_normal_triangle.dot(PC.cross(PA));
double gamma = 1-alpha-beta;
if((beta+gamma) < 1 && beta > 0 && gamma > 0) {
return true;
}
Actually its not even a triangle, just about random Points. Can someone explain me or knows how i compute the barycentric Coordinates for 3 given Vectors?