/* ----------------------------------------------------------------------------- This source file is part of the GameTools Project http://www.gametools.org Author: Martin Szydlowski ----------------------------------------------------------------------------- */ #include "OgreBvhRenderable.h" #include "OgreBvHierarchySceneManager.h" #include "OgreBvHierarchyInterface.h" namespace Ogre { BvHierarchyInterface::BvHierarchyInterface(BvHierarchySceneManager *sm, RenderSystem *rsys): PlatformHierarchyInterface(sm, rsys) { } bool BvHierarchyInterface::IsLeaf(GtpVisibility::HierarchyNode *node) const { return BVHNODEPTR_CAST(node)->isLeaf(); } void BvHierarchyInterface::TraverseNode(GtpVisibility::HierarchyNode *node) { ++ mNumTraversedNodes; BvHierarchy::Node * kdnode = BVHNODEPTR_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 BvHierarchyInterface::RenderNode(GtpVisibility::HierarchyNode *node) { BvHierarchy::Node * kdnode = BVHNODEPTR_CAST(node); if (kdnode->lastRendered() != mFrameId) { kdnode->setLastRendered(mFrameId); BvHierarchySceneManager * ksm = static_cast(mSceneManager); ksm->_renderNode(kdnode, mCamera, mOnlyShadowCasters, mLeavePassesInQueue); mVisibleNodes.push_back(node); } } void BvHierarchyInterface::PullUpVisibility(GtpVisibility::HierarchyNode *node) const { BvHierarchy::Node * kdnode = BVHNODEPTR_CAST(node); while (kdnode && !kdnode->isNodeVisible()) { kdnode->setNodeVisible(true); kdnode = kdnode->getParent(); } } float BvHierarchyInterface::GetSquaredDistance(GtpVisibility::HierarchyNode *node) const { const Vector3 pos = BVHNODEPTR_CAST(node)->mAABB.getCenter(); return (mCameraPosition - pos).squaredLength(); } AxisAlignedBox * BvHierarchyInterface::GetBoundingBox(GtpVisibility::HierarchyNode *node) { // reuse box if node is the same // only create renderable bounding box for new node if (node != mSavedNode) { mSavedNode = node; mBox = BVHNODEPTR_CAST(node)->_getWorldAABB(); } return &mBox; } bool BvHierarchyInterface::HasGeometry(GtpVisibility::HierarchyNode *node) const { return BVHNODEPTR_CAST(node)->hasGeometry(); } void BvHierarchyInterface::SetNodeVisible(GtpVisibility::HierarchyNode *node, const bool visible) const { BVHNODEPTR_CAST(node)->setNodeVisible(visible); } bool BvHierarchyInterface::IsNodeVisible(GtpVisibility::HierarchyNode *node) const { return BVHNODEPTR_CAST(node)->isNodeVisible(); } void BvHierarchyInterface::SetLastVisited(GtpVisibility::HierarchyNode *node, const unsigned int frameId) const { BVHNODEPTR_CAST(node)->setLastVisited(frameId); } unsigned int BvHierarchyInterface::LastVisited(GtpVisibility::HierarchyNode *node) const { return BVHNODEPTR_CAST(node)->lastVisited(); } void BvHierarchyInterface::VisualizeCulledNode(GtpVisibility::HierarchyNode *node, GtpVisibility::CullingType type) const { WireBoundingBox *box = BVHNODEPTR_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 BvHierarchyInterface::GetNodeGeometryList(GtpVisibility::HierarchyNode *node, GtpVisibility::GeometryVector *geometryList, bool includeChildren) { BVHNODEPTR_CAST(node)->getGeometryList(geometryList); } } // namespace Ogre