source: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreBiHierarchyCamera.cpp @ 2348

Revision 2348, 2.6 KB checked in by vizrt_christian_seidl, 18 years ago (diff)

Added: BIHierarchy SceneManager?

BITerrain SceneManager?

Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of the GameTools Project
4http://www.gametools.org
5
6Author: Martin Szydlowski
7-----------------------------------------------------------------------------
8*/
9
10#include "OgreBiHierarchyCamera.h"
11
12namespace Ogre
13{
14
15BiHierarchyCamera::BiHierarchyCamera(const String& name, SceneManager *sm):
16Camera(name, sm)
17{
18
19}
20
21BiHierarchyCamera::~BiHierarchyCamera()
22{
23
24}
25
26//-----------------------------------------------------------------------
27// enhanced vis calculation - borrowed from OctreeCamera - indicate when entire box inside the frustum
28BiHierarchyCamera::NodeVisibility BiHierarchyCamera::getVisibilityEnhanced(const AxisAlignedBox& box) const
29{
30        ++ mNumVisQueries;
31       
32        // Null boxes always invisible
33        if ( box.isNull() )
34                return BIHNV_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 BIHNV_NONE;
78        }
79
80        if ( all_inside )
81                return BIHNV_FULL;
82        else
83                return BIHNV_PART;
84}
85
86//-----------------------------------------------------------------------
87// simple vis calculation - does the same as isVisible, only different return type
88BiHierarchyCamera::NodeVisibility BiHierarchyCamera::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) ? BIHNV_PART : BIHNV_NONE;
97        }
98        else
99        {
100                return Frustum::isVisible(box, culledBy) ? BIHNV_PART : BIHNV_NONE;
101        }
102}
103
104} // namespace Ogre
Note: See TracBrowser for help on using the repository browser.