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