class_camera.rst 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. .. _class_Camera:
  2. Camera
  3. ======
  4. **Inherits:** :ref:`Spatial<class_spatial>` **<** :ref:`Node<class_node>` **<** :ref:`Object<class_object>`
  5. **Inherited By:** :ref:`InterpolatedCamera<class_interpolatedcamera>`
  6. **Category:** Core
  7. Brief Description
  8. -----------------
  9. Camera node, displays from a point of view.
  10. Member Functions
  11. ----------------
  12. +----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  13. | :ref:`Vector3<class_vector3>` | :ref:`project_ray_normal<class_Camera_project_ray_normal>` **(** :ref:`Vector2<class_vector2>` screen_point **)** const |
  14. +----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  15. | :ref:`Vector3<class_vector3>` | :ref:`project_local_ray_normal<class_Camera_project_local_ray_normal>` **(** :ref:`Vector2<class_vector2>` screen_point **)** const |
  16. +----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  17. | :ref:`Vector3<class_vector3>` | :ref:`project_ray_origin<class_Camera_project_ray_origin>` **(** :ref:`Vector2<class_vector2>` screen_point **)** const |
  18. +----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  19. | :ref:`Vector2<class_vector2>` | :ref:`unproject_position<class_Camera_unproject_position>` **(** :ref:`Vector3<class_vector3>` world_point **)** const |
  20. +----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  21. | :ref:`bool<class_bool>` | :ref:`is_position_behind<class_Camera_is_position_behind>` **(** :ref:`Vector3<class_vector3>` world_point **)** const |
  22. +----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  23. | :ref:`Vector3<class_vector3>` | :ref:`project_position<class_Camera_project_position>` **(** :ref:`Vector2<class_vector2>` screen_point **)** const |
  24. +----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  25. | void | :ref:`set_perspective<class_Camera_set_perspective>` **(** :ref:`float<class_float>` fov, :ref:`float<class_float>` z_near, :ref:`float<class_float>` z_far **)** |
  26. +----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  27. | void | :ref:`set_orthogonal<class_Camera_set_orthogonal>` **(** :ref:`float<class_float>` size, :ref:`float<class_float>` z_near, :ref:`float<class_float>` z_far **)** |
  28. +----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  29. | void | :ref:`make_current<class_Camera_make_current>` **(** **)** |
  30. +----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  31. | void | :ref:`clear_current<class_Camera_clear_current>` **(** **)** |
  32. +----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  33. | :ref:`bool<class_bool>` | :ref:`is_current<class_Camera_is_current>` **(** **)** const |
  34. +----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  35. | :ref:`Transform<class_transform>` | :ref:`get_camera_transform<class_Camera_get_camera_transform>` **(** **)** const |
  36. +----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  37. | :ref:`float<class_float>` | :ref:`get_fov<class_Camera_get_fov>` **(** **)** const |
  38. +----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  39. | :ref:`float<class_float>` | :ref:`get_size<class_Camera_get_size>` **(** **)** const |
  40. +----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`float<class_float>` | :ref:`get_zfar<class_Camera_get_zfar>` **(** **)** const |
  42. +----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | :ref:`float<class_float>` | :ref:`get_znear<class_Camera_get_znear>` **(** **)** const |
  44. +----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`int<class_int>` | :ref:`get_projection<class_Camera_get_projection>` **(** **)** const |
  46. +----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | void | :ref:`set_visible_layers<class_Camera_set_visible_layers>` **(** :ref:`int<class_int>` mask **)** |
  48. +----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | :ref:`int<class_int>` | :ref:`get_visible_layers<class_Camera_get_visible_layers>` **(** **)** const |
  50. +----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | void | :ref:`set_environment<class_Camera_set_environment>` **(** :ref:`Environment<class_environment>` env **)** |
  52. +----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | :ref:`Environment<class_environment>` | :ref:`get_environment<class_Camera_get_environment>` **(** **)** const |
  54. +----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | void | :ref:`set_keep_aspect_mode<class_Camera_set_keep_aspect_mode>` **(** :ref:`int<class_int>` mode **)** |
  56. +----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | :ref:`int<class_int>` | :ref:`get_keep_aspect_mode<class_Camera_get_keep_aspect_mode>` **(** **)** const |
  58. +----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  59. Numeric Constants
  60. -----------------
  61. - **PROJECTION_PERSPECTIVE** = **0** --- Perspective Projection (object's size on the screen becomes smaller when far away).
  62. - **PROJECTION_ORTHOGONAL** = **1** --- Orthogonal Projection (objects remain the same size on the screen no matter how far away they are).
  63. - **KEEP_WIDTH** = **0**
  64. - **KEEP_HEIGHT** = **1**
  65. Description
  66. -----------
  67. Camera is a special node that displays what is visible from its current location. Cameras register themselves in the nearest :ref:`Viewport<class_viewport>` node (when ascending the tree). Only one camera can be active per viewport. If no viewport is available ascending the tree, the Camera will register in the global viewport. In other words, a Camera just provides *3D* display capabilities to a :ref:`Viewport<class_viewport>`, and, without one, a scene registered in that :ref:`Viewport<class_viewport>` (or higher viewports) can't be displayed.
  68. Member Function Description
  69. ---------------------------
  70. .. _class_Camera_project_ray_normal:
  71. - :ref:`Vector3<class_vector3>` **project_ray_normal** **(** :ref:`Vector2<class_vector2>` screen_point **)** const
  72. Return a normal vector in worldspace, that is the result of projecting a point on the :ref:`Viewport<class_viewport>` rectangle by the camera projection. This is useful for casting rays in the form of (origin,normal) for object intersection or picking.
  73. .. _class_Camera_project_local_ray_normal:
  74. - :ref:`Vector3<class_vector3>` **project_local_ray_normal** **(** :ref:`Vector2<class_vector2>` screen_point **)** const
  75. .. _class_Camera_project_ray_origin:
  76. - :ref:`Vector3<class_vector3>` **project_ray_origin** **(** :ref:`Vector2<class_vector2>` screen_point **)** const
  77. Return a 3D position in worldspace, that is the result of projecting a point on the :ref:`Viewport<class_viewport>` rectangle by the camera projection. This is useful for casting rays in the form of (origin,normal) for object intersection or picking.
  78. .. _class_Camera_unproject_position:
  79. - :ref:`Vector2<class_vector2>` **unproject_position** **(** :ref:`Vector3<class_vector3>` world_point **)** const
  80. Return how a 3D point in worldspace maps to a 2D coordinate in the :ref:`Viewport<class_viewport>` rectangle.
  81. .. _class_Camera_is_position_behind:
  82. - :ref:`bool<class_bool>` **is_position_behind** **(** :ref:`Vector3<class_vector3>` world_point **)** const
  83. .. _class_Camera_project_position:
  84. - :ref:`Vector3<class_vector3>` **project_position** **(** :ref:`Vector2<class_vector2>` screen_point **)** const
  85. .. _class_Camera_set_perspective:
  86. - void **set_perspective** **(** :ref:`float<class_float>` fov, :ref:`float<class_float>` z_near, :ref:`float<class_float>` z_far **)**
  87. Set the camera projection to perspective mode, by specifying a *FOV* Y angle in degrees (FOV means Field of View), and the *near* and *far* clip planes in worldspace units.
  88. .. _class_Camera_set_orthogonal:
  89. - void **set_orthogonal** **(** :ref:`float<class_float>` size, :ref:`float<class_float>` z_near, :ref:`float<class_float>` z_far **)**
  90. Set the camera projection to orthogonal mode, by specifying a width and the *near* and *far* clip planes in worldspace units. (As a hint, 2D games often use this projection, with values specified in pixels)
  91. .. _class_Camera_make_current:
  92. - void **make_current** **(** **)**
  93. Make this camera the current Camera for the :ref:`Viewport<class_viewport>` (see class description). If the Camera Node is outside the scene tree, it will attempt to become current once it's added.
  94. .. _class_Camera_clear_current:
  95. - void **clear_current** **(** **)**
  96. .. _class_Camera_is_current:
  97. - :ref:`bool<class_bool>` **is_current** **(** **)** const
  98. Return whether the Camera is the current one in the :ref:`Viewport<class_viewport>`, or plans to become current (if outside the scene tree).
  99. .. _class_Camera_get_camera_transform:
  100. - :ref:`Transform<class_transform>` **get_camera_transform** **(** **)** const
  101. Get the camera transform. Subclassed cameras (such as CharacterCamera) may provide different transforms than the :ref:`Node<class_node>` transform.
  102. .. _class_Camera_get_fov:
  103. - :ref:`float<class_float>` **get_fov** **(** **)** const
  104. .. _class_Camera_get_size:
  105. - :ref:`float<class_float>` **get_size** **(** **)** const
  106. .. _class_Camera_get_zfar:
  107. - :ref:`float<class_float>` **get_zfar** **(** **)** const
  108. .. _class_Camera_get_znear:
  109. - :ref:`float<class_float>` **get_znear** **(** **)** const
  110. .. _class_Camera_get_projection:
  111. - :ref:`int<class_int>` **get_projection** **(** **)** const
  112. .. _class_Camera_set_visible_layers:
  113. - void **set_visible_layers** **(** :ref:`int<class_int>` mask **)**
  114. .. _class_Camera_get_visible_layers:
  115. - :ref:`int<class_int>` **get_visible_layers** **(** **)** const
  116. .. _class_Camera_set_environment:
  117. - void **set_environment** **(** :ref:`Environment<class_environment>` env **)**
  118. .. _class_Camera_get_environment:
  119. - :ref:`Environment<class_environment>` **get_environment** **(** **)** const
  120. .. _class_Camera_set_keep_aspect_mode:
  121. - void **set_keep_aspect_mode** **(** :ref:`int<class_int>` mode **)**
  122. .. _class_Camera_get_keep_aspect_mode:
  123. - :ref:`int<class_int>` **get_keep_aspect_mode** **(** **)** const