summaryrefslogtreecommitdiff
path: root/scene/3d
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2021-06-14 19:05:43 +0200
committerGitHub <noreply@github.com>2021-06-14 19:05:43 +0200
commitaa43b5a3f47c943499d6d586491ef20ec5c81359 (patch)
tree142911685af3212ba94035f6bbb5d2183c75ed72 /scene/3d
parent3f613236e093e853381cddbdc8fc83abb0f0c828 (diff)
parentbd40474bd6ee850d3f86d0da290e320bd0264fc3 (diff)
Merge pull request #48287 from aaronfranke/camera-is-frustum
Diffstat (limited to 'scene/3d')
-rw-r--r--scene/3d/camera_3d.cpp11
-rw-r--r--scene/3d/camera_3d.h1
2 files changed, 12 insertions, 0 deletions
diff --git a/scene/3d/camera_3d.cpp b/scene/3d/camera_3d.cpp
index 1c9418ae83..6b8851b4f8 100644
--- a/scene/3d/camera_3d.cpp
+++ b/scene/3d/camera_3d.cpp
@@ -500,6 +500,7 @@ void Camera3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_doppler_tracking", "mode"), &Camera3D::set_doppler_tracking);
ClassDB::bind_method(D_METHOD("get_doppler_tracking"), &Camera3D::get_doppler_tracking);
ClassDB::bind_method(D_METHOD("get_frustum"), &Camera3D::get_frustum);
+ ClassDB::bind_method(D_METHOD("is_position_in_frustum", "world_point"), &Camera3D::is_position_in_frustum);
ClassDB::bind_method(D_METHOD("get_camera_rid"), &Camera3D::get_camera);
ClassDB::bind_method(D_METHOD("set_cull_mask_bit", "layer", "enable"), &Camera3D::set_cull_mask_bit);
@@ -623,6 +624,16 @@ Vector<Plane> Camera3D::get_frustum() const {
return cm.get_projection_planes(get_camera_transform());
}
+bool Camera3D::is_position_in_frustum(const Vector3 &p_position) const {
+ Vector<Plane> frustum = get_frustum();
+ for (int i = 0; i < frustum.size(); i++) {
+ if (frustum[i].is_point_over(p_position)) {
+ return false;
+ }
+ }
+ return true;
+}
+
void Camera3D::set_v_offset(float p_offset) {
v_offset = p_offset;
_update_camera();
diff --git a/scene/3d/camera_3d.h b/scene/3d/camera_3d.h
index d9ebe78f1a..c6efc8f9a9 100644
--- a/scene/3d/camera_3d.h
+++ b/scene/3d/camera_3d.h
@@ -153,6 +153,7 @@ public:
bool get_cull_mask_bit(int p_layer) const;
virtual Vector<Plane> get_frustum() const;
+ bool is_position_in_frustum(const Vector3 &p_position) const;
void set_environment(const Ref<Environment> &p_environment);
Ref<Environment> get_environment() const;