sceneSetup.I 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. // Filename: sceneSetup.I
  2. // Created by: drose (27Mar02)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
  8. //
  9. // All use of this software is subject to the terms of the Panda 3d
  10. // Software license. You should have received a copy of this license
  11. // along with this source code; you will also find a current copy of
  12. // the license at http://etc.cmu.edu/panda3d/docs/license/ .
  13. //
  14. // To contact the maintainers of this program write to
  15. // [email protected] .
  16. //
  17. ////////////////////////////////////////////////////////////////////
  18. ////////////////////////////////////////////////////////////////////
  19. // Function: SceneSetup::Constructor
  20. // Access: Public
  21. // Description:
  22. ////////////////////////////////////////////////////////////////////
  23. INLINE SceneSetup::
  24. SceneSetup() {
  25. _inverted = false;
  26. _initial_state = RenderState::make_empty();
  27. _camera_transform = TransformState::make_identity();
  28. _world_transform = TransformState::make_identity();
  29. _cs_transform = TransformState::make_identity();
  30. }
  31. ////////////////////////////////////////////////////////////////////
  32. // Function: SceneSetup::set_scene_root
  33. // Access: Public
  34. // Description: Specifies the root node of the scene.
  35. ////////////////////////////////////////////////////////////////////
  36. INLINE void SceneSetup::
  37. set_scene_root(const NodePath &scene_root) {
  38. _scene_root = scene_root;
  39. }
  40. ////////////////////////////////////////////////////////////////////
  41. // Function: SceneSetup::get_scene_root
  42. // Access: Public
  43. // Description: Returns the root node of the scene.
  44. ////////////////////////////////////////////////////////////////////
  45. INLINE const NodePath &SceneSetup::
  46. get_scene_root() const {
  47. return _scene_root;
  48. }
  49. ////////////////////////////////////////////////////////////////////
  50. // Function: SceneSetup::set_camera_path
  51. // Access: Public
  52. // Description: Specifies the NodePath to the camera.
  53. ////////////////////////////////////////////////////////////////////
  54. INLINE void SceneSetup::
  55. set_camera_path(const NodePath &camera_path) {
  56. _camera_path = camera_path;
  57. }
  58. ////////////////////////////////////////////////////////////////////
  59. // Function: SceneSetup::get_camera_path
  60. // Access: Public
  61. // Description: Returns the NodePath to the camera.
  62. ////////////////////////////////////////////////////////////////////
  63. INLINE const NodePath &SceneSetup::
  64. get_camera_path() const {
  65. return _camera_path;
  66. }
  67. ////////////////////////////////////////////////////////////////////
  68. // Function: SceneSetup::set_camera_node
  69. // Access: Public
  70. // Description: Specifies the camera used to render the scene.
  71. ////////////////////////////////////////////////////////////////////
  72. INLINE void SceneSetup::
  73. set_camera_node(Camera *camera_node) {
  74. _camera_node = camera_node;
  75. }
  76. ////////////////////////////////////////////////////////////////////
  77. // Function: SceneSetup::get_camera_node
  78. // Access: Public
  79. // Description: Returns the camera used to render the scene.
  80. ////////////////////////////////////////////////////////////////////
  81. INLINE Camera *SceneSetup::
  82. get_camera_node() const {
  83. return _camera_node;
  84. }
  85. ////////////////////////////////////////////////////////////////////
  86. // Function: SceneSetup::set_lens
  87. // Access: Public
  88. // Description: Indicates the particular Lens used for rendering.
  89. ////////////////////////////////////////////////////////////////////
  90. INLINE void SceneSetup::
  91. set_lens(const Lens *lens) {
  92. _lens = lens;
  93. }
  94. ////////////////////////////////////////////////////////////////////
  95. // Function: SceneSetup::get_lens
  96. // Access: Public
  97. // Description: Returns the particular Lens used for rendering.
  98. ////////////////////////////////////////////////////////////////////
  99. INLINE const Lens *SceneSetup::
  100. get_lens() const {
  101. return _lens;
  102. }
  103. ////////////////////////////////////////////////////////////////////
  104. // Function: SceneSetup::set_inverted
  105. // Access: Published
  106. // Description: Changes the current setting of the inverted flag.
  107. // When this is true, the scene is rendered into the
  108. // window upside-down and backwards, that is, inverted
  109. // as if viewed through a mirror placed on the floor.
  110. ////////////////////////////////////////////////////////////////////
  111. INLINE void SceneSetup::
  112. set_inverted(bool inverted) {
  113. _inverted = inverted;
  114. }
  115. ////////////////////////////////////////////////////////////////////
  116. // Function: SceneSetup::get_inverted
  117. // Access: Published
  118. // Description: Returns the current setting of the inverted flag.
  119. // When this is true, the scene is rendered into the
  120. // window upside-down, flipped like a mirror along the X
  121. // axis.
  122. ////////////////////////////////////////////////////////////////////
  123. INLINE bool SceneSetup::
  124. get_inverted() const {
  125. return _inverted;
  126. }
  127. ////////////////////////////////////////////////////////////////////
  128. // Function: SceneSetup::get_cull_center
  129. // Access: Public
  130. // Description: Returns the point from which the culling operations
  131. // will be performed. This is normally the camera, but
  132. // if camera->set_cull_center() has been specified, it
  133. // will be that special node instead.
  134. ////////////////////////////////////////////////////////////////////
  135. INLINE const NodePath &SceneSetup::
  136. get_cull_center() const {
  137. if (_camera_node->get_cull_center().is_empty()) {
  138. return _camera_path;
  139. } else {
  140. return _camera_node->get_cull_center();
  141. }
  142. }
  143. ////////////////////////////////////////////////////////////////////
  144. // Function: SceneSetup::set_initial_state
  145. // Access: Published
  146. // Description: Sets the initial state which is applied to all nodes
  147. // in the scene, as if it were set at the top of the
  148. // scene graph.
  149. ////////////////////////////////////////////////////////////////////
  150. INLINE void SceneSetup::
  151. set_initial_state(const RenderState *state) {
  152. _initial_state = state;
  153. }
  154. ////////////////////////////////////////////////////////////////////
  155. // Function: SceneSetup::get_initial_state
  156. // Access: Published
  157. // Description: Returns the initial state as set by a previous call
  158. // to set_initial_state().
  159. ////////////////////////////////////////////////////////////////////
  160. INLINE const RenderState *SceneSetup::
  161. get_initial_state() const {
  162. return _initial_state;
  163. }
  164. ////////////////////////////////////////////////////////////////////
  165. // Function: SceneSetup::set_camera_transform
  166. // Access: Public
  167. // Description: Specifies the position of the camera relative to the
  168. // starting node, without any compensating
  169. // coordinate-system transforms that might have been
  170. // introduced for the purposes of rendering.
  171. ////////////////////////////////////////////////////////////////////
  172. INLINE void SceneSetup::
  173. set_camera_transform(const TransformState *camera_transform) {
  174. _camera_transform = camera_transform;
  175. }
  176. ////////////////////////////////////////////////////////////////////
  177. // Function: SceneSetup::get_camera_transform
  178. // Access: Public
  179. // Description: Returns the position of the camera relative to the
  180. // starting node, without any compensating
  181. // coordinate-system transforms that might have been
  182. // introduced for the purposes of rendering.
  183. ////////////////////////////////////////////////////////////////////
  184. INLINE const TransformState *SceneSetup::
  185. get_camera_transform() const {
  186. return _camera_transform;
  187. }
  188. ////////////////////////////////////////////////////////////////////
  189. // Function: SceneSetup::set_world_transform
  190. // Access: Public
  191. // Description: Specifies the position of the starting node relative
  192. // to the camera. This is the inverse of the camera
  193. // transform.
  194. ////////////////////////////////////////////////////////////////////
  195. INLINE void SceneSetup::
  196. set_world_transform(const TransformState *world_transform) {
  197. _world_transform = world_transform;
  198. _render_transform = _cs_transform->compose(_world_transform);
  199. }
  200. ////////////////////////////////////////////////////////////////////
  201. // Function: SceneSetup::get_world_transform
  202. // Access: Public
  203. // Description: Returns the position of the starting node relative
  204. // to the camera. This is the inverse of the camera
  205. // transform.
  206. ////////////////////////////////////////////////////////////////////
  207. INLINE const TransformState *SceneSetup::
  208. get_world_transform() const {
  209. return _world_transform;
  210. }
  211. ////////////////////////////////////////////////////////////////////
  212. // Function: SceneSetup::set_cs_transform
  213. // Access: Public
  214. // Description: Specifies the pretransformation to apply to the world
  215. // transform to produce the appropriate transformation
  216. // for rendering. This is usually the appropriate
  217. // coordinate-system conversion for the current GSG.
  218. ////////////////////////////////////////////////////////////////////
  219. INLINE void SceneSetup::
  220. set_cs_transform(const TransformState *cs_transform) {
  221. _cs_transform = cs_transform;
  222. _render_transform = _cs_transform->compose(_world_transform);
  223. }
  224. ////////////////////////////////////////////////////////////////////
  225. // Function: SceneSetup::get_cs_transform
  226. // Access: Public
  227. // Description: Returns the pretransformation to apply to the world
  228. // transform to produce the appropriate transformation
  229. // for rendering.
  230. ////////////////////////////////////////////////////////////////////
  231. INLINE const TransformState *SceneSetup::
  232. get_cs_transform() const {
  233. return _cs_transform;
  234. }
  235. ////////////////////////////////////////////////////////////////////
  236. // Function: SceneSetup::get_render_transform
  237. // Access: Public
  238. // Description: Returns the position of the starting node relative
  239. // to the camera, pretransformed as appropriate for
  240. // rendering. This is the same as the world transform,
  241. // with a possible coordinate-system conversion applied.
  242. //
  243. // Note that this value is always the position of the
  244. // starting node, not the current node, even if it is
  245. // sampled during a traversal. To get the render
  246. // transform of the current node check in the current
  247. // CullTraverserData.
  248. ////////////////////////////////////////////////////////////////////
  249. INLINE const TransformState *SceneSetup::
  250. get_render_transform() const {
  251. return _render_transform;
  252. }