|
1390 | 1390 | --------------------------------------- |
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 | | -There is no standard portable definition of pi, so we just define our own constant for it. We'll |
1394 | | -also throw common useful constants and future utility functions in `rtweekend.h`, our general main |
1395 | | -header file. |
| 1393 | +We'll also throw common useful constants and future utility functions in here. This new header, |
| 1394 | +`rtweekend.h`, will be our general main header file. |
1396 | 1395 |
|
1397 | 1396 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
1398 | 1397 | #ifndef RTWEEKEND_H |
|
1432 | 1431 | [Listing [rtweekend-initial]: <kbd>[rtweekend.h]</kbd> The rtweekend.h common header] |
1433 | 1432 |
|
1434 | 1433 | All main program files will include `rtweekend.h` first, so most other header files (where the bulk |
1435 | | -of our code will reside) can assume that these definitions are already available. (Headers included |
1436 | | -inside `rtweekend.h` still need to include any of their dependencies.) We'll make some updates with |
1437 | | -this assumption in mind. |
| 1434 | +of our code will reside) can assume these definitions are already available. Headers included inside |
| 1435 | +`rtweekend.h` still need to include any of their dependencies. We'll make some updates with this |
| 1436 | +assumption in mind. |
1438 | 1437 |
|
1439 | 1438 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ delete |
| 1439 | + #include "vec3.h" |
| 1440 | + |
1440 | 1441 | #include <iostream> |
1441 | 1442 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
1442 | | - [Listing [assume-rtw-color]: <kbd>[color.h]</kbd> Assume rtweekend.h in color.h] |
| 1443 | + [Listing [assume-rtw-color]: <kbd>[color.h]</kbd> Assume rtweekend.h inclusion for color.h] |
1443 | 1444 |
|
1444 | 1445 |
|
1445 | 1446 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ delete |
1446 | 1447 | #include "ray.h" |
1447 | 1448 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
1448 | | - [Listing [assume-rtw-hittable]: <kbd>[hittable.h]</kbd> Assume rtweekend.h in hittable.h] |
| 1449 | + [Listing [assume-rtw-hittable]: <kbd>[hittable.h]</kbd> |
| 1450 | + Assume rtweekend.h inclusion for hittable.h |
| 1451 | + ] |
1449 | 1452 |
|
1450 | 1453 |
|
1451 | 1454 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ delete |
|
1459 | 1462 | using std::shared_ptr; |
1460 | 1463 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
1461 | 1464 | [Listing [assume-rtw-hittable-list]: <kbd>[hittable_list.h]</kbd> |
1462 | | - Assume rtweekend.h in hittable_list.h |
| 1465 | + Assume rtweekend.h inclusion for hittable_list.h |
1463 | 1466 | ] |
1464 | 1467 |
|
1465 | 1468 |
|
1466 | 1469 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ delete |
1467 | 1470 | #include "vec3.h" |
1468 | 1471 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
1469 | | - [Listing [assume-rtw-sphere]: <kbd>[sphere.h]</kbd> Assume rtweekend.h in sphere.h] |
| 1472 | + [Listing [assume-rtw-sphere]: <kbd>[sphere.h]</kbd> Assume rtweekend.h inclusion for sphere.h] |
1470 | 1473 |
|
1471 | 1474 |
|
1472 | 1475 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ delete |
|
1475 | 1478 |
|
1476 | 1479 | using std::sqrt; |
1477 | 1480 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
1478 | | - [Listing [assume-rtw-vec3]: <kbd>[vec3.h]</kbd> Assume rtweekend.h in vec3.h] |
| 1481 | + [Listing [assume-rtw-vec3]: <kbd>[vec3.h]</kbd> Assume rtweekend.h inclusion for vec3.h] |
1479 | 1482 |
|
1480 | 1483 | <div class='together'> |
1481 | 1484 | And now the new main: |
|
2944 | 2947 | In service of this, we'll create a new vector method -- `vec3::near_zero()` -- that returns true if |
2945 | 2948 | the vector is very close to zero in all dimensions. |
2946 | 2949 |
|
2947 | | -We'll need to use the C++ standard library function `std::fabs`, which returns the absolute value of |
2948 | | -its input. We'll add this to `rtweekend.h` since we'll use this in several future locations. |
| 2950 | +The following changes will use the C++ standard library function `std::fabs`, which returns the |
| 2951 | +absolute value of its input, so add this to our standard header. |
2949 | 2952 |
|
2950 | 2953 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
2951 | 2954 | // C++ Std Usings |
|
2960 | 2963 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
2961 | 2964 | [Listing [declare-fabs]: <kbd>[rtweekend.h]</kbd> Declaring std::fabs()] |
2962 | 2965 |
|
| 2966 | + |
2963 | 2967 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
2964 | 2968 | class vec3 { |
2965 | 2969 | ... |
|
0 commit comments