[59] | 1 | #include "OgreOctreeHierarchyInterface.h"
|
---|
| 2 | #include "OgreVisibilityOctreeSceneManager.h"
|
---|
| 3 | #include <OgreOctree.h>
|
---|
[94] | 4 | #include <OgreLogManager.h>
|
---|
| 5 |
|
---|
[74] | 6 | #include <windows.h>
|
---|
[59] | 7 |
|
---|
| 8 | namespace Ogre {
|
---|
[94] | 9 |
|
---|
[59] | 10 | //-----------------------------------------------------------------------
|
---|
| 11 | OctreeHierarchyInterface::OctreeHierarchyInterface(SceneManager *sm, RenderSystem *rsys):
|
---|
| 12 | PlatformHierarchyInterface(sm, rsys)
|
---|
| 13 | {
|
---|
| 14 | }
|
---|
| 15 | //-----------------------------------------------------------------------
|
---|
| 16 | void OctreeHierarchyInterface::TraverseNode(GtpVisibility::HierarchyNode *node)
|
---|
| 17 | {
|
---|
| 18 | mNumTraversedNodes ++;
|
---|
| 19 |
|
---|
[87] | 20 | Octree *octree = static_cast<Octree *>(node);
|
---|
| 21 |
|
---|
[59] | 22 | // if we come across some renderable geometry => render it
|
---|
[87] | 23 | if (octree->mNodes.size() > 0)
|
---|
| 24 | {
|
---|
| 25 | RenderNode(node);
|
---|
| 26 | }
|
---|
[59] | 27 |
|
---|
[87] | 28 | // if not all subtrees are empty
|
---|
[94] | 29 | //if (octree->numNodes() > (int)octree->mNodes.size())
|
---|
| 30 | if (!IsLeaf(node))
|
---|
[59] | 31 | {
|
---|
[87] | 32 | for(int i=0; i<8; ++i)
|
---|
[59] | 33 | {
|
---|
[87] | 34 | Octree *nextChild =
|
---|
| 35 | octree->mChildren[(i & 4) >> 2][(i & 2) >> 1][i & 1];
|
---|
| 36 |
|
---|
| 37 | if (nextChild)
|
---|
| 38 | {
|
---|
| 39 | mDistanceQueue->push(nextChild);
|
---|
| 40 | }
|
---|
[59] | 41 | }
|
---|
| 42 | }
|
---|
| 43 | }
|
---|
| 44 | //-----------------------------------------------------------------------
|
---|
[74] | 45 | bool OctreeHierarchyInterface::IsLeaf(GtpVisibility::HierarchyNode *node) const
|
---|
[59] | 46 | {
|
---|
[94] | 47 | Octree *octree = static_cast<Octree *>(node);
|
---|
| 48 | // HACK: if there are subtrees, they are empty => we are not interested in them
|
---|
| 49 | return octree->numNodes() == (int)octree->mNodes.size();
|
---|
[59] | 50 | }
|
---|
| 51 | //-----------------------------------------------------------------------
|
---|
[74] | 52 | bool OctreeHierarchyInterface::HasGeometry(GtpVisibility::HierarchyNode *node) const
|
---|
[59] | 53 | {
|
---|
[87] | 54 | return static_cast<Octree *>(node)->mNodes.size() > 0;
|
---|
[59] | 55 | }
|
---|
| 56 | //-----------------------------------------------------------------------
|
---|
| 57 | void OctreeHierarchyInterface::SetNumOctreeNodes(unsigned int num)
|
---|
| 58 | {
|
---|
| 59 | mNumOctreeNodes = num;
|
---|
| 60 | }
|
---|
| 61 | //-----------------------------------------------------------------------
|
---|
[87] | 62 | float OctreeHierarchyInterface::GetSquaredDistance(GtpVisibility::HierarchyNode *node) const
|
---|
[59] | 63 | {
|
---|
[87] | 64 | AxisAlignedBox *box = &static_cast<Octree *>(node)->mBox;
|
---|
[74] | 65 | Vector3 mid = ((box->getMinimum() - box->getMaximum()) * 0.5) + box->getMinimum();
|
---|
[86] | 66 |
|
---|
[94] | 67 | return (mCullCamera->getDerivedPosition() - mid).squaredLength();
|
---|
[59] | 68 | }
|
---|
| 69 | //-----------------------------------------------------------------------
|
---|
[74] | 70 | void OctreeHierarchyInterface::SetNodeVisible(GtpVisibility::HierarchyNode *node,
|
---|
| 71 | const bool visible)
|
---|
[59] | 72 | {
|
---|
| 73 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
| 74 | static_cast<Octree *>(node)->setOctreeVisible(visible);
|
---|
| 75 | #endif
|
---|
| 76 | }
|
---|
| 77 | //-----------------------------------------------------------------------
|
---|
[74] | 78 | void OctreeHierarchyInterface::SetLastVisited(GtpVisibility::HierarchyNode *node,
|
---|
| 79 | const unsigned int frameId)
|
---|
[59] | 80 | {
|
---|
| 81 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
| 82 | static_cast<Octree *>(node)->setLastVisited(frameId);
|
---|
| 83 | #endif
|
---|
| 84 | }
|
---|
| 85 | //-----------------------------------------------------------------------
|
---|
| 86 | void OctreeHierarchyInterface::PullUpVisibility(GtpVisibility::HierarchyNode *node)
|
---|
| 87 | {
|
---|
| 88 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
| 89 | Octree *octant = static_cast<Octree *>(node);
|
---|
| 90 |
|
---|
| 91 | while(octant && !octant->isOctreeVisible())
|
---|
| 92 | {
|
---|
| 93 | octant->setOctreeVisible(true);
|
---|
| 94 | octant = octant->getParent();
|
---|
| 95 | }
|
---|
| 96 | #endif
|
---|
| 97 | }
|
---|
| 98 | //-----------------------------------------------------------------------
|
---|
| 99 | void OctreeHierarchyInterface::RenderNode(GtpVisibility::HierarchyNode *node)
|
---|
| 100 | {
|
---|
| 101 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
| 102 | Octree *octant = static_cast<Octree *>(node);
|
---|
| 103 |
|
---|
| 104 | if (octant->lastRendered() != mFrameId)
|
---|
| 105 | {
|
---|
| 106 | octant->setLastRendered(mFrameId);
|
---|
| 107 |
|
---|
| 108 | static_cast<OctreeSceneManager *>(mSceneManager)->_renderOctant(mCamera, octant);
|
---|
| 109 |
|
---|
| 110 | mNumRenderedNodes ++;
|
---|
| 111 | }
|
---|
| 112 | #endif
|
---|
| 113 | }
|
---|
| 114 | //-----------------------------------------------------------------------
|
---|
[74] | 115 | bool OctreeHierarchyInterface::IsNodeVisible(GtpVisibility::HierarchyNode *node) const
|
---|
[59] | 116 | {
|
---|
| 117 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
| 118 | return static_cast<Octree *>(node)->isOctreeVisible();
|
---|
| 119 | #else
|
---|
| 120 | return true;
|
---|
| 121 | #endif
|
---|
| 122 | }
|
---|
| 123 | //-----------------------------------------------------------------------
|
---|
[74] | 124 | unsigned int OctreeHierarchyInterface::LastVisited(GtpVisibility::HierarchyNode *node) const
|
---|
[59] | 125 | {
|
---|
| 126 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
| 127 | return static_cast<Octree *>(node)->lastVisited();
|
---|
| 128 | #else
|
---|
| 129 | return 0;
|
---|
| 130 | #endif
|
---|
| 131 | }
|
---|
| 132 | //-----------------------------------------------------------------------
|
---|
| 133 | AxisAlignedBox *OctreeHierarchyInterface::GetBoundingBox(GtpVisibility::HierarchyNode *node)
|
---|
| 134 | {
|
---|
[85] | 135 | if(node != mPreviousNode)
|
---|
| 136 | {
|
---|
| 137 | mPreviousNode = node;
|
---|
| 138 | static_cast<Octree *>(node)->_getCullBounds(&mBox);
|
---|
| 139 | }
|
---|
[59] | 140 |
|
---|
| 141 | return &mBox;
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | } // namespace Ogre
|
---|