GL Studio C++ Runtime API
cull.h
Go to the documentation of this file.
1/*! \file
2 \brief The disti::Culler class. Implements view frustum culling.
3
4 \par Copyright Information
5
6 Copyright (c) 2017 by The DiSTI Corporation.<br>
7 11301 Corporate Blvd; Suite 100<br>
8 Orlando, Florida 32817<br>
9 USA<br>
10 <br>
11 All rights reserved.<br>
12
13 This Software contains proprietary trade secrets of DiSTI and may not be
14reproduced, in whole or part, in any form, or by any means of electronic,
15mechanical, or otherwise, without the written permission of DiSTI. Said
16permission may be derived through the purchase of applicable DiSTI product
17licenses which detail the distribution rights of this content and any
18Derivative Works based on this or other copyrighted DiSTI Software.
19
20 NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
21AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
22PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
23AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
24IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
25PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
26
27 LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
28IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
29INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
30DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
31INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
32INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBILITY
33OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
34EXCEED FIVE DOLLARS (US$5.00).
35
36 The aforementioned terms and restrictions are governed by the laws of the
37State of Florida and the United States of America.
38
39*/
40#ifndef _CULL_H
41#define _CULL_H
42
43#include "util.h"
44#include "vertex.h"
45
46namespace disti
47{
48/** The Culler class. Implements view frustum culling. */
49class Culler
50{
51public:
52 /** Return type for culling function */
53 typedef enum
54 {
55 OUTSIDE_FRUSTUM, /** The object was entirely outside of the viewing frustum */
56 INTERSECTS_FRUSTUM, /** The object intersects the viewing frustum */
57 INSIDE_FRUSTUM /** The object was entirely inside the viewing frustum */
59
60 /** Definitions for the six frustum clipping planes */
61 typedef enum
62 {
63 RIGHT_PLANE,
64 LEFT_PLANE,
65 BOTTOM_PLANE,
66 TOP_PLANE,
67 FAR_PLANE,
68 NEAR_PLANE
70
71protected:
72 bool _enabled; ///< Whether or not culling is enabled.
73
74 PlaneClass _planes[ 6 ]; ///< Array of six clipping planes to define the frustum.
75
76public:
77 /** Culler constructor
78 * \param enabled Whether or not to actually to the culling test
79 */
80 GLS_EXPORT Culler( bool enabled = true );
81
82 /// Reads the current OpenGL projection matrices and determines the six frustum planes
83 /// Note: This assumes a perspective projection, but it will work with orthographic,
84 /// though it could be optimized better if it was known that Ortho is being used.
85 /// \param matrices A return reference for the frustum.
87
88 /// \param v The center of the sphere.
89 /// \param radius The radius of the sphere.
90 /// \return Whether the sphere is inside, outside or intersects the view frustum.
91 GLS_EXPORT CullResultEnum SphereInFrustum( const Vector& v, const float radius ) const;
92
93 /// Slightly faster sphere culling because it doesn't test seperately
94 /// for intersection and it ignores the Enabled() state.
95 /// \param center The center of the sphere.
96 /// \param radius The radius of the sphere.
97 /// \return True if outside or intersecting, false if inside.
98 inline bool SphereOutsideFrustum( const Vector& center, const float radius ) const
99 {
100 if( ( _planes[ 0 ].a * center.x + _planes[ 0 ].b * center.y + _planes[ 0 ].c * center.z + _planes[ 0 ].d ) <= -radius )
101 return true;
102 if( ( _planes[ 1 ].a * center.x + _planes[ 1 ].b * center.y + _planes[ 1 ].c * center.z + _planes[ 1 ].d ) <= -radius )
103 return true;
104 if( ( _planes[ 2 ].a * center.x + _planes[ 2 ].b * center.y + _planes[ 2 ].c * center.z + _planes[ 2 ].d ) <= -radius )
105 return true;
106 if( ( _planes[ 3 ].a * center.x + _planes[ 3 ].b * center.y + _planes[ 3 ].c * center.z + _planes[ 3 ].d ) <= -radius )
107 return true;
108 if( ( _planes[ 4 ].a * center.x + _planes[ 4 ].b * center.y + _planes[ 4 ].c * center.z + _planes[ 4 ].d ) <= -radius )
109 return true;
110 if( ( _planes[ 5 ].a * center.x + _planes[ 5 ].b * center.y + _planes[ 5 ].c * center.z + _planes[ 5 ].d ) <= -radius )
111 return true;
112
113 return false; // inside (or intersecting)
114 }
115
116 /** Accessor method to get whether or not culling is enabled
117 * \return Whether or not culling is enabled
118 */
119 inline bool Enabled() const { return _enabled; }
120
121 /// Accessor method to set whether or not culling is enabled.
122 /// Be careful with this, because the Culler is usually passed by reference.
123 /// \param newVal The enabled value to set.
124 inline void Enabled( bool newVal ) { _enabled = newVal; }
125
126 /// Returns the clip plane values for the desired plane index.
127 /// \param whichPlane The index for the clipping plane to return.
128 /// \return A reference to the desired clipping plane for this view frustum.
129 GLS_EXPORT const PlaneClass& Plane( const ClippingPlanesEnum& whichPlane ) const;
130};
131
132} // namespace disti
133
134#endif
Definition: cull.h:50
bool _enabled
Whether or not culling is enabled.
Definition: cull.h:72
void Enabled(bool newVal)
Definition: cull.h:124
ClippingPlanesEnum
Definition: cull.h:62
bool SphereOutsideFrustum(const Vector &center, const float radius) const
Definition: cull.h:98
bool Enabled() const
Definition: cull.h:119
void ExtractFrustum(OpenGLMatrices &matrices)
Culler(bool enabled=true)
PlaneClass _planes[6]
Array of six clipping planes to define the frustum.
Definition: cull.h:74
const PlaneClass & Plane(const ClippingPlanesEnum &whichPlane) const
CullResultEnum
Definition: cull.h:54
@ INSIDE_FRUSTUM
Definition: cull.h:57
@ INTERSECTS_FRUSTUM
Definition: cull.h:56
CullResultEnum SphereInFrustum(const Vector &v, const float radius) const
Class to contain current OpenGL view, projection and draw matrices.
Definition: util.h:544
Definition: vertex.h:568
float d
A coefficient to describe a 3D plane: aX + bY + cZ + d = 0.
Definition: vertex.h:573
float b
A coefficient to describe a 3D plane: aX + bY + cZ + d = 0.
Definition: vertex.h:571
float c
A coefficient to describe a 3D plane: aX + bY + cZ + d = 0.
Definition: vertex.h:572
Definition: vertex.h:85
float y
The Y component.
Definition: vertex.h:88
float x
The X component.
Definition: vertex.h:87
float z
The Z component.
Definition: vertex.h:89
#define GLS_EXPORT
Macro denoting which functions should be visible from the runtime library.
Definition: gls_include.h:52
Force inclusion of the DirectShow library.
Definition: bmpimage.h:47
Generally useful defines, macros, enumerations and function prototypes.
The disti::Vertex class. A class for manipulating 3D vertices.