CmViewport.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. #include "CmRect.h"
  30. #include <boost/signals/connection.hpp>
  31. namespace CamelotFramework {
  32. /** \addtogroup Core
  33. * @{
  34. */
  35. /** \addtogroup RenderSystem
  36. * @{
  37. */
  38. /** An abstraction of a viewport, i.e. a rendering region on a render
  39. target.
  40. @remarks
  41. A viewport is the meeting of a camera and a rendering surface -
  42. the camera renders the scene from a viewpoint, and places its
  43. results into some subset of a rendering target, which may be the
  44. whole surface or just a part of the surface. Each viewport has a
  45. single camera as source and a single target as destination. A
  46. camera only has 1 viewport, but a render target may have several.
  47. A viewport also has a Z-order, i.e. if there is more than one
  48. viewport on a single render target and they overlap, one must
  49. obscure the other in some predetermined way.
  50. */
  51. class CM_EXPORT Viewport
  52. {
  53. public:
  54. Viewport();
  55. /** The usual constructor.
  56. @param
  57. cam Pointer to a camera to be the source for the image.
  58. @param
  59. target Pointer to the render target to be the destination
  60. for the rendering.
  61. @param
  62. left
  63. @param
  64. top
  65. @param
  66. width
  67. @param
  68. height
  69. Dimensions of the viewport, expressed as a value between
  70. 0 and 1. This allows the dimensions to apply irrespective of
  71. changes in the target's size: e.g. to fill the whole area,
  72. values of 0,0,1,1 are appropriate.
  73. @param
  74. ZOrder Relative Z-order on the target. Lower = further to
  75. the front.
  76. */
  77. Viewport(
  78. RenderTargetPtr target,
  79. float left = 0.0f, float top = 0.0f,
  80. float width = 1.0f, float height = 1.0f,
  81. int ZOrder = 0);
  82. /** Default destructor.
  83. */
  84. virtual ~Viewport();
  85. /** Retrieves a pointer to the render target for this viewport.
  86. */
  87. RenderTargetPtr getTarget(void) const;
  88. /** Gets the Z-Order of this viewport. */
  89. int getZOrder(void) const;
  90. /** Gets one of the relative dimensions of the viewport,
  91. a value between 0.0 and 1.0.
  92. */
  93. float getNormalizedLeft(void) const;
  94. /** Gets one of the relative dimensions of the viewport, a value
  95. between 0.0 and 1.0.
  96. */
  97. float getNormalizedTop(void) const;
  98. /** Gets one of the relative dimensions of the viewport, a value
  99. between 0.0 and 1.0.
  100. */
  101. float getNormalizedWidth(void) const;
  102. /** Gets one of the relative dimensions of the viewport, a value
  103. between 0.0 and 1.0.
  104. */
  105. float getNormalizedHeight(void) const;
  106. /** Gets one of the actual dimensions of the viewport, a value in
  107. pixels.
  108. */
  109. int getLeft(void) const;
  110. /** Gets one of the actual dimensions of the viewport, a value in
  111. pixels.
  112. */
  113. int getTop(void) const;
  114. /** Gets one of the actual dimensions of the viewport, a value in
  115. pixels.
  116. */
  117. int getWidth(void) const;
  118. /** Gets one of the actual dimensions of the viewport, a value in
  119. pixels.
  120. */
  121. int getHeight(void) const;
  122. /** Sets the dimensions (after creation).
  123. @param
  124. left
  125. @param
  126. top
  127. @param
  128. width
  129. @param
  130. height Dimensions relative to the size of the target,
  131. represented as real values between 0 and 1. i.e. the full
  132. target area is 0, 0, 1, 1.
  133. */
  134. void setDimensions(float left, float top, float width, float height);
  135. /** Access to actual dimensions (based on target size).
  136. */
  137. const Rect& getDimensions() const { return mDimensions; }
  138. protected:
  139. RenderTargetPtr mTarget;
  140. // Relative dimensions, irrespective of target dimensions (0..1)
  141. float mRelLeft, mRelTop, mRelWidth, mRelHeight;
  142. // Actual dimensions, based on target dimensions
  143. Rect mDimensions;
  144. boost::signals::connection mTargetConn;
  145. /// ZOrder
  146. int mZOrder;
  147. /** Notifies the viewport of a possible change in dimensions.
  148. @remarks
  149. Used by the target to update the viewport's dimensions
  150. (usually the result of a change in target size).
  151. @note
  152. Internal use by engine only.
  153. */
  154. void updateDimensions(void);
  155. void targetResized(RenderTarget* target);
  156. };
  157. /** @} */
  158. /** @} */
  159. }
  160. #endif