CmViewport.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. -----------------------------------------------------------------------------
  3. This source file is part of OGRE
  4. (Object-oriented Graphics Rendering Engine)
  5. For the latest info, see http://www.ogre3d.org/
  6. Copyright (c) 2000-2011 Torus Knot Software Ltd
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. THE SOFTWARE.
  22. -----------------------------------------------------------------------------
  23. */
  24. #ifndef __Viewport_H__
  25. #define __Viewport_H__
  26. #include "CmPrerequisites.h"
  27. #include "CmCommonEnums.h"
  28. #include "CmColor.h"
  29. namespace CamelotEngine {
  30. /** \addtogroup Core
  31. * @{
  32. */
  33. /** \addtogroup RenderSystem
  34. * @{
  35. */
  36. /** An abstraction of a viewport, i.e. a rendering region on a render
  37. target.
  38. @remarks
  39. A viewport is the meeting of a camera and a rendering surface -
  40. the camera renders the scene from a viewpoint, and places its
  41. results into some subset of a rendering target, which may be the
  42. whole surface or just a part of the surface. Each viewport has a
  43. single camera as source and a single target as destination. A
  44. camera only has 1 viewport, but a render target may have several.
  45. A viewport also has a Z-order, i.e. if there is more than one
  46. viewport on a single render target and they overlap, one must
  47. obscure the other in some predetermined way.
  48. */
  49. class CM_EXPORT Viewport
  50. {
  51. public:
  52. Viewport();
  53. /** The usual constructor.
  54. @param
  55. cam Pointer to a camera to be the source for the image.
  56. @param
  57. target Pointer to the render target to be the destination
  58. for the rendering.
  59. @param
  60. left
  61. @param
  62. top
  63. @param
  64. width
  65. @param
  66. height
  67. Dimensions of the viewport, expressed as a value between
  68. 0 and 1. This allows the dimensions to apply irrespective of
  69. changes in the target's size: e.g. to fill the whole area,
  70. values of 0,0,1,1 are appropriate.
  71. @param
  72. ZOrder Relative Z-order on the target. Lower = further to
  73. the front.
  74. */
  75. Viewport(
  76. RenderTargetPtr target,
  77. float left = 0.0f, float top = 0.0f,
  78. float width = 1.0f, float height = 1.0f,
  79. int ZOrder = 0);
  80. /** Default destructor.
  81. */
  82. virtual ~Viewport();
  83. /** Retrieves a pointer to the render target for this viewport.
  84. */
  85. RenderTargetPtr getTarget(void) const;
  86. /** Gets the Z-Order of this viewport. */
  87. int getZOrder(void) const;
  88. /** Gets one of the relative dimensions of the viewport,
  89. a value between 0.0 and 1.0.
  90. */
  91. float getLeft(void) const;
  92. /** Gets one of the relative dimensions of the viewport, a value
  93. between 0.0 and 1.0.
  94. */
  95. float getTop(void) const;
  96. /** Gets one of the relative dimensions of the viewport, a value
  97. between 0.0 and 1.0.
  98. */
  99. float getWidth(void) const;
  100. /** Gets one of the relative dimensions of the viewport, a value
  101. between 0.0 and 1.0.
  102. */
  103. float getHeight(void) const;
  104. /** Gets one of the actual dimensions of the viewport, a value in
  105. pixels.
  106. */
  107. int getActualLeft(void) const;
  108. /** Gets one of the actual dimensions of the viewport, a value in
  109. pixels.
  110. */
  111. int getActualTop(void) const;
  112. /** Gets one of the actual dimensions of the viewport, a value in
  113. pixels.
  114. */
  115. int getActualWidth(void) const;
  116. /** Gets one of the actual dimensions of the viewport, a value in
  117. pixels.
  118. */
  119. int getActualHeight(void) const;
  120. /** Sets the dimensions (after creation).
  121. @param
  122. left
  123. @param
  124. top
  125. @param
  126. width
  127. @param
  128. height Dimensions relative to the size of the target,
  129. represented as real values between 0 and 1. i.e. the full
  130. target area is 0, 0, 1, 1.
  131. */
  132. void setDimensions(float left, float top, float width, float height);
  133. /** Access to actual dimensions (based on target size).
  134. */
  135. void getActualDimensions(
  136. int &left, int &top, int &width, int &height ) const;
  137. protected:
  138. RenderTargetPtr mTarget;
  139. // Relative dimensions, irrespective of target dimensions (0..1)
  140. float mRelLeft, mRelTop, mRelWidth, mRelHeight;
  141. // Actual dimensions, based on target dimensions
  142. int mActLeft, mActTop, mActWidth, mActHeight;
  143. /// ZOrder
  144. int mZOrder;
  145. /** Notifies the viewport of a possible change in dimensions.
  146. @remarks
  147. Used by the target to update the viewport's dimensions
  148. (usually the result of a change in target size).
  149. @note
  150. Internal use by engine only.
  151. */
  152. void updateDimensions(void);
  153. };
  154. /** @} */
  155. /** @} */
  156. }
  157. #endif