Changeset View
Changeset View
Standalone View
Standalone View
source/graphics/tests/test_Camera.h
Show First 20 Lines • Show All 117 Lines • ▼ Show 20 Lines | bool EqualPlanes(const CPlane& p1, const CPlane& p2) const | ||||
const float EPS = 1e-3f; | const float EPS = 1e-3f; | ||||
if (std::fabs(p1.m_Dist - p2.m_Dist) >= EPS) | if (std::fabs(p1.m_Dist - p2.m_Dist) >= EPS) | ||||
return false; | return false; | ||||
return | return | ||||
std::fabs(p1.m_Norm.X - p2.m_Norm.X) < EPS && | std::fabs(p1.m_Norm.X - p2.m_Norm.X) < EPS && | ||||
std::fabs(p1.m_Norm.Y - p2.m_Norm.Y) < EPS && | std::fabs(p1.m_Norm.Y - p2.m_Norm.Y) < EPS && | ||||
std::fabs(p1.m_Norm.Z - p2.m_Norm.Z) < EPS; | std::fabs(p1.m_Norm.Z - p2.m_Norm.Z) < EPS; | ||||
} | } | ||||
void test_persepctive_plane_points() | |||||
{ | |||||
SViewPort viewPort; | |||||
viewPort.m_X = 0; | |||||
viewPort.m_Y = 0; | |||||
viewPort.m_Width = 512; | |||||
viewPort.m_Height = 512; | |||||
CCamera camera; | |||||
camera.SetViewPort(viewPort); | |||||
camera.LookAlong( | |||||
CVector3D(0.0f, 0.0f, 0.0f), | |||||
CVector3D(0.0f, 0.0f, 1.0f), | |||||
CVector3D(0.0f, 1.0f, 0.0f) | |||||
); | |||||
camera.m_Orientation.SetTranslation(CVector3D(1.0f, 2.0f, 3.0f)); | |||||
camera.SetPerspectiveProjection(1.0f, 101.0f, DEGTORAD(90.0f)); | |||||
std::array<CVector3D, 4> points; | |||||
// Zero distance point is the origin of all camera rays, | |||||
// so all plane points should be stay there. | |||||
camera.GetCameraPlanePoints(0.0f, points); | |||||
for (const CVector3D& point : points) | |||||
TS_ASSERT_EQUALS(point, CVector3D(0.0f, 0.0f, 0.0f)); | |||||
// Points lying on the far plane. | |||||
std::array<CVector3D, 4> expectedFarPoints = { | |||||
CVector3D(-101.0f, -101.0f, 101.0f), | |||||
CVector3D(101.0f, -101.0f, 101.0f), | |||||
CVector3D(101.0f, 101.0f, 101.0f), | |||||
CVector3D(-101.0f, 101.0f, 101.0f) | |||||
}; | |||||
camera.GetCameraPlanePoints(camera.GetFarPlane(), points); | |||||
TS_ASSERT_EQUALS(points, expectedFarPoints); | |||||
} | |||||
}; | }; |
Wildfire Games · Phabricator