/* ----------------------------------------------------------------------------- This source file is part of the GameTools Project http://www.gametools.org Author: Martin Szydlowski ----------------------------------------------------------------------------- */ #include "OgreBihRenderable.h" #include "OgreBiHierarchySceneManager.h" #include "OgreBiHierarchyInterface.h" namespace Ogre { BiHierarchyInterface::BiHierarchyInterface(BiHierarchySceneManager *sm, RenderSystem *rsys): PlatformHierarchyInterface(sm, rsys) { } bool BiHierarchyInterface::IsLeaf(GtpVisibility::HierarchyNode *node) const { return BIHNODEPTR_CAST(node)->isLeaf(); } void BiHierarchyInterface::TraverseNode(GtpVisibility::HierarchyNode *node) { ++ mNumTraversedNodes; BiHierarchy::Node * kdnode = BIHNODEPTR_CAST(node); // if the node is a leaf and has geometry => render it if (kdnode->isLeaf()) { if (!kdnode->isEmpty()) { RenderNode(node); } } else { if (kdnode->getLeftChild()) mDistanceQueue->push(kdnode->getLeftChild()); if (kdnode->getRightChild()) mDistanceQueue->push(kdnode->getRightChild()); } } void BiHierarchyInterface::RenderNode(GtpVisibility::HierarchyNode *node) { BiHierarchy::Node * kdnode = BIHNODEPTR_CAST(node); if (kdnode->lastRendered() != mFrameId) { kdnode->setLastRendered(mFrameId); BiHierarchySceneManager * ksm = static_cast(mSceneManager); ksm->_renderNode(kdnode, mCamera, mOnlyShadowCasters, mLeavePassesInQueue); mVisibleNodes.push_back(node); } } void BiHierarchyInterface::PullUpVisibility(GtpVisibility::HierarchyNode *node) const { BiHierarchy::Node * kdnode = BIHNODEPTR_CAST(node); while (kdnode && !kdnode->isNodeVisible()) { kdnode->setNodeVisible(true); kdnode = kdnode->getParent(); } } float BiHierarchyInterface::GetSquaredDistance(GtpVisibility::HierarchyNode *node) const { const Vector3 pos = BIHNODEPTR_CAST(node)->mAABB.getCenter(); return (mCameraPosition - pos).squaredLength(); } AxisAlignedBox * BiHierarchyInterface::GetBoundingBox(GtpVisibility::HierarchyNode *node) { // reuse box if node is the same // only create renderable bounding box for new node if (node != mOldNode) { mOldNode = node; mBox = BIHNODEPTR_CAST(node)->_getWorldAABB(); } return &mBox; } bool BiHierarchyInterface::HasGeometry(GtpVisibility::HierarchyNode *node) const { return BIHNODEPTR_CAST(node)->hasGeometry(); } void BiHierarchyInterface::SetNodeVisible(GtpVisibility::HierarchyNode *node, const bool visible) const { BIHNODEPTR_CAST(node)->setNodeVisible(visible); } bool BiHierarchyInterface::IsNodeVisible(GtpVisibility::HierarchyNode *node) const { return BIHNODEPTR_CAST(node)->isNodeVisible(); } void BiHierarchyInterface::SetLastVisited(GtpVisibility::HierarchyNode *node, const unsigned int frameId) const { BIHNODEPTR_CAST(node)->setLastVisited(frameId); } unsigned int BiHierarchyInterface::LastVisited(GtpVisibility::HierarchyNode *node) const { return BIHNODEPTR_CAST(node)->lastVisited(); } void BiHierarchyInterface::VisualizeCulledNode(GtpVisibility::HierarchyNode *node, GtpVisibility::CullingType type) const { WireBoundingBox *box = BIHNODEPTR_CAST(node)->getWireBoundingBox(); if (type == GtpVisibility::FRUSTUM_CULLED) { box->setMaterial("FrustumCulledNodesMaterial"); } else // type == GtpVisibility::QUERY_CULLED { box->setMaterial("QueryCulledNodesMaterial"); } static_cast(mSceneManager)->getRenderQueue()->addRenderable(box); } void BiHierarchyInterface::GetNodeGeometryList(GtpVisibility::HierarchyNode *node, GeometryVector *geometryList, bool includeChildren) { BIHNODEPTR_CAST(node)->getGeometryList(geometryList); } } // namespace Ogre