diff options
Diffstat (limited to 'scene/3d/camera_3d.cpp')
-rw-r--r-- | scene/3d/camera_3d.cpp | 71 |
1 files changed, 45 insertions, 26 deletions
diff --git a/scene/3d/camera_3d.cpp b/scene/3d/camera_3d.cpp index 99d3b68996..8dc5cd4aba 100644 --- a/scene/3d/camera_3d.cpp +++ b/scene/3d/camera_3d.cpp @@ -75,8 +75,9 @@ void Camera3D::_validate_property(PropertyInfo &p_property) const { } void Camera3D::_update_camera() { - if (!is_inside_tree()) + if (!is_inside_tree()) { return; + } RenderingServer::get_singleton()->camera_set_transform(camera, get_camera_transform()); @@ -86,8 +87,9 @@ void Camera3D::_update_camera() { get_viewport()->_camera_transform_changed_notify(); */ - if (get_tree()->is_node_being_edited(this) || !is_current()) + if (get_tree()->is_node_being_edited(this) || !is_current()) { return; + } get_viewport()->_camera_transform_changed_notify(); @@ -106,8 +108,9 @@ void Camera3D::_notification(int p_what) { ERR_FAIL_COND(!viewport); bool first_camera = viewport->_camera_add(this); - if (current || first_camera) + if (current || first_camera) { viewport->_camera_set(this); + } } break; case NOTIFICATION_TRANSFORM_CHANGED: { @@ -154,8 +157,9 @@ Transform Camera3D::get_camera_transform() const { } void Camera3D::set_perspective(float p_fovy_degrees, float p_z_near, float p_z_far) { - if (!force_change && fov == p_fovy_degrees && p_z_near == near && p_z_far == far && mode == PROJECTION_PERSPECTIVE) + if (!force_change && fov == p_fovy_degrees && p_z_near == near && p_z_far == far && mode == PROJECTION_PERSPECTIVE) { return; + } fov = p_fovy_degrees; near = p_z_near; @@ -168,8 +172,9 @@ void Camera3D::set_perspective(float p_fovy_degrees, float p_z_near, float p_z_f } void Camera3D::set_orthogonal(float p_size, float p_z_near, float p_z_far) { - if (!force_change && size == p_size && p_z_near == near && p_z_far == far && mode == PROJECTION_ORTHOGONAL) + if (!force_change && size == p_size && p_z_near == near && p_z_far == far && mode == PROJECTION_ORTHOGONAL) { return; + } size = p_size; @@ -183,8 +188,9 @@ void Camera3D::set_orthogonal(float p_size, float p_z_near, float p_z_far) { } void Camera3D::set_frustum(float p_size, Vector2 p_offset, float p_z_near, float p_z_far) { - if (!force_change && size == p_size && frustum_offset == p_offset && p_z_near == near && p_z_far == far && mode == PROJECTION_FRUSTUM) + if (!force_change && size == p_size && frustum_offset == p_offset && p_z_near == near && p_z_far == far && mode == PROJECTION_FRUSTUM) { return; + } size = p_size; frustum_offset = p_offset; @@ -213,8 +219,9 @@ RID Camera3D::get_camera() const { void Camera3D::make_current() { current = true; - if (!is_inside_tree()) + if (!is_inside_tree()) { return; + } get_viewport()->_camera_set(this); @@ -223,8 +230,9 @@ void Camera3D::make_current() { void Camera3D::clear_current(bool p_enable_next) { current = false; - if (!is_inside_tree()) + if (!is_inside_tree()) { return; + } if (get_viewport()->get_camera() == this) { get_viewport()->_camera_set(nullptr); @@ -246,8 +254,9 @@ void Camera3D::set_current(bool p_current) { bool Camera3D::is_current() const { if (is_inside_tree() && !get_tree()->is_node_being_edited(this)) { return get_viewport()->get_camera() == this; - } else + } else { return current; + } } bool Camera3D::_can_gizmo_scale() const { @@ -320,10 +329,11 @@ Vector<Vector3> Camera3D::get_near_plane_points() const { CameraMatrix cm; - if (mode == PROJECTION_ORTHOGONAL) + if (mode == PROJECTION_ORTHOGONAL) { cm.set_orthogonal(size, viewport_size.aspect(), near, far, keep_aspect == KEEP_WIDTH); - else + } else { cm.set_perspective(fov, viewport_size.aspect(), near, far, keep_aspect == KEEP_WIDTH); + } Vector3 endpoints[8]; cm.get_endpoints(Transform(), endpoints); @@ -343,10 +353,11 @@ Point2 Camera3D::unproject_position(const Vector3 &p_pos) const { CameraMatrix cm; - if (mode == PROJECTION_ORTHOGONAL) + if (mode == PROJECTION_ORTHOGONAL) { cm.set_orthogonal(size, viewport_size.aspect(), near, far, keep_aspect == KEEP_WIDTH); - else + } else { cm.set_perspective(fov, viewport_size.aspect(), near, far, keep_aspect == KEEP_WIDTH); + } Plane p(get_camera_transform().xform_inv(p_pos), 1.0); @@ -370,10 +381,11 @@ Vector3 Camera3D::project_position(const Point2 &p_point, float p_z_depth) const CameraMatrix cm; - if (mode == PROJECTION_ORTHOGONAL) + if (mode == PROJECTION_ORTHOGONAL) { cm.set_orthogonal(size, viewport_size.aspect(), p_z_depth, far, keep_aspect == KEEP_WIDTH); - else + } else { cm.set_perspective(fov, viewport_size.aspect(), p_z_depth, far, keep_aspect == KEEP_WIDTH); + } Vector2 vp_he = cm.get_viewport_half_extents(); @@ -389,10 +401,11 @@ Vector3 Camera3D::project_position(const Point2 &p_point, float p_z_depth) const void Camera3D::set_environment(const Ref<Environment> &p_environment) { environment = p_environment; - if (environment.is_valid()) + if (environment.is_valid()) { RS::get_singleton()->camera_set_environment(camera, environment->get_rid()); - else + } else { RS::get_singleton()->camera_set_environment(camera, RID()); + } _update_camera_mode(); } @@ -402,10 +415,11 @@ Ref<Environment> Camera3D::get_environment() const { void Camera3D::set_effects(const Ref<CameraEffects> &p_effects) { effects = p_effects; - if (effects.is_valid()) + if (effects.is_valid()) { RS::get_singleton()->camera_set_camera_effects(camera, effects->get_rid()); - else + } else { RS::get_singleton()->camera_set_camera_effects(camera, RID()); + } _update_camera_mode(); } @@ -425,8 +439,9 @@ Camera3D::KeepAspect Camera3D::get_keep_aspect_mode() const { } void Camera3D::set_doppler_tracking(DopplerTracking p_tracking) { - if (doppler_tracking == p_tracking) + if (doppler_tracking == p_tracking) { return; + } doppler_tracking = p_tracking; if (p_tracking != DOPPLER_TRACKING_DISABLED) { @@ -600,10 +615,11 @@ Vector<Plane> Camera3D::get_frustum() const { Size2 viewport_size = get_viewport()->get_visible_rect().size; CameraMatrix cm; - if (mode == PROJECTION_PERSPECTIVE) + if (mode == PROJECTION_PERSPECTIVE) { cm.set_perspective(fov, viewport_size.aspect(), near, far, keep_aspect == KEEP_WIDTH); - else + } else { cm.set_orthogonal(size, viewport_size.aspect(), near, far, keep_aspect == KEEP_WIDTH); + } return cm.get_projection_planes(get_camera_transform()); } @@ -761,10 +777,11 @@ uint32_t ClippedCamera3D::get_collision_mask() const { void ClippedCamera3D::set_collision_mask_bit(int p_bit, bool p_value) { uint32_t mask = get_collision_mask(); - if (p_value) + if (p_value) { mask |= 1 << p_bit; - else + } else { mask &= ~(1 << p_bit); + } set_collision_mask(mask); } @@ -779,8 +796,9 @@ void ClippedCamera3D::add_exception_rid(const RID &p_rid) { void ClippedCamera3D::add_exception(const Object *p_object) { ERR_FAIL_NULL(p_object); const CollisionObject3D *co = Object::cast_to<CollisionObject3D>(p_object); - if (!co) + if (!co) { return; + } add_exception_rid(co->get_rid()); } @@ -791,8 +809,9 @@ void ClippedCamera3D::remove_exception_rid(const RID &p_rid) { void ClippedCamera3D::remove_exception(const Object *p_object) { ERR_FAIL_NULL(p_object); const CollisionObject3D *co = Object::cast_to<CollisionObject3D>(p_object); - if (!co) + if (!co) { return; + } remove_exception_rid(co->get_rid()); } |