Performs a ray - primitive intersection test.
Returns an Intersection object with the associated information.
If the ray did not hit the primitive, the distance will be negative.
Source
Intersection intersect(Ray r, num prevBestDistance) {
Intersection intersect = new Intersection();
// perform calculations in homogeneous space
// check if ray is orthogonal to normal (= parallel to plane)
Vector4 homDir = new Vector4(r.direction.x, r.direction.y, r.direction.z, 0.0);
double div = homDir.dot(equation);
if (div.abs() > EPS) {
// calculate distance from ray origin to plane
// use homogeneous vector4 representation
Vector4 vec4 = -(r.origin.xyzz..w = 1.0);
var dist = vec4.dot(equation) / div;
intersect.distance = dist;
intersect.prim = this;
intersect.hitPoint = r.getPoint3(dist);
}
return intersect;
}