6 Frustum::Frustum(Camera& camera, glm::vec3 right, glm::vec3 up)
8 float fov = camera.GetFoV();
9 float aspectRatio = camera.GetAspectRatio();
10 glm::vec3 cameraPosition = camera.GetPosition();
11 glm::vec3 cameraDirection = camera.GetRotation();
12 glm::vec2 clippingPlanes = camera.GetClippingPlanes();
14 float nearPlaneHeight = 2 * tan(fov / 2) * clippingPlanes.x;
15 float nearPlaneWidth = nearPlaneHeight * aspectRatio;
17 float farPlaneHeight = 2 * tan(fov / 2) * clippingPlanes.y;
18 float farPlaneWidth = farPlaneHeight * aspectRatio;
20 glm::vec3 farCenter = cameraPosition + cameraDirection * clippingPlanes.y;
22 glm::vec3 ftl = farCenter + (up * farPlaneHeight / 2.0f) - (right * farPlaneWidth / 2.0f);
23 glm::vec3 ftr = farCenter + (up * farPlaneHeight / 2.0f) + (right * farPlaneWidth / 2.0f);
24 glm::vec3 fbl = farCenter - (up * farPlaneHeight / 2.0f) - (right * farPlaneWidth / 2.0f);
25 glm::vec3 fbr = farCenter - (up * farPlaneHeight / 2.0f) + (right * farPlaneWidth / 2.0f);
27 glm::vec3 nearCenter = cameraPosition + cameraDirection * clippingPlanes.x;
29 glm::vec3 ntl = nearCenter + (up * nearPlaneHeight / 2.0f) - (right * nearPlaneWidth / 2.0f);
30 glm::vec3 ntr = nearCenter + (up * nearPlaneHeight / 2.0f) + (right * nearPlaneWidth / 2.0f);
31 glm::vec3 nbl = nearCenter - (up * nearPlaneHeight / 2.0f) - (right * nearPlaneWidth / 2.0f);
32 glm::vec3 nbr = nearCenter - (up * nearPlaneHeight / 2.0f) + (right * nearPlaneWidth / 2.0f);
34 topFace = Face(ntr, ntl, ftl);
35 bottomFace = Face(nbl, nbr, fbl);
36 leftFace = Face(ntl, nbl, fbl);
37 rightFace = Face(nbr, ntr, fbr);
38 frontFace = Face(ntl, ntr, nbr);
39 backFace = Face(ftr, ftl, fbl);
42 Frustum::Face::Face(glm::vec3 p0, glm::vec3 p1, glm::vec3 p2)
51 glm::normalize(normal);
53 d = glm::dot(-normal, p0);
Face GetBottomFace() const
Face GetFrontFace() const
Face GetRightFace() const