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 "";
	}
}
Esempio n. 2
0
    //---------------------------------------------------------------------
    void PCZIntersectionSceneQuery::execute(IntersectionSceneQueryListener* listener)
    {
        typedef std::pair<MovableObject *, MovableObject *> MovablePair;
        typedef std::set
            < std::pair<MovableObject *, MovableObject *> > MovableSet;

        MovableSet set;

        // Iterate over all movable types
        Root::MovableObjectFactoryIterator factIt = 
            Root::getSingleton().getMovableObjectFactoryIterator();
        while(factIt.hasMoreElements())
        {
            SceneManager::MovableObjectIterator it = 
                mParentSceneMgr->getMovableObjectIterator(
                factIt.getNext()->getType());
            while( it.hasMoreElements() )
            {

                MovableObject * e = it.getNext();
                PCZone * zone = ((PCZSceneNode*)(e->getParentSceneNode()))->getHomeZone();
                PCZSceneNodeList list;
                //find the nodes that intersect the AAB
                static_cast<PCZSceneManager*>( mParentSceneMgr ) -> findNodesIn( e->getWorldBoundingBox(), list, zone, 0 );
                //grab all moveables from the node that intersect...
                PCZSceneNodeList::iterator nit = list.begin();
                while( nit != list.end() )
                {
                    SceneNode::ObjectIterator oit = (*nit) -> getAttachedObjectIterator();
                    while( oit.hasMoreElements() )
                    {
                        MovableObject * m = oit.getNext();

                        if( m != e &&
                            set.find( MovablePair(e,m)) == set.end() &&
                            set.find( MovablePair(m,e)) == set.end() &&
                            (m->getQueryFlags() & mQueryMask) &&
                            (m->getTypeFlags() & mQueryTypeMask) &&
                            m->isInScene() && 
                            e->getWorldBoundingBox().intersects( m->getWorldBoundingBox() ) )
                        {
                            listener -> queryResult( e, m );
                            // deal with attached objects, since they are not directly attached to nodes
                            if (m->getMovableType() == "Entity")
                            {
                                Entity* e2 = static_cast<Entity*>(m);
                                Entity::ChildObjectListIterator childIt = e2->getAttachedObjectIterator();
                                while(childIt.hasMoreElements())
                                {
                                    MovableObject* c = childIt.getNext();
                                    if (c->getQueryFlags() & mQueryMask && 
                                        e->getWorldBoundingBox().intersects( c->getWorldBoundingBox() ))
                                    {
                                        listener->queryResult(e, c);
                                    }
                                }
                            }
                        }
                        set.insert( MovablePair(e,m) );

                    }
                    ++nit;
                }

            }
        }
    }