MCPcopy Create free account
hub / github.com/defold/defold / TEST

Function TEST

engine/dlib/src/test/test_intersection.cpp:41–76  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39using namespace dmVMath;
40
41TEST(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
78TEST(dmVMath, TestFrustumSphere)
79{

Callers

nothing calls this directly

Calls 11

CreateFrustumFromMatrixFunction · 0.85
DistanceToPlaneFunction · 0.85
TestFrustumSphereFunction · 0.85
identityFunction · 0.85
TestFrustumOBBFunction · 0.85
sqrtFunction · 0.85
Point3Class · 0.50
Vector3Class · 0.50
getXMethod · 0.45
getYMethod · 0.45
getZMethod · 0.45

Tested by

no test coverage detected