| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "core/templates/interpolated_property.h" |
| 34 |
#include "scene/3d/node_3d.h" |
| 35 |
#include "scene/3d/velocity_tracker_3d.h" |
| 36 |
#include "scene/resources/camera_attributes.h" |
| 37 |
#include "scene/resources/compositor.h" |
| 38 |
#include "scene/resources/environment.h" |
| 39 |
|
| 40 |
class Camera3D : public Node3D { |
| 41 |
GDCLASS(Camera3D, Node3D); |
| 42 |
|
| 43 |
public: |
| 44 |
enum ProjectionType { |
| 45 |
PROJECTION_PERSPECTIVE, |
| 46 |
PROJECTION_ORTHOGONAL, |
| 47 |
PROJECTION_FRUSTUM |
| 48 |
}; |
| 49 |
|
| 50 |
enum KeepAspect { |
| 51 |
KEEP_WIDTH, |
| 52 |
KEEP_HEIGHT |
| 53 |
}; |
| 54 |
|
| 55 |
enum DopplerTracking { |
| 56 |
DOPPLER_TRACKING_DISABLED, |
| 57 |
DOPPLER_TRACKING_IDLE_STEP, |
| 58 |
DOPPLER_TRACKING_PHYSICS_STEP |
| 59 |
}; |
| 60 |
|
| 61 |
private: |
| 62 |
bool force_change = false; |
| 63 |
bool current = false; |
| 64 |
Viewport *viewport = nullptr; |
| 65 |
|
| 66 |
ProjectionType mode = PROJECTION_PERSPECTIVE; |
| 67 |
|
| 68 |
InterpolatedProperty<real_t> fov = 75.0; |
| 69 |
InterpolatedProperty<real_t> size = 1.0; |
| 70 |
InterpolatedProperty<Vector2> frustum_offset; |
| 71 |
|
| 72 |
InterpolatedProperty<real_t> _near = 0.05; |
| 73 |
InterpolatedProperty<real_t> _far = 4000.0; |
| 74 |
real_t v_offset = 0.0; |
| 75 |
real_t h_offset = 0.0; |
| 76 |
KeepAspect keep_aspect = KEEP_HEIGHT; |
| 77 |
|
| 78 |
RID camera; |
| 79 |
RID scenario_id; |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
uint32_t layers = 0xfffff; |
| 84 |
|
| 85 |
Ref<Environment> environment; |
| 86 |
Ref<CameraAttributes> attributes; |
| 87 |
Ref<Compositor> compositor; |
| 88 |
void _attributes_changed(); |
| 89 |
|
| 90 |
|
| 91 |
friend class Viewport; |
| 92 |
void _update_audio_listener_state(); |
| 93 |
TypedArray<Plane> _get_frustum() const; |
| 94 |
|
| 95 |
DopplerTracking doppler_tracking = DOPPLER_TRACKING_DISABLED; |
| 96 |
Ref<VelocityTracker3D> velocity_tracker; |
| 97 |
|
| 98 |
#ifndef PHYSICS_3D_DISABLED |
| 99 |
RID pyramid_shape; |
| 100 |
Vector<Vector3> pyramid_shape_points; |
| 101 |
#endif |
| 102 |
|
| 103 |
|
| 104 |
bool _desired_process_internal = false; |
| 105 |
bool _desired_physics_process_internal = false; |
| 106 |
|
| 107 |
void _update_process_mode(); |
| 108 |
|
| 109 |
protected: |
| 110 |
|
| 111 |
|
| 112 |
void set_desired_process_modes(bool p_process_internal, bool p_physics_process_internal); |
| 113 |
|
| 114 |
virtual void _physics_interpolated_changed() override; |
| 115 |
virtual Transform3D _get_adjusted_camera_transform(const Transform3D &p_xform) const; |
| 116 |
|
| 117 |
|
| 118 |
void _update_camera(); |
| 119 |
virtual void _request_camera_update(); |
| 120 |
void _update_camera_mode(); |
| 121 |
|
| 122 |
virtual void fti_pump_property() override; |
| 123 |
virtual void fti_update_servers_property() override; |
| 124 |
virtual void fti_update_servers_xform() override; |
| 125 |
|
| 126 |
void _notification(int p_what); |
| 127 |
void _validate_property(PropertyInfo &p_property) const; |
| 128 |
|
| 129 |
static void _bind_methods(); |
| 130 |
|
| 131 |
Projection _get_camera_projection(real_t p_near) const; |
| 132 |
|
| 133 |
public: |
| 134 |
enum { |
| 135 |
NOTIFICATION_BECAME_CURRENT = 50, |
| 136 |
NOTIFICATION_LOST_CURRENT = 51 |
| 137 |
}; |
| 138 |
|
| 139 |
void set_perspective(real_t p_fovy_degrees, real_t p_z_near, real_t p_z_far); |
| 140 |
void set_orthogonal(real_t p_size, real_t p_z_near, real_t p_z_far); |
| 141 |
void set_frustum(real_t p_size, Vector2 p_offset, real_t p_z_near, real_t p_z_far); |
| 142 |
void set_projection(Camera3D::ProjectionType p_mode); |
| 143 |
|
| 144 |
void make_current(); |
| 145 |
void clear_current(bool p_enable_next = true); |
| 146 |
void set_current(bool p_enabled); |
| 147 |
bool is_current() const; |
| 148 |
|
| 149 |
RID get_camera() const; |
| 150 |
|
| 151 |
real_t get_fov() const; |
| 152 |
real_t get_size() const; |
| 153 |
real_t get_far() const; |
| 154 |
real_t get_near() const; |
| 155 |
Vector2 get_frustum_offset() const; |
| 156 |
|
| 157 |
ProjectionType get_projection() const; |
| 158 |
|
| 159 |
void set_fov(real_t p_fov); |
| 160 |
void set_size(real_t p_size); |
| 161 |
void set_far(real_t p_far); |
| 162 |
void set_near(real_t p_near); |
| 163 |
void set_frustum_offset(Vector2 p_offset); |
| 164 |
|
| 165 |
virtual Transform3D get_camera_transform() const; |
| 166 |
virtual Projection get_camera_projection() const; |
| 167 |
|
| 168 |
virtual Vector3 project_ray_normal(const Point2 &p_pos) const; |
| 169 |
virtual Vector3 project_ray_origin(const Point2 &p_pos) const; |
| 170 |
virtual Vector3 project_local_ray_normal(const Point2 &p_pos) const; |
| 171 |
virtual Point2 unproject_position(const Vector3 &p_pos) const; |
| 172 |
bool is_position_behind(const Vector3 &p_pos) const; |
| 173 |
virtual Vector3 project_position(const Point2 &p_point, real_t p_z_depth) const; |
| 174 |
|
| 175 |
Vector<Vector3> get_near_plane_points() const; |
| 176 |
|
| 177 |
void set_cull_mask(uint32_t p_layers); |
| 178 |
uint32_t get_cull_mask() const; |
| 179 |
|
| 180 |
void set_cull_mask_value(int p_layer_number, bool p_enable); |
| 181 |
bool get_cull_mask_value(int p_layer_number) const; |
| 182 |
|
| 183 |
virtual Vector<Plane> get_frustum() const; |
| 184 |
bool is_position_in_frustum(const Vector3 &p_position) const; |
| 185 |
|
| 186 |
void set_environment(const Ref<Environment> &p_environment); |
| 187 |
Ref<Environment> get_environment() const; |
| 188 |
|
| 189 |
void set_attributes(const Ref<CameraAttributes> &p_effects); |
| 190 |
Ref<CameraAttributes> get_attributes() const; |
| 191 |
|
| 192 |
void set_compositor(const Ref<Compositor> &p_compositor); |
| 193 |
Ref<Compositor> get_compositor() const; |
| 194 |
|
| 195 |
void set_keep_aspect_mode(KeepAspect p_aspect); |
| 196 |
KeepAspect get_keep_aspect_mode() const; |
| 197 |
|
| 198 |
void set_v_offset(real_t p_offset); |
| 199 |
real_t get_v_offset() const; |
| 200 |
|
| 201 |
void set_h_offset(real_t p_offset); |
| 202 |
real_t get_h_offset() const; |
| 203 |
|
| 204 |
void set_doppler_tracking(DopplerTracking p_tracking); |
| 205 |
DopplerTracking get_doppler_tracking() const; |
| 206 |
|
| 207 |
Vector3 get_doppler_tracked_velocity() const; |
| 208 |
|
| 209 |
#ifndef PHYSICS_3D_DISABLED |
| 210 |
RID get_pyramid_shape_rid(); |
| 211 |
#endif |
| 212 |
|
| 213 |
Camera3D(); |
| 214 |
~Camera3D(); |
| 215 |
}; |
| 216 |
|
| 217 |
VARIANT_ENUM_CAST(Camera3D::ProjectionType); |
| 218 |
VARIANT_ENUM_CAST(Camera3D::KeepAspect); |
| 219 |
VARIANT_ENUM_CAST(Camera3D::DopplerTracking); |