/* ----------------------------------------------------------------------------- This source file is part of the GameTools Project http://www.gametools.org Author: Martin Szydlowski ----------------------------------------------------------------------------- */ #include "OgreKdTreeSceneNode.h" #include "OgreKdTreeSceneManager.h" #include namespace Ogre { // TRIVIA: this function is _not_ called for nodes which did not change since the last frame // only exception: the root node ... it's aabb should be null however, so we don't care void KdTreeSceneNode::_updateBounds(void) { // Reset bounds first mWorldAABB.setNull(); // Update bounds from own attached objects ObjectMap::iterator i; for (i = mObjectsByName.begin(); i != mObjectsByName.end(); ++i) { // Merge world bounds of each object mWorldAABB.merge(i->second->getWorldBoundingBox(true)); } if (!mWorldAABB.isNull()) { static_cast(mCreator)->_updateNode(this); } } void KdTreeSceneNode::forceComputeAABB(AxisAlignedBox& aabb) // OBSOLETE !! { // Update bounds from own attached objects ObjectMap::iterator i; for (i = mObjectsByName.begin(); i != mObjectsByName.end(); ++i) { // Merge world bounds of each object aabb.merge(i->second->getWorldBoundingBox(true)); } // Merge with children ChildNodeMap::iterator child; for (child = mChildren.begin(); child != mChildren.end(); ++child) { KdTreeSceneNode* sceneChild = static_cast(child->second); sceneChild->forceComputeAABB(aabb); } } void KdTreeSceneNode::computeScene(PlaneEventList& events, AxisAlignedBox& aabb, int& nObjects, bool includeChildren) { // first compute nodes AABB mWorldAABB.setNull(); // Update bounds from own attached objects ObjectMap::iterator i; for (i = mObjectsByName.begin(); i != mObjectsByName.end(); ++i) { // Merge world bounds of each object mWorldAABB.merge(i->second->getWorldBoundingBox(true)); } if (!mWorldAABB.isNull()) { // merge aabb with global AABB aabb.merge(mWorldAABB); // increase object count nObjects++; // generate events PlaneEvent::Dimension axes[] = {PlaneEvent::PED_X, PlaneEvent::PED_Y, PlaneEvent::PED_Z}; Vector3 min = mWorldAABB.getMinimum(); Vector3 max = mWorldAABB.getMaximum(); //PlaneEvent * e; for (int i = 0; i < 3; i++) { // 1-D and 2-D objects if (min[i] == max[i]) { //e = new PlaneEvent(this, min, axes[i], PlaneEvent::PET_ON); //sceneinfo.events.push_back(*e); events.push_back(PlaneEvent(this, min, axes[i], PlaneEvent::PET_ON)); } else { //e = new PlaneEvent(this, min, axes[i], PlaneEvent::PET_START); //sceneinfo.events.push_back(*e); //e = new PlaneEvent(this, max, axes[i], PlaneEvent::PET_END); //sceneinfo.events.push_back(*e); events.push_back(PlaneEvent(this, min, axes[i], PlaneEvent::PET_START)); events.push_back(PlaneEvent(this, max, axes[i], PlaneEvent::PET_END)); } } } // Merge with children if (includeChildren) { ChildNodeMap::iterator child; for (child = mChildren.begin(); child != mChildren.end(); ++child) { KdTreeSceneNode* sceneChild = static_cast(child->second); sceneChild->computeScene(events, aabb, nObjects); } } } //void KdTreeSceneNode::_findVisibleObjects(Camera* cam, RenderQueue* queue, // bool includeChildren, bool displayNodes, bool onlyShadowCasters) void KdTreeSceneNode::queueObjects(Camera* cam, RenderQueue* queue, bool onlyShadowCasters) { //SceneNode::_findVisibleObjects(cam, queue, includeChildren, displayNodes, onlyShadowCasters); // Add all entities ObjectMap::iterator iobj; ObjectMap::iterator iobjend = mObjectsByName.end(); for (iobj = mObjectsByName.begin(); iobj != iobjend; ++iobj) { // Tell attached objects about camera position (incase any extra processing they want to do) iobj->second->_notifyCurrentCamera(cam); if (!onlyShadowCasters || iobj->second->getCastShadows()) { iobj->second->_updateRenderQueue(queue); } } // Check if the bounding box should be shown. // See if our flag is set or if the scene manager flag is set. if (mShowBoundingBox || (mCreator && mCreator->getShowBoundingBoxes())) { _addBoundingBoxToQueue(queue); } } AxisAlignedBox KdTreeSceneNode::getBoundingBox() const { return mWorldAABB; } // DEBUG String KdTreeSceneNode::dumpToString() { String objects; // Add all entities ObjectMap::iterator iobj = mObjectsByName.begin(); ObjectMap::iterator iobjend = mObjectsByName.end(); while (iobj != iobjend) { objects += " " + iobj->second->getName(); iobj++; } objects += " Attached to " + StringConverter::toString(mLeaves.size()) + " KdLeaves."; return objects; } }