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 | {
|
---|
18 |
|
---|
19 | }
|
---|
20 |
|
---|
21 | KdTreeCamera::~KdTreeCamera()
|
---|
22 | {
|
---|
23 |
|
---|
24 | }
|
---|
25 |
|
---|
26 | //-----------------------------------------------------------------------
|
---|
27 | // enhanced vis calculation - borrowed from OctreeCamera - indicate when entire box inside the frustum
|
---|
28 | KdTreeCamera::NodeVisibility KdTreeCamera::getVisibilityEnhanced(const AxisAlignedBox& box) const
|
---|
29 | {
|
---|
30 | ++ mNumVisQueries;
|
---|
31 |
|
---|
32 | // Null boxes always invisible
|
---|
33 | if ( box.isNull() )
|
---|
34 | return KDNV_NONE;
|
---|
35 |
|
---|
36 | // Make any pending updates to the calculated frustum planes
|
---|
37 | updateFrustumPlanes();
|
---|
38 |
|
---|
39 | // Get corners of the box
|
---|
40 | const Vector3* pCorners = box.getAllCorners();
|
---|
41 |
|
---|
42 | // For each plane, see if all points are on the negative side
|
---|
43 | // If so, object is not visible.
|
---|
44 | // If one or more are, it's partial.
|
---|
45 | // If all aren't, full
|
---|
46 |
|
---|
47 | int corners[ 8 ] = {0, 4, 3, 5, 2, 6, 1, 7};
|
---|
48 |
|
---|
49 | int planes[ 6 ] = {FRUSTUM_PLANE_TOP, FRUSTUM_PLANE_BOTTOM,
|
---|
50 | FRUSTUM_PLANE_LEFT, FRUSTUM_PLANE_RIGHT,
|
---|
51 | FRUSTUM_PLANE_FAR, FRUSTUM_PLANE_NEAR };
|
---|
52 |
|
---|
53 | bool all_inside = true;
|
---|
54 |
|
---|
55 | for ( int plane = 0; plane < 6; ++plane )
|
---|
56 | {
|
---|
57 |
|
---|
58 | // Skip far plane if infinite view frustum
|
---|
59 | if (mFarDist == 0 && planes[ plane ] == FRUSTUM_PLANE_FAR)
|
---|
60 | continue;
|
---|
61 |
|
---|
62 | bool all_outside = true;
|
---|
63 |
|
---|
64 | float distance = 0;
|
---|
65 |
|
---|
66 | for ( int corner = 0; corner < 8; ++corner )
|
---|
67 | {
|
---|
68 | distance = mFrustumPlanes[ planes[ plane ] ].getDistance( pCorners[ corners[ corner ] ] );
|
---|
69 | all_outside = all_outside && ( distance < 0 );
|
---|
70 | all_inside = all_inside && ( distance >= 0 );
|
---|
71 |
|
---|
72 | if ( !all_outside && !all_inside )
|
---|
73 | break;
|
---|
74 | }
|
---|
75 |
|
---|
76 | if ( all_outside )
|
---|
77 | return KDNV_NONE;
|
---|
78 | }
|
---|
79 |
|
---|
80 | if ( all_inside )
|
---|
81 | return KDNV_FULL;
|
---|
82 | else
|
---|
83 | return KDNV_PART;
|
---|
84 | }
|
---|
85 |
|
---|
86 | //-----------------------------------------------------------------------
|
---|
87 | // simple vis calculation - does the same as isVisible, only different return type
|
---|
88 | KdTreeCamera::NodeVisibility KdTreeCamera::getVisibilitySimple(const AxisAlignedBox& box) const
|
---|
89 | {
|
---|
90 | ++ mNumVisQueries;
|
---|
91 |
|
---|
92 | // dummy
|
---|
93 | FrustumPlane* culledBy = 0;
|
---|
94 | if (mCullFrustum)
|
---|
95 | {
|
---|
96 | return mCullFrustum->isVisible(box, culledBy) ? KDNV_PART : KDNV_NONE;
|
---|
97 | }
|
---|
98 | else
|
---|
99 | {
|
---|
100 | return Frustum::isVisible(box, culledBy) ? KDNV_PART : KDNV_NONE;
|
---|
101 | }
|
---|
102 | }
|
---|
103 |
|
---|
104 | } // namespace Ogre |
---|