[897] | 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>
|
---|
[925] | 8 | #include "OgrePlatformHierarchyInterface.h"
|
---|
[897] | 9 |
|
---|
[2280] | 10 |
|
---|
| 11 |
|
---|
[897] | 12 | namespace Ogre {
|
---|
| 13 |
|
---|
| 14 | //-----------------------------------------------------------------------
|
---|
[2505] | 15 | void PlatformQueryManager::SetViewport(Viewport *vp)
|
---|
| 16 | {
|
---|
| 17 | mViewport = vp;
|
---|
| 18 | }
|
---|
| 19 | //-----------------------------------------------------------------------
|
---|
[2171] | 20 | void PlatformQueryManager::ComputeFromPointVisibility(
|
---|
[2280] | 21 | const Vector3 &point,
|
---|
| 22 | NodeInfoContainer *visibleNodes,
|
---|
| 23 | MeshInfoContainer *visibleGeometry,
|
---|
| 24 | PatchInfoContainer *visiblePatches,
|
---|
| 25 | const bool relativeVisibility,
|
---|
| 26 | const bool approximateVisibility)
|
---|
[897] | 27 | {
|
---|
[2455] | 28 | SceneManager *sm = static_cast<PlatformHierarchyInterface *>
|
---|
[2171] | 29 | (mHierarchyInterface)->GetSceneManager();
|
---|
[897] | 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 |
|
---|
[2171] | 37 |
|
---|
| 38 | //////////////
|
---|
| 39 | //-- initialise new camera
|
---|
| 40 |
|
---|
[897] | 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 |
|
---|
[2171] | 53 | ///////////////
|
---|
| 54 | //-- capture visibility from all 6 directions
|
---|
| 55 |
|
---|
[897] | 56 | for (int dir=0; dir < 6; dir++)
|
---|
| 57 | {
|
---|
| 58 | sign *= -1;
|
---|
| 59 |
|
---|
[140] | 60 | // Print camera details
|
---|
[2171] | 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 | }
|
---|
[173] | 68 |
|
---|
[897] | 69 | // prevent from initialising geometry / node array again
|
---|
| 70 | if (dir > 0)
|
---|
| 71 | mWasInitialised = true;
|
---|
| 72 |
|
---|
[2171] | 73 | ComputeCameraVisibility(*cam,
|
---|
| 74 | visibleNodes,
|
---|
| 75 | visibleGeometry,
|
---|
| 76 | visiblePatches,
|
---|
[2255] | 77 | relativeVisibility,
|
---|
| 78 | approximateVisibility);
|
---|
[897] | 79 |
|
---|
| 80 | // permute directions
|
---|
| 81 | Vector3 direction(0,0,0);
|
---|
[2171] | 82 | direction[dir / 2] = sign;
|
---|
[897] | 83 |
|
---|
| 84 | cam->setDirection(direction);
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | // reset camera
|
---|
| 88 | mViewport->setCamera(savedCam);
|
---|
| 89 | }
|
---|
| 90 | //-----------------------------------------------------------------------
|
---|
[2171] | 91 | void PlatformQueryManager::ComputeCameraVisibility(
|
---|
[2255] | 92 | const Camera &camera,
|
---|
[2280] | 93 | NodeInfoContainer *visibleNodes,
|
---|
| 94 | MeshInfoContainer *visibleGeometry,
|
---|
| 95 | PatchInfoContainer *visiblePatches,
|
---|
[2255] | 96 | const bool relativeVisibility,
|
---|
| 97 | const bool approximateVisibility)
|
---|
[897] | 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);
|
---|
[2171] | 117 |
|
---|
[2505] | 118 | // render scene once to fill depth buffer
|
---|
| 119 | sm->_renderScene(pCam, mViewport, false);
|
---|
[897] | 120 |
|
---|
[2505] | 121 | mWasInitialised = false; // reset flag
|
---|
[897] | 122 | mViewport->setOverlaysEnabled(overlayEnabled); // reset old overlay status
|
---|
[173] | 123 | mViewport->setBackgroundColour(bg); // reset background color
|
---|
[897] | 124 | }
|
---|
| 125 |
|
---|
| 126 | } // namespace Ogre
|
---|