1 | #include "OgrePlatformQueryManager.h"
|
---|
2 | #include "OcclusionQuery.h"
|
---|
3 | #include <OgreSceneManager.h>
|
---|
4 | #include <OgreLogManager.h>
|
---|
5 | #include <OgreStringConverter.h>
|
---|
6 | #include <vector>
|
---|
7 | #include <OgreSubEntity.h>
|
---|
8 | #include "OgrePlatformHierarchyInterface.h"
|
---|
9 |
|
---|
10 |
|
---|
11 |
|
---|
12 | namespace Ogre {
|
---|
13 |
|
---|
14 | //-----------------------------------------------------------------------
|
---|
15 | void PlatformQueryManager::SetViewport(Viewport *vp)
|
---|
16 | {
|
---|
17 | mViewport = vp;
|
---|
18 | }
|
---|
19 | //-----------------------------------------------------------------------
|
---|
20 | void PlatformQueryManager::ComputeFromPointVisibility(
|
---|
21 | const Vector3 &point,
|
---|
22 | NodeInfoContainer *visibleNodes,
|
---|
23 | MeshInfoContainer *visibleGeometry,
|
---|
24 | PatchInfoContainer *visiblePatches,
|
---|
25 | const bool relativeVisibility,
|
---|
26 | const bool approximateVisibility)
|
---|
27 | {
|
---|
28 | SceneManager *sm = static_cast<PlatformHierarchyInterface *>
|
---|
29 | (mHierarchyInterface)->GetSceneManager();
|
---|
30 |
|
---|
31 | // create a camera for the point query
|
---|
32 | Camera *cam = sm->createCamera("PointQueryCam");
|
---|
33 |
|
---|
34 | //save old camera
|
---|
35 | Camera *savedCam = mViewport->getCamera();
|
---|
36 |
|
---|
37 |
|
---|
38 | //////////////
|
---|
39 | //-- initialise new camera
|
---|
40 |
|
---|
41 | mViewport->setCamera(cam);
|
---|
42 | cam->setPosition(point);
|
---|
43 |
|
---|
44 | cam->setNearClipDistance(savedCam->getNearClipDistance());
|
---|
45 | cam->setFarClipDistance(savedCam->getFarClipDistance());
|
---|
46 |
|
---|
47 | // set frustum to 45 degrees so all the scene can be captured with 6 shots
|
---|
48 | cam->setAspectRatio(1.0);
|
---|
49 | cam->setFOVy(Radian(Math::HALF_PI));
|
---|
50 |
|
---|
51 | int sign = -1;
|
---|
52 |
|
---|
53 | ///////////////
|
---|
54 | //-- capture visibility from all 6 directions
|
---|
55 |
|
---|
56 | for (int dir=0; dir < 6; dir++)
|
---|
57 | {
|
---|
58 | sign *= -1;
|
---|
59 |
|
---|
60 | // Print camera details
|
---|
61 | if (0)
|
---|
62 | {
|
---|
63 | std::stringstream d;
|
---|
64 | d << "Point query camera: " + StringConverter::toString(cam->getDerivedPosition()) +
|
---|
65 | " " + "O: " + StringConverter::toString(cam->getDerivedOrientation());
|
---|
66 | LogManager::getSingleton().logMessage(d.str());
|
---|
67 | }
|
---|
68 |
|
---|
69 | // prevent from initialising geometry / node array again
|
---|
70 | if (dir > 0)
|
---|
71 | mWasInitialised = true;
|
---|
72 |
|
---|
73 | ComputeCameraVisibility(*cam,
|
---|
74 | visibleNodes,
|
---|
75 | visibleGeometry,
|
---|
76 | visiblePatches,
|
---|
77 | relativeVisibility,
|
---|
78 | approximateVisibility);
|
---|
79 |
|
---|
80 | // permute directions
|
---|
81 | Vector3 direction(0,0,0);
|
---|
82 | direction[dir / 2] = sign;
|
---|
83 |
|
---|
84 | cam->setDirection(direction);
|
---|
85 | }
|
---|
86 |
|
---|
87 | // reset camera
|
---|
88 | mViewport->setCamera(savedCam);
|
---|
89 | }
|
---|
90 | //-----------------------------------------------------------------------
|
---|
91 | void PlatformQueryManager::ComputeCameraVisibility(
|
---|
92 | const Camera &camera,
|
---|
93 | NodeInfoContainer *visibleNodes,
|
---|
94 | MeshInfoContainer *visibleGeometry,
|
---|
95 | PatchInfoContainer *visiblePatches,
|
---|
96 | const bool relativeVisibility,
|
---|
97 | const bool approximateVisibility)
|
---|
98 | {
|
---|
99 | // we need access to the scene manager and the rendersystem
|
---|
100 | PlatformHierarchyInterface *pfHierarchyInterface =
|
---|
101 | static_cast<PlatformHierarchyInterface *>(mHierarchyInterface);
|
---|
102 |
|
---|
103 | SceneManager *sm = pfHierarchyInterface->GetSceneManager();
|
---|
104 |
|
---|
105 |
|
---|
106 | // const_cast allowed because camera is not changed in renderScene
|
---|
107 | Camera *pCam = const_cast<Camera *>(&camera);
|
---|
108 |
|
---|
109 | // disable overlays, reset them later
|
---|
110 | bool overlayEnabled = mViewport->getOverlaysEnabled();
|
---|
111 | mViewport->setOverlaysEnabled(false);
|
---|
112 |
|
---|
113 | // clear background with black (i.e., not a valid item id)
|
---|
114 | ColourValue bg = mViewport->getBackgroundColour();
|
---|
115 | mViewport->setBackgroundColour(ColourValue(0, 0, 0, 0));
|
---|
116 | //pfHierarchyInterface->GetRenderSystem()->clearFrameBuffer(FBT_COLOUR | FBT_DEPTH);
|
---|
117 |
|
---|
118 | // render scene once to fill depth buffer
|
---|
119 | sm->_renderScene(pCam, mViewport, false);
|
---|
120 |
|
---|
121 | mWasInitialised = false; // reset flag
|
---|
122 | mViewport->setOverlaysEnabled(overlayEnabled); // reset old overlay status
|
---|
123 | mViewport->setBackgroundColour(bg); // reset background color
|
---|
124 | }
|
---|
125 |
|
---|
126 | } // namespace Ogre
|
---|