//--------------------------------------------------------------------- void PCZSceneManager::fireShadowTexturesPreCaster(Light* light, Camera* camera, size_t iteration) { PCZSceneNode* camNode = (PCZSceneNode*)camera->getParentSceneNode(); if (light->getType() == Light::LT_DIRECTIONAL) { if (camNode->getHomeZone() != mActiveCameraZone) addPCZSceneNode(camNode, mActiveCameraZone); } else { PCZSceneNode* lightNode = (PCZSceneNode*)light->getParentSceneNode(); assert(lightNode); PCZone* lightZone = lightNode->getHomeZone(); if (camNode->getHomeZone() != lightZone) addPCZSceneNode(camNode, lightZone); } SceneManager::fireShadowTexturesPreCaster(light, camera, iteration); }
//----------------------------------------------------------------------- void PCZLight::updateZones(PCZone * defaultZone, unsigned long frameCount) { //update the zones this light affects PCZone * homeZone; affectedZonesList.clear(); mAffectsVisibleZone = false; PCZSceneNode * sn = (PCZSceneNode*)(this->getParentSceneNode()); if (sn) { // start with the zone the light is in homeZone = sn->getHomeZone(); if (homeZone) { affectedZonesList.push_back(homeZone); if (homeZone->getLastVisibleFrame() == frameCount) { mAffectsVisibleZone = true; } } else { // error - scene node has no homezone! // just say it affects the default zone and leave it at that. affectedZonesList.push_back(defaultZone); if (defaultZone->getLastVisibleFrame() == frameCount) { mAffectsVisibleZone = true; } return; } } else { // ERROR! not connected to a scene node, // just say it affects the default zone and leave it at that. affectedZonesList.push_back(defaultZone); if (defaultZone->getLastVisibleFrame() == frameCount) { mAffectsVisibleZone = true; } return; } // now check visibility of each portal in the home zone. If visible to // the light then add the target zone of the portal to the list of // affected zones and recurse into the target zone static PCZFrustum portalFrustum; Vector3 v = getDerivedPosition(); portalFrustum.setOrigin(v); homeZone->_checkLightAgainstPortals(this, frameCount, &portalFrustum, 0); }
/* if destroySceneNodes is true, then all nodes which have the destroyed zone as their homezone are desroyed too. If destroySceneNodes is false then all scene nodes which have the zone as their homezone will have their homezone pointer set to 0, which will allow them to be re-assigned either by the user or via the automatic re-assignment routine */ void PCZSceneManager::destroyZone(PCZone* zone, bool destroySceneNodes) { // need to remove this zone from all lights affected zones list, // otherwise next frame _calcZonesAffectedByLights will call PCZLight::getNeedsUpdate() // which will try to access the zone pointer and will cause an access violation MovableObjectCollection* lights = getMovableObjectCollection(PCZLightFactory::FACTORY_TYPE_NAME); { OGRE_LOCK_MUTEX(lights->mutex) // Is locking necessary in destroyZone? I don't know.. MovableObjectIterator it(lights->map.begin(), lights->map.end()); while(it.hasMoreElements()) { PCZLight* l = static_cast<PCZLight*>(it.getNext()); if(l) { // no need to check, this function does that anyway. if exists, is erased. l->removeZoneFromAffectedZonesList(zone); } } } // if not destroying scene nodes, then make sure any nodes who have // this zone as homezone are set to have 0 for a homezone for (SceneNodeList::iterator i = mSceneNodes.begin(); i != mSceneNodes.end(); ++i) { PCZSceneNode * pczsn = (PCZSceneNode*)(i->second); if (!destroySceneNodes) { if (pczsn->getHomeZone() == zone) { pczsn->setHomeZone(0); } } // reset all node visitor lists // note, it might be more efficient to only do this to nodes which // are actually visiting the zone being destroyed, but visitor lists // get cleared every frame anyway, so it's not THAT big a deal. pczsn->clearNodeFromVisitedZones(); } ZoneMap::iterator it; it = mZones.find(zone->getName()); if (it != mZones.end()) { mZones.erase(zone->getName()); } OGRE_DELETE zone; }
void Octree::_findNodes(const PlaneBoundedVolume &t, PCZSceneNodeList &list, PCZSceneNode *exclude, bool includeVisitors, bool full ) { if ( !full ) { AxisAlignedBox obox; _getCullBounds( &obox ); Intersection isect = intersect( t, obox ); if ( isect == OUTSIDE ) return ; full = ( isect == INSIDE ); } PCZSceneNodeList::iterator it = mNodes.begin(); while ( it != mNodes.end() ) { PCZSceneNode * on = ( *it ); if ( on != exclude && (on->getHomeZone() == mZone || includeVisitors )) { if ( full ) { // make sure the node isn't already on the list list.insert( on ); } else { Intersection nsect = intersect( t, on -> _getWorldAABB() ); if ( nsect != OUTSIDE ) { // make sure the node isn't already on the list list.insert( on ); } } } ++it; } Octree* child; if ( (child=mChildren[ 0 ][ 0 ][ 0 ]) != 0 ) child->_findNodes( t, list, exclude, includeVisitors, full ); if ( (child=mChildren[ 1 ][ 0 ][ 0 ]) != 0 ) child->_findNodes( t, list, exclude, includeVisitors, full ); if ( (child=mChildren[ 0 ][ 1 ][ 0 ]) != 0 ) child->_findNodes( t, list, exclude, includeVisitors, full ); if ( (child=mChildren[ 1 ][ 1 ][ 0 ]) != 0 ) child->_findNodes( t, list, exclude, includeVisitors, full ); if ( (child=mChildren[ 0 ][ 0 ][ 1 ]) != 0 ) child->_findNodes( t, list, exclude, includeVisitors, full ); if ( (child=mChildren[ 1 ][ 0 ][ 1 ]) != 0 ) child->_findNodes( t, list, exclude, includeVisitors, full ); if ( (child=mChildren[ 0 ][ 1 ][ 1 ]) != 0 ) child->_findNodes( t, list, exclude, includeVisitors, full ); if ( (child=mChildren[ 1 ][ 1 ][ 1 ]) != 0 ) child->_findNodes( t, list, exclude, includeVisitors, full ); }