Ejemplo n.º 1
0
// postExchange callback
// Purposes:
//		- Update effectors based on input state transferred from master node.
//		- Synchronize slave nodes with master node based on transferred data. This is not necessary
//		  for our system, but here's an example for cluster-based systems.
void postExchange(arMasterSlaveFramework& framework)
{
	// Presumably the master node already is up-to-date, so we ignore it.
	if(!framework.getMaster()) {
		
		// Update effectors.
		rightHand.updateState(framework.getInputState());
		leftHand.updateState(framework.getInputState());
		
		// Synchronize shared memory.
		vector<arInteractable*>::iterator i;
		for(i=objects.begin(); i != objects.end(); ++i) 
		{
			Object* oby = ((Object*)(*i));
			oby->setMatrix(oby->matrix.v);
		}
	}

}
Ejemplo n.º 2
0
// preExchange callback
// Purposes:
//		- Handle navigation updates.
//		- Process user input.
//		- Set random variables.
//		- Update shared memory.
// Notes:
//		This is only called on the master node of the cluster and before shared memory is 
//		transferred to the slave nodes.
void preExchange(arMasterSlaveFramework& framework)
{
	// Handle navigation update. The resulting navigation matrix is automatically transferred
	// to the slave nodes.
	framework.navUpdate();
	
	currentTimeGlobal = framework.getTime();
	
	double currentTime = framework.getTime();
	
	// Process user input.
	
	
	// Update shared memory.
	
	// Transfer data about objects to slave nodes.

	// Detect right hand collisions.
	rightHand.detectCollisions(rightHand, objects);

	// Extend left ray to collision point.
	leftHand.extend(leftHand, objects);

	// Update input state (placement matrix & button states) of our effectors.
	rightHand.updateState(framework.getInputState());
	leftHand.updateState(framework.getInputState());
	// Handle any interaction with the objects (see interaction/arInteractionUtilities.h).
	
	list<arInteractable*> objectlist;
	std::copy(objects.begin (), objects.end (), std::back_inserter(objectlist));
	
	ar_pollingInteraction(rightHand, objectlist);
	ar_pollingInteraction(leftHand, objectlist);
	
	
	// Play click sound if right hand has grabbed an object.
	if(rightHand.getGrabbedObject() != 0) 
	{
		dsLoop(clickSound, "click.mp3", -1, 1.0, arVector3(0, 0, 0));
	}
	// Or reset the trigger
	else 
	{
		dsLoop(clickSound, "click.mp3", 0, 1.0, arVector3(0, 0, 0));
	}
	
	
	
	// Update shared memory.
	
	// Transfer data about objects to slave nodes.

	vector<arInteractable*>::iterator i;
	for(i=objects.begin(); i != objects.end(); ++i) 
	{
		Object* oby = ((Object*)(*i));
		oby->matrix = oby->getMatrix();
	}

	
	arMatrix4 navMatrix = ar_getNavMatrix();

}
Ejemplo n.º 3
0
void onPreExchange( arMasterSlaveFramework &fw )
{
    fw.navUpdate();
    // update the input state (placement matrix & button states) of our effector.
    primary.updateState( fw.getInputState() );
    secondary.updateState( fw.getInputState() );
	
	if( primary.getButton( WiiMote::HOME ) && secondary.getButton( WiiMote::HOME ) )
	{
		helpOn = true;
		setMenuOff();
		fw.setDrawCallback( drawHelp );
	}
	
	if( helpOn )
	{
		if( primary.getButton( WiiMote::A ) || secondary.getButton( WiiMote::A ) )
		{
			helpOn = false;
			fw.setDrawCallback( doSceneGraph );
			return;
		}
	}
	else
	{

		//used for scale the world (and possibly other scales later)
		WiiMote::updateTipDistance(primary, secondary);
		scaleWorld();
		moveWorld( fw );
		
		std::map<WiiMote::button_t, std::list<WiiMote*> > buttonMap;
		WiiMote::ButtonList buttons = secondary.getDownButtons();
		for( WiiMote::ButtonList::iterator it = buttons.begin(); it != buttons.end(); ++it )
		{  // Process all butons just pressed on secondary
			if( buttonMap.find( *it ) == buttonMap.end() )
				buttonMap.insert( std::make_pair( *it, std::list<WiiMote*>( 1, &secondary ) ) );
			else
				buttonMap[*it].push_back( &secondary );
		}
		
		buttons = primary.getDownButtons();
		for( WiiMote::ButtonList::iterator it = buttons.begin(); it != buttons.end(); ++it )
		{   // Process all butons just pressed on primary
			if( buttonMap.find( *it ) == buttonMap.end() )
				buttonMap.insert( std::make_pair( *it, std::list<WiiMote*>( 1, &primary ) ) );
			else
				buttonMap[*it].push_back( &primary );
		}
	
        buttons = primary.getUpButtons();
        for( WiiMote::ButtonList::iterator it = buttons.begin(); it != buttons.end(); ++it )
        {
            switch( *it )
            {
            case WiiMote::A:
            case WiiMote::B:
                if( primary.getGrabbedObject() )
                    primary.requestUngrab( primary.getGrabbedObject() );
                break;
            default:
                break;
            }
        }
        
        buttons = secondary.getUpButtons();
        for( WiiMote::ButtonList::iterator it = buttons.begin(); it != buttons.end(); ++it )
        {
            switch( *it )
            {
            case WiiMote::A:
            case WiiMote::B:
                if( secondary.getGrabbedObject() )
                    secondary.requestUngrab( secondary.getGrabbedObject() );
                break;
            default:
                break;
            }
        }
		
		for( std::map<WiiMote::button_t, std::list<WiiMote*> >::iterator it = buttonMap.begin(); it != buttonMap.end(); ++it )
		{
			switch( it->first )
			{
			case WiiMote::HOME:
				toggleMenu();
				break;
			case WiiMote::DOWN:
				if( menuOn )
					menu->pressedDown();
				break;
			case WiiMote::RIGHT:
				if( menuOn )
					menu->pressedRight();
				break;
			case WiiMote::LEFT:
				if( menuOn )
					menu->pressedLeft();
				break;
			case WiiMote::UP:
				if( menuOn )
					menu->pressedUp();
				break;
			case WiiMote::MINUS:
				cout << "MINUS was pressed" << endl;
				if( !menuOn )
				{
					iSelectMenuObj = 1;
					for( std::list<arInteractable*>::iterator it = SelectedObjects.begin(); it != SelectedObjects.end(); ++it )
						if( Node *n = dynamic_cast<Node*>( *it ) )
							n->setSelected( false );
					SelectedObjects.clear();
				}
				break;
			case WiiMote::PLUS:
				cout << "PLUS was pressed" << endl;
				if( !menuOn )
					iSelectMenuObj = 2;
				break;
			case WiiMote::A:
				iSelectMenuObj = 0;
				if( menuOn )
				{
					switch( menu->pressedA() )
					{
					case REDRAW:
						setMenuOff();
						setMenuOn();
						break;
					case CLOSE:
						setMenuOff();
						break;
					default:
						break;
					}
				}
				break;
			case WiiMote::ONE:
				for(std::list<WiiMote*>::iterator itt = it->second.begin(); itt != it->second.end(); ++itt)
				{
					(*itt)->toggleLightSaber();
				}
				break;
			default:
				break;
			}
		}
		
		// do ray-casting after menu actions
		if ( !menuOn ) {
			rightClosest = primary.closestObject(interactableObjects);
			leftClosest = secondary.closestObject(interactableObjects);
		}
		
		if( rightClosest )
		{
			rightClosest->touch( primary );
			
			if( primary.getButton( WiiMote::A ) && primary.getButton( WiiMote::B ) )
			{
				primary.requestScaleGrab( rightClosest );
			}
			else if( primary.getButton( WiiMote::A ) )
			{
				primary.requestPosGrab( rightClosest );
			}
			else if( primary.getButton( WiiMote::B ) )
			{
				primary.requestRotGrab( rightClosest );
			}
			else if(((primary.getButton( WiiMote::PLUS )) || (primary.getButton( WiiMote::MINUS ))) && ((iSelectMenuObj == 1) || (iSelectMenuObj == 2)))
			{
				bool found = false;
				std::list<arInteractable*> tempSelectedObjects;
				while (!SelectedObjects.empty())
				{
					if ( SelectedObjects.front() == rightClosest )
					{
						cout << "Removing right hand object to selected list" << endl;
						rightClosest->setSelected( false );
						SelectedObjects.pop_front();
						found = true;
						iSelectMenuObj = 0;
						break;
					}
					else
					{
						tempSelectedObjects.push_back( SelectedObjects.front() );
						SelectedObjects.pop_front();
					}
				}
				
				while (!tempSelectedObjects.empty())
				{
					SelectedObjects.push_back( tempSelectedObjects.front() );
					if( Node *n = dynamic_cast<Node*>( tempSelectedObjects.front() ) )
						n->setSelected( true );
					tempSelectedObjects.pop_front();
				}
				
				if (!found)
				{
					cout << "Adding right hand object to selected list" << endl;
					SelectedObjects.push_back( rightClosest );
					rightClosest->setSelected( true );
					iSelectMenuObj = 0;
				}
			}
		}
			
		if( leftClosest )
		{
			leftClosest->touch( secondary );
			if( secondary.getButton( WiiMote::A ) && secondary.getButton( WiiMote::B ) )
			{
				secondary.requestScaleGrab( leftClosest );
			}
			else if( secondary.getButton( WiiMote::A ) )
			{
				secondary.requestPosGrab( leftClosest );
			}
			else if( secondary.getButton( WiiMote::B ) )
			{
				secondary.requestRotGrab( leftClosest );
			}
			else if(((secondary.getButton( WiiMote::PLUS )) || (secondary.getButton( WiiMote::MINUS ))) && ((iSelectMenuObj == 1) || (iSelectMenuObj == 2)))
			{
				bool found = false;
				std::list<arInteractable*> tempSelectedObjects;
				while (!SelectedObjects.empty())
				{
					if ( SelectedObjects.front() == leftClosest )
					{
						cout << "Removing left hand object to selected list" << endl;
						leftClosest->setSelected( false );
						SelectedObjects.pop_front();
						found = true;
						iSelectMenuObj = 0;
						break;
					}
					else
					{
						tempSelectedObjects.push_back( SelectedObjects.front() );
						SelectedObjects.pop_front();
					}
				}
				
				while (!tempSelectedObjects.empty())
				{
					SelectedObjects.push_back( tempSelectedObjects.front() );
					if( Node *n = dynamic_cast<Node*>( tempSelectedObjects.front() ) )
						n->setSelected( true );
					tempSelectedObjects.pop_front();
				}
				
				if (!found)
				{
					cout << "Adding left hand object to selected list" << endl;
					SelectedObjects.push_back( leftClosest );
					leftClosest->setSelected( true );
					iSelectMenuObj = 0;
				}
			}
		}
	}
	
}