|
| 1 | +/** |
| 2 | + * @file BatCave.c |
| 3 | + * @author Edward Palmer |
| 4 | + * @date 2025-01-31 |
| 5 | + * |
| 6 | + * @copyright Copyright (c) 2025 |
| 7 | + * |
| 8 | + */ |
| 9 | + |
| 10 | +extern "C" |
| 11 | +{ |
| 12 | +#include "engine/RenderSettings.h" |
| 13 | +#include "utility/PPMWriter.h" |
| 14 | +} |
| 15 | + |
| 16 | +#include "engine/PhotonEngine.hpp" |
| 17 | +#include "engine/Scene.hpp" |
| 18 | +#include "engine/primitives/BVHNode.hpp" |
| 19 | +#include "engine/primitives/Cube.hpp" |
| 20 | +#include "engine/primitives/Plane.hpp" |
| 21 | +#include "engine/primitives/Primitive.hpp" |
| 22 | + |
| 23 | +#include <cstdlib> |
| 24 | +#include <vector> |
| 25 | + |
| 26 | +Primitive *makeDarkKnightRoom(double length, double width, double height); |
| 27 | + |
| 28 | +int main(int argc, const char *argv[]) |
| 29 | +{ |
| 30 | + parseCLIOptions(argc, argv); |
| 31 | + |
| 32 | + // Create the camera: |
| 33 | + const double aspectRatio = ((double)gRenderSettings.pixelsWide / (double)gRenderSettings.pixelsHigh); |
| 34 | + Camera camera(45.0, aspectRatio, 1, 0, point3(-2.5, 2, 10), point3(0, 2, 0)); |
| 35 | + |
| 36 | + Primitive *room = makeDarkKnightRoom(20, 16.0, 5); |
| 37 | + |
| 38 | + Scene scene; |
| 39 | + scene.addObject(room); |
| 40 | + |
| 41 | + // Monolith: |
| 42 | + for (int i = 0; i < 4; i++) |
| 43 | + { |
| 44 | + for (int j = 0; j < 9; j++) |
| 45 | + { |
| 46 | + Primitive *cube = new Cube(point3(0.5 * i, 0.25 + 0.5 * j, 0), zeroVector(), 0.5, |
| 47 | + makeLambertian(makeSolidTexture(color3(.01, .01, .01)))); |
| 48 | + |
| 49 | + scene.addObject(cube); |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + PhotonEngine engine(gRenderSettings.pixelsWide, gRenderSettings.pixelsHigh); |
| 54 | + |
| 55 | + PPMImage *outputImage = engine.render(&scene, &camera); |
| 56 | + |
| 57 | + writeBinary16BitPPMImage(outputImage, gRenderSettings.outputPath); |
| 58 | + |
| 59 | + freePPMImage(outputImage); |
| 60 | + |
| 61 | + return 0; |
| 62 | +} |
| 63 | + |
| 64 | + |
| 65 | +Primitive *makeDarkKnightRoom(double length, double width, double height) |
| 66 | +{ |
| 67 | + const double halfRoomW = 0.5 * width; |
| 68 | + const double halfRoomL = 0.5 * length; |
| 69 | + |
| 70 | + Material *wallMaterial = makeLambertian(makeSolidTexture(color3(0.05, 0.05, 0.05))); |
| 71 | + Material *lightMaterial = makeEmitter(color3(.9, .9, .9)); |
| 72 | + |
| 73 | + std::vector<Primitive *> objects; |
| 74 | + |
| 75 | + objects.push_back(new Plane(point3(halfRoomW, 0, 0), vector3(-1, 0, 0), wallMaterial)); |
| 76 | + objects.push_back(new Plane(point3(-halfRoomW, 0, 0), vector3(1, 0, 0), wallMaterial)); |
| 77 | + objects.push_back(new Plane(point3(0, 0, -halfRoomL), vector3(0, 0, 1), wallMaterial)); |
| 78 | + objects.push_back(new Plane(point3(0, 0, halfRoomL), vector3(0, 0, -1), wallMaterial)); |
| 79 | + objects.push_back(new Plane(point3(0, height, 0), vector3(0, -1, 0), wallMaterial)); |
| 80 | + objects.push_back(new Plane(point3(0, 0, 0), vector3(0, 1, 0), wallMaterial)); |
| 81 | + |
| 82 | + // Create all of the lights on the ceiling: |
| 83 | + for (int i = -halfRoomW; i <= halfRoomW; i += 1) |
| 84 | + { |
| 85 | + for (int j = -halfRoomL; j <= halfRoomL; j += 1) |
| 86 | + { |
| 87 | + Primitive *floorPanel = new Cube(point3(i + 0.495, -0.490, j + 0.495), zeroVector(), 0.99, wallMaterial); |
| 88 | + |
| 89 | + Primitive *ceilingPanel = |
| 90 | + new Cube(point3(i + 0.495, height + .494, j + 0.495), zeroVector(), 0.99, lightMaterial); |
| 91 | + |
| 92 | + objects.push_back(floorPanel); |
| 93 | + objects.push_back(ceilingPanel); |
| 94 | + } |
| 95 | + } |
| 96 | + |
| 97 | + objects.shrink_to_fit(); |
| 98 | + return new BVHNode(objects.data(), 0, objects.size()); |
| 99 | +} |
0 commit comments