class_camera.rst 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. .. _class_Camera:
  2. Camera
  3. ======
  4. **Inherits:** :ref:`Spatial<class_spatial>`
  5. **Category:** Core
  6. Camera node, displays from a point of view.
  7. Member Functions
  8. ----------------
  9. +----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  10. | :ref:`Vector3<class_vector3>` | :ref:`project_ray_normal<class_Camera_project_ray_normal>` **(** :ref:`Vector2<class_vector2>` screen_point **)** const |
  11. +----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  12. | :ref:`Vector3<class_vector3>` | :ref:`project_local_ray_normal<class_Camera_project_local_ray_normal>` **(** :ref:`Vector2<class_vector2>` screen_point **)** const |
  13. +----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  14. | :ref:`Vector3<class_vector3>` | :ref:`project_ray_origin<class_Camera_project_ray_origin>` **(** :ref:`Vector2<class_vector2>` screen_point **)** const |
  15. +----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  16. | :ref:`Vector2<class_vector2>` | :ref:`unproject_position<class_Camera_unproject_position>` **(** :ref:`Vector3<class_vector3>` world_point **)** const |
  17. +----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  18. | :ref:`bool<class_bool>` | :ref:`is_position_behind<class_Camera_is_position_behind>` **(** :ref:`Vector3<class_vector3>` world_point **)** const |
  19. +----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  20. | :ref:`Vector3<class_vector3>` | :ref:`project_position<class_Camera_project_position>` **(** :ref:`Vector2<class_vector2>` screen_point **)** const |
  21. +----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  22. | 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 **)** |
  23. +----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  24. | 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 **)** |
  25. +----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  26. | void | :ref:`make_current<class_Camera_make_current>` **(** **)** |
  27. +----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  28. | void | :ref:`clear_current<class_Camera_clear_current>` **(** **)** |
  29. +----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  30. | :ref:`bool<class_bool>` | :ref:`is_current<class_Camera_is_current>` **(** **)** const |
  31. +----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  32. | :ref:`Transform<class_transform>` | :ref:`get_camera_transform<class_Camera_get_camera_transform>` **(** **)** const |
  33. +----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  34. | :ref:`float<class_float>` | :ref:`get_fov<class_Camera_get_fov>` **(** **)** const |
  35. +----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  36. | :ref:`float<class_float>` | :ref:`get_size<class_Camera_get_size>` **(** **)** const |
  37. +----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  38. | :ref:`float<class_float>` | :ref:`get_zfar<class_Camera_get_zfar>` **(** **)** const |
  39. +----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  40. | :ref:`float<class_float>` | :ref:`get_znear<class_Camera_get_znear>` **(** **)** const |
  41. +----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  42. | :ref:`int<class_int>` | :ref:`get_projection<class_Camera_get_projection>` **(** **)** const |
  43. +----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  44. | void | :ref:`set_visible_layers<class_Camera_set_visible_layers>` **(** :ref:`int<class_int>` mask **)** |
  45. +----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  46. | :ref:`int<class_int>` | :ref:`get_visible_layers<class_Camera_get_visible_layers>` **(** **)** const |
  47. +----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  48. | void | :ref:`set_environment<class_Camera_set_environment>` **(** :ref:`Environment<class_environment>` env **)** |
  49. +----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  50. | :ref:`Environment<class_environment>` | :ref:`get_environment<class_Camera_get_environment>` **(** **)** const |
  51. +----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  52. | void | :ref:`set_keep_aspect_mode<class_Camera_set_keep_aspect_mode>` **(** :ref:`int<class_int>` mode **)** |
  53. +----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  54. | :ref:`int<class_int>` | :ref:`get_keep_aspect_mode<class_Camera_get_keep_aspect_mode>` **(** **)** const |
  55. +----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  56. Numeric Constants
  57. -----------------
  58. - **PROJECTION_PERSPECTIVE** = **0** --- Perspective Projection (object's size on the screen becomes smaller when far away).
  59. - **PROJECTION_ORTHOGONAL** = **1** --- Orthogonal Projection (objects remain the same size on the screen no matter how far away they are).
  60. - **KEEP_WIDTH** = **0**
  61. - **KEEP_HEIGHT** = **1**
  62. Description
  63. -----------
  64. 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 :ref:`Scene<class_scene>` registered in that :ref:`Viewport<class_viewport>` (or higher viewports) can't be displayed.
  65. Member Function Description
  66. ---------------------------
  67. .. _class_Camera_project_ray_normal:
  68. - :ref:`Vector3<class_vector3>` **project_ray_normal** **(** :ref:`Vector2<class_vector2>` screen_point **)** const
  69. 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.
  70. .. _class_Camera_project_local_ray_normal:
  71. - :ref:`Vector3<class_vector3>` **project_local_ray_normal** **(** :ref:`Vector2<class_vector2>` screen_point **)** const
  72. .. _class_Camera_project_ray_origin:
  73. - :ref:`Vector3<class_vector3>` **project_ray_origin** **(** :ref:`Vector2<class_vector2>` screen_point **)** const
  74. 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.
  75. .. _class_Camera_unproject_position:
  76. - :ref:`Vector2<class_vector2>` **unproject_position** **(** :ref:`Vector3<class_vector3>` world_point **)** const
  77. Return how a 3D point in worldpsace maps to a 2D coordinate in the :ref:`Viewport<class_viewport>` rectangle.
  78. .. _class_Camera_is_position_behind:
  79. - :ref:`bool<class_bool>` **is_position_behind** **(** :ref:`Vector3<class_vector3>` world_point **)** const
  80. .. _class_Camera_project_position:
  81. - :ref:`Vector3<class_vector3>` **project_position** **(** :ref:`Vector2<class_vector2>` screen_point **)** const
  82. .. _class_Camera_set_perspective:
  83. - void **set_perspective** **(** :ref:`float<class_float>` fov, :ref:`float<class_float>` z_near, :ref:`float<class_float>` z_far **)**
  84. 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.
  85. .. _class_Camera_set_orthogonal:
  86. - void **set_orthogonal** **(** :ref:`float<class_float>` size, :ref:`float<class_float>` z_near, :ref:`float<class_float>` z_far **)**
  87. 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)
  88. .. _class_Camera_make_current:
  89. - void **make_current** **(** **)**
  90. 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.
  91. .. _class_Camera_clear_current:
  92. - void **clear_current** **(** **)**
  93. .. _class_Camera_is_current:
  94. - :ref:`bool<class_bool>` **is_current** **(** **)** const
  95. Return wether the Camera is the current one in the :ref:`Viewport<class_viewport>`, or plans to become current (if outside the scene tree).
  96. .. _class_Camera_get_camera_transform:
  97. - :ref:`Transform<class_transform>` **get_camera_transform** **(** **)** const
  98. Get the camera transform. Subclassed cameras (such as CharacterCamera) may provide different transforms than the :ref:`Node<class_node>` transform.
  99. .. _class_Camera_get_fov:
  100. - :ref:`float<class_float>` **get_fov** **(** **)** const
  101. .. _class_Camera_get_size:
  102. - :ref:`float<class_float>` **get_size** **(** **)** const
  103. .. _class_Camera_get_zfar:
  104. - :ref:`float<class_float>` **get_zfar** **(** **)** const
  105. .. _class_Camera_get_znear:
  106. - :ref:`float<class_float>` **get_znear** **(** **)** const
  107. .. _class_Camera_get_projection:
  108. - :ref:`int<class_int>` **get_projection** **(** **)** const
  109. .. _class_Camera_set_visible_layers:
  110. - void **set_visible_layers** **(** :ref:`int<class_int>` mask **)**
  111. .. _class_Camera_get_visible_layers:
  112. - :ref:`int<class_int>` **get_visible_layers** **(** **)** const
  113. .. _class_Camera_set_environment:
  114. - void **set_environment** **(** :ref:`Environment<class_environment>` env **)**
  115. .. _class_Camera_get_environment:
  116. - :ref:`Environment<class_environment>` **get_environment** **(** **)** const
  117. .. _class_Camera_set_keep_aspect_mode:
  118. - void **set_keep_aspect_mode** **(** :ref:`int<class_int>` mode **)**
  119. .. _class_Camera_get_keep_aspect_mode:
  120. - :ref:`int<class_int>` **get_keep_aspect_mode** **(** **)** const