1 | /*
|
---|
2 | -----------------------------------------------------------------------------
|
---|
3 | This source file is part of the GameTools Project
|
---|
4 | http://www.gametools.org
|
---|
5 |
|
---|
6 | Author: Martin Szydlowski
|
---|
7 | -----------------------------------------------------------------------------
|
---|
8 | */
|
---|
9 |
|
---|
10 | #include "OgreKdTreeCamera.h"
|
---|
11 |
|
---|
12 | namespace Ogre
|
---|
13 | {
|
---|
14 |
|
---|
15 | KdTreeCamera::KdTreeCamera(const String& name, SceneManager *sm):
|
---|
16 | Camera(name, sm),
|
---|
17 | mEnhancedVisMode(true)
|
---|
18 | {
|
---|
19 | //getVisibility = getVisibilityEnhanced;
|
---|
20 | }
|
---|
21 |
|
---|
22 | KdTreeCamera::~KdTreeCamera()
|
---|
23 | {
|
---|
24 |
|
---|
25 | }
|
---|
26 |
|
---|
27 | void KdTreeCamera::setEnhancedVisMode(bool enhanced)
|
---|
28 | {
|
---|
29 | mEnhancedVisMode = enhanced;
|
---|
30 | }
|
---|
31 |
|
---|
32 | bool KdTreeCamera::getEnhancedVisMode()
|
---|
33 | {
|
---|
34 | return mEnhancedVisMode;
|
---|
35 | }
|
---|
36 |
|
---|
37 | //-----------------------------------------------------------------------
|
---|
38 | // enhanced vis calculation - borrowed from OctreeCamera - indicate when entire box inside the frustum
|
---|
39 | KdTreeCamera::NodeVisibility KdTreeCamera::getVisibilityEnhanced(const AxisAlignedBox& box) const
|
---|
40 | {
|
---|
41 | //++ mNumVisQueries;
|
---|
42 | // Null boxes always invisible
|
---|
43 | if ( box.isNull() )
|
---|
44 | return KDNV_NONE;
|
---|
45 |
|
---|
46 | // Make any pending updates to the calculated frustum planes
|
---|
47 | updateFrustumPlanes();
|
---|
48 |
|
---|
49 | // Get corners of the box
|
---|
50 | const Vector3* pCorners = box.getAllCorners();
|
---|
51 |
|
---|
52 | // For each plane, see if all points are on the negative side
|
---|
53 | // If so, object is not visible.
|
---|
54 | // If one or more are, it's partial.
|
---|
55 | // If all aren't, full
|
---|
56 |
|
---|
57 | int corners[ 8 ] = {0, 4, 3, 5, 2, 6, 1, 7};
|
---|
58 |
|
---|
59 | int planes[ 6 ] = {FRUSTUM_PLANE_TOP, FRUSTUM_PLANE_BOTTOM,
|
---|
60 | FRUSTUM_PLANE_LEFT, FRUSTUM_PLANE_RIGHT,
|
---|
61 | FRUSTUM_PLANE_FAR, FRUSTUM_PLANE_NEAR };
|
---|
62 |
|
---|
63 | bool all_inside = true;
|
---|
64 |
|
---|
65 | for ( int plane = 0; plane < 6; ++plane )
|
---|
66 | {
|
---|
67 |
|
---|
68 | // Skip far plane if infinite view frustum
|
---|
69 | if (mFarDist == 0 && planes[ plane ] == FRUSTUM_PLANE_FAR)
|
---|
70 | continue;
|
---|
71 |
|
---|
72 | bool all_outside = true;
|
---|
73 |
|
---|
74 | float distance = 0;
|
---|
75 |
|
---|
76 | for ( int corner = 0; corner < 8; ++corner )
|
---|
77 | {
|
---|
78 | distance = mFrustumPlanes[ planes[ plane ] ].getDistance( pCorners[ corners[ corner ] ] );
|
---|
79 | all_outside = all_outside && ( distance < 0 );
|
---|
80 | all_inside = all_inside && ( distance >= 0 );
|
---|
81 |
|
---|
82 | if ( !all_outside && !all_inside )
|
---|
83 | break;
|
---|
84 | }
|
---|
85 |
|
---|
86 | if ( all_outside )
|
---|
87 | return KDNV_NONE;
|
---|
88 | }
|
---|
89 |
|
---|
90 | if ( all_inside )
|
---|
91 | return KDNV_FULL;
|
---|
92 | else
|
---|
93 | return KDNV_PART;
|
---|
94 | }
|
---|
95 |
|
---|
96 | //-----------------------------------------------------------------------
|
---|
97 | // simple vis calculation - does the same as isVisible, only different return type
|
---|
98 | KdTreeCamera::NodeVisibility KdTreeCamera::getVisibilitySimple(const AxisAlignedBox& box) const
|
---|
99 | {
|
---|
100 | //++ mNumVisQueries;
|
---|
101 |
|
---|
102 | // dummy
|
---|
103 | FrustumPlane* culledBy = 0;
|
---|
104 | if (mCullFrustum)
|
---|
105 | {
|
---|
106 | return mCullFrustum->isVisible(box, culledBy) ? KDNV_PART : KDNV_NONE;
|
---|
107 | }
|
---|
108 | else
|
---|
109 | {
|
---|
110 | return Frustum::isVisible(box, culledBy) ? KDNV_PART : KDNV_NONE;
|
---|
111 | }
|
---|
112 | }
|
---|
113 |
|
---|
114 | //KdTreeCamera::NodeVisibility KdTreeCamera::getVisibility(const AxisAlignedBox& box) const
|
---|
115 | //{
|
---|
116 | // // dummy
|
---|
117 | // FrustumPlane* culledBy = 0;
|
---|
118 | // if (mCullFrustum)
|
---|
119 | // {
|
---|
120 | // return mCullFrustum->isVisible(box, culledBy) ? KDNV_PART : KDNV_NONE;
|
---|
121 | // }
|
---|
122 | // else
|
---|
123 | // {
|
---|
124 | // return Frustum::isVisible(box, culledBy) ? KDNV_PART : KDNV_NONE;
|
---|
125 | // }
|
---|
126 | //}
|
---|
127 | } // namespace Ogre |
---|