| 39 | using namespace dmVMath; |
| 40 | |
| 41 | TEST(dmVMath, CreateFrustum) |
| 42 | { |
| 43 | dmVMath::Point3 cam_pos = dmVMath::Point3(0.0f, 0.0f, 0); |
| 44 | dmVMath::Matrix4 view = Matrix4::lookAt(cam_pos, dmVMath::Point3(cam_pos.getX(), cam_pos.getY(), cam_pos.getZ()-1), dmVMath::Vector3(0,1,0)); // eye, lookat, up |
| 45 | |
| 46 | dmVMath::Matrix4 proj = dmVMath::Matrix4::orthographic(0.0f, FRUSTUM_WIDTH, 0.0f, FRUSTUM_HEIGHT, 10.0f, 100.0f); |
| 47 | |
| 48 | dmVMath::Matrix4 view_proj = proj * view; |
| 49 | |
| 50 | dmIntersection::Frustum frustum; |
| 51 | dmIntersection::CreateFrustumFromMatrix(view_proj, true, 6, frustum); |
| 52 | |
| 53 | float px = FRUSTUM_WIDTH / 2.0f; |
| 54 | float py = FRUSTUM_HEIGHT / 2.0f; |
| 55 | float pz = -FRUSTUM_NEAR -(FRUSTUM_FAR - FRUSTUM_NEAR) / 2.0f; |
| 56 | |
| 57 | // Making sure all planes point inwards, and are located at the correct distances |
| 58 | |
| 59 | ASSERT_NEAR(-10.0f, dmIntersection::DistanceToPlane(frustum.m_Planes[0], dmVMath::Point3(-10.0f, py, pz)), 0.001f); |
| 60 | ASSERT_NEAR( 10.0f, dmIntersection::DistanceToPlane(frustum.m_Planes[0], dmVMath::Point3( 10.0f, py, pz)), 0.001f); |
| 61 | |
| 62 | ASSERT_NEAR(-10.0f, dmIntersection::DistanceToPlane(frustum.m_Planes[1], dmVMath::Point3(110.0f, py, pz)), 0.001f); |
| 63 | ASSERT_NEAR( 10.0f, dmIntersection::DistanceToPlane(frustum.m_Planes[1], dmVMath::Point3( 90.0f, py, pz)), 0.001f); |
| 64 | |
| 65 | ASSERT_NEAR(-10.0f, dmIntersection::DistanceToPlane(frustum.m_Planes[2], dmVMath::Point3(px, -10.0f, pz)), 0.001f); |
| 66 | ASSERT_NEAR( 10.0f, dmIntersection::DistanceToPlane(frustum.m_Planes[2], dmVMath::Point3(px, 10.0f, pz)), 0.001f); |
| 67 | |
| 68 | ASSERT_NEAR(-10.0f, dmIntersection::DistanceToPlane(frustum.m_Planes[3], dmVMath::Point3(px, 90.0f, pz)), 0.001f); |
| 69 | ASSERT_NEAR( 10.0f, dmIntersection::DistanceToPlane(frustum.m_Planes[3], dmVMath::Point3(px, 70.0f, pz)), 0.001f); |
| 70 | |
| 71 | ASSERT_NEAR(-10.0f, dmIntersection::DistanceToPlane(frustum.m_Planes[4], dmVMath::Point3(px, py, 0.0f)), 0.001f); |
| 72 | ASSERT_NEAR( 10.0f, dmIntersection::DistanceToPlane(frustum.m_Planes[4], dmVMath::Point3(px, py, -20.0f)), 0.001f); |
| 73 | |
| 74 | ASSERT_NEAR(-10.0f, dmIntersection::DistanceToPlane(frustum.m_Planes[5], dmVMath::Point3(px, py, -110.0f)), 0.001f); |
| 75 | ASSERT_NEAR( 10.0f, dmIntersection::DistanceToPlane(frustum.m_Planes[5], dmVMath::Point3(px, py, -90.0f)), 0.001f); |
| 76 | } |
| 77 | |
| 78 | TEST(dmVMath, TestFrustumSphere) |
| 79 | { |
nothing calls this directly
no test coverage detected