sceneCameraState.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _SCENECAMERASTATE_H_
  23. #define _SCENECAMERASTATE_H_
  24. #ifndef _MATHUTIL_FRUSTUM_H_
  25. #include "math/util/frustum.h"
  26. #endif
  27. #ifndef _MRECT_H_
  28. #include "math/mRect.h"
  29. #endif
  30. #ifndef _MMATRIX_H_
  31. #include "math/mMatrix.h"
  32. #endif
  33. /// An object that combines all the state that is relevant to looking into the
  34. /// scene from a particular point of view.
  35. class SceneCameraState
  36. {
  37. protected:
  38. /// The screen-space viewport rectangle.
  39. RectI mViewport;
  40. /// The viewing frustum.
  41. Frustum mFrustum;
  42. /// The inverse of the frustum's transform stored here for caching.
  43. MatrixF mWorldViewMatrix;
  44. /// The projection matrix.
  45. MatrixF mProjectionMatrix;
  46. /// World-space vector representing the view direction.
  47. Point3F mViewDirection;
  48. /// Internal constructor.
  49. SceneCameraState() {}
  50. public:
  51. /// Freeze the given viewing state.
  52. ///
  53. /// @param viewport Screen-space viewport rectangle.
  54. /// @param frustum Camera frustum.
  55. /// @param worldView World->view matrix.
  56. /// @param projection Projection matrix.
  57. SceneCameraState( const RectI& viewport, const Frustum& frustum, const MatrixF& worldView, const MatrixF& projection );
  58. /// Capture the view state from the current GFX state.
  59. static SceneCameraState fromGFX();
  60. ///
  61. static SceneCameraState fromGFXWithViewport( const RectI& viewport );
  62. /// Return the screen-space viewport rectangle.
  63. const RectI& getViewport() const { return mViewport; }
  64. /// Return the camera frustum.
  65. const Frustum& getFrustum() const { return mFrustum; }
  66. /// Return the view position. This is a shortcut for getFrustum().getPosition().
  67. const Point3F& getViewPosition() const { return mFrustum.getPosition(); }
  68. /// Return the world-space view vector.
  69. const Point3F& getViewDirection() const { return mViewDirection; }
  70. /// Return the view->world transform. This is a shortcut for getFrustum().getTransform().
  71. const MatrixF& getViewWorldMatrix() const { return mFrustum.getTransform(); }
  72. /// Return the world->view transform.
  73. const MatrixF& getWorldViewMatrix() const { return mWorldViewMatrix; }
  74. /// Return the projection transform.
  75. const MatrixF& getProjectionMatrix() const { return mProjectionMatrix; }
  76. };
  77. #endif // !_SCENECAMERASTATE_H_