public bool IntersectP(Ray ray, out double hitt0, out double hitt1) { double t0 = 0, t1 = ray.TMax; for (int i = 0; i < 3; ++i) { // Update interval for _i_th bounding box slab double invRayDir = 1 / ray.Direction[i]; double tNear = (MinPoint[i] - ray.Origin[i]) * invRayDir; double tFar = (MaxPoint[i] - ray.Origin[i]) * invRayDir; // Update parametric interval from slab intersection $t$ values if (tNear > tFar) { double temp = tNear; tNear = tFar; tFar = temp; } // Update _tFar_ to ensure robust ray--bounds intersection tFar *= 1 + 2 * PbrtMath.Gamma(3); t0 = tNear > t0 ? tNear : t0; t1 = tFar < t1 ? tFar : t1; if (t0 > t1) { hitt0 = 0.0; hitt1 = 0.0; return(false); } } hitt0 = t0; hitt1 = t1; return(true); }
public Point3D ExecuteTransform(Point3D p, out Vector3D pError) { double x = p.X, y = p.Y, z = p.Z; // Compute transformed coordinates from point _pt_ double xp = M[0, 0] * x + M[0, 1] * y + M[0, 2] * z + M[0, 3]; double yp = M[1, 0] * x + M[1, 1] * y + M[1, 2] * z + M[1, 3]; double zp = M[2, 0] * x + M[2, 1] * y + M[2, 2] * z + M[2, 3]; double wp = M[3, 0] * x + M[3, 1] * y + M[3, 2] * z + M[3, 3]; // Compute absolute error for transformed point double xAbsSum = (Math.Abs(M[0, 0] * x) + Math.Abs(M[0, 1] * y) + Math.Abs(M[0, 2] * z) + Math.Abs(M[0, 3])); double yAbsSum = (Math.Abs(M[1, 0] * x) + Math.Abs(M[1, 1] * y) + Math.Abs(M[1, 2] * z) + Math.Abs(M[1, 3])); double zAbsSum = (Math.Abs(M[2, 0] * x) + Math.Abs(M[2, 1] * y) + Math.Abs(M[2, 2] * z) + Math.Abs(M[2, 3])); pError = PbrtMath.Gamma(3) * new Vector3D(xAbsSum, yAbsSum, zAbsSum); //CHECK_NE(wp, 0); if (wp == 1.0) { return(new Point3D(xp, yp, zp)); } else { return(new Point3D(xp, yp, zp) / wp); } }
public bool IntersectP(Ray ray, Vector3D invDir, bool[] dirIsNeg) { // Check for ray intersection against $x$ and $y$ slabs double tMin = (this[dirIsNeg[0] ? 1 : 0].X - ray.Origin.X) * invDir.X; double tMax = (this[dirIsNeg[0] ? 0 : 1].X - ray.Origin.X) * invDir.X; double tyMin = (this[dirIsNeg[1] ? 1 : 0].Y - ray.Origin.Y) * invDir.Y; double tyMax = (this[dirIsNeg[1] ? 0 : 1].Y - ray.Origin.Y) * invDir.Y; // Update _tMax_ and _tyMax_ to ensure robust bounds intersection tMax *= 1.0 + 2.0 * PbrtMath.Gamma(3); tyMax *= 1.0 + 2.0 * PbrtMath.Gamma(3); if (tMin > tyMax || tyMin > tMax) { return(false); } if (tyMin > tMin) { tMin = tyMin; } if (tyMax < tMax) { tMax = tyMax; } // Check for ray intersection against $z$ slab double tzMin = (this[dirIsNeg[2] ? 1 : 0].Z - ray.Origin.Z) * invDir.Z; double tzMax = (this[dirIsNeg[2] ? 0 : 1].Z - ray.Origin.Z) * invDir.Z; // Update _tzMax_ to ensure robust bounds intersection tzMax *= 1.0 + 2.0 * PbrtMath.Gamma(3); if (tMin > tzMax || tzMin > tMax) { return(false); } if (tzMin > tMin) { tMin = tzMin; } if (tzMax < tMax) { tMax = tzMax; } return((tMin < ray.TMax) && (tMax > 0.0)); }