Skip to content

Commit

Permalink
Add support for infinite projection matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
Flarkk committed Aug 23, 2024
1 parent 77dcf97 commit 3490a89
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions core/math/projection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,14 @@ Plane Projection::get_projection_plane(Planes p_plane) const {
matrix[11] - matrix[10],
matrix[15] - matrix[14]);

new_plane.normal = -new_plane.normal;
new_plane.normalize();
if (new_plane.normal[0] == 0 && new_plane.normal[1] == 0 && new_plane.normal[2] == 0) {
new_plane.normal = Vector3(0, 0, -1);
new_plane.d = INFINITY;
} else {
new_plane.normal = -new_plane.normal;
new_plane.normalize();
}

return new_plane;
}
case PLANE_LEFT: {
Expand Down Expand Up @@ -408,6 +414,10 @@ real_t Projection::get_z_far() const {
matrix[11] - matrix[10],
matrix[15] - matrix[14]);

if (new_plane.normal[0] == 0 && new_plane.normal[1] == 0 && new_plane.normal[2] == 0) {
return INFINITY;
}

new_plane.normalize();

return new_plane.d;
Expand Down Expand Up @@ -459,7 +469,13 @@ Vector2 Projection::get_far_plane_half_extents() const {
matrix[7] - matrix[6],
matrix[11] - matrix[10],
-matrix[15] + matrix[14]);
far_plane.normalize();

if (far_plane.normal[0] == 0 && far_plane.normal[1] == 0 && far_plane.normal[2] == 0) {
far_plane.normal = Vector3(0, 0, 1);
far_plane.d = -INFINITY;
} else {
far_plane.normalize();
}

///////--- Right Plane ---///////
Plane right_plane = Plane(matrix[3] - matrix[0],
Expand Down Expand Up @@ -537,8 +553,13 @@ Vector<Plane> Projection::get_projection_planes(const Transform3D &p_transform)
matrix[11] - matrix[10],
matrix[15] - matrix[14]);

new_plane.normal = -new_plane.normal;
new_plane.normalize();
if (new_plane.normal[0] == 0 && new_plane.normal[1] == 0 && new_plane.normal[2] == 0) {
new_plane.normal = Vector3(0, 0, -1);
new_plane.d = INFINITY;
} else {
new_plane.normal = -new_plane.normal;
new_plane.normalize();
}

planes.write[1] = p_transform.xform(new_plane);

Expand Down

0 comments on commit 3490a89

Please sign in to comment.