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