diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/glxx.cpp | 45 | ||||
-rw-r--r-- | tests/raytracexx.cpp | 31 | ||||
-rw-r--r-- | tests/testsxx.cpp | 35 | ||||
-rw-r--r-- | tests/testsxx.hpp | 4 |
4 files changed, 57 insertions, 58 deletions
diff --git a/tests/glxx.cpp b/tests/glxx.cpp index eb74209..aaf7b7b 100644 --- a/tests/glxx.cpp +++ b/tests/glxx.cpp @@ -26,37 +26,24 @@ int main() { using namespace Dimension; - // Set the resilience low for tests - resilience(SEVERITY_LOW); - - // Background color - Color background = sRGB(0.0, 0.1, 0.25); - background.filter(0.1); - - // Canvas - Canvas canvas(768, 480); - - // Camera - Perspective_Camera camera( - Matrix::rotation(Vector(0.0, 1.0, 0.0)) - * Matrix::translation(Vector(0.0, 0.0, -4.0)) - * Matrix::scale( - Vector(static_cast<double>(canvas.width())/canvas.height(), 1.0, 1.0) - ) - ); + Scene scene = default_scene(); - // Scene - Scene scene(background, camera, canvas); + Perspective_Camera& camera + = dynamic_cast<Perspective_Camera&>(scene.camera()); - // Objects in scene - - Sphere sphere; - sphere.trans(inverse(Matrix::scale(Vector(1.25, 1.25, 1.25)))); - scene.push_object(sphere); + Cube* cube; + for (Scene::Iterator i = scene.begin(); i != scene.end(); ++i) { + cube = dynamic_cast<Cube*>(&*i); + if (cube) { + break; + } + } + if (!cube) { + throw Dimension_Error("Couldn't find a cube in the default scene."); + } - Cube cube; - cube.trans(inverse(Matrix::rotation(Vector(0.75, 0.0, 0.0)))); - scene.push_object(cube); + // Set the resilience low for tests + resilience(SEVERITY_LOW); Raytracer raytracer(scene); GL_Drawer drawer(scene.canvas()); @@ -71,7 +58,7 @@ main() { drawer.draw(); display.flush(); - cube.trans(inverse(Matrix::rotation(Vector(0.025, 0.0, 0.0)))*cube.trans()); + cube->trans(inverse(Matrix::rotation(Vector(0.025, 0.0, 0.0)))*cube->trans()); camera.trans(Matrix::rotation(Vector(0.0, -0.05, 0.0))*camera.trans()); } diff --git a/tests/raytracexx.cpp b/tests/raytracexx.cpp index c04e525..4202347 100644 --- a/tests/raytracexx.cpp +++ b/tests/raytracexx.cpp @@ -28,34 +28,7 @@ main() { // Set the resilience low for tests resilience(SEVERITY_LOW); - // Background color - Color background = sRGB(0.0, 0.1, 0.25); - background.filter(0.1); - - // Canvas - Canvas canvas(768, 480); - - // Camera - Perspective_Camera camera( - Matrix::rotation(Vector(0.0, 1.0, 0.0)) - * Matrix::translation(Vector(0.0, 0.0, -4.0)) - * Matrix::scale( - Vector(static_cast<double>(canvas.width())/canvas.height(), 1.0, 1.0) - ) - ); - - // Scene - Scene scene(background, camera, canvas); - - // Objects in scene - - Sphere sphere; - sphere.trans(inverse(Matrix::scale(Vector(1.25, 1.25, 1.25)))); - scene.push_object(sphere); - - Cube cube; - cube.trans(inverse(Matrix::rotation(Vector(0.75, 0.0, 0.0)))); - scene.push_object(cube); + Scene scene = default_scene(); // Render the scene { @@ -66,7 +39,7 @@ main() { // Write the canvas std::ofstream file("raytracexx.png"); - PNG_Writer writer(canvas, file); + PNG_Writer writer(scene.canvas(), file); Progress progress = writer.write_async(); std::cout << "Writing PNG file: " << progress << std::endl; diff --git a/tests/testsxx.cpp b/tests/testsxx.cpp index f3dcca5..399e50f 100644 --- a/tests/testsxx.cpp +++ b/tests/testsxx.cpp @@ -21,6 +21,41 @@ namespace Dimension { + Scene + default_scene() + { + // Background color + Color background = sRGB(0.0, 0.1, 0.25); + background.filter(0.1); + + // Canvas + Canvas canvas(768, 480); + + // Camera + Perspective_Camera camera( + Matrix::rotation(Vector(0.0, 1.0, 0.0)) + * Matrix::translation(Vector(0.0, 0.0, -4.0)) + * Matrix::scale( + Vector(static_cast<double>(canvas.width())/canvas.height(), 1.0, 1.0) + ) + ); + + // Scene + Scene scene(background, camera, canvas); + + // Objects in scene + + Sphere sphere; + sphere.trans(inverse(Matrix::scale(Vector(1.25, 1.25, 1.25)))); + scene.push_object(sphere); + + Cube cube; + cube.trans(inverse(Matrix::rotation(Vector(0.75, 0.0, 0.0)))); + scene.push_object(cube); + + return scene; + } + Display::Display(const Canvas& canvas) : m_display(dmnsn_new_display(canvas.dmnsn())) { diff --git a/tests/testsxx.hpp b/tests/testsxx.hpp index 0e522ad..1101196 100644 --- a/tests/testsxx.hpp +++ b/tests/testsxx.hpp @@ -26,6 +26,10 @@ namespace Dimension { + // Helper to return a basic scene + Scene default_scene(); + + // Display abstraction class Display { public: |