Ogre::Real LuaScriptUtilities::GetRadius(Ogre::SceneNode* const sceneNode) { sceneNode->_updateBounds(); const Ogre::AxisAlignedBox aabb = sceneNode->_getWorldAABB(); return aabb.getHalfSize().length(); }
int HOO::allocateEntityToNode(Ogre::SceneManager *& SceneManager, Ogre::SceneNode *& node, Ogre::Entity*& Ent , const Ogre::String& entityName, const Ogre::String& meshName, HOO::entityVector * debugEntityVector){ try{ Ent = SceneManager->createEntity( entityName, meshName ); node->attachObject(Ent); } catch( Ogre::Exception & e ){ Ent = SceneManager->createEntity( entityName, "cube.mesh"); debugEntityVector->push_back(Ent); Ogre::String message = "WARNING ! Failed to load the following mesh : "; message += meshName; Ogre::LogManager::getSingletonPtr()->logMessage( message); node->attachObject(Ent); float scale=0.2f; node->setScale(scale,scale,scale); Ogre::String txtName = "ErrorTxtObject_n"; txtName += debugEntityVector->size(); Ogre::MovableText* msg = new Ogre::MovableText(txtName, message ,"BlueHighway-8",int(2/scale),Ogre::ColourValue::Green); msg->setTextAlignment(Ogre::MovableText::H_CENTER, Ogre::MovableText::V_CENTER); // Center horizontally and display above the node Ogre::AxisAlignedBox AABB =Ent->getWorldBoundingBox(true); msg->setLocalTranslation(Ogre::Vector3(0.0f,AABB.getHalfSize()[2]+0.1f,0.0f)); node->attachObject(msg); return HOO::ALLOCATEFAIL; } return HOO::SUCCESS; }
//----------------------------------------------------------------------- bool Light::isInLightRange(const Ogre::AxisAlignedBox& container) const { bool isIntersect = true; //Check the 2 simple / obvious situations. Light is directional or light source is inside the container if ((mLightType != LT_DIRECTIONAL) && (container.intersects(mDerivedPosition) == false)) { //Check that the container is within the sphere of the light isIntersect = Math::intersects(Sphere(mDerivedPosition, mRange),container); //If this is a spotlight, do a more specific check if ((isIntersect) && (mLightType == LT_SPOTLIGHT) && (mSpotOuter.valueRadians() <= Math::PI)) { //Create a rough bounding box around the light and check if Quaternion localToWorld = Vector3::NEGATIVE_UNIT_Z.getRotationTo(mDerivedDirection); Real boxOffset = Math::Sin(mSpotOuter * 0.5) * mRange; AxisAlignedBox lightBoxBound; lightBoxBound.merge(Vector3::ZERO); lightBoxBound.merge(localToWorld * Vector3(boxOffset, boxOffset, -mRange)); lightBoxBound.merge(localToWorld * Vector3(-boxOffset, boxOffset, -mRange)); lightBoxBound.merge(localToWorld * Vector3(-boxOffset, -boxOffset, -mRange)); lightBoxBound.merge(localToWorld * Vector3(boxOffset, -boxOffset, -mRange)); lightBoxBound.setMaximum(lightBoxBound.getMaximum() + mDerivedPosition); lightBoxBound.setMinimum(lightBoxBound.getMinimum() + mDerivedPosition); isIntersect = lightBoxBound.intersects(container); //If the bounding box check succeeded do one more test if (isIntersect) { //Check intersection again with the bounding sphere of the container //Helpful for when the light is at an angle near one of the vertexes of the bounding box isIntersect = isInLightRange(Sphere(container.getCenter(), container.getHalfSize().length())); } } } return isIntersect; }
bool RoomsManager::UpdateObject(Room::ObjectType* object) { bool updated=false, inrooms=false; Room *room; //std::vector<Room*>::iterator iPos=Rooms.begin(), iEnd=Rooms.end(); inrooms=false; //for (size_t i=0;i<Rooms.Size;++i) Ogre::AxisAlignedBox box = object->GetRoomable()->GetBoundingBox(), *RoomBox; //assert() for (RoomsPool::ListNode *pos = Rooms.GetBegin(); pos!=NULL; pos=pos->Next) { room = pos->Value; RoomBox = room->GetBox(); if (RoomBox->intersects(box)) { updated = room->UpdateObject(object); if (updated) { inrooms=true; } } } if (!inrooms) { /*char log[100]; sprintf(log,"Rooms 1: empty room set for object %d\n",object->GetScriptable()->GetID()); Debugging::Log("Warnings.log",log);*/ IRoomable *rmbl = object->GetRoomable(); IPhysical *phys = object->GetPhysical(); if (rmbl) { rmbl->RemoveFromRooms(); rmbl->GetRooms()->Clear(); switch (rmbl->GetRoomOnly()) { case IRoomable::ROM_RESTORE: { for (RoomsPool::ListNode *pos = Rooms.GetBegin(); pos!=NULL; pos=pos->Next) { Ogre::AxisAlignedBox *box = pos->Value->GetBox(); Ogre::Vector3 center = box->getCenter(); Ogre::Vector3 position = object->GetPosition(); Ogre::Vector3 dist = position - center; int sqradius = AAUtilities::f2i(box->getHalfSize().squaredLength())+3*phys->GetRadius(); int sqdist = AAUtilities::f2i(dist.squaredLength()); if (sqradius>sqdist) { //GetPhysical()->SetForwardDirection(GetOrientation()*Vector3::UNIT_Z); //object->GetPhysical(); //object->RestoreBackupPosition(); //Ogre::Vector3 newdir=phys->GetLastVelocity(); //phys->Stop(); phys->SetReplacingDirection(-dist.normalisedCopy()*10); break; } } AddOuterObject(object); //object->RestoreBackupPosition(); break; } case IRoomable::ROM_DESTROY: { CommonDeclarations::DeleteObjectRequest(object); break; } case IRoomable::ROM_SCRIPT: { IScriptable *scr = object->GetScriptable(); if (scr && scr->GetID()>0) ScriptManager::GetInstance()->Call("OnOutOfRooms", "i", false, object->GetScriptable()->GetID()); break; } case IRoomable::ROM_NONE: { AddOuterObject(object); break; } }; } } return inrooms; }