public static bool IntersectRayTriangle(Ray ray, LVector3 t1, LVector3 t2, LVector3 t3, out LVector3 intersection) { intersection = LVector3.zero; LVector3 edge1 = t2.sub(t1); LVector3 edge2 = t3.sub(t1); LVector3 pvec = ray.direction.cross(edge2); LFloat det = edge1.dot(pvec); if (IsZero(det)) { var p = new Plane(t1, t2, t3); if (p.testPoint(ray.origin) == PlaneSide.OnPlane && IsPointInTriangle(ray.origin, t1, t2, t3)) { intersection.set(ray.origin); return(true); } return(false); } det = 1 / det; LVector3 tvec = ray.origin.sub(t1); LFloat u = tvec.dot(pvec) * det; if (u < 0 || u > 1) { return(false); } LVector3 qvec = tvec.cross(edge1); LFloat v = ray.direction.dot(qvec) * det; if (v < 0 || u + v > 1) { return(false); } LFloat t = edge2.dot(qvec) * det; if (t < 0) { return(false); } if (t <= FLOAT_ROUNDING_ERROR) { intersection.set(ray.origin); } else { ray.getEndPoint(intersection, t); } return(true); }
public static bool IntersectSegmentPlane(LVector3 start, LVector3 end, Plane plane, LVector3 intersection) { LVector3 dir = end.sub(start); LFloat denom = dir.dot(plane.getNormal()); LFloat t = -(start.dot(plane.getNormal()) + plane.getD()) / denom; if (t < 0 || t > 1) { return(false); } intersection.set(start).Add(dir.scl(t)); return(true); }
public void set(LVector3 point, LVector3 normal) { this.normal.set(normal); d = -point.dot(normal); }
public LFloat distance(LVector3 point) { return(normal.dot(point) + d); }
public void set(LVector3 point1, LVector3 point2, LVector3 point3) { normal = (point1).sub(point2).cross(point2.x - point3.x, point2.y - point3.y, point2.z - point3.z).nor(); d = -point1.dot(normal); }