| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | /*  camera_3d.cpp                                                        */ | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*                       This file is part of:                           */ | 
					
						
							|  |  |  | /*                           GODOT ENGINE                                */ | 
					
						
							| 
									
										
										
										
											2017-08-27 14:16:55 +02:00
										 |  |  | /*                      https://godotengine.org                          */ | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2021-01-01 20:13:46 +01:00
										 |  |  | /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur.                 */ | 
					
						
							|  |  |  | /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md).   */ | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* Permission is hereby granted, free of charge, to any person obtaining */ | 
					
						
							|  |  |  | /* a copy of this software and associated documentation files (the       */ | 
					
						
							|  |  |  | /* "Software"), to deal in the Software without restriction, including   */ | 
					
						
							|  |  |  | /* without limitation the rights to use, copy, modify, merge, publish,   */ | 
					
						
							|  |  |  | /* distribute, sublicense, and/or sell copies of the Software, and to    */ | 
					
						
							|  |  |  | /* permit persons to whom the Software is furnished to do so, subject to */ | 
					
						
							|  |  |  | /* the following conditions:                                             */ | 
					
						
							|  |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* The above copyright notice and this permission notice shall be        */ | 
					
						
							|  |  |  | /* included in all copies or substantial portions of the Software.       */ | 
					
						
							|  |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */ | 
					
						
							|  |  |  | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */ | 
					
						
							|  |  |  | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ | 
					
						
							|  |  |  | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */ | 
					
						
							|  |  |  | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */ | 
					
						
							|  |  |  | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */ | 
					
						
							|  |  |  | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2018-01-05 00:50:27 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | #include "camera_3d.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | #include "collision_object_3d.h"
 | 
					
						
							| 
									
										
										
										
											2020-11-07 19:33:38 -03:00
										 |  |  | #include "core/config/engine.h"
 | 
					
						
							| 
									
										
										
										
											2018-09-11 18:13:45 +02:00
										 |  |  | #include "core/math/camera_matrix.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | #include "scene/resources/material.h"
 | 
					
						
							|  |  |  | #include "scene/resources/surface_tool.h"
 | 
					
						
							| 
									
										
										
										
											2020-07-01 14:18:13 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | void Camera3D::_update_audio_listener_state() { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | void Camera3D::_request_camera_update() { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	_update_camera(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | void Camera3D::_update_camera_mode() { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	force_change = true; | 
					
						
							|  |  |  | 	switch (mode) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		case PROJECTION_PERSPECTIVE: { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			set_perspective(fov, near, far); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		} break; | 
					
						
							|  |  |  | 		case PROJECTION_ORTHOGONAL: { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			set_orthogonal(size, near, far); | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 		} break; | 
					
						
							| 
									
										
										
										
											2019-02-19 17:17:02 +01:00
										 |  |  | 		case PROJECTION_FRUSTUM: { | 
					
						
							|  |  |  | 			set_frustum(size, frustum_offset, near, far); | 
					
						
							|  |  |  | 		} break; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | void Camera3D::_validate_property(PropertyInfo &p_property) const { | 
					
						
							| 
									
										
										
										
											2017-12-07 00:31:03 -06:00
										 |  |  | 	if (p_property.name == "fov") { | 
					
						
							| 
									
										
										
										
											2019-02-19 17:17:02 +01:00
										 |  |  | 		if (mode != PROJECTION_PERSPECTIVE) { | 
					
						
							| 
									
										
										
										
											2017-12-07 00:31:03 -06:00
										 |  |  | 			p_property.usage = PROPERTY_USAGE_NOEDITOR; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-12-07 00:31:03 -06:00
										 |  |  | 	} else if (p_property.name == "size") { | 
					
						
							| 
									
										
										
										
											2019-02-19 17:17:02 +01:00
										 |  |  | 		if (mode != PROJECTION_ORTHOGONAL && mode != PROJECTION_FRUSTUM) { | 
					
						
							|  |  |  | 			p_property.usage = PROPERTY_USAGE_NOEDITOR; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} else if (p_property.name == "frustum_offset") { | 
					
						
							|  |  |  | 		if (mode != PROJECTION_FRUSTUM) { | 
					
						
							| 
									
										
										
										
											2017-12-07 00:31:03 -06:00
										 |  |  | 			p_property.usage = PROPERTY_USAGE_NOEDITOR; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | void Camera3D::_update_camera() { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (!is_inside_tree()) { | 
					
						
							| 
									
										
										
										
											2017-12-25 01:31:28 +09:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-12-25 01:31:28 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 15:21:27 -03:00
										 |  |  | 	RenderingServer::get_singleton()->camera_set_transform(camera, get_camera_transform()); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-14 12:26:56 +01:00
										 |  |  | 	// here goes listener stuff
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	if (viewport_ptr && is_inside_scene() && is_current()) | 
					
						
							|  |  |  | 		get_viewport()->_camera_transform_changed_notify(); | 
					
						
							|  |  |  | 	*/ | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (get_tree()->is_node_being_edited(this) || !is_current()) { | 
					
						
							| 
									
										
										
										
											2017-12-07 12:13:20 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-12-07 12:13:20 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	get_viewport()->_camera_transform_changed_notify(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | void Camera3D::_notification(int p_what) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	switch (p_what) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		case NOTIFICATION_ENTER_WORLD: { | 
					
						
							| 
									
										
										
										
											2021-03-12 19:05:16 +05:30
										 |  |  | 			// Needs to track the Viewport because it's needed on NOTIFICATION_EXIT_WORLD
 | 
					
						
							| 
									
										
										
										
											2019-03-10 04:59:52 +01:00
										 |  |  | 			// and Spatial will handle it first, including clearing its reference to the Viewport,
 | 
					
						
							|  |  |  | 			// therefore making it impossible to subclasses to access it
 | 
					
						
							|  |  |  | 			viewport = get_viewport(); | 
					
						
							|  |  |  | 			ERR_FAIL_COND(!viewport); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			bool first_camera = viewport->_camera_add(this); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			if (current || first_camera) { | 
					
						
							| 
									
										
										
										
											2019-03-10 04:59:52 +01:00
										 |  |  | 				viewport->_camera_set(this); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 		} break; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		case NOTIFICATION_TRANSFORM_CHANGED: { | 
					
						
							|  |  |  | 			_request_camera_update(); | 
					
						
							| 
									
										
										
										
											2017-07-15 01:23:10 -03:00
										 |  |  | 			if (doppler_tracking != DOPPLER_TRACKING_DISABLED) { | 
					
						
							|  |  |  | 				velocity_tracker->update_position(get_global_transform().origin); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		} break; | 
					
						
							|  |  |  | 		case NOTIFICATION_EXIT_WORLD: { | 
					
						
							| 
									
										
										
										
											2016-01-02 17:18:45 -03:00
										 |  |  | 			if (!get_tree()->is_node_being_edited(this)) { | 
					
						
							|  |  |  | 				if (is_current()) { | 
					
						
							|  |  |  | 					clear_current(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					current = true; //keep it true
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-02 17:18:45 -03:00
										 |  |  | 				} else { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					current = false; | 
					
						
							| 
									
										
										
										
											2016-01-02 17:18:45 -03:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-01-02 17:18:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-10 04:59:52 +01:00
										 |  |  | 			if (viewport) { | 
					
						
							|  |  |  | 				viewport->_camera_remove(this); | 
					
						
							| 
									
										
										
										
											2020-04-02 01:20:12 +02:00
										 |  |  | 				viewport = nullptr; | 
					
						
							| 
									
										
										
										
											2019-03-10 04:59:52 +01:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-10-12 02:13:22 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		} break; | 
					
						
							|  |  |  | 		case NOTIFICATION_BECAME_CURRENT: { | 
					
						
							| 
									
										
										
										
											2019-03-10 04:59:52 +01:00
										 |  |  | 			if (viewport) { | 
					
						
							| 
									
										
										
										
											2020-04-18 11:00:51 +02:00
										 |  |  | 				viewport->find_world_3d()->_register_camera(this); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} break; | 
					
						
							|  |  |  | 		case NOTIFICATION_LOST_CURRENT: { | 
					
						
							| 
									
										
										
										
											2019-03-10 04:59:52 +01:00
										 |  |  | 			if (viewport) { | 
					
						
							| 
									
										
										
										
											2020-04-18 11:00:51 +02:00
										 |  |  | 				viewport->find_world_3d()->_remove_camera(this); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-17 01:08:21 -04:00
										 |  |  | Transform3D Camera3D::get_camera_transform() const { | 
					
						
							|  |  |  | 	Transform3D tr = get_global_transform().orthonormalized(); | 
					
						
							| 
									
										
										
										
											2018-07-09 21:07:15 +02:00
										 |  |  | 	tr.origin += tr.basis.get_axis(1) * v_offset; | 
					
						
							|  |  |  | 	tr.origin += tr.basis.get_axis(0) * h_offset; | 
					
						
							|  |  |  | 	return tr; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | void Camera3D::set_perspective(float p_fovy_degrees, float p_z_near, float p_z_far) { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (!force_change && fov == p_fovy_degrees && p_z_near == near && p_z_far == far && mode == PROJECTION_PERSPECTIVE) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	fov = p_fovy_degrees; | 
					
						
							|  |  |  | 	near = p_z_near; | 
					
						
							|  |  |  | 	far = p_z_far; | 
					
						
							|  |  |  | 	mode = PROJECTION_PERSPECTIVE; | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 15:21:27 -03:00
										 |  |  | 	RenderingServer::get_singleton()->camera_set_perspective(camera, fov, near, far); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	update_gizmo(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	force_change = false; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-05-14 14:29:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | void Camera3D::set_orthogonal(float p_size, float p_z_near, float p_z_far) { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (!force_change && size == p_size && p_z_near == near && p_z_far == far && mode == PROJECTION_ORTHOGONAL) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	size = p_size; | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	near = p_z_near; | 
					
						
							|  |  |  | 	far = p_z_far; | 
					
						
							|  |  |  | 	mode = PROJECTION_ORTHOGONAL; | 
					
						
							|  |  |  | 	force_change = false; | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 15:21:27 -03:00
										 |  |  | 	RenderingServer::get_singleton()->camera_set_orthogonal(camera, size, near, far); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	update_gizmo(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | void Camera3D::set_frustum(float p_size, Vector2 p_offset, float p_z_near, float p_z_far) { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (!force_change && size == p_size && frustum_offset == p_offset && p_z_near == near && p_z_far == far && mode == PROJECTION_FRUSTUM) { | 
					
						
							| 
									
										
										
										
											2019-02-19 17:17:02 +01:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-02-19 17:17:02 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	size = p_size; | 
					
						
							|  |  |  | 	frustum_offset = p_offset; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	near = p_z_near; | 
					
						
							|  |  |  | 	far = p_z_far; | 
					
						
							|  |  |  | 	mode = PROJECTION_FRUSTUM; | 
					
						
							|  |  |  | 	force_change = false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 15:21:27 -03:00
										 |  |  | 	RenderingServer::get_singleton()->camera_set_frustum(camera, size, frustum_offset, near, far); | 
					
						
							| 
									
										
										
										
											2019-02-19 17:17:02 +01:00
										 |  |  | 	update_gizmo(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | void Camera3D::set_projection(Camera3D::Projection p_mode) { | 
					
						
							| 
									
										
										
										
											2019-02-19 17:17:02 +01:00
										 |  |  | 	if (p_mode == PROJECTION_PERSPECTIVE || p_mode == PROJECTION_ORTHOGONAL || p_mode == PROJECTION_FRUSTUM) { | 
					
						
							| 
									
										
										
										
											2017-12-07 00:31:03 -06:00
										 |  |  | 		mode = p_mode; | 
					
						
							|  |  |  | 		_update_camera_mode(); | 
					
						
							| 
									
										
										
										
											2021-02-10 17:18:45 -03:00
										 |  |  | 		notify_property_list_changed(); | 
					
						
							| 
									
										
										
										
											2017-12-07 00:31:03 -06:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | RID Camera3D::get_camera() const { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	return camera; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | void Camera3D::make_current() { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	current = true; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (!is_inside_tree()) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-31 15:09:52 -03:00
										 |  |  | 	get_viewport()->_camera_set(this); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	//get_scene()->call_group(SceneMainLoop::GROUP_CALL_REALTIME,camera_group,"_camera_make_current",this);
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | void Camera3D::clear_current(bool p_enable_next) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	current = false; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (!is_inside_tree()) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (get_viewport()->get_camera() == this) { | 
					
						
							| 
									
										
										
										
											2020-04-02 01:20:12 +02:00
										 |  |  | 		get_viewport()->_camera_set(nullptr); | 
					
						
							| 
									
										
										
										
											2018-03-16 19:10:26 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (p_enable_next) { | 
					
						
							|  |  |  | 			get_viewport()->_camera_make_next_current(this); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | void Camera3D::set_current(bool p_current) { | 
					
						
							| 
									
										
										
										
											2017-12-07 00:31:03 -06:00
										 |  |  | 	if (p_current) { | 
					
						
							|  |  |  | 		make_current(); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		clear_current(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | bool Camera3D::is_current() const { | 
					
						
							| 
									
										
										
										
											2016-01-02 17:18:45 -03:00
										 |  |  | 	if (is_inside_tree() && !get_tree()->is_node_being_edited(this)) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		return get_viewport()->get_camera() == this; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return current; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | bool Camera3D::_can_gizmo_scale() const { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | Vector3 Camera3D::project_ray_normal(const Point2 &p_pos) const { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	Vector3 ray = project_local_ray_normal(p_pos); | 
					
						
							|  |  |  | 	return get_camera_transform().basis.xform(ray).normalized(); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | Vector3 Camera3D::project_local_ray_normal(const Point2 &p_pos) const { | 
					
						
							| 
									
										
										
										
											2019-08-08 22:11:48 +02:00
										 |  |  | 	ERR_FAIL_COND_V_MSG(!is_inside_tree(), Vector3(), "Camera is not inside scene."); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-02 17:18:45 -03:00
										 |  |  | 	Size2 viewport_size = get_viewport()->get_camera_rect_size(); | 
					
						
							|  |  |  | 	Vector2 cpos = get_viewport()->get_camera_coords(p_pos); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	Vector3 ray; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (mode == PROJECTION_ORTHOGONAL) { | 
					
						
							|  |  |  | 		ray = Vector3(0, 0, -1); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		CameraMatrix cm; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		cm.set_perspective(fov, viewport_size.aspect(), near, far, keep_aspect == KEEP_WIDTH); | 
					
						
							| 
									
										
										
										
											2020-01-21 18:39:16 +00:00
										 |  |  | 		Vector2 screen_he = cm.get_viewport_half_extents(); | 
					
						
							|  |  |  | 		ray = Vector3(((cpos.x / viewport_size.width) * 2.0 - 1.0) * screen_he.x, ((1.0 - (cpos.y / viewport_size.height)) * 2.0 - 1.0) * screen_he.y, -near).normalized(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return ray; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | Vector3 Camera3D::project_ray_origin(const Point2 &p_pos) const { | 
					
						
							| 
									
										
										
										
											2019-08-08 22:11:48 +02:00
										 |  |  | 	ERR_FAIL_COND_V_MSG(!is_inside_tree(), Vector3(), "Camera is not inside scene."); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-02 17:18:45 -03:00
										 |  |  | 	Size2 viewport_size = get_viewport()->get_camera_rect_size(); | 
					
						
							|  |  |  | 	Vector2 cpos = get_viewport()->get_camera_coords(p_pos); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ERR_FAIL_COND_V(viewport_size.y == 0, Vector3()); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (mode == PROJECTION_PERSPECTIVE) { | 
					
						
							|  |  |  | 		return get_camera_transform().origin; | 
					
						
							|  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2014-10-27 22:54:32 -03:00
										 |  |  | 		Vector2 pos = cpos / viewport_size; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		float vsize, hsize; | 
					
						
							|  |  |  | 		if (keep_aspect == KEEP_WIDTH) { | 
					
						
							|  |  |  | 			vsize = size / viewport_size.aspect(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			hsize = size; | 
					
						
							|  |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			hsize = size * viewport_size.aspect(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			vsize = size; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		Vector3 ray; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		ray.x = pos.x * (hsize)-hsize / 2; | 
					
						
							|  |  |  | 		ray.y = (1.0 - pos.y) * (vsize)-vsize / 2; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		ray.z = -near; | 
					
						
							|  |  |  | 		ray = get_camera_transform().xform(ray); | 
					
						
							|  |  |  | 		return ray; | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | bool Camera3D::is_position_behind(const Vector3 &p_pos) const { | 
					
						
							| 
									
										
										
										
											2020-10-17 01:08:21 -04:00
										 |  |  | 	Transform3D t = get_global_transform(); | 
					
						
							| 
									
										
										
										
											2020-06-26 16:52:02 +02:00
										 |  |  | 	Vector3 eyedir = -t.basis.get_axis(2).normalized(); | 
					
						
							|  |  |  | 	return eyedir.dot(p_pos - t.origin) < near; | 
					
						
							| 
									
										
										
										
											2015-04-28 22:05:01 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | Vector<Vector3> Camera3D::get_near_plane_points() const { | 
					
						
							| 
									
										
										
										
											2019-08-08 22:11:48 +02:00
										 |  |  | 	ERR_FAIL_COND_V_MSG(!is_inside_tree(), Vector<Vector3>(), "Camera is not inside scene."); | 
					
						
							| 
									
										
										
										
											2018-08-21 11:48:17 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	Size2 viewport_size = get_viewport()->get_visible_rect().size; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	CameraMatrix cm; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (mode == PROJECTION_ORTHOGONAL) { | 
					
						
							| 
									
										
										
										
											2018-08-21 11:48:17 -03:00
										 |  |  | 		cm.set_orthogonal(size, viewport_size.aspect(), near, far, keep_aspect == KEEP_WIDTH); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2018-08-21 11:48:17 -03:00
										 |  |  | 		cm.set_perspective(fov, viewport_size.aspect(), near, far, keep_aspect == KEEP_WIDTH); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-08-21 11:48:17 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	Vector3 endpoints[8]; | 
					
						
							| 
									
										
										
										
											2020-10-17 01:08:21 -04:00
										 |  |  | 	cm.get_endpoints(Transform3D(), endpoints); | 
					
						
							| 
									
										
										
										
											2018-08-21 11:48:17 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	Vector<Vector3> points; | 
					
						
							|  |  |  | 	points.push_back(Vector3()); | 
					
						
							|  |  |  | 	for (int i = 0; i < 4; i++) { | 
					
						
							|  |  |  | 		points.push_back(endpoints[i + 4]); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return points; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | Point2 Camera3D::unproject_position(const Vector3 &p_pos) const { | 
					
						
							| 
									
										
										
										
											2019-08-08 22:11:48 +02:00
										 |  |  | 	ERR_FAIL_COND_V_MSG(!is_inside_tree(), Vector2(), "Camera is not inside scene."); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-02 17:18:45 -03:00
										 |  |  | 	Size2 viewport_size = get_viewport()->get_visible_rect().size; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	CameraMatrix cm; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (mode == PROJECTION_ORTHOGONAL) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		cm.set_orthogonal(size, viewport_size.aspect(), near, far, keep_aspect == KEEP_WIDTH); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		cm.set_perspective(fov, viewport_size.aspect(), near, far, keep_aspect == KEEP_WIDTH); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	Plane p(get_camera_transform().xform_inv(p_pos), 1.0); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	p = cm.xform4(p); | 
					
						
							| 
									
										
										
										
											2020-05-10 16:47:11 +02:00
										 |  |  | 	p.normal /= p.d; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	Point2 res; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	res.x = (p.normal.x * 0.5 + 0.5) * viewport_size.x; | 
					
						
							|  |  |  | 	res.y = (-p.normal.y * 0.5 + 0.5) * viewport_size.y; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | Vector3 Camera3D::project_position(const Point2 &p_point, float p_z_depth) const { | 
					
						
							| 
									
										
										
										
											2019-08-08 22:11:48 +02:00
										 |  |  | 	ERR_FAIL_COND_V_MSG(!is_inside_tree(), Vector3(), "Camera is not inside scene."); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-09 15:10:09 -05:00
										 |  |  | 	if (p_z_depth == 0 && mode != PROJECTION_ORTHOGONAL) { | 
					
						
							| 
									
										
										
										
											2019-05-28 23:14:13 +10:00
										 |  |  | 		return get_global_transform().origin; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-01-02 17:18:45 -03:00
										 |  |  | 	Size2 viewport_size = get_viewport()->get_visible_rect().size; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	CameraMatrix cm; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (mode == PROJECTION_ORTHOGONAL) { | 
					
						
							| 
									
										
										
										
											2020-01-09 14:34:31 +00:00
										 |  |  | 		cm.set_orthogonal(size, viewport_size.aspect(), p_z_depth, far, keep_aspect == KEEP_WIDTH); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2020-01-09 14:34:31 +00:00
										 |  |  | 		cm.set_perspective(fov, viewport_size.aspect(), p_z_depth, far, keep_aspect == KEEP_WIDTH); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-21 18:39:16 +00:00
										 |  |  | 	Vector2 vp_he = cm.get_viewport_half_extents(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	Vector2 point; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	point.x = (p_point.x / viewport_size.x) * 2.0 - 1.0; | 
					
						
							|  |  |  | 	point.y = (1.0 - (p_point.y / viewport_size.y)) * 2.0 - 1.0; | 
					
						
							| 
									
										
										
										
											2020-01-21 18:39:16 +00:00
										 |  |  | 	point *= vp_he; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-28 23:14:13 +10:00
										 |  |  | 	Vector3 p(point.x, point.y, -p_z_depth); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return get_camera_transform().xform(p); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | void Camera3D::set_environment(const Ref<Environment> &p_environment) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	environment = p_environment; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (environment.is_valid()) { | 
					
						
							| 
									
										
										
										
											2020-03-27 15:21:27 -03:00
										 |  |  | 		RS::get_singleton()->camera_set_environment(camera, environment->get_rid()); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2020-03-27 15:21:27 -03:00
										 |  |  | 		RS::get_singleton()->camera_set_environment(camera, RID()); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-12-07 00:31:03 -06:00
										 |  |  | 	_update_camera_mode(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | Ref<Environment> Camera3D::get_environment() const { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	return environment; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | void Camera3D::set_effects(const Ref<CameraEffects> &p_effects) { | 
					
						
							| 
									
										
										
										
											2020-01-13 15:37:24 -03:00
										 |  |  | 	effects = p_effects; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (effects.is_valid()) { | 
					
						
							| 
									
										
										
										
											2020-03-27 15:21:27 -03:00
										 |  |  | 		RS::get_singleton()->camera_set_camera_effects(camera, effects->get_rid()); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2020-03-27 15:21:27 -03:00
										 |  |  | 		RS::get_singleton()->camera_set_camera_effects(camera, RID()); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-01-13 15:37:24 -03:00
										 |  |  | 	_update_camera_mode(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | Ref<CameraEffects> Camera3D::get_effects() const { | 
					
						
							| 
									
										
										
										
											2020-01-13 15:37:24 -03:00
										 |  |  | 	return effects; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | void Camera3D::set_keep_aspect_mode(KeepAspect p_aspect) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	keep_aspect = p_aspect; | 
					
						
							| 
									
										
										
										
											2020-03-27 15:21:27 -03:00
										 |  |  | 	RenderingServer::get_singleton()->camera_set_use_vertical_aspect(camera, p_aspect == KEEP_WIDTH); | 
					
						
							| 
									
										
										
										
											2017-12-07 00:31:03 -06:00
										 |  |  | 	_update_camera_mode(); | 
					
						
							| 
									
										
										
										
											2021-02-10 17:18:45 -03:00
										 |  |  | 	notify_property_list_changed(); | 
					
						
							| 
									
										
										
										
											2014-09-15 20:06:37 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | Camera3D::KeepAspect Camera3D::get_keep_aspect_mode() const { | 
					
						
							| 
									
										
										
										
											2014-09-15 20:06:37 -03:00
										 |  |  | 	return keep_aspect; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | void Camera3D::set_doppler_tracking(DopplerTracking p_tracking) { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (doppler_tracking == p_tracking) { | 
					
						
							| 
									
										
										
										
											2017-07-15 01:23:10 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-07-15 01:23:10 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	doppler_tracking = p_tracking; | 
					
						
							|  |  |  | 	if (p_tracking != DOPPLER_TRACKING_DISABLED) { | 
					
						
							| 
									
										
										
										
											2017-09-30 16:19:07 +02:00
										 |  |  | 		velocity_tracker->set_track_physics_step(doppler_tracking == DOPPLER_TRACKING_PHYSICS_STEP); | 
					
						
							| 
									
										
										
										
											2019-02-26 09:15:51 -03:00
										 |  |  | 		if (is_inside_tree()) { | 
					
						
							|  |  |  | 			velocity_tracker->reset(get_global_transform().origin); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-07-15 01:23:10 -03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-12-07 00:31:03 -06:00
										 |  |  | 	_update_camera_mode(); | 
					
						
							| 
									
										
										
										
											2017-07-15 01:23:10 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | Camera3D::DopplerTracking Camera3D::get_doppler_tracking() const { | 
					
						
							| 
									
										
										
										
											2017-07-15 01:23:10 -03:00
										 |  |  | 	return doppler_tracking; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | void Camera3D::_bind_methods() { | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("project_ray_normal", "screen_point"), &Camera3D::project_ray_normal); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("project_local_ray_normal", "screen_point"), &Camera3D::project_local_ray_normal); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("project_ray_origin", "screen_point"), &Camera3D::project_ray_origin); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("unproject_position", "world_point"), &Camera3D::unproject_position); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("is_position_behind", "world_point"), &Camera3D::is_position_behind); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("project_position", "screen_point", "z_depth"), &Camera3D::project_position); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("set_perspective", "fov", "z_near", "z_far"), &Camera3D::set_perspective); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("set_orthogonal", "size", "z_near", "z_far"), &Camera3D::set_orthogonal); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("set_frustum", "size", "offset", "z_near", "z_far"), &Camera3D::set_frustum); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("make_current"), &Camera3D::make_current); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("clear_current", "enable_next"), &Camera3D::clear_current, DEFVAL(true)); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("set_current"), &Camera3D::set_current); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("is_current"), &Camera3D::is_current); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_camera_transform"), &Camera3D::get_camera_transform); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_fov"), &Camera3D::get_fov); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_frustum_offset"), &Camera3D::get_frustum_offset); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_size"), &Camera3D::get_size); | 
					
						
							| 
									
										
										
										
											2020-12-16 12:40:42 +00:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("get_far"), &Camera3D::get_far); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_near"), &Camera3D::get_near); | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("set_fov"), &Camera3D::set_fov); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("set_frustum_offset"), &Camera3D::set_frustum_offset); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("set_size"), &Camera3D::set_size); | 
					
						
							| 
									
										
										
										
											2020-12-16 12:40:42 +00:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("set_far"), &Camera3D::set_far); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("set_near"), &Camera3D::set_near); | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("get_projection"), &Camera3D::get_projection); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("set_projection"), &Camera3D::set_projection); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("set_h_offset", "ofs"), &Camera3D::set_h_offset); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_h_offset"), &Camera3D::get_h_offset); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("set_v_offset", "ofs"), &Camera3D::set_v_offset); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_v_offset"), &Camera3D::get_v_offset); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("set_cull_mask", "mask"), &Camera3D::set_cull_mask); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_cull_mask"), &Camera3D::get_cull_mask); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("set_environment", "env"), &Camera3D::set_environment); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_environment"), &Camera3D::get_environment); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("set_effects", "env"), &Camera3D::set_effects); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_effects"), &Camera3D::get_effects); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("set_keep_aspect_mode", "mode"), &Camera3D::set_keep_aspect_mode); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_keep_aspect_mode"), &Camera3D::get_keep_aspect_mode); | 
					
						
							|  |  |  | 	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); | 
					
						
							| 
									
										
										
										
											2021-04-28 21:14:12 -04:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("is_position_in_frustum", "world_point"), &Camera3D::is_position_in_frustum); | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | 	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("get_cull_mask_bit", "layer"), &Camera3D::get_cull_mask_bit); | 
					
						
							| 
									
										
										
										
											2018-07-29 20:05:16 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-13 12:47:24 +01:00
										 |  |  | 	//ClassDB::bind_method(D_METHOD("_camera_make_current"),&Camera::_camera_make_current );
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-07 00:31:03 -06:00
										 |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::INT, "keep_aspect", PROPERTY_HINT_ENUM, "Keep Width,Keep Height"), "set_keep_aspect_mode", "get_keep_aspect_mode"); | 
					
						
							|  |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::INT, "cull_mask", PROPERTY_HINT_LAYERS_3D_RENDER), "set_cull_mask", "get_cull_mask"); | 
					
						
							|  |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "environment", PROPERTY_HINT_RESOURCE_TYPE, "Environment"), "set_environment", "get_environment"); | 
					
						
							| 
									
										
										
										
											2020-01-13 15:37:24 -03:00
										 |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "effects", PROPERTY_HINT_RESOURCE_TYPE, "CameraEffects"), "set_effects", "get_effects"); | 
					
						
							| 
									
										
										
											
												Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
											
										 
											2020-02-24 15:20:53 -03:00
										 |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "h_offset"), "set_h_offset", "get_h_offset"); | 
					
						
							|  |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "v_offset"), "set_v_offset", "get_v_offset"); | 
					
						
							| 
									
										
										
										
											2017-12-07 00:31:03 -06:00
										 |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::INT, "doppler_tracking", PROPERTY_HINT_ENUM, "Disabled,Idle,Physics"), "set_doppler_tracking", "get_doppler_tracking"); | 
					
						
							| 
									
										
										
										
											2019-02-19 17:17:02 +01:00
										 |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::INT, "projection", PROPERTY_HINT_ENUM, "Perspective,Orthogonal,Frustum"), "set_projection", "get_projection"); | 
					
						
							| 
									
										
										
										
											2017-12-07 00:31:03 -06:00
										 |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "current"), "set_current", "is_current"); | 
					
						
							| 
									
										
										
											
												Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
											
										 
											2020-02-24 15:20:53 -03:00
										 |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "fov", PROPERTY_HINT_RANGE, "1,179,0.1"), "set_fov", "get_fov"); | 
					
						
							|  |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "size", PROPERTY_HINT_RANGE, "0.1,16384,0.01"), "set_size", "get_size"); | 
					
						
							| 
									
										
										
										
											2019-02-19 17:17:02 +01:00
										 |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "frustum_offset"), "set_frustum_offset", "get_frustum_offset"); | 
					
						
							| 
									
										
										
										
											2020-12-16 12:40:42 +00:00
										 |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "near", PROPERTY_HINT_EXP_RANGE, "0.001,10,0.001,or_greater"), "set_near", "get_near"); | 
					
						
							|  |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "far", PROPERTY_HINT_EXP_RANGE, "0.01,4000,0.01,or_greater"), "set_far", "get_far"); | 
					
						
							| 
									
										
										
										
											2017-12-07 00:31:03 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-20 17:45:01 +02:00
										 |  |  | 	BIND_ENUM_CONSTANT(PROJECTION_PERSPECTIVE); | 
					
						
							|  |  |  | 	BIND_ENUM_CONSTANT(PROJECTION_ORTHOGONAL); | 
					
						
							| 
									
										
										
										
											2019-02-19 17:17:02 +01:00
										 |  |  | 	BIND_ENUM_CONSTANT(PROJECTION_FRUSTUM); | 
					
						
							| 
									
										
										
										
											2014-09-15 20:06:37 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-20 17:45:01 +02:00
										 |  |  | 	BIND_ENUM_CONSTANT(KEEP_WIDTH); | 
					
						
							|  |  |  | 	BIND_ENUM_CONSTANT(KEEP_HEIGHT); | 
					
						
							| 
									
										
										
										
											2017-07-15 01:23:10 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-02 09:57:12 +02:00
										 |  |  | 	BIND_ENUM_CONSTANT(DOPPLER_TRACKING_DISABLED); | 
					
						
							|  |  |  | 	BIND_ENUM_CONSTANT(DOPPLER_TRACKING_IDLE_STEP); | 
					
						
							|  |  |  | 	BIND_ENUM_CONSTANT(DOPPLER_TRACKING_PHYSICS_STEP); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | float Camera3D::get_fov() const { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	return fov; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | float Camera3D::get_size() const { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	return size; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-16 12:40:42 +00:00
										 |  |  | float Camera3D::get_near() const { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	return near; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | Vector2 Camera3D::get_frustum_offset() const { | 
					
						
							| 
									
										
										
										
											2019-02-19 17:17:02 +01:00
										 |  |  | 	return frustum_offset; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-16 12:40:42 +00:00
										 |  |  | float Camera3D::get_far() const { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	return far; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | Camera3D::Projection Camera3D::get_projection() const { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	return mode; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | void Camera3D::set_fov(float p_fov) { | 
					
						
							| 
									
										
										
										
											2019-12-29 11:36:57 +08:00
										 |  |  | 	ERR_FAIL_COND(p_fov < 1 || p_fov > 179); | 
					
						
							| 
									
										
										
										
											2017-12-07 00:31:03 -06:00
										 |  |  | 	fov = p_fov; | 
					
						
							|  |  |  | 	_update_camera_mode(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | void Camera3D::set_size(float p_size) { | 
					
						
							| 
									
										
										
										
											2019-12-29 11:36:57 +08:00
										 |  |  | 	ERR_FAIL_COND(p_size < 0.1 || p_size > 16384); | 
					
						
							| 
									
										
										
										
											2017-12-07 00:31:03 -06:00
										 |  |  | 	size = p_size; | 
					
						
							|  |  |  | 	_update_camera_mode(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-16 12:40:42 +00:00
										 |  |  | void Camera3D::set_near(float p_near) { | 
					
						
							|  |  |  | 	near = p_near; | 
					
						
							| 
									
										
										
										
											2017-12-07 00:31:03 -06:00
										 |  |  | 	_update_camera_mode(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | void Camera3D::set_frustum_offset(Vector2 p_offset) { | 
					
						
							| 
									
										
										
										
											2019-02-19 17:17:02 +01:00
										 |  |  | 	frustum_offset = p_offset; | 
					
						
							|  |  |  | 	_update_camera_mode(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-16 12:40:42 +00:00
										 |  |  | void Camera3D::set_far(float p_far) { | 
					
						
							|  |  |  | 	far = p_far; | 
					
						
							| 
									
										
										
										
											2017-12-07 00:31:03 -06:00
										 |  |  | 	_update_camera_mode(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | void Camera3D::set_cull_mask(uint32_t p_layers) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	layers = p_layers; | 
					
						
							| 
									
										
										
										
											2020-03-27 15:21:27 -03:00
										 |  |  | 	RenderingServer::get_singleton()->camera_set_cull_mask(camera, layers); | 
					
						
							| 
									
										
										
										
											2017-12-07 00:31:03 -06:00
										 |  |  | 	_update_camera_mode(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | uint32_t Camera3D::get_cull_mask() const { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	return layers; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | void Camera3D::set_cull_mask_bit(int p_layer, bool p_enable) { | 
					
						
							| 
									
										
										
										
											2018-07-29 20:05:16 -03:00
										 |  |  | 	ERR_FAIL_INDEX(p_layer, 32); | 
					
						
							|  |  |  | 	if (p_enable) { | 
					
						
							|  |  |  | 		set_cull_mask(layers | (1 << p_layer)); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		set_cull_mask(layers & (~(1 << p_layer))); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | bool Camera3D::get_cull_mask_bit(int p_layer) const { | 
					
						
							| 
									
										
										
										
											2018-07-29 20:05:16 -03:00
										 |  |  | 	ERR_FAIL_INDEX_V(p_layer, 32, false); | 
					
						
							|  |  |  | 	return (layers & (1 << p_layer)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | Vector<Plane> Camera3D::get_frustum() const { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ERR_FAIL_COND_V(!is_inside_world(), Vector<Plane>()); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-02 17:18:45 -03:00
										 |  |  | 	Size2 viewport_size = get_viewport()->get_visible_rect().size; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	CameraMatrix cm; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (mode == PROJECTION_PERSPECTIVE) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		cm.set_perspective(fov, viewport_size.aspect(), near, far, keep_aspect == KEEP_WIDTH); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		cm.set_orthogonal(size, viewport_size.aspect(), near, far, keep_aspect == KEEP_WIDTH); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-03 00:10:51 -03:00
										 |  |  | 	return cm.get_projection_planes(get_camera_transform()); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-28 21:14:12 -04:00
										 |  |  | 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; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | void Camera3D::set_v_offset(float p_offset) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	v_offset = p_offset; | 
					
						
							| 
									
										
										
										
											2017-01-14 18:03:38 +01:00
										 |  |  | 	_update_camera(); | 
					
						
							| 
									
										
										
										
											2015-01-03 11:06:53 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | float Camera3D::get_v_offset() const { | 
					
						
							| 
									
										
										
										
											2015-01-03 11:06:53 -03:00
										 |  |  | 	return v_offset; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | void Camera3D::set_h_offset(float p_offset) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	h_offset = p_offset; | 
					
						
							| 
									
										
										
										
											2015-01-03 11:06:53 -03:00
										 |  |  | 	_update_camera(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | float Camera3D::get_h_offset() const { | 
					
						
							| 
									
										
										
										
											2015-01-03 11:06:53 -03:00
										 |  |  | 	return h_offset; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | Vector3 Camera3D::get_doppler_tracked_velocity() const { | 
					
						
							| 
									
										
										
										
											2017-07-15 01:23:10 -03:00
										 |  |  | 	if (doppler_tracking != DOPPLER_TRACKING_DISABLED) { | 
					
						
							|  |  |  | 		return velocity_tracker->get_tracked_linear_velocity(); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		return Vector3(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-05-14 14:29:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | Camera3D::Camera3D() { | 
					
						
							| 
									
										
										
										
											2020-03-27 15:21:27 -03:00
										 |  |  | 	camera = RenderingServer::get_singleton()->camera_create(); | 
					
						
							| 
									
										
										
										
											2019-10-31 14:32:46 +01:00
										 |  |  | 	set_perspective(75.0, 0.05, 4000.0); | 
					
						
							| 
									
										
										
										
											2020-03-27 15:21:27 -03:00
										 |  |  | 	RenderingServer::get_singleton()->camera_set_cull_mask(camera, layers); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	//active=false;
 | 
					
						
							| 
									
										
										
										
											2017-07-15 01:23:10 -03:00
										 |  |  | 	velocity_tracker.instance(); | 
					
						
							| 
									
										
										
										
											2017-01-12 20:35:46 -03:00
										 |  |  | 	set_notify_transform(true); | 
					
						
							| 
									
										
										
										
											2018-07-18 13:47:42 -03:00
										 |  |  | 	set_disable_scale(true); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | Camera3D::~Camera3D() { | 
					
						
							| 
									
										
										
										
											2020-03-27 15:21:27 -03:00
										 |  |  | 	RenderingServer::get_singleton()->free(camera); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2018-08-21 11:48:17 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | ////////////////////////////////////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 08:44:44 +01:00
										 |  |  | void ClippedCamera3D::set_margin(float p_margin) { | 
					
						
							| 
									
										
										
										
											2018-08-21 11:48:17 -03:00
										 |  |  | 	margin = p_margin; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-05-14 14:29:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 08:44:44 +01:00
										 |  |  | float ClippedCamera3D::get_margin() const { | 
					
						
							| 
									
										
										
										
											2018-08-21 11:48:17 -03:00
										 |  |  | 	return margin; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-05-14 14:29:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-18 15:52:29 -03:00
										 |  |  | void ClippedCamera3D::set_process_callback(ClipProcessCallback p_mode) { | 
					
						
							|  |  |  | 	if (process_callback == p_mode) { | 
					
						
							| 
									
										
										
										
											2018-08-21 11:48:17 -03:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-02-18 15:52:29 -03:00
										 |  |  | 	process_callback = p_mode; | 
					
						
							|  |  |  | 	set_process_internal(process_callback == CLIP_PROCESS_IDLE); | 
					
						
							|  |  |  | 	set_physics_process_internal(process_callback == CLIP_PROCESS_PHYSICS); | 
					
						
							| 
									
										
										
										
											2018-08-21 11:48:17 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-05-14 14:29:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-18 15:52:29 -03:00
										 |  |  | ClippedCamera3D::ClipProcessCallback ClippedCamera3D::get_process_callback() const { | 
					
						
							|  |  |  | 	return process_callback; | 
					
						
							| 
									
										
										
										
											2018-08-21 11:48:17 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-17 01:08:21 -04:00
										 |  |  | Transform3D ClippedCamera3D::get_camera_transform() const { | 
					
						
							|  |  |  | 	Transform3D t = Camera3D::get_camera_transform(); | 
					
						
							| 
									
										
										
										
											2018-08-21 11:48:17 -03:00
										 |  |  | 	t.origin += -t.basis.get_axis(Vector3::AXIS_Z).normalized() * clip_offset; | 
					
						
							|  |  |  | 	return t; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 08:44:44 +01:00
										 |  |  | void ClippedCamera3D::_notification(int p_what) { | 
					
						
							| 
									
										
										
										
											2018-08-21 11:48:17 -03:00
										 |  |  | 	if (p_what == NOTIFICATION_INTERNAL_PROCESS || p_what == NOTIFICATION_INTERNAL_PHYSICS_PROCESS) { | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | 		Node3D *parent = Object::cast_to<Node3D>(get_parent()); | 
					
						
							| 
									
										
										
										
											2018-08-21 11:48:17 -03:00
										 |  |  | 		if (!parent) { | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-18 11:00:51 +02:00
										 |  |  | 		PhysicsDirectSpaceState3D *dspace = get_world_3d()->get_direct_space_state(); | 
					
						
							| 
									
										
										
										
											2018-08-21 11:48:17 -03:00
										 |  |  | 		ERR_FAIL_COND(!dspace); // most likely physics set to threads
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		Vector3 cam_fw = -get_global_transform().basis.get_axis(Vector3::AXIS_Z).normalized(); | 
					
						
							|  |  |  | 		Vector3 cam_pos = get_global_transform().origin; | 
					
						
							|  |  |  | 		Vector3 parent_pos = parent->get_global_transform().origin; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		Plane parent_plane(parent_pos, cam_fw); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (parent_plane.is_point_over(cam_pos)) { | 
					
						
							|  |  |  | 			//cam is beyond parent plane
 | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		Vector3 ray_from = parent_plane.project(cam_pos); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-12 19:05:16 +05:30
										 |  |  | 		clip_offset = 0; //reset by default
 | 
					
						
							| 
									
										
										
										
											2018-08-21 11:48:17 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		{ //check if points changed
 | 
					
						
							|  |  |  | 			Vector<Vector3> local_points = get_near_plane_points(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			bool all_equal = true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			for (int i = 0; i < 5; i++) { | 
					
						
							|  |  |  | 				if (points[i] != local_points[i]) { | 
					
						
							|  |  |  | 					all_equal = false; | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (!all_equal) { | 
					
						
							| 
									
										
										
										
											2020-03-27 15:21:27 -03:00
										 |  |  | 				PhysicsServer3D::get_singleton()->shape_set_data(pyramid_shape, local_points); | 
					
						
							| 
									
										
										
										
											2018-08-21 11:48:17 -03:00
										 |  |  | 				points = local_points; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-17 01:08:21 -04:00
										 |  |  | 		Transform3D xf = get_global_transform(); | 
					
						
							| 
									
										
										
										
											2018-08-21 11:48:17 -03:00
										 |  |  | 		xf.origin = ray_from; | 
					
						
							|  |  |  | 		xf.orthonormalize(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-09 11:11:06 +01:00
										 |  |  | 		float closest_safe = 1.0f, closest_unsafe = 1.0f; | 
					
						
							|  |  |  | 		if (dspace->cast_motion(pyramid_shape, xf, cam_pos - ray_from, margin, closest_safe, closest_unsafe, exclude, collision_mask, clip_to_bodies, clip_to_areas)) { | 
					
						
							|  |  |  | 			clip_offset = cam_pos.distance_to(ray_from + (cam_pos - ray_from) * closest_safe); | 
					
						
							| 
									
										
										
										
											2018-08-21 11:48:17 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		_update_camera(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (p_what == NOTIFICATION_LOCAL_TRANSFORM_CHANGED) { | 
					
						
							|  |  |  | 		update_gizmo(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 08:44:44 +01:00
										 |  |  | void ClippedCamera3D::set_collision_mask(uint32_t p_mask) { | 
					
						
							| 
									
										
										
										
											2018-08-21 11:48:17 -03:00
										 |  |  | 	collision_mask = p_mask; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 08:44:44 +01:00
										 |  |  | uint32_t ClippedCamera3D::get_collision_mask() const { | 
					
						
							| 
									
										
										
										
											2018-08-21 11:48:17 -03:00
										 |  |  | 	return collision_mask; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 08:44:44 +01:00
										 |  |  | void ClippedCamera3D::set_collision_mask_bit(int p_bit, bool p_value) { | 
					
						
							| 
									
										
										
										
											2021-04-30 17:19:04 +02:00
										 |  |  | 	ERR_FAIL_INDEX_MSG(p_bit, 32, "Collision layer bit must be between 0 and 31 inclusive."); | 
					
						
							| 
									
										
										
										
											2018-08-21 11:48:17 -03:00
										 |  |  | 	uint32_t mask = get_collision_mask(); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (p_value) { | 
					
						
							| 
									
										
										
										
											2018-08-21 11:48:17 -03:00
										 |  |  | 		mask |= 1 << p_bit; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2018-08-21 11:48:17 -03:00
										 |  |  | 		mask &= ~(1 << p_bit); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-08-21 11:48:17 -03:00
										 |  |  | 	set_collision_mask(mask); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 08:44:44 +01:00
										 |  |  | bool ClippedCamera3D::get_collision_mask_bit(int p_bit) const { | 
					
						
							| 
									
										
										
										
											2021-04-30 17:19:04 +02:00
										 |  |  | 	ERR_FAIL_INDEX_V_MSG(p_bit, 32, false, "Collision mask bit must be between 0 and 31 inclusive."); | 
					
						
							| 
									
										
										
										
											2018-08-21 11:48:17 -03:00
										 |  |  | 	return get_collision_mask() & (1 << p_bit); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 08:44:44 +01:00
										 |  |  | void ClippedCamera3D::add_exception_rid(const RID &p_rid) { | 
					
						
							| 
									
										
										
										
											2018-08-21 11:48:17 -03:00
										 |  |  | 	exclude.insert(p_rid); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 08:44:44 +01:00
										 |  |  | void ClippedCamera3D::add_exception(const Object *p_object) { | 
					
						
							| 
									
										
										
										
											2018-08-21 11:48:17 -03:00
										 |  |  | 	ERR_FAIL_NULL(p_object); | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | 	const CollisionObject3D *co = Object::cast_to<CollisionObject3D>(p_object); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (!co) { | 
					
						
							| 
									
										
										
										
											2018-08-21 11:48:17 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-08-21 11:48:17 -03:00
										 |  |  | 	add_exception_rid(co->get_rid()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 08:44:44 +01:00
										 |  |  | void ClippedCamera3D::remove_exception_rid(const RID &p_rid) { | 
					
						
							| 
									
										
										
										
											2018-08-21 11:48:17 -03:00
										 |  |  | 	exclude.erase(p_rid); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 08:44:44 +01:00
										 |  |  | void ClippedCamera3D::remove_exception(const Object *p_object) { | 
					
						
							| 
									
										
										
										
											2018-08-21 11:48:17 -03:00
										 |  |  | 	ERR_FAIL_NULL(p_object); | 
					
						
							| 
									
										
										
										
											2020-03-26 18:49:16 -03:00
										 |  |  | 	const CollisionObject3D *co = Object::cast_to<CollisionObject3D>(p_object); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (!co) { | 
					
						
							| 
									
										
										
										
											2018-08-21 11:48:17 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-08-21 11:48:17 -03:00
										 |  |  | 	remove_exception_rid(co->get_rid()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 08:44:44 +01:00
										 |  |  | void ClippedCamera3D::clear_exceptions() { | 
					
						
							| 
									
										
										
										
											2018-08-21 11:48:17 -03:00
										 |  |  | 	exclude.clear(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-08-21 15:30:41 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 08:44:44 +01:00
										 |  |  | float ClippedCamera3D::get_clip_offset() const { | 
					
						
							| 
									
										
										
										
											2019-06-14 17:39:13 +02:00
										 |  |  | 	return clip_offset; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 08:44:44 +01:00
										 |  |  | void ClippedCamera3D::set_clip_to_areas(bool p_clip) { | 
					
						
							| 
									
										
										
										
											2018-08-21 15:30:41 -03:00
										 |  |  | 	clip_to_areas = p_clip; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 08:44:44 +01:00
										 |  |  | bool ClippedCamera3D::is_clip_to_areas_enabled() const { | 
					
						
							| 
									
										
										
										
											2018-08-21 15:30:41 -03:00
										 |  |  | 	return clip_to_areas; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 08:44:44 +01:00
										 |  |  | void ClippedCamera3D::set_clip_to_bodies(bool p_clip) { | 
					
						
							| 
									
										
										
										
											2018-08-21 15:30:41 -03:00
										 |  |  | 	clip_to_bodies = p_clip; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 08:44:44 +01:00
										 |  |  | bool ClippedCamera3D::is_clip_to_bodies_enabled() const { | 
					
						
							| 
									
										
										
										
											2018-08-21 15:30:41 -03:00
										 |  |  | 	return clip_to_bodies; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 08:44:44 +01:00
										 |  |  | void ClippedCamera3D::_bind_methods() { | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("set_margin", "margin"), &ClippedCamera3D::set_margin); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_margin"), &ClippedCamera3D::get_margin); | 
					
						
							| 
									
										
										
										
											2018-08-21 11:48:17 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-18 15:52:29 -03:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("set_process_callback", "process_callback"), &ClippedCamera3D::set_process_callback); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_process_callback"), &ClippedCamera3D::get_process_callback); | 
					
						
							| 
									
										
										
										
											2018-08-21 11:48:17 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 08:44:44 +01:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("set_collision_mask", "mask"), &ClippedCamera3D::set_collision_mask); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_collision_mask"), &ClippedCamera3D::get_collision_mask); | 
					
						
							| 
									
										
										
										
											2018-08-21 11:48:17 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 08:44:44 +01:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("set_collision_mask_bit", "bit", "value"), &ClippedCamera3D::set_collision_mask_bit); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("get_collision_mask_bit", "bit"), &ClippedCamera3D::get_collision_mask_bit); | 
					
						
							| 
									
										
										
										
											2018-08-21 11:48:17 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 08:44:44 +01:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("add_exception_rid", "rid"), &ClippedCamera3D::add_exception_rid); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("add_exception", "node"), &ClippedCamera3D::add_exception); | 
					
						
							| 
									
										
										
										
											2018-08-21 11:48:17 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 08:44:44 +01:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("remove_exception_rid", "rid"), &ClippedCamera3D::remove_exception_rid); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("remove_exception", "node"), &ClippedCamera3D::remove_exception); | 
					
						
							| 
									
										
										
										
											2018-08-21 11:48:17 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 08:44:44 +01:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("set_clip_to_areas", "enable"), &ClippedCamera3D::set_clip_to_areas); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("is_clip_to_areas_enabled"), &ClippedCamera3D::is_clip_to_areas_enabled); | 
					
						
							| 
									
										
										
										
											2018-08-21 15:30:41 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 08:44:44 +01:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("get_clip_offset"), &ClippedCamera3D::get_clip_offset); | 
					
						
							| 
									
										
										
										
											2019-06-14 17:39:13 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 08:44:44 +01:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("set_clip_to_bodies", "enable"), &ClippedCamera3D::set_clip_to_bodies); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("is_clip_to_bodies_enabled"), &ClippedCamera3D::is_clip_to_bodies_enabled); | 
					
						
							| 
									
										
										
										
											2018-08-21 15:30:41 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 08:44:44 +01:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("clear_exceptions"), &ClippedCamera3D::clear_exceptions); | 
					
						
							| 
									
										
										
										
											2018-08-21 11:48:17 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
											
												Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
											
										 
											2020-02-24 15:20:53 -03:00
										 |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "margin", PROPERTY_HINT_RANGE, "0,32,0.01"), "set_margin", "get_margin"); | 
					
						
							| 
									
										
										
										
											2021-02-18 15:52:29 -03:00
										 |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::INT, "process_callback", PROPERTY_HINT_ENUM, "Physics,Idle"), "set_process_callback", "get_process_callback"); | 
					
						
							| 
									
										
										
										
											2018-08-21 11:48:17 -03:00
										 |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_mask", "get_collision_mask"); | 
					
						
							| 
									
										
										
										
											2018-08-21 15:30:41 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	ADD_GROUP("Clip To", "clip_to"); | 
					
						
							|  |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "clip_to_areas", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_clip_to_areas", "is_clip_to_areas_enabled"); | 
					
						
							|  |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "clip_to_bodies", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_clip_to_bodies", "is_clip_to_bodies_enabled"); | 
					
						
							| 
									
										
										
										
											2018-08-23 13:53:05 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	BIND_ENUM_CONSTANT(CLIP_PROCESS_PHYSICS); | 
					
						
							|  |  |  | 	BIND_ENUM_CONSTANT(CLIP_PROCESS_IDLE); | 
					
						
							| 
									
										
										
										
											2018-08-21 11:48:17 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-05-14 14:29:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 08:44:44 +01:00
										 |  |  | ClippedCamera3D::ClippedCamera3D() { | 
					
						
							| 
									
										
										
										
											2018-08-21 11:48:17 -03:00
										 |  |  | 	set_physics_process_internal(true); | 
					
						
							|  |  |  | 	set_notify_local_transform(Engine::get_singleton()->is_editor_hint()); | 
					
						
							|  |  |  | 	points.resize(5); | 
					
						
							| 
									
										
										
										
											2020-03-27 15:21:27 -03:00
										 |  |  | 	pyramid_shape = PhysicsServer3D::get_singleton()->shape_create(PhysicsServer3D::SHAPE_CONVEX_POLYGON); | 
					
						
							| 
									
										
										
										
											2018-08-21 11:48:17 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-05-14 14:29:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 08:44:44 +01:00
										 |  |  | ClippedCamera3D::~ClippedCamera3D() { | 
					
						
							| 
									
										
										
										
											2020-03-27 15:21:27 -03:00
										 |  |  | 	PhysicsServer3D::get_singleton()->free(pyramid_shape); | 
					
						
							| 
									
										
										
										
											2018-08-21 11:48:17 -03:00
										 |  |  | } |