Adding small unit tests

This commit is contained in:
Michaël Lemaire 2013-06-13 17:37:29 +02:00
parent feb422cd11
commit c4cc784003
2 changed files with 12 additions and 0 deletions

View file

@ -309,6 +309,11 @@ Vector3 cameraUnproject(CameraDefinition* camera, Vector3 point)
{ {
point.x = (point.x / (0.5 * camera->width) - 1.0); point.x = (point.x / (0.5 * camera->width) - 1.0);
point.y = -(point.y / (0.5 * camera->height) - 1.0); point.y = -(point.y / (0.5 * camera->height) - 1.0);
if (point.z < 1.0)
{
point.x = -point.x;
point.y = -point.y;
}
return m4Transform(camera->unproject, point); return m4Transform(camera->unproject, point);
} }

View file

@ -29,6 +29,9 @@ START_TEST(test_camera_projection)
Vector3 point = cameraProject(cam, v3(12.0, 5.2, -6.3)); Vector3 point = cameraProject(cam, v3(12.0, 5.2, -6.3));
point = cameraUnproject(cam, point); point = cameraUnproject(cam, point);
ck_assert_vector_values(point, 12.0, 5.2, -6.3); ck_assert_vector_values(point, 12.0, 5.2, -6.3);
point = cameraProject(cam, v3(-25.1, 8.3, 1.3));
point = cameraUnproject(cam, point);
ck_assert_vector_values(point, -25.1, 8.3, 1.3);
cameraDeleteDefinition(cam); cameraDeleteDefinition(cam);
} }
@ -45,6 +48,10 @@ START_TEST(test_camera_depth)
/* Test the real depth getter */ /* Test the real depth getter */
Vector3 point = cameraProject(cam, v3(12.5, 0.0, 0.0)); Vector3 point = cameraProject(cam, v3(12.5, 0.0, 0.0));
ck_assert_double_eq(cameraGetRealDepth(cam, point), 12.5); ck_assert_double_eq(cameraGetRealDepth(cam, point), 12.5);
point = cameraProject(cam, v3(12.5, 8.0, -3.0));
ck_assert_double_eq(cameraGetRealDepth(cam, point), 12.5);
point = cameraProject(cam, v3(12.5, 12.0, 58.0));
ck_assert_double_eq(cameraGetRealDepth(cam, point), 12.5);
cameraDeleteDefinition(cam); cameraDeleteDefinition(cam);
} }