//--------------------------------------------------------------------- void DefaultAxisAlignedBoxSceneQuery::execute(SceneQueryListener* listener) { // Iterate over all movable types Root::MovableObjectFactoryIterator factIt = Root::getSingleton().getMovableObjectFactoryIterator(); while(factIt.hasMoreElements()) { SceneManager::MovableObjectIterator objItA = mParentSceneMgr->getMovableObjectIterator( factIt.getNext()->getType()); while (objItA.hasMoreElements()) { MovableObject* a = objItA.getNext(); // skip whole group if type doesn't match if (!(a->getTypeFlags() & mQueryTypeMask)) break; if ((a->getQueryFlags() & mQueryMask) && a->isInScene() && mAABB.intersects(a->getWorldBoundingBox())) { if (!listener->queryResult(a)) return; } } } }
//--------------------------------------------------------------------- void PagingLandScapeOctreePlaneBoundedVolumeListSceneQuery::execute( SceneQueryListener* listener ) { PlaneBoundedVolumeList::iterator pi, piend; piend = mVolumes.end( ); for ( pi = mVolumes.begin( ); pi != piend; ++pi ) { std::list < SceneNode* > list; //find the nodes that intersect the AAB static_cast< PagingLandScapeOctreeSceneManager* >( mParentSceneMgr )->findNodesIn( *pi, list, 0 ); //grab all moveables from the node that intersect... std::list < SceneNode* >::iterator it = list.begin( ); while ( it != list.end( ) ) { SceneNode::ObjectIterator oit = ( *it )->getAttachedObjectIterator( ); while ( oit.hasMoreElements( ) ) { MovableObject* m = oit.getNext( ); if ( ( m->getQueryFlags( ) & mQueryMask ) && m->isInScene( ) && ( *pi ).intersects( m->getWorldBoundingBox( ) ) ) { listener->queryResult( m ); } } ++it; } } }
//--------------------------------------------------------------------- void DefaultPlaneBoundedVolumeListSceneQuery::execute(SceneQueryListener* listener) { // Iterate over all movable types Root::MovableObjectFactoryIterator factIt = Root::getSingleton().getMovableObjectFactoryIterator(); while(factIt.hasMoreElements()) { SceneManager::MovableObjectIterator objItA = mParentSceneMgr->getMovableObjectIterator( factIt.getNext()->getType()); while (objItA.hasMoreElements()) { MovableObject* a = objItA.getNext(); // skip whole group if type doesn't match if (!(a->getTypeFlags() & mQueryTypeMask)) break; PlaneBoundedVolumeList::iterator pi, piend; piend = mVolumes.end(); for (pi = mVolumes.begin(); pi != piend; ++pi) { PlaneBoundedVolume& vol = *pi; // Do AABB / plane volume test if ((a->getQueryFlags() & mQueryMask) && a->isInScene() && vol.intersects(a->getWorldBoundingBox())) { if (!listener->queryResult(a)) return; break; } } } } }
MovableObject* SceneNode::detachObject(unsigned short index) { MovableObject* ret; if (index < sceneObjects_.size()) { ObjectMap::iterator i = sceneObjects_.begin(); // Increment (must do this one at a time) while (index--)++i; ret = i->second; sceneObjects_.erase(i); ret->notifyAttached((SceneNode*)0); // Make sure bounds get updated (must go right to the top) notifyUpdate( BoundsChangedBit ); return ret; } else { SML_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, "Object index out of bounds."); } return 0; }
//----------------------------------------------------------------------- MovableObject* SceneNode::detachObject(unsigned short index) { MovableObject* ret; if (index < mObjectsByName.size()) { ObjectMap::iterator i = mObjectsByName.begin(); // Increment (must do this one at a time) while (index--)++i; ret = i->second; mObjectsByName.erase(i); ret->_notifyAttached((SceneNode*)0); // Make sure bounds get updated (must go right to the top) needUpdate(); return ret; } else { OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Object index out of bounds.", "SceneNode::getAttchedEntity"); } }
//--------------------------------------------------------------------- void PagingLandScapeOctreeRaySceneQuery::execute( RaySceneQueryListener* listener ) { std::list < SceneNode* > list; //find the nodes that intersect the AAB static_cast< PagingLandScapeOctreeSceneManager* >( mParentSceneMgr )->findNodesIn( mRay, list, 0 ); //grab all movables from the node that intersect... std::list < SceneNode* >::iterator it = list.begin( ); while ( it != list.end( ) ) { SceneNode::ObjectIterator oit = ( *it )->getAttachedObjectIterator( ); while ( oit.hasMoreElements( ) ) { MovableObject* m = oit.getNext( ); if ( ( m->getQueryFlags( ) & mQueryMask ) && m->isInScene( ) ) { std::pair< bool, Real > result = mRay.intersects( m->getWorldBoundingBox( ) ); if ( result.first ) { listener->queryResult( m, result.second ); } } } ++it; } }
void RendererSystemComponent::DestroySceneNode(Ogre::SceneNode* sceneNode) { Ogre::Node::ChildNodeIterator children = sceneNode->getChildIterator(); while(children.hasMoreElements()) { SceneNode* childSceneNode = static_cast<SceneNode*>(children.getNext()); this->DestroySceneNode(childSceneNode); } SceneNode::ObjectIterator objects = sceneNode->getAttachedObjectIterator(); while(objects.hasMoreElements()) { MovableObject* object = objects.getNext(); if(object->getMovableType() == EntityFactory::FACTORY_TYPE_NAME) { Entity* entity = m_scene->GetSceneManager()->getEntity(object->getName()); Ogre::Entity::ChildObjectListIterator childObjects = entity->getAttachedObjectIterator(); while(childObjects.hasMoreElements()) { m_scene->GetSceneManager()->destroyMovableObject(childObjects.getNext()); } } m_scene->GetSceneManager()->destroyMovableObject(object); } sceneNode->removeAndDestroyAllChildren(); }
Ogre::String ObjectControl::mousePressed(QPoint lastPos,float w,float h) { using namespace Ogre; float RatioX = float(lastPos.x())/w; float RatioY = float(lastPos.y())/h; MovableObject* nodeM = getNode(RatioX,RatioY); if( nodeM != NULL ) { String name = nodeM->getParentSceneNode()->getName(); if ( name == "move_widget_x" ) { Vector3 objPos = Vector3(node->_getWorldAABB().getCenter()); planeXNode->setPosition(objPos); planeYNode->setPosition(objPos); planeZNode->setPosition(objPos); currntOperation=MoveX; } else if ( name == "move_widget_y" ) { Vector3 objPos = Vector3(node->_getWorldAABB().getCenter()); planeXNode->setPosition(objPos); planeYNode->setPosition(objPos); planeZNode->setPosition(objPos); currntOperation=MoveY; } else if ( name == "move_widget_z" ) { Vector3 objPos = Vector3(node->_getWorldAABB().getCenter()); planeXNode->setPosition(objPos); planeYNode->setPosition(objPos); planeZNode->setPosition(objPos); currntOperation=MoveZ; } else if ( name == "rotate_widget_x" ) currntOperation = RotateX; else if ( name == "rotate_widget_y" ) currntOperation = RotateY; else if ( name == "rotate_widget_z" ) currntOperation = RotateZ; else if ( name == "scale_widget_x" ) currntOperation = ScaleX; else if ( name == "scale_widget_y" ) currntOperation = ScaleY; else if ( name == "scale_widget_z" ) currntOperation = ScaleZ; else if ( name == "scale_widget_xyz" ) currntOperation = ScaleXYZ; else { if (currentMode==Move_Mode ) selectObjectForEdit(name.c_str(),"move_widget" ); else if (currentMode==Rotate_Mode) selectObjectForEdit(name.c_str(),"rotate_widget"); else if (currentMode==Scale_Mode ) selectObjectForEdit(name.c_str(),"scale_widget" ); } return name; } else { reset(); return ""; } }
//----------------------------------------------------------------------- //----------------------------------------------------------------------- MovableObject* MovableObjectFactory::createInstance( const String& name, SceneManager* manager, const NameValuePairList* params) { MovableObject* m = createInstanceImpl(name, params); m->_notifyCreator(this); m->_notifyManager(manager); return m; }
//------------------------------------------------------------------------- void World::_applyCollision(void) { // Collision detection IntersectionSceneQueryResult& results = mIntersectionQuery->execute(); // Movables to Movables SceneQueryMovableIntersectionList::iterator it, itend; itend = results.movables2movables.end(); for (it = results.movables2movables.begin(); it != itend; ++it) { /* debugging MovableObject *mo1, *mo2; mo1 = it->first; mo2 = it->second; */ // Get user defined objects (generic in OGRE) UserDefinedObject *uo1, *uo2; uo1 = it->first->getUserObject(); uo2 = it->second->getUserObject(); // Only perform collision if we have UserDefinedObject links if (uo1 && uo2) { // Cast to ApplicationObject ApplicationObject *ao1, *ao2; ao1 = static_cast<ApplicationObject*>(uo1); ao2 = static_cast<ApplicationObject*>(uo2); // Do detailed collision test ao1->testCollide(ao2); } } // Movables to World SceneQueryMovableWorldFragmentIntersectionList::iterator wit, witend; witend = results.movables2world.end(); for (wit = results.movables2world.begin(); wit != witend; ++wit) { MovableObject *mo = wit->first; SceneQuery::WorldFragment *wf = wit->second; // Get user defined objects (generic in OGRE) UserDefinedObject *uo = mo->getUserObject(); // Only perform collision if we have UserDefinedObject link if (uo) { // Cast to ApplicationObject ApplicationObject *ao = static_cast<ApplicationObject*>(uo); // Do detailed collision test ao->testCollide(wf); } } }
//----------------------------------------------------------------------- void SceneNode::updateFromParent() { if ( hasParent() ) { // Set level //level_ = getParent()->getLevel() + 1; derivedOrientation_ = getParentOrientation() * orientation_; /*if ( queryFlag( SceneNode::OrientationInheritedBit ) ) { // Combine orientation with that of parent derivedOrientation_ = getParentOrientation() * orientation_; } else { // No inheritance derivedOrientation_ = orientation_; }*/ //derivedScale_ = parentScale * scale_; derivedScale_ = getParentScale(); // Update scale /*if ( queryFlag( SceneNode::ScaleInheritedBit ) ) { // Scale own position by parent scale, NB just combine // as equivalent axes, no shearing //derivedScale_ = parentScale * scale_; derivedScale_ = getParentScale(); } else { // No inheritance derivedScale_ = scale_; }*/ // Change position vector based on parent's orientation & scale //derivedPosition_ = parentOrientation * (parentScale_ * position_); derivedPosition_ = getParentOrientation() * position_; // Add altered position vector to parents derivedPosition_ += getParentPosition(); } else { level_ = 0; // Root node, no parent derivedOrientation_ = orientation_; derivedPosition_ = position_; derivedScale_ = scale_; } validWorldTransform_ = true; // Notify objects that it has been moved ObjectMap::const_iterator i; for (i = sceneObjects_.begin(); i != sceneObjects_.end(); ++i) { MovableObject* object = i->second; object->notifyMoved(); } }
//----------------------------------------------------------------------- void SceneNode::detachAllObjects(void) { ObjectMap::iterator itr; for ( itr = mObjectsByName.begin(); itr != mObjectsByName.end(); ++itr ) { MovableObject* ret = itr->second; ret->_notifyAttached((SceneNode*)0); } mObjectsByName.clear(); // Make sure bounds get updated (must go right to the top) needUpdate(); }
//----------------------------------------------------------------------- void SceneNode::updateFromParentImpl(void) const { Node::updateFromParentImpl(); // Notify objects that it has been moved ObjectMap::const_iterator i; for (i = mObjectsByName.begin(); i != mObjectsByName.end(); ++i) { MovableObject* object = i->second; object->_notifyMoved(); } }
void SceneNode::detachObject( MovableObject & object ) { auto it = std::find_if( m_objects.begin(), m_objects.end(), [&object]( std::reference_wrapper< MovableObject > obj ) { return obj.get().getName() == object.getName(); } ); if ( it != m_objects.end() ) { m_objects.erase( it ); object.attachTo( nullptr ); } }
void SceneNode::detachAllObjects(void) { ObjectMap::iterator itr; MovableObject* ret; for ( itr = sceneObjects_.begin(); itr != sceneObjects_.end(); itr++ ) { ret = itr->second; ret->notifyAttached((SceneNode*)0); } sceneObjects_.clear(); // Make sure bounds get updated (must go right to the top) notifyUpdate( BoundsChangedBit ); }
//----------------------------------------------------------------------- SceneNode::~SceneNode() { // Detach all objects, do this manually to avoid needUpdate() call // which can fail because of deleted items ObjectMap::iterator itr; for ( itr = mObjectsByName.begin(); itr != mObjectsByName.end(); ++itr ) { MovableObject* ret = itr->second; ret->_notifyAttached((SceneNode*)0); } mObjectsByName.clear(); OGRE_DELETE mWireBoundingBox; }
MovableObject* SceneNode::detachObject(const std::string& name) { ObjectMap::iterator it = sceneObjects_.find(name); if (it == sceneObjects_.end()) { SML_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, "Object " + name + " is not attached to this node."); } MovableObject* ret = it->second; sceneObjects_.erase(it); ret->notifyAttached((SceneNode*)0); // Make sure bounds get updated (must go right to the top) notifyUpdate( BoundsChangedBit ); return ret; }
//--------------------------------------------------------------------- void PCZPlaneBoundedVolumeListSceneQuery::execute(SceneQueryListener* listener) { std::set<SceneNode*> checkedSceneNodes; PlaneBoundedVolumeList::iterator pi, piend; piend = mVolumes.end(); for (pi = mVolumes.begin(); pi != piend; ++pi) { PCZSceneNodeList list; //find the nodes that intersect the Plane bounded Volume static_cast<PCZSceneManager*>( mParentSceneMgr ) -> findNodesIn( *pi, list, mStartZone, (PCZSceneNode*)mExcludeNode ); //grab all moveables from the node that intersect... PCZSceneNodeList::iterator it, itend; itend = list.end(); for (it = list.begin(); it != itend; ++it) { // avoid double-check same scene node if (!checkedSceneNodes.insert(*it).second) continue; SceneNode::ObjectIterator oit = (*it) -> getAttachedObjectIterator(); while( oit.hasMoreElements() ) { MovableObject * m = oit.getNext(); if( (m->getQueryFlags() & mQueryMask) && (m->getTypeFlags() & mQueryTypeMask) && m->isInScene() && (*pi).intersects( m->getWorldBoundingBox() ) ) { listener -> queryResult( m ); // deal with attached objects, since they are not directly attached to nodes if (m->getMovableType() == "Entity") { Entity* e = static_cast<Entity*>(m); Entity::ChildObjectListIterator childIt = e->getAttachedObjectIterator(); while(childIt.hasMoreElements()) { MovableObject* c = childIt.getNext(); if (c->getQueryFlags() & mQueryMask && (*pi).intersects( c->getWorldBoundingBox())) { listener->queryResult(c); } } } } } } }//for // reset startzone and exclude node mStartZone = 0; mExcludeNode = 0; }
int TCP_Socket::recvObj(int commitTag, MovableObject &theObject, FEM_ObjectBroker &theBroker, ChannelAddress *theAddress) { // first check address is the only address a TCP_socket can send to SocketAddress *theSocketAddress = 0; if (theAddress != 0) { if (theAddress->getType() == SOCKET_TYPE) theSocketAddress = (SocketAddress *)theAddress; else { opserr << "TCP_Socket::recvObj() - a TCP_Socket "; opserr << "can only communicate with a TCP_Socket"; opserr << " address given is not of type SocketAddress\n"; return -1; } if (bcmp((char *) &other_Addr.addr_in, (char *) &theSocketAddress->address.addr, theSocketAddress->addrLength) != 0) { opserr << "TCP_Socket::recvObj() - a TCP_Socket "; opserr << "can only communicate with one other TCP_Socket\n"; return -1; } } return theObject.recvSelf(commitTag, *this, theBroker); }
int UDP_Socket::recvObj(int commitTag, MovableObject &theObject, FEM_ObjectBroker &theBroker, ChannelAddress *theAddress) { int res = theObject.recvSelf(commitTag, *this, theBroker); if (res < 0) return res; // check the address that message came from was correct if (theAddress != 0) { SocketAddress *theSocketAddress = 0; if (theAddress->getType() == SOCKET_TYPE) { theSocketAddress = (SocketAddress *)theAddress; if (memcmp((char *) &theSocketAddress->address.addr, (char *) &other_Addr.addr, theSocketAddress->addrLength) != 0) { opserr << "UDP_Socket::recvObj() - a UDP_Socket "; opserr << "can only look at first incoming message\n"; opserr << "The last message did not come from write scource\n"; return -1; } } else { opserr << "UDP_Socket::recvObj() - a UDP_Socket "; opserr << "can only communicate with a UDP_Socket"; opserr << " address given is not of type SocketAddress\n"; return -1; } } return 0; }
int UDP_Socket::sendObj(int commitTag, MovableObject &theObject, ChannelAddress *theAddress) { // set up the address of the Socket to which data will be sent if (theAddress != 0) { SocketAddress *theSocketAddress = 0; if (theAddress->getType() == SOCKET_TYPE) { theSocketAddress = (SocketAddress *)theAddress; bcopy((char *) &theSocketAddress->address.addr, (char *) &other_Addr.addr, theSocketAddress->addrLength); addrLength = theSocketAddress->addrLength; } else { opserr << "UDP_Socket::sendObj() - a UDP_Socket "; opserr << "can only communicate with a UDP_Socket"; opserr << " address given is not of type SocketAddress\n"; return -1; } } return theObject.sendSelf(commitTag, *this); }
int FE_Datastore::sendObj(int commitTag, MovableObject &theObject, ChannelAddress *theAddress) { return theObject.sendSelf(commitTag, *this); }
int FileChannel::sendObj(int commitTag, MovableObject &theObject, ChannelAddress *theAddress){ if ( !theFile ) return -1; return theObject.sendSelf(commitTag, *this); }
//服务的 Update efd::AsyncResult MovementService::OnTick() { efd::TimeType gameTime = m_pServiceManager->GetTime(efd::kCLASSID_GameTimeClock); efd::TimeType timeDelta = gameTime - m_lastUpdate; m_lastUpdate = gameTime; efd::map<egf::EntityID, MovableObjectPtr>::iterator iter = m_MovableObjectMap.begin(); while (iter != m_MovableObjectMap.end()) { MovableObject* pHandler = iter->second; pHandler->Update(timeDelta); iter++; } //继续 Tick return efd::AsyncResult_Pending ; }
//----------------------------------------------------------------------- MovableObject* SceneNode::detachObject(const String& name) { ObjectMap::iterator it = mObjectsByName.find(name); if (it == mObjectsByName.end()) { OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, "Object " + name + " is not attached " "to this node.", "SceneNode::detachObject"); } MovableObject* ret = it->second; mObjectsByName.erase(it); ret->_notifyAttached((SceneNode*)0); // Make sure bounds get updated (must go right to the top) needUpdate(); return ret; }
/** Destructor */ SubObject::~SubObject() { // Destroy all attached entities and scene nodes unsigned short count = node_->numAttachedObjects(); for (unsigned short i = 0; i < count; i++) { MovableObject* obj = node_->getAttachedObject(0U); node_->detachObject((unsigned short)0); node_->getCreator()->destroyMovableObject(obj->getName(), obj->getMovableType()); } node_->getParentSceneNode()->removeAndDestroyChild(node_->getName()); // Remove from world if the subobject was separated off if (body_.get()) { body_->setUserPointer(0); game_->getWorld()->removeCollisionObject(body_.get()); } }
int FE_Datastore::recvObj(int commitTag, MovableObject &theObject, FEM_ObjectBroker &theNewBroker, ChannelAddress *theAddress) { return theObject.recvSelf(commitTag, *this, theNewBroker); }
//--------------------------------------------------------------------- void PCZRaySceneQuery::execute(RaySceneQueryListener* listener) { PCZSceneNodeList list; //find the nodes that intersect the Ray static_cast<PCZSceneManager*>( mParentSceneMgr ) -> findNodesIn( mRay, list, mStartZone, (PCZSceneNode*)mExcludeNode ); //grab all moveables from the node that intersect... PCZSceneNodeList::iterator it = list.begin(); while( it != list.end() ) { SceneNode::ObjectIterator oit = (*it) -> getAttachedObjectIterator(); while( oit.hasMoreElements() ) { MovableObject * m = oit.getNext(); if( (m->getQueryFlags() & mQueryMask) && (m->getTypeFlags() & mQueryTypeMask) && m->isInScene() ) { std::pair<bool, Real> result = mRay.intersects(m->getWorldBoundingBox()); if( result.first ) { listener -> queryResult( m, result.second ); // deal with attached objects, since they are not directly attached to nodes if (m->getMovableType() == "Entity") { Entity* e = static_cast<Entity*>(m); Entity::ChildObjectListIterator childIt = e->getAttachedObjectIterator(); while(childIt.hasMoreElements()) { MovableObject* c = childIt.getNext(); if (c->getQueryFlags() & mQueryMask) { result = mRay.intersects(c->getWorldBoundingBox()); if (result.first) { listener->queryResult(c, result.second); } } } } } } } ++it; } // reset startzone and exclude node mStartZone = 0; mExcludeNode = 0; }
int FileChannel::recvObj(int commitTag, MovableObject &theObject, FEM_ObjectBroker &theBroker, ChannelAddress *theAddress) { if ( !theFile ) return -1; setCommitStep( commitTag ); return theObject.recvSelf(commitTag, *this, theBroker); }
AxisAlignedBox getWorldAABB(SceneNode* node) { AxisAlignedBox aabb; // merge with attached objects for (int i=0; i<node->numAttachedObjects(); ++i) { MovableObject* o = node->getAttachedObject(i); aabb.merge(o->getWorldBoundingBox(true)); } // merge with child nodes for (int i=0; i<node->numChildren(); ++i) { SceneNode* child = static_cast<SceneNode*>(node->getChild(i)); aabb.merge( getWorldAABB(child) ); } return aabb; }