diff --git a/core/math/aabb.cpp b/core/math/aabb.cpp
index e1d49dacc07a..76e9e74dea70 100644
--- a/core/math/aabb.cpp
+++ b/core/math/aabb.cpp
@@ -117,11 +117,6 @@ AABB AABB::intersection(const AABB &p_aabb) const {
return AABB(min, max - min);
}
-#ifdef MINGW_ENABLED
-#undef near
-#undef far
-#endif
-
bool AABB::intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *r_clip, Vector3 *r_normal) const {
#ifdef MATH_CHECKS
if (unlikely(size.x < 0 || size.y < 0 || size.z < 0)) {
@@ -130,8 +125,8 @@ bool AABB::intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *
#endif
Vector3 c1, c2;
Vector3 end = position + size;
- real_t near = -1e20;
- real_t far = 1e20;
+ real_t depth_near = -1e20;
+ real_t depth_far = 1e20;
int axis = 0;
for (int i = 0; i < 3; i++) {
@@ -146,14 +141,14 @@ bool AABB::intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *
if (c1[i] > c2[i]) {
SWAP(c1, c2);
}
- if (c1[i] > near) {
- near = c1[i];
+ if (c1[i] > depth_near) {
+ depth_near = c1[i];
axis = i;
}
- if (c2[i] < far) {
- far = c2[i];
+ if (c2[i] < depth_far) {
+ depth_far = c2[i];
}
- if ((near > far) || (far < 0)) {
+ if ((depth_near > depth_far) || (depth_far < 0)) {
return false;
}
}
diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp
index eb840fcb5144..83b5a136fdab 100644
--- a/editor/plugins/node_3d_editor_plugin.cpp
+++ b/editor/plugins/node_3d_editor_plugin.cpp
@@ -943,13 +943,13 @@ void Node3DEditorViewport::_select_region() {
}
}
- Plane near(-_get_camera_normal(), cam_pos);
- near.d -= get_znear();
- frustum.push_back(near);
+ Plane near_plane = Plane(-_get_camera_normal(), cam_pos);
+ near_plane.d -= get_znear();
+ frustum.push_back(near_plane);
- Plane far = -near;
- far.d += get_zfar();
- frustum.push_back(far);
+ Plane far_plane = -near_plane;
+ far_plane.d += get_zfar();
+ frustum.push_back(far_plane);
if (spatial_editor->get_single_selected_node()) {
Node3D *single_selected = spatial_editor->get_single_selected_node();
diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Projection.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Projection.cs
index 4c9e21fb7919..a646caad3e9d 100644
--- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Projection.cs
+++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Projection.cs
@@ -254,7 +254,7 @@ public static Projection CreateForHmd(int eye, real_t aspect, real_t intraocular
/// The near clipping distance.
/// The far clipping distance.
/// The created projection.
- public static Projection CreateFrustum(real_t left, real_t right, real_t bottom, real_t top, real_t near, real_t far)
+ public static Projection CreateFrustum(real_t left, real_t right, real_t bottom, real_t top, real_t depth_near, real_t depth_far)
{
if (right <= left)
{
@@ -264,18 +264,18 @@ public static Projection CreateFrustum(real_t left, real_t right, real_t bottom,
{
throw new ArgumentException("top is less or equal to bottom.");
}
- if (far <= near)
+ if (depth_far <= depth_near)
{
throw new ArgumentException("far is less or equal to near.");
}
- real_t x = 2 * near / (right - left);
- real_t y = 2 * near / (top - bottom);
+ real_t x = 2 * depth_near / (right - left);
+ real_t y = 2 * depth_near / (top - bottom);
real_t a = (right + left) / (right - left);
real_t b = (top + bottom) / (top - bottom);
- real_t c = -(far + near) / (far - near);
- real_t d = -2 * far * near / (far - near);
+ real_t c = -(depth_far + depth_near) / (depth_far - depth_near);
+ real_t d = -2 * depth_far * depth_near / (depth_far - depth_near);
return new Projection(
new Vector4(x, 0, 0, 0),
@@ -297,13 +297,13 @@ public static Projection CreateFrustum(real_t left, real_t right, real_t bottom,
/// The far clipping distance.
/// If the field of view is flipped over the projection's diagonal.
/// The created projection.
- public static Projection CreateFrustumAspect(real_t size, real_t aspect, Vector2 offset, real_t near, real_t far, bool flipFov)
+ public static Projection CreateFrustumAspect(real_t size, real_t aspect, Vector2 offset, real_t depth_near, real_t depth_far, bool flipFov)
{
if (!flipFov)
{
size *= aspect;
}
- return CreateFrustum(-size / 2 + offset.X, +size / 2 + offset.X, -size / aspect / 2 + offset.Y, +size / aspect / 2 + offset.Y, near, far);
+ return CreateFrustum(-size / 2 + offset.X, +size / 2 + offset.X, -size / aspect / 2 + offset.Y, +size / aspect / 2 + offset.Y, depth_near, depth_far);
}
///
diff --git a/scene/debugger/scene_debugger.cpp b/scene/debugger/scene_debugger.cpp
index d539f45d3186..19e5693736d7 100644
--- a/scene/debugger/scene_debugger.cpp
+++ b/scene/debugger/scene_debugger.cpp
@@ -72,11 +72,6 @@ void SceneDebugger::deinitialize() {
}
}
-#ifdef MINGW_ENABLED
-#undef near
-#undef far
-#endif
-
#ifdef DEBUG_ENABLED
Error SceneDebugger::parse_message(void *p_user, const String &p_msg, const Array &p_args, bool &r_captured) {
SceneTree *scene_tree = SceneTree::get_singleton();
@@ -124,12 +119,12 @@ Error SceneDebugger::parse_message(void *p_user, const String &p_msg, const Arra
Transform3D transform = p_args[0];
bool is_perspective = p_args[1];
float size_or_fov = p_args[2];
- float near = p_args[3];
- float far = p_args[4];
+ float depth_near = p_args[3];
+ float depth_far = p_args[4];
if (is_perspective) {
- scene_tree->get_root()->set_camera_3d_override_perspective(size_or_fov, near, far);
+ scene_tree->get_root()->set_camera_3d_override_perspective(size_or_fov, depth_near, depth_far);
} else {
- scene_tree->get_root()->set_camera_3d_override_orthogonal(size_or_fov, near, far);
+ scene_tree->get_root()->set_camera_3d_override_orthogonal(size_or_fov, depth_near, depth_far);
}
scene_tree->get_root()->set_camera_3d_override_transform(transform);
#endif // _3D_DISABLED
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index a0fae16120ab..9e8047ce4987 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -896,13 +896,13 @@ void Viewport::_process_picking() {
if (camera_3d) {
Vector3 from = camera_3d->project_ray_origin(pos);
Vector3 dir = camera_3d->project_ray_normal(pos);
- real_t far = camera_3d->get_far();
+ real_t depth_far = camera_3d->get_far();
PhysicsDirectSpaceState3D *space = PhysicsServer3D::get_singleton()->space_get_direct_state(find_world_3d()->get_space());
if (space) {
PhysicsDirectSpaceState3D::RayParameters ray_params;
ray_params.from = from;
- ray_params.to = from + dir * far;
+ ray_params.to = from + dir * depth_far;
ray_params.collide_with_areas = true;
ray_params.pick_ray = true;
diff --git a/scene/resources/camera_attributes.cpp b/scene/resources/camera_attributes.cpp
index af5df165b3a4..3a021720c687 100644
--- a/scene/resources/camera_attributes.cpp
+++ b/scene/resources/camera_attributes.cpp
@@ -373,11 +373,6 @@ real_t CameraAttributesPhysical::get_fov() const {
return frustum_fov;
}
-#ifdef MINGW_ENABLED
-#undef near
-#undef far
-#endif
-
void CameraAttributesPhysical::_update_frustum() {
//https://en.wikipedia.org/wiki/Circle_of_confusion#Circle_of_confusion_diameter_limit_based_on_d/1500
Vector2i sensor_size = Vector2i(36, 24); // Matches high-end DSLR, could be made variable if there is demand.
@@ -393,12 +388,12 @@ void CameraAttributesPhysical::_update_frustum() {
// that it is not picked up by the camera sensors.
// To be properly physically-based, we would run the DoF shader at all depths. To be efficient, we are only running it where the CoC
// will be visible, this introduces some value shifts in the near field that we have to compensate for below.
- float near = ((hyperfocal_length * u) / (hyperfocal_length + (u - frustum_focal_length))) / 1000.0; // In meters.
- float far = ((hyperfocal_length * u) / (hyperfocal_length - (u - frustum_focal_length))) / 1000.0; // In meters.
+ float depth_near = ((hyperfocal_length * u) / (hyperfocal_length + (u - frustum_focal_length))) / 1000.0; // In meters.
+ float depth_far = ((hyperfocal_length * u) / (hyperfocal_length - (u - frustum_focal_length))) / 1000.0; // In meters.
float scale = (frustum_focal_length / (u - frustum_focal_length)) * (frustum_focal_length / exposure_aperture);
- bool use_far = (far < frustum_far) && (far > 0.0);
- bool use_near = near > frustum_near;
+ bool use_far = (depth_far < frustum_far) && (depth_far > 0.0);
+ bool use_near = depth_near > frustum_near;
#ifdef DEBUG_ENABLED
if (OS::get_singleton()->get_current_rendering_method() == "gl_compatibility") {
// Force disable DoF in editor builds to suppress warnings.
diff --git a/servers/rendering/renderer_scene_render.cpp b/servers/rendering/renderer_scene_render.cpp
index cd89bb314b9b..dce301d87b7c 100644
--- a/servers/rendering/renderer_scene_render.cpp
+++ b/servers/rendering/renderer_scene_render.cpp
@@ -47,11 +47,6 @@ void RendererSceneRender::CameraData::set_camera(const Transform3D p_transform,
taa_jitter = p_taa_jitter;
}
-#ifdef MINGW_ENABLED
-#undef near
-#undef far
-#endif
-
void RendererSceneRender::CameraData::set_multiview_camera(uint32_t p_view_count, const Transform3D *p_transforms, const Projection *p_projections, bool p_is_orthogonal, bool p_vaspect) {
ERR_FAIL_COND_MSG(p_view_count != 2, "Incorrect view count for stereoscopic view");
@@ -90,7 +85,7 @@ void RendererSceneRender::CameraData::set_multiview_camera(uint32_t p_view_count
// 5. figure out far plane, this could use some improvement, we may have our far plane too close like this, not sure if this matters
Vector3 far_center = (planes[0][Projection::PLANE_FAR].get_center() + planes[1][Projection::PLANE_FAR].get_center()) * 0.5;
- Plane far(-z, far_center);
+ Plane far_plane = Plane(-z, far_center);
/////////////////////////////////////////////////////////////////////////////
// Figure out our top/bottom planes
@@ -98,9 +93,9 @@ void RendererSceneRender::CameraData::set_multiview_camera(uint32_t p_view_count
// 6. Intersect far and left planes with top planes from both eyes, save the point with highest y as top_left.
Vector3 top_left, other;
ERR_FAIL_COND_MSG(
- !far.intersect_3(planes[0][Projection::PLANE_LEFT], planes[0][Projection::PLANE_TOP], &top_left), "Can't determine left camera far/left/top vector");
+ !far_plane.intersect_3(planes[0][Projection::PLANE_LEFT], planes[0][Projection::PLANE_TOP], &top_left), "Can't determine left camera far/left/top vector");
ERR_FAIL_COND_MSG(
- !far.intersect_3(planes[1][Projection::PLANE_LEFT], planes[1][Projection::PLANE_TOP], &other), "Can't determine right camera far/left/top vector");
+ !far_plane.intersect_3(planes[1][Projection::PLANE_LEFT], planes[1][Projection::PLANE_TOP], &other), "Can't determine right camera far/left/top vector");
if (y.dot(top_left) < y.dot(other)) {
top_left = other;
}
@@ -108,9 +103,9 @@ void RendererSceneRender::CameraData::set_multiview_camera(uint32_t p_view_count
// 7. Intersect far and left planes with bottom planes from both eyes, save the point with lowest y as bottom_left.
Vector3 bottom_left;
ERR_FAIL_COND_MSG(
- !far.intersect_3(planes[0][Projection::PLANE_LEFT], planes[0][Projection::PLANE_BOTTOM], &bottom_left), "Can't determine left camera far/left/bottom vector");
+ !far_plane.intersect_3(planes[0][Projection::PLANE_LEFT], planes[0][Projection::PLANE_BOTTOM], &bottom_left), "Can't determine left camera far/left/bottom vector");
ERR_FAIL_COND_MSG(
- !far.intersect_3(planes[1][Projection::PLANE_LEFT], planes[1][Projection::PLANE_BOTTOM], &other), "Can't determine right camera far/left/bottom vector");
+ !far_plane.intersect_3(planes[1][Projection::PLANE_LEFT], planes[1][Projection::PLANE_BOTTOM], &other), "Can't determine right camera far/left/bottom vector");
if (y.dot(other) < y.dot(bottom_left)) {
bottom_left = other;
}
@@ -118,9 +113,9 @@ void RendererSceneRender::CameraData::set_multiview_camera(uint32_t p_view_count
// 8. Intersect far and right planes with top planes from both eyes, save the point with highest y as top_right.
Vector3 top_right;
ERR_FAIL_COND_MSG(
- !far.intersect_3(planes[0][Projection::PLANE_RIGHT], planes[0][Projection::PLANE_TOP], &top_right), "Can't determine left camera far/right/top vector");
+ !far_plane.intersect_3(planes[0][Projection::PLANE_RIGHT], planes[0][Projection::PLANE_TOP], &top_right), "Can't determine left camera far/right/top vector");
ERR_FAIL_COND_MSG(
- !far.intersect_3(planes[1][Projection::PLANE_RIGHT], planes[1][Projection::PLANE_TOP], &other), "Can't determine right camera far/right/top vector");
+ !far_plane.intersect_3(planes[1][Projection::PLANE_RIGHT], planes[1][Projection::PLANE_TOP], &other), "Can't determine right camera far/right/top vector");
if (y.dot(top_right) < y.dot(other)) {
top_right = other;
}
@@ -128,9 +123,9 @@ void RendererSceneRender::CameraData::set_multiview_camera(uint32_t p_view_count
// 9. Intersect far and right planes with bottom planes from both eyes, save the point with lowest y as bottom_right.
Vector3 bottom_right;
ERR_FAIL_COND_MSG(
- !far.intersect_3(planes[0][Projection::PLANE_RIGHT], planes[0][Projection::PLANE_BOTTOM], &bottom_right), "Can't determine left camera far/right/bottom vector");
+ !far_plane.intersect_3(planes[0][Projection::PLANE_RIGHT], planes[0][Projection::PLANE_BOTTOM], &bottom_right), "Can't determine left camera far/right/bottom vector");
ERR_FAIL_COND_MSG(
- !far.intersect_3(planes[1][Projection::PLANE_RIGHT], planes[1][Projection::PLANE_BOTTOM], &other), "Can't determine right camera far/right/bottom vector");
+ !far_plane.intersect_3(planes[1][Projection::PLANE_RIGHT], planes[1][Projection::PLANE_BOTTOM], &other), "Can't determine right camera far/right/bottom vector");
if (y.dot(other) < y.dot(bottom_right)) {
bottom_right = other;
}
@@ -145,29 +140,29 @@ void RendererSceneRender::CameraData::set_multiview_camera(uint32_t p_view_count
// Figure out our near plane points
// 12. Create a near plane using -camera z and the eye further along in that axis.
- Plane near;
+ Plane near_plane;
Vector3 neg_z = -z;
if (neg_z.dot(p_transforms[1].origin) < neg_z.dot(p_transforms[0].origin)) {
- near = Plane(neg_z, p_transforms[0].origin);
+ near_plane = Plane(neg_z, p_transforms[0].origin);
} else {
- near = Plane(neg_z, p_transforms[1].origin);
+ near_plane = Plane(neg_z, p_transforms[1].origin);
}
// 13. Intersect near plane with bottm/left planes, to obtain min_vec then top/right to obtain max_vec
Vector3 min_vec;
ERR_FAIL_COND_MSG(
- !near.intersect_3(bottom, planes[0][Projection::PLANE_LEFT], &min_vec), "Can't determine left camera near/left/bottom vector");
+ !near_plane.intersect_3(bottom, planes[0][Projection::PLANE_LEFT], &min_vec), "Can't determine left camera near/left/bottom vector");
ERR_FAIL_COND_MSG(
- !near.intersect_3(bottom, planes[1][Projection::PLANE_LEFT], &other), "Can't determine right camera near/left/bottom vector");
+ !near_plane.intersect_3(bottom, planes[1][Projection::PLANE_LEFT], &other), "Can't determine right camera near/left/bottom vector");
if (x.dot(other) < x.dot(min_vec)) {
min_vec = other;
}
Vector3 max_vec;
ERR_FAIL_COND_MSG(
- !near.intersect_3(top, planes[0][Projection::PLANE_RIGHT], &max_vec), "Can't determine left camera near/right/top vector");
+ !near_plane.intersect_3(top, planes[0][Projection::PLANE_RIGHT], &max_vec), "Can't determine left camera near/right/top vector");
ERR_FAIL_COND_MSG(
- !near.intersect_3(top, planes[1][Projection::PLANE_RIGHT], &other), "Can't determine right camera near/right/top vector");
+ !near_plane.intersect_3(top, planes[1][Projection::PLANE_RIGHT], &other), "Can't determine right camera near/right/top vector");
if (x.dot(max_vec) < x.dot(other)) {
max_vec = other;
}
@@ -177,8 +172,8 @@ void RendererSceneRender::CameraData::set_multiview_camera(uint32_t p_view_count
Vector3 local_max_vec = main_transform_inv.xform(max_vec);
// 15. get x and y from these to obtain left, top, right bottom for the frustum. Get the distance from near plane to camera origin to obtain near, and the distance from the far plane to the camer origin to obtain far.
- float z_near = -near.distance_to(main_transform.origin);
- float z_far = -far.distance_to(main_transform.origin);
+ float z_near = -near_plane.distance_to(main_transform.origin);
+ float z_far = -far_plane.distance_to(main_transform.origin);
// 16. Use this to build the combined camera matrix.
main_projection.set_frustum(local_min_vec.x, local_max_vec.x, local_min_vec.y, local_max_vec.y, z_near, z_far);
diff --git a/tests/scene/test_camera_3d.h b/tests/scene/test_camera_3d.h
index 169486d10821..830c667257ba 100644
--- a/tests/scene/test_camera_3d.h
+++ b/tests/scene/test_camera_3d.h
@@ -65,17 +65,17 @@ TEST_CASE("[SceneTree][Camera3D] Getters and setters") {
}
SUBCASE("Camera frustum properties") {
- constexpr float near = 0.2f;
- constexpr float far = 995.0f;
+ constexpr float depth_near = 0.2f;
+ constexpr float depth_far = 995.0f;
constexpr float fov = 120.0f;
constexpr float size = 7.0f;
constexpr float h_offset = 1.1f;
constexpr float v_offset = -1.6f;
const Vector2 frustum_offset(5, 7);
- test_camera->set_near(near);
- CHECK(test_camera->get_near() == near);
- test_camera->set_far(far);
- CHECK(test_camera->get_far() == far);
+ test_camera->set_near(depth_near);
+ CHECK(test_camera->get_near() == depth_near);
+ test_camera->set_far(depth_far);
+ CHECK(test_camera->get_far() == depth_far);
test_camera->set_fov(fov);
CHECK(test_camera->get_fov() == fov);
test_camera->set_size(size);