-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_camera.cpp
49 lines (35 loc) · 1.45 KB
/
test_camera.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// File: test_camera.cpp
// Author: Samuel McFalls
// Description: Tests the Camera module
#include "catch.hpp"
#include "camera.hpp"
TEST_CASE("Tests the camera constructors", "[camera]") {
Camera defaultCamera = Camera();
Camera customCamera = Camera(Vec3(1, 1, 1),
Vec3(0, 0, 1), 10, 256, 256, 0.01, 0.01);
REQUIRE(defaultCamera.getSizeX() == 0);
REQUIRE(defaultCamera.getSizeY() == 0);
REQUIRE(customCamera.getSizeX() == 256);
REQUIRE(customCamera.getSizeY() == 256);
REQUIRE(customCamera.getCenter() == Vec3(1, 1, 1));
REQUIRE(customCamera.getNormal() == Vec3(0, 0, 1));
}
TEST_CASE("Tests the camera pixel ray generation", "[camera]") {
Camera cam1 = Camera(Vec3(0, 0, 0),
Vec3(0, 0, 1), 10, 256, 256, 0.01, 0.01);
Camera cam2 = Camera(Vec3(0, 0, 0),
Vec3(0, 1, 1), 10, 256, 256, 0.01, 0.01);
Ray ray1 = cam1.pixelRay(0, 0);
REQUIRE(ray1.getOrigin() == Vec3(0, 0, -10));
REQUIRE(ray1.getDestination().getX() - (-1.275) < 1e-9);
REQUIRE(ray1.getDestination().getY() - (-1.275) < 1e-9);
REQUIRE(ray1.getDestination().getZ() - (0) < 1e-9);
Ray ray2 = cam1.pixelRay(255, 255);
REQUIRE(ray1.getOrigin() == Vec3(0, 0, -10));
REQUIRE(ray1.getDestination().getX() - (1.275) < 1e-9);
REQUIRE(ray1.getDestination().getY() - (1.275) < 1e-9);
REQUIRE(ray1.getDestination().getZ() - (0) < 1e-9);
// The testing here is really hard, so I've elected to just test visually
//Ray ray3 = cam2.pixelRay(0, 0);
//REQUIRE(ray3.getOrigin() == Vec3());
}