|
584 | 584 |
|
585 | 585 | bool hit(const ray& r, double tmin, double tmax) const { |
586 | 586 | for (int a = 0; a < 3; a++) { |
587 | | - auto t0 = ffmin((_min[a] - r.origin()[a]) / r.direction()[a], |
588 | | - (_max[a] - r.origin()[a]) / r.direction()[a]); |
589 | | - auto t1 = ffmax((_min[a] - r.origin()[a]) / r.direction()[a], |
590 | | - (_max[a] - r.origin()[a]) / r.direction()[a]); |
591 | | - tmin = ffmax(t0, tmin); |
592 | | - tmax = ffmin(t1, tmax); |
| 587 | + auto t0 = fmin((_min[a] - r.origin()[a]) / r.direction()[a], |
| 588 | + (_max[a] - r.origin()[a]) / r.direction()[a]); |
| 589 | + auto t1 = fmax((_min[a] - r.origin()[a]) / r.direction()[a], |
| 590 | + (_max[a] - r.origin()[a]) / r.direction()[a]); |
| 591 | + tmin = fmax(t0, tmin); |
| 592 | + tmax = fmin(t1, tmax); |
593 | 593 | if (tmax <= tmin) |
594 | 594 | return false; |
595 | 595 | } |
|
603 | 603 | [Listing [aabb]: <kbd>[aabb.h]</kbd> Axis-aligned bounding box class] |
604 | 604 | </div> |
605 | 605 |
|
606 | | -Note that we use the simple custom `ffmax()` function (defined in `rtweekend.h`) instead of the C++ |
607 | | -standard library `fmax()` utility. `ffmax()` is quite a bit faster because it doesn’t worry about |
608 | | -`NaN`s and other exceptions. |
609 | | - |
610 | 606 |
|
611 | 607 | An Optimized AABB Hit Method |
612 | 608 | ----------------------------- |
|
722 | 718 |
|
723 | 719 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
724 | 720 | aabb surrounding_box(aabb box0, aabb box1) { |
725 | | - point3 small(ffmin(box0.min().x(), box1.min().x()), |
726 | | - ffmin(box0.min().y(), box1.min().y()), |
727 | | - ffmin(box0.min().z(), box1.min().z())); |
| 721 | + point3 small(fmin(box0.min().x(), box1.min().x()), |
| 722 | + fmin(box0.min().y(), box1.min().y()), |
| 723 | + fmin(box0.min().z(), box1.min().z())); |
728 | 724 |
|
729 | | - point3 big(ffmax(box0.max().x(), box1.max().x()), |
730 | | - ffmax(box0.max().y(), box1.max().y()), |
731 | | - ffmax(box0.max().z(), box1.max().z())); |
| 725 | + point3 big(fmax(box0.max().x(), box1.max().x()), |
| 726 | + fmax(box0.max().y(), box1.max().y()), |
| 727 | + fmax(box0.max().z(), box1.max().z())); |
732 | 728 |
|
733 | 729 | return aabb(small,big); |
734 | 730 | } |
|
1595 | 1591 | temp_p *= 2; |
1596 | 1592 | } |
1597 | 1593 |
|
1598 | | - return fabs(accum); |
| 1594 | + return ffabs(accum); |
1599 | 1595 | } |
1600 | 1596 | ... |
1601 | 1597 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
2553 | 2549 | vec3 tester(newx, y, newz); |
2554 | 2550 |
|
2555 | 2551 | for (int c = 0; c < 3; c++) { |
2556 | | - min[c] = ffmin(min[c], tester[c]); |
2557 | | - max[c] = ffmax(max[c], tester[c]); |
| 2552 | + min[c] = fmin(min[c], tester[c]); |
| 2553 | + max[c] = fmax(max[c], tester[c]); |
2558 | 2554 | } |
2559 | 2555 | } |
2560 | 2556 | } |
|
0 commit comments