Add is_position_in_frustum to Camera3D
This commit is contained in:
@ -55,10 +55,19 @@
|
|||||||
<argument index="0" name="world_point" type="Vector3">
|
<argument index="0" name="world_point" type="Vector3">
|
||||||
</argument>
|
</argument>
|
||||||
<description>
|
<description>
|
||||||
Returns [code]true[/code] if the given position is behind the camera.
|
Returns [code]true[/code] if the given position is behind the camera (the blue part of the linked diagram). [url=https://raw.githubusercontent.com/godotengine/godot-docs/master/img/camera3d_position_frustum.png]See this diagram[/url] for an overview of position query methods.
|
||||||
[b]Note:[/b] A position which returns [code]false[/code] may still be outside the camera's field of view.
|
[b]Note:[/b] A position which returns [code]false[/code] may still be outside the camera's field of view.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
|
<method name="is_position_in_frustum" qualifiers="const">
|
||||||
|
<return type="bool">
|
||||||
|
</return>
|
||||||
|
<argument index="0" name="world_point" type="Vector3">
|
||||||
|
</argument>
|
||||||
|
<description>
|
||||||
|
Returns [code]true[/code] if the given position is inside the camera's frustum (the green part of the linked diagram). [url=https://raw.githubusercontent.com/godotengine/godot-docs/master/img/camera3d_position_frustum.png]See this diagram[/url] for an overview of position query methods.
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
<method name="make_current">
|
<method name="make_current">
|
||||||
<return type="void">
|
<return type="void">
|
||||||
</return>
|
</return>
|
||||||
|
|||||||
@ -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("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_doppler_tracking"), &Camera3D::get_doppler_tracking);
|
||||||
ClassDB::bind_method(D_METHOD("get_frustum"), &Camera3D::get_frustum);
|
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("get_camera_rid"), &Camera3D::get_camera);
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("set_cull_mask_bit", "layer", "enable"), &Camera3D::set_cull_mask_bit);
|
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());
|
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) {
|
void Camera3D::set_v_offset(float p_offset) {
|
||||||
v_offset = p_offset;
|
v_offset = p_offset;
|
||||||
_update_camera();
|
_update_camera();
|
||||||
|
|||||||
@ -153,6 +153,7 @@ public:
|
|||||||
bool get_cull_mask_bit(int p_layer) const;
|
bool get_cull_mask_bit(int p_layer) const;
|
||||||
|
|
||||||
virtual Vector<Plane> get_frustum() 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);
|
void set_environment(const Ref<Environment> &p_environment);
|
||||||
Ref<Environment> get_environment() const;
|
Ref<Environment> get_environment() const;
|
||||||
|
|||||||
Reference in New Issue
Block a user