10 {
11 float zFar = cam.GetFar();
12 float zNear = cam.GetNear();
13 float aspectRatio = cam.GetAspectRatio();
14 float fov = cam.GetFOV();
15
16 glm::vec3 front = cam.GetFrontVec();
17 glm::vec3 right = cam.GetRightVec();
18 glm::vec3 up = cam.GetUpVec();
19 glm::vec3 position = cam.gameObject->GetPosition();
20
21 float tanFovHalf = tan(fov / 2.0f);
22
23 float nearHeight = 2.0f * tanFovHalf * zNear;
24 float nearWidth = nearHeight * aspectRatio;
25 float farHeight = 2.0f * tanFovHalf * zFar;
26 float farWidth = farHeight * aspectRatio;
27
28 glm::vec3 nearCenter = position + front * zNear;
29 glm::vec3 farCenter = position + front * zFar;
30
31 const glm::vec3 nearTopLeft = nearCenter + up * (nearHeight * 0.5f) - right * (nearWidth * 0.5f);
32 const glm::vec3 nearTopRight = nearCenter + up * (nearHeight * 0.5f) + right * (nearWidth * 0.5f);
33 const glm::vec3 nearBottomLeft = nearCenter - up * (nearHeight * 0.5f) - right * (nearWidth * 0.5f);
34 const glm::vec3 nearBottomRight = nearCenter - up * (nearHeight * 0.5f) + right * (nearWidth * 0.5f);
35
36 const glm::vec3 farTopLeft = farCenter + up * (farHeight * 0.5f) - right * (farWidth * 0.5f);
37 const glm::vec3 farTopRight = farCenter + up * (farHeight * 0.5f) + right * (farWidth * 0.5f);
38 const glm::vec3 farBottomLeft = farCenter - up * (farHeight * 0.5f) - right * (farWidth * 0.5f);
39 const glm::vec3 farBottomRight = farCenter - up * (farHeight * 0.5f) + right * (farWidth * 0.5f);
40
47 }
void Set(const glm::vec3 &normal, const glm::vec3 &point)