camera.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*************************************************************************/
  2. /* camera.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #ifndef CAMERA_H
  31. #define CAMERA_H
  32. #include "scene/3d/spatial.h"
  33. #include "scene/3d/spatial_velocity_tracker.h"
  34. #include "scene/main/viewport.h"
  35. #include "scene/resources/environment.h"
  36. /**
  37. @author Juan Linietsky <reduzio@gmail.com>
  38. */
  39. class Camera : public Spatial {
  40. GDCLASS(Camera, Spatial);
  41. public:
  42. enum Projection {
  43. PROJECTION_PERSPECTIVE,
  44. PROJECTION_ORTHOGONAL
  45. };
  46. enum KeepAspect {
  47. KEEP_WIDTH,
  48. KEEP_HEIGHT
  49. };
  50. enum DopplerTracking {
  51. DOPPLER_TRACKING_DISABLED,
  52. DOPPLER_TRACKING_IDLE_STEP,
  53. DOPPLER_TRACKING_PHYSICS_STEP
  54. };
  55. private:
  56. bool force_change;
  57. bool current;
  58. Projection mode;
  59. float fov;
  60. float size;
  61. float near, far;
  62. float v_offset;
  63. float h_offset;
  64. KeepAspect keep_aspect;
  65. RID camera;
  66. RID scenario_id;
  67. //String camera_group;
  68. uint32_t layers;
  69. Ref<Environment> environment;
  70. virtual bool _can_gizmo_scale() const;
  71. //void _camera_make_current(Node *p_camera);
  72. friend class Viewport;
  73. void _update_audio_listener_state();
  74. DopplerTracking doppler_tracking;
  75. Ref<SpatialVelocityTracker> velocity_tracker;
  76. protected:
  77. void _update_camera();
  78. virtual void _request_camera_update();
  79. void _update_camera_mode();
  80. bool _set(const StringName &p_name, const Variant &p_value);
  81. bool _get(const StringName &p_name, Variant &r_ret) const;
  82. void _get_property_list(List<PropertyInfo> *p_list) const;
  83. void _notification(int p_what);
  84. static void _bind_methods();
  85. public:
  86. enum {
  87. NOTIFICATION_BECAME_CURRENT = 50,
  88. NOTIFICATION_LOST_CURRENT = 51
  89. };
  90. void set_perspective(float p_fovy_degrees, float p_z_near, float p_z_far);
  91. void set_orthogonal(float p_size, float p_z_near, float p_z_far);
  92. void make_current();
  93. void clear_current();
  94. bool is_current() const;
  95. RID get_camera() const;
  96. float get_fov() const;
  97. float get_size() const;
  98. float get_zfar() const;
  99. float get_znear() const;
  100. Projection get_projection() const;
  101. virtual Transform get_camera_transform() const;
  102. Vector3 project_ray_normal(const Point2 &p_pos) const;
  103. virtual Vector3 project_ray_origin(const Point2 &p_pos) const;
  104. Vector3 project_local_ray_normal(const Point2 &p_pos) const;
  105. virtual Point2 unproject_position(const Vector3 &p_pos) const;
  106. bool is_position_behind(const Vector3 &p_pos) const;
  107. virtual Vector3 project_position(const Point2 &p_point) const;
  108. void set_cull_mask(uint32_t p_layers);
  109. uint32_t get_cull_mask() const;
  110. virtual Vector<Plane> get_frustum() const;
  111. void set_environment(const Ref<Environment> &p_environment);
  112. Ref<Environment> get_environment() const;
  113. void set_keep_aspect_mode(KeepAspect p_aspect);
  114. KeepAspect get_keep_aspect_mode() const;
  115. void set_v_offset(float p_offset);
  116. float get_v_offset() const;
  117. void set_h_offset(float p_offset);
  118. float get_h_offset() const;
  119. void set_doppler_tracking(DopplerTracking p_tracking);
  120. DopplerTracking get_doppler_tracking() const;
  121. Vector3 get_doppler_tracked_velocity() const;
  122. Camera();
  123. ~Camera();
  124. };
  125. VARIANT_ENUM_CAST(Camera::Projection);
  126. VARIANT_ENUM_CAST(Camera::KeepAspect);
  127. VARIANT_ENUM_CAST(Camera::DopplerTracking);
  128. #endif