sceneCameraState.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. /// Actual head position (will be - eye pos)
  45. MatrixF mHeadWorldViewMatrix;
  46. /// The projection matrix.
  47. MatrixF mProjectionMatrix;
  48. /// World-space vector representing the view direction.
  49. Point3F mViewDirection;
  50. /// Internal constructor.
  51. SceneCameraState() {}
  52. public:
  53. /// Freeze the given viewing state.
  54. ///
  55. /// @param viewport Screen-space viewport rectangle.
  56. /// @param frustum Camera frustum.
  57. /// @param worldView World->view matrix.
  58. /// @param projection Projection matrix.
  59. SceneCameraState( const RectI& viewport, const Frustum& frustum, const MatrixF& worldView, const MatrixF& projection );
  60. /// Capture the view state from the current GFX state.
  61. static SceneCameraState fromGFX();
  62. ///
  63. static SceneCameraState fromGFXWithViewport( const RectI& viewport );
  64. /// Return the screen-space viewport rectangle.
  65. const RectI& getViewport() const { return mViewport; }
  66. /// Return the camera frustum.
  67. const Frustum& getFrustum() const { return mFrustum; }
  68. /// Return the view position. This is a shortcut for getFrustum().getPosition().
  69. const Point3F& getViewPosition() const { return mFrustum.getPosition(); }
  70. /// Return the world-space view vector.
  71. const Point3F& getViewDirection() const { return mViewDirection; }
  72. /// Returns the world->view transform for the head (used to calculate various display metrics)
  73. const MatrixF& getHeadWorldViewMatrix() const { return mHeadWorldViewMatrix; }
  74. /// Return the view->world transform. This is a shortcut for getFrustum().getTransform().
  75. const MatrixF& getViewWorldMatrix() const { return mFrustum.getTransform(); }
  76. /// Return the world->view transform.
  77. const MatrixF& getWorldViewMatrix() const { return mWorldViewMatrix; }
  78. /// Return the projection transform.
  79. const MatrixF& getProjectionMatrix() const { return mProjectionMatrix; }
  80. };
  81. #endif // !_SCENECAMERASTATE_H_