// Calculating the corners of the view frustum
void calculateFrustumCorners(
float fovY,
float aspectRatio,
float nearPlane,
float farPlane,
glm::vec3 corners[8] // Output array for the 8 corners
) {
float tanHalfFovY = tan(glm::radians(fovY) / 2.0f);
// Near plane dimensions
float nearHeight = 2.0f * nearPlane * tanHalfFovY;
float nearWidth = nearHeight * aspectRatio;
// Far plane dimensions
float farHeight = 2.0f * farPlane * tanHalfFovY;
float farWidth = farHeight * aspectRatio;
// Near plane corners (in view space)
corners[0] = glm::vec3(-nearWidth/2, -nearHeight/2, -nearPlane); // Bottom-left
corners[1] = glm::vec3( nearWidth/2, -nearHeight/2, -nearPlane); // Bottom-right
corners[2] = glm::vec3( nearWidth/2, nearHeight/2, -nearPlane); // Top-right
corners[3] = glm::vec3(-nearWidth/2, nearHeight/2, -nearPlane); // Top-left
// Far plane corners (in view space)
corners[4] = glm::vec3(-farWidth/2, -farHeight/2, -farPlane); // Bottom-left
corners[5] = glm::vec3( farWidth/2, -farHeight/2, -farPlane); // Bottom-right
corners[6] = glm::vec3( farWidth/2, farHeight/2, -farPlane); // Top-right
corners[7] = glm::vec3(-farWidth/2, farHeight/2, -farPlane); // Top-left
}