camera.h 4.7 KB

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