#include "OgreOctreeHierarchyInterface.h" //#include "OgreVisibilityOctreeSceneManager.h" #include #include #include namespace Ogre { //----------------------------------------------------------------------- OctreeHierarchyInterface::OctreeHierarchyInterface(OctreeSceneManager *sm, RenderSystem *rsys): SceneNodeHierarchyInterface(sm, rsys) { } //----------------------------------------------------------------------- void OctreeHierarchyInterface::TraverseNode(GtpVisibility::HierarchyNode *node) { ++ mNumTraversedNodes; Octree *octree = static_cast(node); // if we come across some renderable geometry => render it if (!octree->mNodes.empty()) { RenderNode(node); } // if not all subtrees are empty if (!IsLeaf(node)) { Octree *nextChild; if ((nextChild = octree->mChildren[0][0][0]) != NULL) mDistanceQueue->push(nextChild); if ((nextChild = octree->mChildren[0][0][1]) != NULL) mDistanceQueue->push(nextChild); if ((nextChild = octree->mChildren[0][1][0]) != NULL) mDistanceQueue->push(nextChild); if ((nextChild = octree->mChildren[0][1][1]) != NULL) mDistanceQueue->push(nextChild); if ((nextChild = octree->mChildren[1][0][0]) != NULL) mDistanceQueue->push(nextChild); if ((nextChild = octree->mChildren[1][0][1]) != NULL) mDistanceQueue->push(nextChild); if ((nextChild = octree->mChildren[1][1][0]) != NULL) mDistanceQueue->push(nextChild); if ((nextChild = octree->mChildren[1][1][1]) != NULL) mDistanceQueue->push(nextChild); } } //----------------------------------------------------------------------- bool OctreeHierarchyInterface::IsLeaf(GtpVisibility::HierarchyNode *node) const { Octree *octree = static_cast(node); // HACK: if there are subtrees, they are empty => we are not interested in them return octree->numNodes() == (int)octree->mNodes.size(); } //----------------------------------------------------------------------- bool OctreeHierarchyInterface::HasGeometry(GtpVisibility::HierarchyNode *node) const { return !(static_cast(node))->mNodes.empty(); } //----------------------------------------------------------------------- float OctreeHierarchyInterface::GetSquaredDistance(GtpVisibility::HierarchyNode *node) const { const Vector3 bmin = static_cast(node)->mBox.getMinimum(); const Vector3 bmax = static_cast(node)->mBox.getMaximum(); const Vector3 pos = (bmax - bmin) * 0.5 + bmin; /* std::stringstream d; d << "a: " << (mCameraPosition - pos).squaredLength() << " b: " << (mCullCamera->getDerivedPosition() - pos).squaredLength(); LogManager::getSingleton().logMessage(d.str());*/ return (mCameraPosition - pos).squaredLength(); } //----------------------------------------------------------------------- void OctreeHierarchyInterface::SetNodeVisible(GtpVisibility::HierarchyNode *node, const bool visible) const { #ifdef GTP_VISIBILITY_MODIFIED_OGRE static_cast(node)->setOctreeVisible(visible); #endif } //----------------------------------------------------------------------- void OctreeHierarchyInterface::SetLastVisited(GtpVisibility::HierarchyNode *node, const unsigned int frameId) const { #ifdef GTP_VISIBILITY_MODIFIED_OGRE static_cast(node)->setLastVisited(frameId); #endif } //----------------------------------------------------------------------- void OctreeHierarchyInterface::PullUpVisibility(GtpVisibility::HierarchyNode *node) const { #ifdef GTP_VISIBILITY_MODIFIED_OGRE Octree *octant = static_cast(node); while (octant && !octant->isOctreeVisible()) { octant->setOctreeVisible(true); octant = octant->getParent(); } #endif } //----------------------------------------------------------------------- void OctreeHierarchyInterface::RenderNode(GtpVisibility::HierarchyNode *node) { #ifdef GTP_VISIBILITY_MODIFIED_OGRE Octree *octant = static_cast(node); if (octant->lastRendered() != mFrameId) { octant->setLastRendered(mFrameId); OctreeSceneManager *ocm = static_cast(mSceneManager); ocm->_renderOctant(mCamera, octant, mOnlyShadowCasters, mLeavePassesInQueue); mVisibleNodes.push_back(node); } #endif } //----------------------------------------------------------------------- bool OctreeHierarchyInterface::IsNodeVisible(GtpVisibility::HierarchyNode *node) const { #ifdef GTP_VISIBILITY_MODIFIED_OGRE return static_cast(node)->isOctreeVisible(); #else return true; #endif } //----------------------------------------------------------------------- unsigned int OctreeHierarchyInterface::LastVisited(GtpVisibility::HierarchyNode *node) const { #ifdef GTP_VISIBILITY_MODIFIED_OGRE return static_cast(node)->lastVisited(); #else return 0; #endif } //----------------------------------------------------------------------- AxisAlignedBox *OctreeHierarchyInterface::GetBoundingBox(GtpVisibility::HierarchyNode *node) { // reuse box if node is the same // only create renderable bounding box for new node if (node != mSavedNode) { mSavedNode = node; //static_cast(node)->_getCullBounds(&mBox); mBox = static_cast(node)->_getWorldAABB(); } return &mBox; } //----------------------------------------------------------------------- void OctreeHierarchyInterface::VisualizeCulledNode(GtpVisibility::HierarchyNode *node, GtpVisibility::CullingType type) const { WireBoundingBox *box = static_cast(node)->getWireBoundingBox(); if (type == GtpVisibility::FRUSTUM_CULLED) { box->setMaterial("FrustumCulledNodesMaterial"); } else // type == GtpVisibility::QUERY_CULLED { box->setMaterial("QueryCulledNodesMaterial"); } //static_cast(mSceneManager)->getBoxes()->push_back(box); static_cast(mSceneManager)->getBoxes()->push_back(box); } //----------------------------------------------------------------------- void OctreeHierarchyInterface::GetNodeGeometryList(GtpVisibility::HierarchyNode *node, GtpVisibility::GeometryVector *geometryList, bool includeChildren) { NodeList::const_iterator nodeIt, nodeIt_end; nodeIt_end = static_cast(node)->mNodes.end(); for (nodeIt = static_cast(node)->mNodes.begin(); nodeIt != nodeIt_end; ++nodeIt) { SceneNodeHierarchyInterface::GetNodeGeometryList(*nodeIt, geometryList, includeChildren); } } } // namespace Ogre