5IP_Camera::IP_Camera() :
6 Camera(glm::vec3(0, 0, 0), glm::vec3(0, 0, -1), glm::vec3(0, 1, 0)) {
8 update_projection_matrix();
11IP_Camera::IP_Camera(
const IP_Camera& camera) :
38IP_Camera::~IP_Camera() {
50 std::vector<glm::vec4> ndc = {
51 glm::vec4(-1, -1, -1, 1),
52 glm::vec4( 1, -1, -1, 1),
53 glm::vec4( 1, 1, -1, 1),
54 glm::vec4(-1, 1, -1, 1),
60 std::vector<glm::vec3> ret(ndc.size());
61 for(
unsigned int i = 0; i < ndc.size(); i++) {
63 ret[i] = glm::vec3(tmp) / tmp[3];
70 glm::vec3 cam_dir = glm::normalize(
direction);
76 glm::vec3 left_normal = glm::normalize(glm::cross(fpoints[3] -
position,
77 fpoints[0] - fpoints[3]));
78 glm::vec3 right_normal = glm::normalize(glm::cross(fpoints[1] - fpoints[2],
80 glm::vec3 top_normal = glm::normalize(glm::cross(fpoints[2] - fpoints[3],
82 glm::vec3 bottom_normal = glm::normalize(glm::cross(fpoints[0] -
position,
83 fpoints[1] - fpoints[0]));
85 std::vector<float> ret(5);
86 ret[0] = glm::dot(-cam_dir,
position - near_center);
87 ret[1] = glm::dot(left_normal,
position - fpoints[3]);
88 ret[2] = glm::dot(right_normal,
position - fpoints[2]);
89 ret[3] = glm::dot(top_normal,
position - fpoints[3]);
90 ret[4] = glm::dot(bottom_normal,
position - fpoints[0]);
float height
Viewport height.
float width
Viewport width.
glm::mat4 view_matrix
The view matrix.
glm::vec3 direction
The direction the camera is pointing.
glm::vec3 up
The up vector of the camera.
glm::vec3 position
The camera position.
Camera(glm::vec3 position, glm::vec3 direction, glm::vec3 up)
float near_plane
The near plane of the camera frustum.
float fovy
The vertical field of view angle of the camera.
glm::mat4 projection_matrix
The perspective projection matrix.
std::vector< glm::vec3 > calculate_frustum_points()
Calculates the corner points of the camera's frustum.
std::vector< float > calculate_frustum_distance(glm::vec3 point)
Calculates the distances of a point to all planes of the camera's frustum. Positive values indicate t...
void update_projection_matrix()
Recalculates the projection matrix.