Add another hardcoded scene. Also made a test file for hw3 that should cover all the commands.
This commit is contained in:
@@ -24,6 +24,11 @@ target_include_directories(hw3render PUBLIC ../source/include)
|
||||
target_sources(hw3render PRIVATE hw3render.cpp)
|
||||
target_link_libraries(hw3render rayonnement)
|
||||
|
||||
add_executable(test_render)
|
||||
target_include_directories(test_render PUBLIC ../source/include)
|
||||
target_sources(test_render PRIVATE test_render.cpp)
|
||||
target_link_libraries(test_render rayonnement)
|
||||
|
||||
add_executable(ch5_test)
|
||||
target_include_directories(ch5_test PUBLIC ../source/include)
|
||||
target_sources(ch5_test PRIVATE ch5_test.cpp)
|
||||
@@ -90,4 +95,6 @@ add_test(NAME Chapter11_Test COMMAND $<TARGET_FILE:ch11_test>)
|
||||
add_test(NAME Chapter12_Test COMMAND $<TARGET_FILE:ch12_test>)
|
||||
add_test(NAME Chapter13_Test COMMAND $<TARGET_FILE:ch13_test>)
|
||||
add_test(NAME Chapter13_ConeBonus COMMAND $<TARGET_FILE:ch13_cone>)
|
||||
add_test(NAME Hw3Render COMMAND $<TARGET_FILE:hw3render> ${CMAKE_CURRENT_SOURCE_DIR}/test.hw3scene)
|
||||
add_test(NAME Test_Rendering COMMAND $<TARGET_FILE:test_render>)
|
||||
add_test(NAME Hw3Render COMMAND $<TARGET_FILE:hw3render> ${CMAKE_CURRENT_SOURCE_DIR}/test.hw3scene)
|
||||
add_test(NAME Hw3RenderAllCmds COMMAND $<TARGET_FILE:hw3render> ${CMAKE_CURRENT_SOURCE_DIR}/test_keys.hw3scene)
|
||||
26
tests/test_keys.hw3scene
Normal file
26
tests/test_keys.hw3scene
Normal file
@@ -0,0 +1,26 @@
|
||||
# line with a comment
|
||||
camera 0 0 -1 0 0 0 0 1 0 50
|
||||
|
||||
point 0 4 0 .7 .2 .2
|
||||
point 4 -4 0 .2 .7 .2
|
||||
point -4 -4 0 .2 .2 .7
|
||||
|
||||
color 1 1 1
|
||||
ambient 1 1 1
|
||||
sphere 0 0 0 .3
|
||||
|
||||
color 1 0 0
|
||||
diffuse 0.4 0.4 0.4
|
||||
specular 0.4 0.4 0.4
|
||||
shininess 1
|
||||
emission 0 0 0
|
||||
|
||||
pushTransform
|
||||
scale 0.1 0.1 0.1
|
||||
rotate 0 1 0 45
|
||||
popTransform
|
||||
|
||||
pushTransform
|
||||
translate .4 0 0
|
||||
sphere 0 0 0 .1
|
||||
popTransform
|
||||
133
tests/test_render.cpp
Normal file
133
tests/test_render.cpp
Normal file
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
* DoRayMe - a quick and dirty Raytracer
|
||||
* Render test for reflection in chapter 13.
|
||||
*
|
||||
* Created by Manoël Trapier
|
||||
* Copyright (c) 2020 986-Studio.
|
||||
*
|
||||
*/
|
||||
#include <world.h>
|
||||
#include <light.h>
|
||||
#include <sphere.h>
|
||||
#include <plane.h>
|
||||
#include <cube.h>
|
||||
#include <cylinder.h>
|
||||
#include <material.h>
|
||||
#include <colour.h>
|
||||
#include <canvas.h>
|
||||
#include <camera.h>
|
||||
|
||||
#include <pattern.h>
|
||||
#include <strippattern.h>
|
||||
#include <gradientpattern.h>
|
||||
#include <checkerspattern.h>
|
||||
#include <ringpattern.h>
|
||||
|
||||
#include <transformation.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
World w = World();
|
||||
|
||||
/* Add light */
|
||||
Light light = Light(POINT_LIGHT, Point(-5, 5, -5), Colour(1, 1, 1));
|
||||
w.addLight(&light);
|
||||
|
||||
/* ----------------------------- */
|
||||
|
||||
/* Environment */
|
||||
Plane p1 = Plane();
|
||||
p1.setTransform(translation(0, 0, 5) * rotationX(-M_PI/2));
|
||||
p1.material.pattern = new CheckersPattern(Colour(1, 1, 1), Colour(0.1, 0.1, 0.1));
|
||||
w.addObject(&p1);
|
||||
|
||||
Plane p2 = Plane();
|
||||
p2.setTransform( translation(0, 0, -6) * rotationX(-M_PI/2) );
|
||||
p2.material.pattern = new CheckersPattern(Colour(1, 1, 1), Colour(0.1, 0.1, 0.1));
|
||||
w.addObject(&p2);
|
||||
|
||||
Plane p3 = Plane();
|
||||
p3.setTransform(translation(-6, 0, 0) * rotationZ(M_PI/2) );
|
||||
p3.material.pattern = new CheckersPattern(Colour(1, 1, 1), Colour(0.1, 0.1, 0.1));
|
||||
w.addObject(&p3);
|
||||
|
||||
Plane p4 = Plane();
|
||||
p3.setTransform(translation(6, 0, 0) * rotationZ(M_PI/2) );
|
||||
p3.material.pattern = new CheckersPattern(Colour(1, 1, 1), Colour(0.1, 0.1, 0.1));
|
||||
w.addObject(&p3);
|
||||
|
||||
Plane p5 = Plane();
|
||||
p5.material.pattern = new CheckersPattern(Colour(1, 1, 1), Colour(0.1, 0.1, 0.1));
|
||||
w.addObject(&p5);
|
||||
|
||||
/* ----------------------------- */
|
||||
|
||||
/* Big Sphere */
|
||||
Sphere bigS = Sphere();
|
||||
bigS.setTransform(translation(-0.5, 1, 2) * scaling(2, 2, 2));
|
||||
bigS.material.colour = Colour(0, 0.4, 0.4);
|
||||
bigS.material.shininess = 50;
|
||||
bigS.material.specular = 1;
|
||||
bigS.material.reflective = 0.8;
|
||||
w.addObject(&bigS);
|
||||
|
||||
/* Small Sphere */
|
||||
Sphere smaS = Sphere();
|
||||
smaS.setTransform(translation(2.2, 1, -1));
|
||||
smaS.material.colour = Colour(0.4, 0, 0.4);
|
||||
smaS.material.shininess = 50;
|
||||
smaS.material.specular = 1;
|
||||
smaS.material.reflective = 0.2;
|
||||
w.addObject(&smaS);
|
||||
|
||||
/* Cylinder */
|
||||
Cylinder cyl = Cylinder();
|
||||
cyl.setTransform(translation(-3.5, 0, 1));
|
||||
cyl.isClosed = true;
|
||||
cyl.minCap = -1;
|
||||
cyl.maxCap = 3;
|
||||
cyl.material.colour = Colour(0.4, 1, 0.4);
|
||||
cyl.material.shininess = 20;
|
||||
cyl.material.specular = 1;
|
||||
cyl.material.reflective = 0.01;
|
||||
cyl.material.pattern = new GradientPattern(Colour(0.4, 1, 0.4), Colour(1.0, 0.2, 1.0));
|
||||
cyl.material.pattern->setTransform(scaling(1.1, 1.1, 1.1) * rotationY(M_PI / 2));
|
||||
w.addObject(&cyl);
|
||||
|
||||
/* Cube */
|
||||
Cube cub = Cube();
|
||||
cub.setTransform(translation(0.6, 0.4, -1) * scaling(0.4, 0.4, 0.4) * rotationY(deg_to_rad(60)));
|
||||
cub.material.colour = Colour(1, 0, 0.4);
|
||||
cub.material.shininess = 50;
|
||||
cub.material.specular = 1;
|
||||
cub.material.reflective = 0.3;
|
||||
w.addObject(&cub);
|
||||
|
||||
/* Glass cube */
|
||||
Cube gcub = Cube();
|
||||
gcub.setTransform(translation(-0.5, 0.6, -0.8) * scaling(0.6, 0.6, 0.6) * rotationY(deg_to_rad(40)));
|
||||
gcub.dropShadow = false;
|
||||
gcub.material.colour = Colour(0, 0.4, 0.1);
|
||||
gcub.material.specular = 1;
|
||||
gcub.material.shininess = 400;
|
||||
gcub.material.ambient = 0.1;
|
||||
gcub.material.diffuse = 0.3;
|
||||
gcub.material.reflective = 1;
|
||||
gcub.material.transparency = 1;
|
||||
gcub.material.refractiveIndex = 0.3;
|
||||
w.addObject(&gcub);
|
||||
/* ----------------------------- */
|
||||
|
||||
/* Set the camera */
|
||||
Camera camera = Camera(400, 200, deg_to_rad(90));
|
||||
camera.setTransform(viewTransform(Point(-2, 2.5, -3.5),
|
||||
Point(2, 0, 3),
|
||||
Vector(0, 1, 0)));
|
||||
|
||||
/* Now render it */
|
||||
Canvas image = camera.render(w, 20);
|
||||
|
||||
image.SaveAsPNG("test_renter.png");
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user