CmCamera.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  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 __Camera_H__
  25. #define __Camera_H__
  26. // Default options
  27. #include "CmPrerequisites.h"
  28. #include "CmString.h"
  29. // Matrices & Vectors
  30. #include "CmMatrix4.h"
  31. #include "CmVector3.h"
  32. #include "CmVector2.h"
  33. #include "CmAxisAlignedBox.h"
  34. #include "CmVertexIndexData.h"
  35. #include "CmPlane.h"
  36. #include "CmQuaternion.h"
  37. #include "CmCommon.h"
  38. #include "CmRay.h"
  39. #include "CmComponent.h"
  40. namespace CamelotEngine {
  41. /** Specifies perspective (realistic) or orthographic (architectural) projection.
  42. */
  43. enum ProjectionType
  44. {
  45. PT_ORTHOGRAPHIC,
  46. PT_PERSPECTIVE
  47. };
  48. /** Worldspace clipping planes.
  49. */
  50. enum FrustumPlane
  51. {
  52. FRUSTUM_PLANE_NEAR = 0,
  53. FRUSTUM_PLANE_FAR = 1,
  54. FRUSTUM_PLANE_LEFT = 2,
  55. FRUSTUM_PLANE_RIGHT = 3,
  56. FRUSTUM_PLANE_TOP = 4,
  57. FRUSTUM_PLANE_BOTTOM = 5
  58. };
  59. /** \addtogroup Core
  60. * @{
  61. */
  62. /** \addtogroup Scene
  63. * @{
  64. */
  65. /** A viewpoint from which the scene will be rendered.
  66. @remarks
  67. OGRE renders scenes from a camera viewpoint into a buffer of
  68. some sort, normally a window or a texture (a subclass of
  69. RenderTarget). OGRE cameras support both perspective projection (the default,
  70. meaning objects get smaller the further away they are) and
  71. orthographic projection (blueprint-style, no decrease in size
  72. with distance). Each camera carries with it a style of rendering,
  73. e.g. full textured, flat shaded, wireframe), field of view,
  74. rendering distances etc, allowing you to use OGRE to create
  75. complex multi-window views if required. In addition, more than
  76. one camera can point at a single render target if required,
  77. each rendering to a subset of the target, allowing split screen
  78. and picture-in-picture views.
  79. @par
  80. Cameras maintain their own aspect ratios, field of view, and frustum,
  81. and project co-ordinates into a space measured from -1 to 1 in x and y,
  82. and 0 to 1 in z. At render time, the camera will be rendering to a
  83. Viewport which will translate these parametric co-ordinates into real screen
  84. co-ordinates. Obviously it is advisable that the viewport has the same
  85. aspect ratio as the camera to avoid distortion (unless you want it!).
  86. @par
  87. Note that a Camera can be attached to a SceneNode, using the method
  88. SceneNode::attachObject. If this is done the Camera will combine it's own
  89. position/orientation settings with it's parent SceneNode.
  90. This is useful for implementing more complex Camera / object
  91. relationships i.e. having a camera attached to a world object.
  92. */
  93. class CM_EXPORT Camera : public Component
  94. {
  95. protected:
  96. /// Orthographic or perspective?
  97. ProjectionType mProjType;
  98. /// y-direction field-of-view (default 45)
  99. Radian mFOVy;
  100. /// Far clip distance - default 10000
  101. float mFarDist;
  102. /// Near clip distance - default 100
  103. float mNearDist;
  104. /// x/y viewport ratio - default 1.3333
  105. float mAspect;
  106. /// Ortho height size (world units)
  107. float mOrthoHeight;
  108. /// Off-axis frustum center offset - default (0.0, 0.0)
  109. Vector2 mFrustumOffset;
  110. /// Focal length of frustum (for stereo rendering, defaults to 1.0)
  111. float mFocalLength;
  112. /// The 6 main clipping planes
  113. mutable Plane mFrustumPlanes[6];
  114. /// Stored versions of parent orientation / position
  115. mutable Quaternion mLastParentOrientation;
  116. mutable Vector3 mLastParentPosition;
  117. /// Pre-calced projection matrix for the specific render system
  118. mutable Matrix4 mProjMatrixRS;
  119. /// Pre-calced standard projection matrix but with render system depth range
  120. mutable Matrix4 mProjMatrixRSDepth;
  121. /// Pre-calced standard projection matrix
  122. mutable Matrix4 mProjMatrix;
  123. /// Pre-calced view matrix
  124. mutable Matrix4 mViewMatrix;
  125. /// Something's changed in the frustum shape?
  126. mutable bool mRecalcFrustum;
  127. /// Something re the frustum planes has changed
  128. mutable bool mRecalcFrustumPlanes;
  129. /// Something re the world space corners has changed
  130. mutable bool mRecalcWorldSpaceCorners;
  131. /// Something re the vertex data has changed
  132. mutable bool mRecalcVertexData;
  133. /// Are we using a custom view matrix?
  134. bool mCustomViewMatrix;
  135. /// Are we using a custom projection matrix?
  136. bool mCustomProjMatrix;
  137. /// Have the frustum extents been manually set?
  138. bool mFrustumExtentsManuallySet;
  139. /// Frustum extents
  140. mutable float mLeft, mRight, mTop, mBottom;
  141. // Internal functions for calcs
  142. virtual void calcProjectionParameters(float& left, float& right, float& bottom, float& top) const;
  143. /// Update frustum if out of date
  144. virtual void updateFrustum(void) const;
  145. /// Implementation of updateFrustum (called if out of date)
  146. virtual void updateFrustumImpl(void) const;
  147. virtual void updateFrustumPlanes(void) const;
  148. /// Implementation of updateFrustumPlanes (called if out of date)
  149. virtual void updateFrustumPlanesImpl(void) const;
  150. virtual void updateWorldSpaceCorners(void) const;
  151. /// Implementation of updateWorldSpaceCorners (called if out of date)
  152. virtual void updateWorldSpaceCornersImpl(void) const;
  153. virtual void updateView(void) const;
  154. virtual bool isFrustumOutOfDate(void) const;
  155. /// Signal to update frustum information.
  156. virtual void invalidateFrustum(void) const;
  157. mutable AxisAlignedBox mBoundingBox;
  158. mutable Vector3 mWorldSpaceCorners[8];
  159. public:
  160. /** Sets the Y-dimension Field Of View (FOV) of the frustum.
  161. @remarks
  162. Field Of View (FOV) is the angle made between the frustum's position, and the edges
  163. of the 'screen' onto which the scene is projected. High values (90+ degrees) result in a wide-angle,
  164. fish-eye kind of view, low values (30- degrees) in a stretched, telescopic kind of view. Typical values
  165. are between 45 and 60 degrees.
  166. @par
  167. This value represents the VERTICAL field-of-view. The horizontal field of view is calculated from
  168. this depending on the dimensions of the viewport (they will only be the same if the viewport is square).
  169. @note
  170. Setting the FOV overrides the value supplied for frustum::setNearClipPlane.
  171. */
  172. virtual void setFOVy(const Radian& fovy);
  173. /** Retrieves the frustums Y-dimension Field Of View (FOV).
  174. */
  175. virtual const Radian& getFOVy(void) const;
  176. /** Sets the position of the near clipping plane.
  177. @remarks
  178. The position of the near clipping plane is the distance from the frustums position to the screen
  179. on which the world is projected. The near plane distance, combined with the field-of-view and the
  180. aspect ratio, determines the size of the viewport through which the world is viewed (in world
  181. co-ordinates). Note that this world viewport is different to a screen viewport, which has it's
  182. dimensions expressed in pixels. The frustums viewport should have the same aspect ratio as the
  183. screen viewport it renders into to avoid distortion.
  184. @param
  185. near The distance to the near clipping plane from the frustum in world coordinates.
  186. */
  187. virtual void setNearClipDistance(float nearDist);
  188. /** Sets the position of the near clipping plane.
  189. */
  190. virtual float getNearClipDistance(void) const;
  191. /** Sets the distance to the far clipping plane.
  192. @remarks
  193. The view frustum is a pyramid created from the frustum position and the edges of the viewport.
  194. This method sets the distance for the far end of that pyramid.
  195. Different applications need different values: e.g. a flight sim
  196. needs a much further far clipping plane than a first-person
  197. shooter. An important point here is that the larger the ratio
  198. between near and far clipping planes, the lower the accuracy of
  199. the Z-buffer used to depth-cue pixels. This is because the
  200. Z-range is limited to the size of the Z buffer (16 or 32-bit)
  201. and the max values must be spread over the gap between near and
  202. far clip planes. As it happens, you can affect the accuracy far
  203. more by altering the near distance rather than the far distance,
  204. but keep this in mind.
  205. @param
  206. far The distance to the far clipping plane from the frustum in
  207. world coordinates.If you specify 0, this means an infinite view
  208. distance which is useful especially when projecting shadows; but
  209. be careful not to use a near distance too close.
  210. */
  211. virtual void setFarClipDistance(float farDist);
  212. /** Retrieves the distance from the frustum to the far clipping plane.
  213. */
  214. virtual float getFarClipDistance(void) const;
  215. /** Sets the aspect ratio for the frustum viewport.
  216. @remarks
  217. The ratio between the x and y dimensions of the rectangular area visible through the frustum
  218. is known as aspect ratio: aspect = width / height .
  219. @par
  220. The default for most fullscreen windows is 1.3333 - this is also assumed by Ogre unless you
  221. use this method to state otherwise.
  222. */
  223. virtual void setAspectRatio(float ratio);
  224. /** Retreives the current aspect ratio.
  225. */
  226. virtual float getAspectRatio(void) const;
  227. /** Sets frustum offsets, used in stereo rendering.
  228. @remarks
  229. You can set both horizontal and vertical plane offsets of "eye"; in
  230. stereo rendering frustum is moved in horizontal plane. To be able to
  231. render from two "eyes" you'll need two cameras rendering on two
  232. RenderTargets.
  233. @par
  234. The frustum offsets is in world coordinates, and default to (0, 0) - no offsets.
  235. @param
  236. offset The horizontal and vertical plane offsets.
  237. */
  238. virtual void setFrustumOffset(const Vector2& offset);
  239. /** Sets frustum offsets, used in stereo rendering.
  240. @remarks
  241. You can set both horizontal and vertical plane offsets of "eye"; in
  242. stereo rendering frustum is moved in horizontal plane. To be able to
  243. render from two "eyes" you'll need two cameras rendering on two
  244. RenderTargets.
  245. @par
  246. The frustum offsets is in world coordinates, and default to (0, 0) - no offsets.
  247. @param
  248. horizontal The horizontal plane offset.
  249. @param
  250. vertical The vertical plane offset.
  251. */
  252. virtual void setFrustumOffset(float horizontal = 0.0, float vertical = 0.0);
  253. /** Retrieves the frustum offsets.
  254. */
  255. virtual const Vector2& getFrustumOffset() const;
  256. /** Sets frustum focal length (used in stereo rendering).
  257. @param
  258. focalLength The distance to the focal plane from the frustum in world coordinates.
  259. */
  260. virtual void setFocalLength(float focalLength = 1.0);
  261. /** Returns focal length of frustum.
  262. */
  263. virtual float getFocalLength() const;
  264. /** Manually set the extents of the frustum.
  265. @param left, right, top, bottom The position where the side clip planes intersect
  266. the near clip plane, in eye space
  267. */
  268. virtual void setFrustumExtents(float left, float right, float top, float bottom);
  269. /** Reset the frustum extents to be automatically derived from other params. */
  270. virtual void resetFrustumExtents();
  271. /** Get the extents of the frustum in view space. */
  272. virtual void getFrustumExtents(float& outleft, float& outright, float& outtop, float& outbottom) const;
  273. /** Gets the projection matrix for this frustum adjusted for the current
  274. rendersystem specifics (may be right or left-handed, depth range
  275. may vary).
  276. @remarks
  277. This method retrieves the rendering-API dependent version of the projection
  278. matrix. If you want a 'typical' projection matrix then use
  279. getProjectionMatrix.
  280. */
  281. virtual const Matrix4& getProjectionMatrixRS(void) const;
  282. /** Gets the depth-adjusted projection matrix for the current rendersystem,
  283. but one which still conforms to right-hand rules.
  284. @remarks
  285. This differs from the rendering-API dependent getProjectionMatrix
  286. in that it always returns a right-handed projection matrix result
  287. no matter what rendering API is being used - this is required for
  288. vertex and fragment programs for example. However, the resulting depth
  289. range may still vary between render systems since D3D uses [0,1] and
  290. GL uses [-1,1], and the range must be kept the same between programmable
  291. and fixed-function pipelines.
  292. */
  293. virtual const Matrix4& getProjectionMatrixWithRSDepth(void) const;
  294. /** Gets the normal projection matrix for this frustum, ie the
  295. projection matrix which conforms to standard right-handed rules and
  296. uses depth range [-1,+1].
  297. @remarks
  298. This differs from the rendering-API dependent getProjectionMatrixRS
  299. in that it always returns a right-handed projection matrix with depth
  300. range [-1,+1], result no matter what rendering API is being used - this
  301. is required for some uniform algebra for example.
  302. */
  303. virtual const Matrix4& getProjectionMatrix(void) const;
  304. /** Gets the view matrix for this frustum. Mainly for use by OGRE internally.
  305. */
  306. virtual const Matrix4& getViewMatrix(void) const;
  307. /** Set whether to use a custom view matrix on this frustum.
  308. @remarks
  309. This is an advanced method which allows you to manually set
  310. the view matrix on this frustum, rather than having it calculate
  311. itself based on it's position and orientation.
  312. @note
  313. After enabling a custom view matrix, the frustum will no longer
  314. update on its own based on position / orientation changes. You
  315. are completely responsible for keeping the view matrix up to date.
  316. The custom matrix will be returned from getViewMatrix.
  317. @param enable If true, the custom view matrix passed as the second
  318. parameter will be used in preference to an auto calculated one. If
  319. false, the frustum will revert to auto calculating the view matrix.
  320. @param viewMatrix The custom view matrix to use, the matrix must be an
  321. affine matrix.
  322. @see Frustum::setCustomProjectionMatrix, Matrix4::isAffine
  323. */
  324. virtual void setCustomViewMatrix(bool enable,
  325. const Matrix4& viewMatrix = Matrix4::IDENTITY);
  326. /// Returns whether a custom view matrix is in use
  327. virtual bool isCustomViewMatrixEnabled(void) const
  328. { return mCustomViewMatrix; }
  329. /** Set whether to use a custom projection matrix on this frustum.
  330. @remarks
  331. This is an advanced method which allows you to manually set
  332. the projection matrix on this frustum, rather than having it
  333. calculate itself based on it's position and orientation.
  334. @note
  335. After enabling a custom projection matrix, the frustum will no
  336. longer update on its own based on field of view and near / far
  337. distance changes. You are completely responsible for keeping the
  338. projection matrix up to date if those values change. The custom
  339. matrix will be returned from getProjectionMatrix and derivative
  340. functions.
  341. @param enable If true, the custom projection matrix passed as the
  342. second parameter will be used in preference to an auto calculated
  343. one. If false, the frustum will revert to auto calculating the
  344. projection matrix.
  345. @param projectionMatrix The custom view matrix to use
  346. @see Frustum::setCustomViewMatrix
  347. */
  348. virtual void setCustomProjectionMatrix(bool enable,
  349. const Matrix4& projectionMatrix = Matrix4::IDENTITY);
  350. /// Returns whether a custom projection matrix is in use
  351. virtual bool isCustomProjectionMatrixEnabled(void) const
  352. { return mCustomProjMatrix; }
  353. /** Retrieves the clipping planes of the frustum (world space).
  354. @remarks
  355. The clipping planes are ordered as declared in enumerate constants FrustumPlane.
  356. */
  357. virtual const Plane* getFrustumPlanes(void) const;
  358. /** Retrieves a specified plane of the frustum (world space).
  359. @remarks
  360. Gets a reference to one of the planes which make up the frustum frustum, e.g. for clipping purposes.
  361. */
  362. virtual const Plane& getFrustumPlane( unsigned short plane ) const;
  363. /** Tests whether the given container is visible in the Frustum.
  364. @param
  365. bound Bounding box to be checked (world space)
  366. @param
  367. culledBy Optional pointer to an int which will be filled by the plane number which culled
  368. the box if the result was false;
  369. @returns
  370. If the box was visible, true is returned.
  371. @par
  372. Otherwise, false is returned.
  373. */
  374. virtual bool isVisible(const AxisAlignedBox& bound, FrustumPlane* culledBy = 0) const;
  375. /** Tests whether the given container is visible in the Frustum.
  376. @param
  377. bound Bounding sphere to be checked (world space)
  378. @param
  379. culledBy Optional pointer to an int which will be filled by the plane number which culled
  380. the box if the result was false;
  381. @returns
  382. If the sphere was visible, true is returned.
  383. @par
  384. Otherwise, false is returned.
  385. */
  386. virtual bool isVisible(const Sphere& bound, FrustumPlane* culledBy = 0) const;
  387. /** Tests whether the given vertex is visible in the Frustum.
  388. @param
  389. vert Vertex to be checked (world space)
  390. @param
  391. culledBy Optional pointer to an int which will be filled by the plane number which culled
  392. the box if the result was false;
  393. @returns
  394. If the box was visible, true is returned.
  395. @par
  396. Otherwise, false is returned.
  397. */
  398. virtual bool isVisible(const Vector3& vert, FrustumPlane* culledBy = 0) const;
  399. /** Overridden from MovableObject */
  400. const AxisAlignedBox& getBoundingBox(void) const;
  401. /** Overridden from MovableObject */
  402. float getBoundingRadius(void) const;
  403. /** Gets the world space corners of the frustum.
  404. @remarks
  405. The corners are ordered as follows: top-right near,
  406. top-left near, bottom-left near, bottom-right near,
  407. top-right far, top-left far, bottom-left far, bottom-right far.
  408. */
  409. virtual const Vector3* getWorldSpaceCorners(void) const;
  410. /** Sets the type of projection to use (orthographic or perspective). Default is perspective.
  411. */
  412. virtual void setProjectionType(ProjectionType pt);
  413. /** Retrieves info on the type of projection used (orthographic or perspective).
  414. */
  415. virtual ProjectionType getProjectionType(void) const;
  416. /** Sets the orthographic window settings, for use with orthographic rendering only.
  417. @note Calling this method will recalculate the aspect ratio, use
  418. setOrthoWindowHeight or setOrthoWindowWidth alone if you wish to
  419. preserve the aspect ratio but just fit one or other dimension to a
  420. particular size.
  421. @param w, h The dimensions of the view window in world units
  422. */
  423. virtual void setOrthoWindow(float w, float h);
  424. /** Sets the orthographic window height, for use with orthographic rendering only.
  425. @note The width of the window will be calculated from the aspect ratio.
  426. @param h The height of the view window in world units
  427. */
  428. virtual void setOrthoWindowHeight(float h);
  429. /** Sets the orthographic window width, for use with orthographic rendering only.
  430. @note The height of the window will be calculated from the aspect ratio.
  431. @param w The width of the view window in world units
  432. */
  433. virtual void setOrthoWindowWidth(float w);
  434. /** Gets the orthographic window height, for use with orthographic rendering only.
  435. */
  436. virtual float getOrthoWindowHeight() const;
  437. /** Gets the orthographic window width, for use with orthographic rendering only.
  438. @note This is calculated from the orthographic height and the aspect ratio
  439. */
  440. virtual float getOrthoWindowWidth() const;
  441. /** Project a sphere onto the near plane and get the bounding rectangle.
  442. @param sphere The world-space sphere to project
  443. @param radius Radius of the sphere
  444. @param left, top, right, bottom Pointers to destination values, these
  445. will be completed with the normalised device coordinates (in the
  446. range {-1,1})
  447. @returns true if the sphere was projected to a subset of the near plane,
  448. false if the entire near plane was contained
  449. */
  450. virtual bool projectSphere(const Sphere& sphere,
  451. float* left, float* top, float* right, float* bottom) const;
  452. /// Small constant used to reduce far plane projection to avoid inaccuracies
  453. static const float INFINITE_FAR_PLANE_ADJUST;
  454. protected:
  455. /// Rendering type
  456. PolygonMode mSceneDetail;
  457. /** Viewing window.
  458. @remarks
  459. Generalize camera class for the case, when viewing frustum doesn't cover all viewport.
  460. */
  461. float mWLeft, mWTop, mWRight, mWBottom;
  462. /// Is viewing window used.
  463. bool mWindowSet;
  464. /// Windowed viewport clip planes
  465. mutable vector<Plane>::type mWindowClipPlanes;
  466. // Was viewing window changed.
  467. mutable bool mRecalcWindow;
  468. /** Whether aspect ratio will automatically be recalculated
  469. when a viewport changes its size
  470. */
  471. bool mAutoAspectRatio;
  472. /// Whether or not the rendering distance of objects should take effect for this camera
  473. bool mUseRenderingDistance;
  474. Viewport* mViewport;
  475. /** Do actual window setting, using parameters set in SetWindow call
  476. @remarks
  477. The method will called on demand.
  478. */
  479. void setWindowImpl(void) const;
  480. /** Helper function for forwardIntersect that intersects rays with canonical plane */
  481. vector<Vector4>::type getRayForwardIntersect(const Vector3& anchor, const Vector3 *dir, float planeOffset) const;
  482. public:
  483. /** Standard destructor.
  484. */
  485. virtual ~Camera();
  486. void init(RenderTarget* target = nullptr,
  487. float left = 0.0f, float top = 0.0f,
  488. float width = 1.0f, float height = 1.0f,
  489. int ZOrder = 0);
  490. Viewport* getViewport() { return mViewport; }
  491. /** Sets the level of rendering detail required from this camera.
  492. @remarks
  493. Each camera is set to render at full detail by default, that is
  494. with full texturing, lighting etc. This method lets you change
  495. that behaviour, allowing you to make the camera just render a
  496. wireframe view, for example.
  497. */
  498. void setPolygonMode(PolygonMode sd);
  499. /** Retrieves the level of detail that the camera will render.
  500. */
  501. PolygonMode getPolygonMode(void) const;
  502. /** Tells the Camera to contact the SceneManager to render from it's viewpoint.
  503. @param vp The viewport to render to
  504. @param includeOverlays Whether or not any overlay objects should be included
  505. */
  506. void _renderScene(Viewport *vp, bool includeOverlays);
  507. /** Gets a world space ray as cast from the camera through a viewport position.
  508. @param screenx, screeny The x and y position at which the ray should intersect the viewport,
  509. in normalised screen coordinates [0,1]
  510. */
  511. Ray getCameraToViewportRay(float screenx, float screeny) const;
  512. /** Gets a world space ray as cast from the camera through a viewport position.
  513. @param screenx, screeny The x and y position at which the ray should intersect the viewport,
  514. in normalised screen coordinates [0,1]
  515. @param outRay Ray instance to populate with result
  516. */
  517. void getCameraToViewportRay(float screenx, float screeny, Ray* outRay) const;
  518. /** Sets the viewing window inside of viewport.
  519. @remarks
  520. This method can be used to set a subset of the viewport as the rendering
  521. target.
  522. @param Left Relative to Viewport - 0 corresponds to left edge, 1 - to right edge (default - 0).
  523. @param Top Relative to Viewport - 0 corresponds to top edge, 1 - to bottom edge (default - 0).
  524. @param Right Relative to Viewport - 0 corresponds to left edge, 1 - to right edge (default - 1).
  525. @param Bottom Relative to Viewport - 0 corresponds to top edge, 1 - to bottom edge (default - 1).
  526. */
  527. virtual void setWindow (float Left, float Top, float Right, float Bottom);
  528. /// Cancel view window.
  529. virtual void resetWindow (void);
  530. /// Returns if a viewport window is being used
  531. virtual bool isWindowSet(void) const { return mWindowSet; }
  532. /// Gets the window clip planes, only applicable if isWindowSet == true
  533. const vector<Plane>::type& getWindowPlanes(void) const;
  534. /** If set to true a viewport that owns this frustum will be able to
  535. recalculate the aspect ratio whenever the frustum is resized.
  536. @remarks
  537. You should set this to true only if the frustum / camera is used by
  538. one viewport at the same time. Otherwise the aspect ratio for other
  539. viewports may be wrong.
  540. */
  541. void setAutoAspectRatio(bool autoratio);
  542. /** Retrieves if AutoAspectRatio is currently set or not
  543. */
  544. bool getAutoAspectRatio(void) const;
  545. /** Forward projects frustum rays to find forward intersection with plane.
  546. @remarks
  547. Forward projection may lead to intersections at infinity.
  548. */
  549. void forwardIntersect(const Plane& worldPlane, vector<Vector4>::type* intersect3d) const;
  550. /************************************************************************/
  551. /* COMPONENT OVERRIDES */
  552. /************************************************************************/
  553. private:
  554. friend class GameObject;
  555. /** Standard constructor.
  556. */
  557. Camera(GameObjectPtr parent);
  558. public:
  559. virtual void update() {}
  560. /************************************************************************/
  561. /* RTTI */
  562. /************************************************************************/
  563. public:
  564. friend class CameraRTTI;
  565. static RTTITypeBase* getRTTIStatic();
  566. virtual RTTITypeBase* getRTTI() const;
  567. protected:
  568. Camera() {} // Serialization only
  569. };
  570. /** @} */
  571. /** @} */
  572. } // namespace CamelotEngine
  573. #endif