/* The following function checks if a node has left it's current home zone. * This is done by checking each portal in the zone. If the node has crossed * the portal, then the current zone is no longer the home zone of the node. The * function then recurses into the connected zones. Once a zone is found where * the node does NOT cross out through a portal, that zone is the new home zone. * When this function is done, the node should have the correct home zone already * set. A pointer is returned to this zone as well. * * NOTE: If the node does not have a home zone when this function is called on it, * the function will do its best to find the proper zone for the node using * bounding box volume testing. This CAN fail to find the correct zone in * some scenarios, so it is best for the user to EXPLICITLY set the home * zone of the node when the node is added to the scene using * PCZSceneNode::setHomeZone() */ void PCZSceneManager::_updateHomeZone( PCZSceneNode * pczsn, bool allowBackTouches ) { // Skip if root PCZoneTree has been destroyed (shutdown conditions) if (!mDefaultZone) return; PCZone * startzone; PCZone * newHomeZone; // start with current home zone of the node startzone = pczsn->getHomeZone(); if (startzone) { if (!pczsn->isAnchored()) { newHomeZone = startzone->updateNodeHomeZone(pczsn, false); } else { newHomeZone = startzone; } if (newHomeZone != startzone) { // add the node to the home zone newHomeZone->_addNode(pczsn); } } else { // the node hasn't had it's home zone set yet, so do our best to // find the home zone using volume testing. Vector3 nodeCenter = pczsn->_getDerivedPosition(); PCZone * bestZone = findZoneForPoint(nodeCenter); // set the best zone as the node's home zone pczsn->setHomeZone(bestZone); // add the node to the zone bestZone->_addNode(pczsn); } return; }