| 310 | */ |
| 311 | |
| 312 | BBox3fa boundSegmentNonlinear(MotionDerivativeCoefficients const& motionDerivCoeffs, |
| 313 | AffineSpace3fa const& xfm0, |
| 314 | AffineSpace3fa const& xfm1, |
| 315 | BBox3fa const& obbox0, |
| 316 | BBox3fa const& obbox1, |
| 317 | BBox3fa const& bbox0, |
| 318 | BBox3fa const& bbox1, |
| 319 | float tmin, |
| 320 | float tmax) |
| 321 | { |
| 322 | BBox3fa delta(Vec3fa(0.f), Vec3fa(0.f)); |
| 323 | float roots[32]; |
| 324 | unsigned int maxNumRoots = 32; |
| 325 | unsigned int numRoots; |
| 326 | const Interval1f interval(tmin, tmax); |
| 327 | |
| 328 | // loop over bounding box corners |
| 329 | for (int ii = 0; ii < 2; ++ii) |
| 330 | for (int jj = 0; jj < 2; ++jj) |
| 331 | for (int kk = 0; kk < 2; ++kk) |
| 332 | { |
| 333 | Vec3fa p0(ii == 0 ? obbox0.lower.x : obbox0.upper.x, |
| 334 | jj == 0 ? obbox0.lower.y : obbox0.upper.y, |
| 335 | kk == 0 ? obbox0.lower.z : obbox0.upper.z); |
| 336 | Vec3fa p1(ii == 0 ? obbox1.lower.x : obbox1.upper.x, |
| 337 | jj == 0 ? obbox1.lower.y : obbox1.upper.y, |
| 338 | kk == 0 ? obbox1.lower.z : obbox1.upper.z); |
| 339 | |
| 340 | // get extrema of motion of bounding box corner for each dimension |
| 341 | for (int dim = 0; dim < 3; ++dim) |
| 342 | { |
| 343 | MotionDerivative motionDerivative(motionDerivCoeffs, dim, p0, p1); |
| 344 | |
| 345 | numRoots = motionDerivative.findRoots(interval, bbox0.lower[dim] - bbox1.lower[dim], roots, maxNumRoots); |
| 346 | for (unsigned int r = 0; r < numRoots; ++r) { |
| 347 | float t = roots[r]; |
| 348 | const BBox3fa bt = lerp(bbox0, bbox1, t); |
| 349 | const Vec3fa pt = xfmPoint(slerp(xfm0, xfm1, t), lerp(p0, p1, t)); |
| 350 | delta.lower[dim] = std::min(delta.lower[dim], pt[dim] - bt.lower[dim]); |
| 351 | } |
| 352 | |
| 353 | numRoots = motionDerivative.findRoots(interval, bbox0.upper[dim] - bbox1.upper[dim], roots, maxNumRoots); |
| 354 | for (unsigned int r = 0; r < numRoots; ++r) { |
| 355 | float t = roots[r]; |
| 356 | const BBox3fa bt = lerp(bbox0, bbox1, t); |
| 357 | const Vec3fa pt = xfmPoint(slerp(xfm0, xfm1, t), lerp(p0, p1, t)); |
| 358 | delta.upper[dim] = std::max(delta.upper[dim], pt[dim] - bt.upper[dim]); |
| 359 | } |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | return delta; |
| 364 | } |
| 365 | |
| 366 | } |
| 367 | |