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