|
1391 | 1391 | We need some math constants that we conveniently define in their own header file. For now we only
|
1392 | 1392 | need infinity, but we will also throw our own definition of pi in there, which we will need later.
|
1393 | 1393 | There is no standard portable definition of pi, so we just define our own constant for it. We'll
|
1394 |
| -throw common useful constants and future utility functions in `rtweekend.h`, our general main header |
1395 |
| -file. |
| 1394 | +also throw common useful constants and future utility functions in `rtweekend.h`, our general main |
| 1395 | +header file. |
1396 | 1396 |
|
1397 | 1397 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
1398 | 1398 | #ifndef RTWEEKEND_H
|
1399 | 1399 | #define RTWEEKEND_H
|
1400 | 1400 |
|
1401 | 1401 | #include <cmath>
|
| 1402 | + #include <iostream> |
1402 | 1403 | #include <limits>
|
1403 | 1404 | #include <memory>
|
1404 | 1405 |
|
1405 | 1406 |
|
1406 |
| - // Usings |
| 1407 | + // C++ Std Usings |
1407 | 1408 |
|
1408 | 1409 | using std::shared_ptr;
|
1409 | 1410 | using std::make_shared;
|
|
1429 | 1430 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
1430 | 1431 | [Listing [rtweekend-initial]: <kbd>[rtweekend.h]</kbd> The rtweekend.h common header]
|
1431 | 1432 |
|
| 1433 | +All main program files will include `rtweekend.h` first, so most other header files (where the bulk |
| 1434 | +of our code will reside) can assume that these definitions are already available. (Headers included |
| 1435 | +inside `rtweekend.h` still need to include any of their dependencies.) We'll make some updates with |
| 1436 | +this assumption in mind. |
| 1437 | + |
| 1438 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ delete |
| 1439 | + #include "vec3.h" |
| 1440 | + |
| 1441 | + #include <iostream> |
| 1442 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1443 | + [Listing [assume-rtw-color]: <kbd>[color.h]</kbd> Assume rtweekend.h in color.h] |
| 1444 | + |
| 1445 | + |
| 1446 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ delete |
| 1447 | + #include "ray.h" |
| 1448 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1449 | + [Listing [assume-rtw-hittable]: <kbd>[hittable.h]</kbd> Assume rtweekend.h in hittable.h] |
| 1450 | + |
| 1451 | + |
| 1452 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ delete |
| 1453 | + #include <memory> |
| 1454 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
| 1455 | + #include <vector> |
| 1456 | + |
| 1457 | + |
| 1458 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ delete |
| 1459 | + using std::shared_ptr; |
| 1460 | + using std::make_shared; |
| 1461 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1462 | + [Listing [assume-rtw-hittable-list]: <kbd>[hittable_list.h]</kbd> |
| 1463 | + Assume rtweekend.h in hittable_list.h |
| 1464 | + ] |
| 1465 | + |
| 1466 | + |
| 1467 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ delete |
| 1468 | + #include "vec3.h" |
| 1469 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1470 | + [Listing [assume-rtw-sphere]: <kbd>[sphere.h]</kbd> Assume rtweekend.h in sphere.h] |
| 1471 | + |
| 1472 | + |
| 1473 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ delete |
| 1474 | + #include <cmath> |
| 1475 | + #include <iostream> |
| 1476 | + |
| 1477 | + using std::sqrt; |
| 1478 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1479 | + [Listing [assume-rtw-vec3]: <kbd>[vec3.h]</kbd> Assume rtweekend.h in vec3.h] |
| 1480 | + |
1432 | 1481 | <div class='together'>
|
1433 |
| -And the new main: |
| 1482 | +And now the new main: |
1434 | 1483 |
|
1435 | 1484 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
|
1436 | 1485 | #include "rtweekend.h"
|
|
1443 | 1492 | #include "sphere.h"
|
1444 | 1493 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
1445 | 1494 |
|
| 1495 | + |
| 1496 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ delete |
1446 | 1497 | #include <iostream>
|
| 1498 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
1447 | 1499 |
|
1448 | 1500 |
|
1449 | 1501 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ delete
|
|
2884 | 2936 | In service of this, we'll create a new vector method -- `vec3::near_zero()` -- that returns true if
|
2885 | 2937 | the vector is very close to zero in all dimensions.
|
2886 | 2938 |
|
| 2939 | +We'll need to use the C++ standard library function `std::fabs`, which returns the absolute value of |
| 2940 | +its input. We'll add this to `rtweekend.h` since we'll use this in several future locations. |
| 2941 | + |
| 2942 | + |
| 2943 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
| 2944 | + // C++ Std Usings |
| 2945 | + |
| 2946 | + |
| 2947 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
| 2948 | + using std::fabs; |
| 2949 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
| 2950 | + using std::make_shared; |
| 2951 | + using std::shared_ptr; |
| 2952 | + using std::sqrt; |
| 2953 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 2954 | + [Listing [declare-fabs]: <kbd>rtweekend.h</kbd> Declaring std::fabs() |
| 2955 | + |
2887 | 2956 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
2888 | 2957 | class vec3 {
|
2889 | 2958 | ...
|
|
0 commit comments