[148] | 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 | |
---|
| 7 | Copyright (c) 2000-2013 Torus Knot Software Ltd |
---|
| 8 | |
---|
| 9 | Permission is hereby granted, free of charge, to any person obtaining a copy |
---|
| 10 | of this software and associated documentation files (the "Software"), to deal |
---|
| 11 | in the Software without restriction, including without limitation the rights |
---|
| 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
---|
| 13 | copies of the Software, and to permit persons to whom the Software is |
---|
| 14 | furnished to do so, subject to the following conditions: |
---|
| 15 | |
---|
| 16 | The above copyright notice and this permission notice shall be included in |
---|
| 17 | all copies or substantial portions of the Software. |
---|
| 18 | |
---|
| 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
| 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
| 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
---|
| 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
| 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
---|
| 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
---|
| 25 | THE SOFTWARE. |
---|
| 26 | ----------------------------------------------------------------------------- |
---|
| 27 | */ |
---|
| 28 | #ifndef __Frustum_H__ |
---|
| 29 | #define __Frustum_H__ |
---|
| 30 | |
---|
| 31 | #include "OgrePrerequisites.h" |
---|
| 32 | #include "OgreMovableObject.h" |
---|
| 33 | #include "OgreRenderable.h" |
---|
| 34 | #include "OgreAxisAlignedBox.h" |
---|
| 35 | #include "OgreVertexIndexData.h" |
---|
| 36 | #include "OgreMovablePlane.h" |
---|
| 37 | #include "OgreHeaderPrefix.h" |
---|
| 38 | |
---|
| 39 | namespace Ogre |
---|
| 40 | { |
---|
| 41 | /** \addtogroup Core |
---|
| 42 | * @{ |
---|
| 43 | */ |
---|
| 44 | /** \addtogroup Math |
---|
| 45 | * @{ |
---|
| 46 | */ |
---|
| 47 | /** Specifies orientation mode. |
---|
| 48 | */ |
---|
| 49 | enum OrientationMode |
---|
| 50 | { |
---|
| 51 | OR_DEGREE_0 = 0, |
---|
| 52 | OR_DEGREE_90 = 1, |
---|
| 53 | OR_DEGREE_180 = 2, |
---|
| 54 | OR_DEGREE_270 = 3, |
---|
| 55 | |
---|
| 56 | OR_PORTRAIT = OR_DEGREE_0, |
---|
| 57 | OR_LANDSCAPERIGHT = OR_DEGREE_90, |
---|
| 58 | OR_LANDSCAPELEFT = OR_DEGREE_270 |
---|
| 59 | }; |
---|
| 60 | |
---|
| 61 | /** Specifies perspective (realistic) or orthographic (architectural) projection. |
---|
| 62 | */ |
---|
| 63 | enum ProjectionType |
---|
| 64 | { |
---|
| 65 | PT_ORTHOGRAPHIC, |
---|
| 66 | PT_PERSPECTIVE |
---|
| 67 | }; |
---|
| 68 | |
---|
| 69 | /** Worldspace clipping planes. |
---|
| 70 | */ |
---|
| 71 | enum FrustumPlane |
---|
| 72 | { |
---|
| 73 | FRUSTUM_PLANE_NEAR = 0, |
---|
| 74 | FRUSTUM_PLANE_FAR = 1, |
---|
| 75 | FRUSTUM_PLANE_LEFT = 2, |
---|
| 76 | FRUSTUM_PLANE_RIGHT = 3, |
---|
| 77 | FRUSTUM_PLANE_TOP = 4, |
---|
| 78 | FRUSTUM_PLANE_BOTTOM = 5 |
---|
| 79 | }; |
---|
| 80 | |
---|
| 81 | /** A frustum represents a pyramid, capped at the near and far end which is |
---|
| 82 | used to represent either a visible area or a projection area. Can be used |
---|
| 83 | for a number of applications. |
---|
| 84 | */ |
---|
| 85 | class _OgreExport Frustum : public MovableObject, public Renderable |
---|
| 86 | { |
---|
| 87 | protected: |
---|
| 88 | /// Orthographic or perspective? |
---|
| 89 | ProjectionType mProjType; |
---|
| 90 | |
---|
| 91 | /// y-direction field-of-view (default 45) |
---|
| 92 | Radian mFOVy; |
---|
| 93 | /// Far clip distance - default 10000 |
---|
| 94 | Real mFarDist; |
---|
| 95 | /// Near clip distance - default 100 |
---|
| 96 | Real mNearDist; |
---|
| 97 | /// x/y viewport ratio - default 1.3333 |
---|
| 98 | Real mAspect; |
---|
| 99 | /// Ortho height size (world units) |
---|
| 100 | Real mOrthoHeight; |
---|
| 101 | /// Off-axis frustum center offset - default (0.0, 0.0) |
---|
| 102 | Vector2 mFrustumOffset; |
---|
| 103 | /// Focal length of frustum (for stereo rendering, defaults to 1.0) |
---|
| 104 | Real mFocalLength; |
---|
| 105 | |
---|
| 106 | /// The 6 main clipping planes |
---|
| 107 | mutable Plane mFrustumPlanes[6]; |
---|
| 108 | |
---|
| 109 | /// Stored versions of parent orientation / position |
---|
| 110 | mutable Quaternion mLastParentOrientation; |
---|
| 111 | mutable Vector3 mLastParentPosition; |
---|
| 112 | |
---|
| 113 | /// Pre-calced projection matrix for the specific render system |
---|
| 114 | mutable Matrix4 mProjMatrixRS; |
---|
| 115 | /// Pre-calced standard projection matrix but with render system depth range |
---|
| 116 | mutable Matrix4 mProjMatrixRSDepth; |
---|
| 117 | /// Pre-calced standard projection matrix |
---|
| 118 | mutable Matrix4 mProjMatrix; |
---|
| 119 | /// Pre-calced view matrix |
---|
| 120 | mutable Matrix4 mViewMatrix; |
---|
| 121 | /// Something's changed in the frustum shape? |
---|
| 122 | mutable bool mRecalcFrustum; |
---|
| 123 | /// Something re the view pos has changed |
---|
| 124 | mutable bool mRecalcView; |
---|
| 125 | /// Something re the frustum planes has changed |
---|
| 126 | mutable bool mRecalcFrustumPlanes; |
---|
| 127 | /// Something re the world space corners has changed |
---|
| 128 | mutable bool mRecalcWorldSpaceCorners; |
---|
| 129 | /// Something re the vertex data has changed |
---|
| 130 | mutable bool mRecalcVertexData; |
---|
| 131 | /// Are we using a custom view matrix? |
---|
| 132 | bool mCustomViewMatrix; |
---|
| 133 | /// Are we using a custom projection matrix? |
---|
| 134 | bool mCustomProjMatrix; |
---|
| 135 | /// Have the frustum extents been manually set? |
---|
| 136 | bool mFrustumExtentsManuallySet; |
---|
| 137 | /// Frustum extents |
---|
| 138 | mutable Real mLeft, mRight, mTop, mBottom; |
---|
| 139 | /// Frustum orientation mode |
---|
| 140 | mutable OrientationMode mOrientationMode; |
---|
| 141 | |
---|
| 142 | // Internal functions for calcs |
---|
| 143 | virtual void calcProjectionParameters(Real& left, Real& right, Real& bottom, Real& top) const; |
---|
| 144 | /// Update frustum if out of date |
---|
| 145 | virtual void updateFrustum(void) const; |
---|
| 146 | /// Update view if out of date |
---|
| 147 | virtual void updateView(void) const; |
---|
| 148 | /// Implementation of updateFrustum (called if out of date) |
---|
| 149 | virtual void updateFrustumImpl(void) const; |
---|
| 150 | /// Implementation of updateView (called if out of date) |
---|
| 151 | virtual void updateViewImpl(void) const; |
---|
| 152 | virtual void updateFrustumPlanes(void) const; |
---|
| 153 | /// Implementation of updateFrustumPlanes (called if out of date) |
---|
| 154 | virtual void updateFrustumPlanesImpl(void) const; |
---|
| 155 | virtual void updateWorldSpaceCorners(void) const; |
---|
| 156 | /// Implementation of updateWorldSpaceCorners (called if out of date) |
---|
| 157 | virtual void updateWorldSpaceCornersImpl(void) const; |
---|
| 158 | virtual void updateVertexData(void) const; |
---|
| 159 | virtual bool isViewOutOfDate(void) const; |
---|
| 160 | virtual bool isFrustumOutOfDate(void) const; |
---|
| 161 | /// Signal to update frustum information. |
---|
| 162 | virtual void invalidateFrustum(void) const; |
---|
| 163 | /// Signal to update view information. |
---|
| 164 | virtual void invalidateView(void) const; |
---|
| 165 | |
---|
| 166 | /// Shared class-level name for Movable type |
---|
| 167 | static String msMovableType; |
---|
| 168 | |
---|
| 169 | mutable AxisAlignedBox mBoundingBox; |
---|
| 170 | mutable VertexData mVertexData; |
---|
| 171 | |
---|
| 172 | MaterialPtr mMaterial; |
---|
| 173 | mutable Vector3 mWorldSpaceCorners[8]; |
---|
| 174 | |
---|
| 175 | /// Is this frustum to act as a reflection of itself? |
---|
| 176 | bool mReflect; |
---|
| 177 | /// Derived reflection matrix |
---|
| 178 | mutable Matrix4 mReflectMatrix; |
---|
| 179 | /// Fixed reflection plane |
---|
| 180 | mutable Plane mReflectPlane; |
---|
| 181 | /// Pointer to a reflection plane (automatically updated) |
---|
| 182 | const MovablePlane* mLinkedReflectPlane; |
---|
| 183 | /// Record of the last world-space reflection plane info used |
---|
| 184 | mutable Plane mLastLinkedReflectionPlane; |
---|
| 185 | |
---|
| 186 | /// Is this frustum using an oblique depth projection? |
---|
| 187 | bool mObliqueDepthProjection; |
---|
| 188 | /// Fixed oblique projection plane |
---|
| 189 | mutable Plane mObliqueProjPlane; |
---|
| 190 | /// Pointer to oblique projection plane (automatically updated) |
---|
| 191 | const MovablePlane* mLinkedObliqueProjPlane; |
---|
| 192 | /// Record of the last world-space oblique depth projection plane info used |
---|
| 193 | mutable Plane mLastLinkedObliqueProjPlane; |
---|
| 194 | |
---|
| 195 | public: |
---|
| 196 | |
---|
| 197 | /// Named constructor |
---|
| 198 | Frustum(const String& name = StringUtil::BLANK); |
---|
| 199 | |
---|
| 200 | virtual ~Frustum(); |
---|
| 201 | /** Sets the Y-dimension Field Of View (FOV) of the frustum. |
---|
| 202 | @remarks |
---|
| 203 | Field Of View (FOV) is the angle made between the frustum's position, and the edges |
---|
| 204 | of the 'screen' onto which the scene is projected. High values (90+ degrees) result in a wide-angle, |
---|
| 205 | fish-eye kind of view, low values (30- degrees) in a stretched, telescopic kind of view. Typical values |
---|
| 206 | are between 45 and 60 degrees. |
---|
| 207 | @par |
---|
| 208 | This value represents the VERTICAL field-of-view. The horizontal field of view is calculated from |
---|
| 209 | this depending on the dimensions of the viewport (they will only be the same if the viewport is square). |
---|
| 210 | @note |
---|
| 211 | Setting the FOV overrides the value supplied for frustum::setNearClipPlane. |
---|
| 212 | */ |
---|
| 213 | virtual void setFOVy(const Radian& fovy); |
---|
| 214 | |
---|
| 215 | /** Retrieves the frustums Y-dimension Field Of View (FOV). |
---|
| 216 | */ |
---|
| 217 | virtual const Radian& getFOVy(void) const; |
---|
| 218 | |
---|
| 219 | /** Sets the position of the near clipping plane. |
---|
| 220 | @remarks |
---|
| 221 | The position of the near clipping plane is the distance from the frustums position to the screen |
---|
| 222 | on which the world is projected. The near plane distance, combined with the field-of-view and the |
---|
| 223 | aspect ratio, determines the size of the viewport through which the world is viewed (in world |
---|
| 224 | co-ordinates). Note that this world viewport is different to a screen viewport, which has it's |
---|
| 225 | dimensions expressed in pixels. The frustums viewport should have the same aspect ratio as the |
---|
| 226 | screen viewport it renders into to avoid distortion. |
---|
| 227 | @param nearDist |
---|
| 228 | The distance to the near clipping plane from the frustum in world coordinates. |
---|
| 229 | */ |
---|
| 230 | virtual void setNearClipDistance(Real nearDist); |
---|
| 231 | |
---|
| 232 | /** Sets the position of the near clipping plane. |
---|
| 233 | */ |
---|
| 234 | virtual Real getNearClipDistance(void) const; |
---|
| 235 | |
---|
| 236 | /** Sets the distance to the far clipping plane. |
---|
| 237 | @remarks |
---|
| 238 | The view frustum is a pyramid created from the frustum position and the edges of the viewport. |
---|
| 239 | This method sets the distance for the far end of that pyramid. |
---|
| 240 | Different applications need different values: e.g. a flight sim |
---|
| 241 | needs a much further far clipping plane than a first-person |
---|
| 242 | shooter. An important point here is that the larger the ratio |
---|
| 243 | between near and far clipping planes, the lower the accuracy of |
---|
| 244 | the Z-buffer used to depth-cue pixels. This is because the |
---|
| 245 | Z-range is limited to the size of the Z buffer (16 or 32-bit) |
---|
| 246 | and the max values must be spread over the gap between near and |
---|
| 247 | far clip planes. As it happens, you can affect the accuracy far |
---|
| 248 | more by altering the near distance rather than the far distance, |
---|
| 249 | but keep this in mind. |
---|
| 250 | @param farDist |
---|
| 251 | The distance to the far clipping plane from the frustum in |
---|
| 252 | world coordinates.If you specify 0, this means an infinite view |
---|
| 253 | distance which is useful especially when projecting shadows; but |
---|
| 254 | be careful not to use a near distance too close. |
---|
| 255 | */ |
---|
| 256 | virtual void setFarClipDistance(Real farDist); |
---|
| 257 | |
---|
| 258 | /** Retrieves the distance from the frustum to the far clipping plane. |
---|
| 259 | */ |
---|
| 260 | virtual Real getFarClipDistance(void) const; |
---|
| 261 | |
---|
| 262 | /** Sets the aspect ratio for the frustum viewport. |
---|
| 263 | @remarks |
---|
| 264 | The ratio between the x and y dimensions of the rectangular area visible through the frustum |
---|
| 265 | is known as aspect ratio: aspect = width / height . |
---|
| 266 | @par |
---|
| 267 | The default for most fullscreen windows is 1.3333 - this is also assumed by Ogre unless you |
---|
| 268 | use this method to state otherwise. |
---|
| 269 | */ |
---|
| 270 | virtual void setAspectRatio(Real ratio); |
---|
| 271 | |
---|
| 272 | /** Retrieves the current aspect ratio. |
---|
| 273 | */ |
---|
| 274 | virtual Real getAspectRatio(void) const; |
---|
| 275 | |
---|
| 276 | /** Sets frustum offsets, used in stereo rendering. |
---|
| 277 | @remarks |
---|
| 278 | You can set both horizontal and vertical plane offsets of "eye"; in |
---|
| 279 | stereo rendering frustum is moved in horizontal plane. To be able to |
---|
| 280 | render from two "eyes" you'll need two cameras rendering on two |
---|
| 281 | RenderTargets. |
---|
| 282 | @par |
---|
| 283 | The frustum offsets is in world coordinates, and default to (0, 0) - no offsets. |
---|
| 284 | @param offset |
---|
| 285 | The horizontal and vertical plane offsets. |
---|
| 286 | */ |
---|
| 287 | virtual void setFrustumOffset(const Vector2& offset); |
---|
| 288 | |
---|
| 289 | /** Sets frustum offsets, used in stereo rendering. |
---|
| 290 | @remarks |
---|
| 291 | You can set both horizontal and vertical plane offsets of "eye"; in |
---|
| 292 | stereo rendering frustum is moved in horizontal plane. To be able to |
---|
| 293 | render from two "eyes" you'll need two cameras rendering on two |
---|
| 294 | RenderTargets. |
---|
| 295 | @par |
---|
| 296 | The frustum offsets is in world coordinates, and default to (0, 0) - no offsets. |
---|
| 297 | @param horizontal |
---|
| 298 | The horizontal plane offset. |
---|
| 299 | @param vertical |
---|
| 300 | The vertical plane offset. |
---|
| 301 | */ |
---|
| 302 | virtual void setFrustumOffset(Real horizontal = 0.0, Real vertical = 0.0); |
---|
| 303 | |
---|
| 304 | /** Retrieves the frustum offsets. |
---|
| 305 | */ |
---|
| 306 | virtual const Vector2& getFrustumOffset() const; |
---|
| 307 | |
---|
| 308 | /** Sets frustum focal length (used in stereo rendering). |
---|
| 309 | @param focalLength |
---|
| 310 | The distance to the focal plane from the frustum in world coordinates. |
---|
| 311 | */ |
---|
| 312 | virtual void setFocalLength(Real focalLength = 1.0); |
---|
| 313 | |
---|
| 314 | /** Returns focal length of frustum. |
---|
| 315 | */ |
---|
| 316 | virtual Real getFocalLength() const; |
---|
| 317 | |
---|
| 318 | /** Manually set the extents of the frustum. |
---|
| 319 | @param left, right, top, bottom The position where the side clip planes intersect |
---|
| 320 | the near clip plane, in eye space |
---|
| 321 | */ |
---|
| 322 | virtual void setFrustumExtents(Real left, Real right, Real top, Real bottom); |
---|
| 323 | /** Reset the frustum extents to be automatically derived from other params. */ |
---|
| 324 | virtual void resetFrustumExtents(); |
---|
| 325 | /** Get the extents of the frustum in view space. */ |
---|
| 326 | virtual void getFrustumExtents(Real& outleft, Real& outright, Real& outtop, Real& outbottom) const; |
---|
| 327 | |
---|
| 328 | |
---|
| 329 | /** Gets the projection matrix for this frustum adjusted for the current |
---|
| 330 | rendersystem specifics (may be right or left-handed, depth range |
---|
| 331 | may vary). |
---|
| 332 | @remarks |
---|
| 333 | This method retrieves the rendering-API dependent version of the projection |
---|
| 334 | matrix. If you want a 'typical' projection matrix then use |
---|
| 335 | getProjectionMatrix. |
---|
| 336 | */ |
---|
| 337 | virtual const Matrix4& getProjectionMatrixRS(void) const; |
---|
| 338 | /** Gets the depth-adjusted projection matrix for the current rendersystem, |
---|
| 339 | but one which still conforms to right-hand rules. |
---|
| 340 | @remarks |
---|
| 341 | This differs from the rendering-API dependent getProjectionMatrix |
---|
| 342 | in that it always returns a right-handed projection matrix result |
---|
| 343 | no matter what rendering API is being used - this is required for |
---|
| 344 | vertex and fragment programs for example. However, the resulting depth |
---|
| 345 | range may still vary between render systems since D3D uses [0,1] and |
---|
| 346 | GL uses [-1,1], and the range must be kept the same between programmable |
---|
| 347 | and fixed-function pipelines. |
---|
| 348 | */ |
---|
| 349 | virtual const Matrix4& getProjectionMatrixWithRSDepth(void) const; |
---|
| 350 | /** Gets the normal projection matrix for this frustum, ie the |
---|
| 351 | projection matrix which conforms to standard right-handed rules and |
---|
| 352 | uses depth range [-1,+1]. |
---|
| 353 | @remarks |
---|
| 354 | This differs from the rendering-API dependent getProjectionMatrixRS |
---|
| 355 | in that it always returns a right-handed projection matrix with depth |
---|
| 356 | range [-1,+1], result no matter what rendering API is being used - this |
---|
| 357 | is required for some uniform algebra for example. |
---|
| 358 | */ |
---|
| 359 | virtual const Matrix4& getProjectionMatrix(void) const; |
---|
| 360 | |
---|
| 361 | /** Gets the view matrix for this frustum. Mainly for use by OGRE internally. |
---|
| 362 | */ |
---|
| 363 | virtual const Matrix4& getViewMatrix(void) const; |
---|
| 364 | |
---|
| 365 | /** Calculate a view matrix for this frustum, relative to a potentially dynamic point. |
---|
| 366 | Mainly for use by OGRE internally when using camera-relative rendering |
---|
| 367 | for frustums that are not the centre (e.g. texture projection) |
---|
| 368 | */ |
---|
| 369 | virtual void calcViewMatrixRelative(const Vector3& relPos, Matrix4& matToUpdate) const; |
---|
| 370 | |
---|
| 371 | /** Set whether to use a custom view matrix on this frustum. |
---|
| 372 | @remarks |
---|
| 373 | This is an advanced method which allows you to manually set |
---|
| 374 | the view matrix on this frustum, rather than having it calculate |
---|
| 375 | itself based on it's position and orientation. |
---|
| 376 | @note |
---|
| 377 | After enabling a custom view matrix, the frustum will no longer |
---|
| 378 | update on its own based on position / orientation changes. You |
---|
| 379 | are completely responsible for keeping the view matrix up to date. |
---|
| 380 | The custom matrix will be returned from getViewMatrix. |
---|
| 381 | @param enable If @c true, the custom view matrix passed as the second |
---|
| 382 | parameter will be used in preference to an auto calculated one. If |
---|
| 383 | false, the frustum will revert to auto calculating the view matrix. |
---|
| 384 | @param viewMatrix The custom view matrix to use, the matrix must be an |
---|
| 385 | affine matrix. |
---|
| 386 | @see Frustum::setCustomProjectionMatrix, Matrix4::isAffine |
---|
| 387 | */ |
---|
| 388 | virtual void setCustomViewMatrix(bool enable, |
---|
| 389 | const Matrix4& viewMatrix = Matrix4::IDENTITY); |
---|
| 390 | /// Returns whether a custom view matrix is in use |
---|
| 391 | virtual bool isCustomViewMatrixEnabled(void) const |
---|
| 392 | { return mCustomViewMatrix; } |
---|
| 393 | |
---|
| 394 | /** Set whether to use a custom projection matrix on this frustum. |
---|
| 395 | @remarks |
---|
| 396 | This is an advanced method which allows you to manually set |
---|
| 397 | the projection matrix on this frustum, rather than having it |
---|
| 398 | calculate itself based on it's position and orientation. |
---|
| 399 | @note |
---|
| 400 | After enabling a custom projection matrix, the frustum will no |
---|
| 401 | longer update on its own based on field of view and near / far |
---|
| 402 | distance changes. You are completely responsible for keeping the |
---|
| 403 | projection matrix up to date if those values change. The custom |
---|
| 404 | matrix will be returned from getProjectionMatrix and derivative |
---|
| 405 | functions. |
---|
| 406 | @param enable |
---|
| 407 | If @c true, the custom projection matrix passed as the |
---|
| 408 | second parameter will be used in preference to an auto calculated |
---|
| 409 | one. If @c false, the frustum will revert to auto calculating the |
---|
| 410 | projection matrix. |
---|
| 411 | @param projectionMatrix |
---|
| 412 | The custom view matrix to use. |
---|
| 413 | @see Frustum::setCustomViewMatrix |
---|
| 414 | */ |
---|
| 415 | virtual void setCustomProjectionMatrix(bool enable, |
---|
| 416 | const Matrix4& projectionMatrix = Matrix4::IDENTITY); |
---|
| 417 | /// Returns whether a custom projection matrix is in use |
---|
| 418 | virtual bool isCustomProjectionMatrixEnabled(void) const |
---|
| 419 | { return mCustomProjMatrix; } |
---|
| 420 | |
---|
| 421 | /** Retrieves the clipping planes of the frustum (world space). |
---|
| 422 | @remarks |
---|
| 423 | The clipping planes are ordered as declared in enumerate constants FrustumPlane. |
---|
| 424 | */ |
---|
| 425 | virtual const Plane* getFrustumPlanes(void) const; |
---|
| 426 | |
---|
| 427 | /** Retrieves a specified plane of the frustum (world space). |
---|
| 428 | @remarks |
---|
| 429 | Gets a reference to one of the planes which make up the frustum frustum, e.g. for clipping purposes. |
---|
| 430 | */ |
---|
| 431 | virtual const Plane& getFrustumPlane( unsigned short plane ) const; |
---|
| 432 | |
---|
| 433 | /** Tests whether the given container is visible in the Frustum. |
---|
| 434 | @param bound |
---|
| 435 | Bounding box to be checked (world space). |
---|
| 436 | @param culledBy |
---|
| 437 | Optional pointer to an int which will be filled by the plane number which culled |
---|
| 438 | the box if the result was @c false; |
---|
| 439 | @return |
---|
| 440 | If the box was visible, @c true is returned. |
---|
| 441 | @par |
---|
| 442 | Otherwise, @c false is returned. |
---|
| 443 | */ |
---|
| 444 | virtual bool isVisible(const AxisAlignedBox& bound, FrustumPlane* culledBy = 0) const; |
---|
| 445 | |
---|
| 446 | /** Tests whether the given container is visible in the Frustum. |
---|
| 447 | @param bound |
---|
| 448 | Bounding sphere to be checked (world space). |
---|
| 449 | @param culledBy |
---|
| 450 | Optional pointer to an int which will be filled by the plane number which culled |
---|
| 451 | the box if the result was @c false; |
---|
| 452 | @return |
---|
| 453 | If the sphere was visible, @c true is returned. |
---|
| 454 | @par |
---|
| 455 | Otherwise, @c false is returned. |
---|
| 456 | */ |
---|
| 457 | virtual bool isVisible(const Sphere& bound, FrustumPlane* culledBy = 0) const; |
---|
| 458 | |
---|
| 459 | /** Tests whether the given vertex is visible in the Frustum. |
---|
| 460 | @param vert |
---|
| 461 | Vertex to be checked (world space). |
---|
| 462 | @param culledBy |
---|
| 463 | Optional pointer to an int which will be filled by the plane number which culled |
---|
| 464 | the box if the result was @c false; |
---|
| 465 | @return |
---|
| 466 | If the sphere was visible, @c true is returned. |
---|
| 467 | @par |
---|
| 468 | Otherwise, @c false is returned. |
---|
| 469 | */ |
---|
| 470 | virtual bool isVisible(const Vector3& vert, FrustumPlane* culledBy = 0) const; |
---|
| 471 | |
---|
| 472 | /// Overridden from MovableObject::getTypeFlags |
---|
| 473 | uint32 getTypeFlags(void) const; |
---|
| 474 | |
---|
| 475 | /** Overridden from MovableObject */ |
---|
| 476 | const AxisAlignedBox& getBoundingBox(void) const; |
---|
| 477 | |
---|
| 478 | /** Overridden from MovableObject */ |
---|
| 479 | Real getBoundingRadius(void) const; |
---|
| 480 | |
---|
| 481 | /** Overridden from MovableObject */ |
---|
| 482 | void _updateRenderQueue(RenderQueue* queue); |
---|
| 483 | |
---|
| 484 | /** Overridden from MovableObject */ |
---|
| 485 | const String& getMovableType(void) const; |
---|
| 486 | |
---|
| 487 | /** Overridden from MovableObject */ |
---|
| 488 | void _notifyCurrentCamera(Camera* cam); |
---|
| 489 | |
---|
| 490 | /** Overridden from Renderable */ |
---|
| 491 | const MaterialPtr& getMaterial(void) const; |
---|
| 492 | |
---|
| 493 | /** Overridden from Renderable */ |
---|
| 494 | void getRenderOperation(RenderOperation& op); |
---|
| 495 | |
---|
| 496 | /** Overridden from Renderable */ |
---|
| 497 | void getWorldTransforms(Matrix4* xform) const; |
---|
| 498 | |
---|
| 499 | /** Overridden from Renderable */ |
---|
| 500 | Real getSquaredViewDepth(const Camera* cam) const; |
---|
| 501 | |
---|
| 502 | /** Overridden from Renderable */ |
---|
| 503 | const LightList& getLights(void) const; |
---|
| 504 | |
---|
| 505 | /** Gets the world space corners of the frustum. |
---|
| 506 | @remarks |
---|
| 507 | The corners are ordered as follows: top-right near, |
---|
| 508 | top-left near, bottom-left near, bottom-right near, |
---|
| 509 | top-right far, top-left far, bottom-left far, bottom-right far. |
---|
| 510 | */ |
---|
| 511 | virtual const Vector3* getWorldSpaceCorners(void) const; |
---|
| 512 | |
---|
| 513 | /** Sets the type of projection to use (orthographic or perspective). Default is perspective. |
---|
| 514 | */ |
---|
| 515 | virtual void setProjectionType(ProjectionType pt); |
---|
| 516 | |
---|
| 517 | /** Retrieves info on the type of projection used (orthographic or perspective). |
---|
| 518 | */ |
---|
| 519 | virtual ProjectionType getProjectionType(void) const; |
---|
| 520 | |
---|
| 521 | /** Sets the orthographic window settings, for use with orthographic rendering only. |
---|
| 522 | @note Calling this method will recalculate the aspect ratio, use |
---|
| 523 | setOrthoWindowHeight or setOrthoWindowWidth alone if you wish to |
---|
| 524 | preserve the aspect ratio but just fit one or other dimension to a |
---|
| 525 | particular size. |
---|
| 526 | @param w |
---|
| 527 | The width of the view window in world units. |
---|
| 528 | @param h |
---|
| 529 | The height of the view window in world units. |
---|
| 530 | */ |
---|
| 531 | virtual void setOrthoWindow(Real w, Real h); |
---|
| 532 | /** Sets the orthographic window height, for use with orthographic rendering only. |
---|
| 533 | @note The width of the window will be calculated from the aspect ratio. |
---|
| 534 | @param h |
---|
| 535 | The height of the view window in world units. |
---|
| 536 | */ |
---|
| 537 | virtual void setOrthoWindowHeight(Real h); |
---|
| 538 | /** Sets the orthographic window width, for use with orthographic rendering only. |
---|
| 539 | @note The height of the window will be calculated from the aspect ratio. |
---|
| 540 | @param w |
---|
| 541 | The width of the view window in world units. |
---|
| 542 | */ |
---|
| 543 | virtual void setOrthoWindowWidth(Real w); |
---|
| 544 | /** Gets the orthographic window height, for use with orthographic rendering only. |
---|
| 545 | */ |
---|
| 546 | virtual Real getOrthoWindowHeight() const; |
---|
| 547 | /** Gets the orthographic window width, for use with orthographic rendering only. |
---|
| 548 | @note This is calculated from the orthographic height and the aspect ratio |
---|
| 549 | */ |
---|
| 550 | virtual Real getOrthoWindowWidth() const; |
---|
| 551 | |
---|
| 552 | /** Modifies this frustum so it always renders from the reflection of itself through the |
---|
| 553 | plane specified. |
---|
| 554 | @remarks |
---|
| 555 | This is obviously useful for performing planar reflections. |
---|
| 556 | */ |
---|
| 557 | virtual void enableReflection(const Plane& p); |
---|
| 558 | /** Modifies this frustum so it always renders from the reflection of itself through the |
---|
| 559 | plane specified. Note that this version of the method links to a plane |
---|
| 560 | so that changes to it are picked up automatically. It is important that |
---|
| 561 | this plane continues to exist whilst this object does; do not destroy |
---|
| 562 | the plane before the frustum. |
---|
| 563 | @remarks |
---|
| 564 | This is obviously useful for performing planar reflections. |
---|
| 565 | */ |
---|
| 566 | virtual void enableReflection(const MovablePlane* p); |
---|
| 567 | |
---|
| 568 | /** Disables reflection modification previously turned on with enableReflection */ |
---|
| 569 | virtual void disableReflection(void); |
---|
| 570 | |
---|
| 571 | /// Returns whether this frustum is being reflected |
---|
| 572 | virtual bool isReflected(void) const { return mReflect; } |
---|
| 573 | /// Returns the reflection matrix of the frustum if appropriate |
---|
| 574 | virtual const Matrix4& getReflectionMatrix(void) const { return mReflectMatrix; } |
---|
| 575 | /// Returns the reflection plane of the frustum if appropriate |
---|
| 576 | virtual const Plane& getReflectionPlane(void) const { return mReflectPlane; } |
---|
| 577 | |
---|
| 578 | /** Project a sphere onto the near plane and get the bounding rectangle. |
---|
| 579 | @param sphere The world-space sphere to project. |
---|
| 580 | @param left |
---|
| 581 | Pointers to destination values, these will be completed with |
---|
| 582 | the normalised device coordinates (in the range {-1,1}). |
---|
| 583 | @param top |
---|
| 584 | Pointers to destination values, these will be completed with |
---|
| 585 | the normalised device coordinates (in the range {-1,1}). |
---|
| 586 | @param right |
---|
| 587 | Pointers to destination values, these will be completed with |
---|
| 588 | the normalised device coordinates (in the range {-1,1}). |
---|
| 589 | @param bottom |
---|
| 590 | Pointers to destination values, these will be completed with |
---|
| 591 | the normalised device coordinates (in the range {-1,1}). |
---|
| 592 | @return @c true if the sphere was projected to a subset of the near plane, |
---|
| 593 | @c false if the entire near plane was contained. |
---|
| 594 | */ |
---|
| 595 | virtual bool projectSphere(const Sphere& sphere, |
---|
| 596 | Real* left, Real* top, Real* right, Real* bottom) const; |
---|
| 597 | |
---|
| 598 | |
---|
| 599 | /** Links the frustum to a custom near clip plane, which can be used |
---|
| 600 | to clip geometry in a custom manner without using user clip planes. |
---|
| 601 | @remarks |
---|
| 602 | There are several applications for clipping a scene arbitrarily by |
---|
| 603 | a single plane; the most common is when rendering a reflection to |
---|
| 604 | a texture, and you only want to render geometry that is above the |
---|
| 605 | water plane (to do otherwise results in artefacts). Whilst it is |
---|
| 606 | possible to use user clip planes, they are not supported on all |
---|
| 607 | cards, and sometimes are not hardware accelerated when they are |
---|
| 608 | available. Instead, where a single clip plane is involved, this |
---|
| 609 | technique uses a 'fudging' of the near clip plane, which is |
---|
| 610 | available and fast on all hardware, to perform as the arbitrary |
---|
| 611 | clip plane. This does change the shape of the frustum, leading |
---|
| 612 | to some depth buffer loss of precision, but for many of the uses of |
---|
| 613 | this technique that is not an issue. |
---|
| 614 | @par |
---|
| 615 | This version of the method links to a plane, rather than requiring |
---|
| 616 | a by-value plane definition, and therefore you can |
---|
| 617 | make changes to the plane (e.g. by moving / rotating the node it is |
---|
| 618 | attached to) and they will automatically affect this object. |
---|
| 619 | @note This technique only works for perspective projection. |
---|
| 620 | @param plane |
---|
| 621 | The plane to link to to perform the clipping. This plane |
---|
| 622 | must continue to exist while the camera is linked to it; do not |
---|
| 623 | destroy it before the frustum. |
---|
| 624 | */ |
---|
| 625 | virtual void enableCustomNearClipPlane(const MovablePlane* plane); |
---|
| 626 | /** Links the frustum to a custom near clip plane, which can be used |
---|
| 627 | to clip geometry in a custom manner without using user clip planes. |
---|
| 628 | @remarks |
---|
| 629 | There are several applications for clipping a scene arbitrarily by |
---|
| 630 | a single plane; the most common is when rendering a reflection to |
---|
| 631 | a texture, and you only want to render geometry that is above the |
---|
| 632 | water plane (to do otherwise results in artefacts). Whilst it is |
---|
| 633 | possible to use user clip planes, they are not supported on all |
---|
| 634 | cards, and sometimes are not hardware accelerated when they are |
---|
| 635 | available. Instead, where a single clip plane is involved, this |
---|
| 636 | technique uses a 'fudging' of the near clip plane, which is |
---|
| 637 | available and fast on all hardware, to perform as the arbitrary |
---|
| 638 | clip plane. This does change the shape of the frustum, leading |
---|
| 639 | to some depth buffer loss of precision, but for many of the uses of |
---|
| 640 | this technique that is not an issue. |
---|
| 641 | @note This technique only works for perspective projection. |
---|
| 642 | @param plane |
---|
| 643 | The plane to link to to perform the clipping. This plane |
---|
| 644 | must continue to exist while the camera is linked to it; do not |
---|
| 645 | destroy it before the frustum. |
---|
| 646 | */ |
---|
| 647 | virtual void enableCustomNearClipPlane(const Plane& plane); |
---|
| 648 | /** Disables any custom near clip plane. */ |
---|
| 649 | virtual void disableCustomNearClipPlane(void); |
---|
| 650 | /** Is a custom near clip plane in use? */ |
---|
| 651 | virtual bool isCustomNearClipPlaneEnabled(void) const |
---|
| 652 | { return mObliqueDepthProjection; } |
---|
| 653 | |
---|
| 654 | /// @copydoc MovableObject::visitRenderables |
---|
| 655 | void visitRenderables(Renderable::Visitor* visitor, |
---|
| 656 | bool debugRenderables = false); |
---|
| 657 | |
---|
| 658 | /// Small constant used to reduce far plane projection to avoid inaccuracies |
---|
| 659 | static const Real INFINITE_FAR_PLANE_ADJUST; |
---|
| 660 | |
---|
| 661 | /** Get the derived position of this frustum. */ |
---|
| 662 | virtual const Vector3& getPositionForViewUpdate(void) const; |
---|
| 663 | /** Get the derived orientation of this frustum. */ |
---|
| 664 | virtual const Quaternion& getOrientationForViewUpdate(void) const; |
---|
| 665 | |
---|
| 666 | /** Gets a world-space list of planes enclosing the frustum. |
---|
| 667 | */ |
---|
| 668 | PlaneBoundedVolume getPlaneBoundedVolume(); |
---|
| 669 | /** Set the orientation mode of the frustum. Default is OR_DEGREE_0 |
---|
| 670 | @remarks |
---|
| 671 | Setting the orientation of a frustum is only supported on |
---|
| 672 | iOS at this time. An exception is thrown on other platforms. |
---|
| 673 | */ |
---|
| 674 | void setOrientationMode(OrientationMode orientationMode); |
---|
| 675 | |
---|
| 676 | /** Get the orientation mode of the frustum. |
---|
| 677 | @remarks |
---|
| 678 | Getting the orientation of a frustum is only supported on |
---|
| 679 | iOS at this time. An exception is thrown on other platforms. |
---|
| 680 | */ |
---|
| 681 | OrientationMode getOrientationMode() const; |
---|
| 682 | |
---|
| 683 | }; |
---|
| 684 | |
---|
| 685 | /** @} */ |
---|
| 686 | /** @} */ |
---|
| 687 | |
---|
| 688 | } // namespace Ogre |
---|
| 689 | |
---|
| 690 | #include "OgreHeaderSuffix.h" |
---|
| 691 | |
---|
| 692 | #endif // __Frustum_H__ |
---|