Esempio n. 1
0
treeLink splayInsert (treeLink tree, Item item) {
    Key v = key (item);
    if (tree == emptyTree)
        return (NEW (item, emptyTree, emptyTree, 1)); 

    if (less (v, key(tree->item))) {
        if (tree->left == emptyTree) {
            return (NEW (item, emptyTree, tree, tree->size+1));
        }
        if (less (v, key (tree->left->item))) {
            tree->left->left = splayInsert (tree->left->left, item);
            tree = rotRight (tree);
        } else {
            tree->left->right = splayInsert (tree->left->right, item);
            tree->left = rotLeft (tree->left);
        }
        return rotRight (tree);
    } else {
        if (tree->right == emptyTree) {
            return (NEW (item, tree, emptyTree, tree->size+1));
        }
        if (less (key (tree->right->item), v)) {
            tree->right->right = splayInsert (tree->right->right, item);
            tree = rotLeft (tree);
        } else {
            tree->right->left = splayInsert (tree->right->left, item);
            tree->right = rotRight (tree->right);
        }
        return rotLeft (tree);
    }
}
Esempio n. 2
0
task rot()
{
    while(true)
    {
        if(vexRT[Btn5U] == 1)
        {
            rotLeft();
        }

        else if(vexRT[Btn6U] == 1)
        {
            rotRight();
        }

        else if(vexRT[Btn5UXmtr2] == 1)
        {
            rotLeft();
        }

        else if(vexRT[Btn6UXmtr2] == 1)
        {
            rotRight();
        }

        else
        {
            motor[LTurn]= 0;
            motor[RTurn]= 0;
            count = 50;
        }
    }
}
Esempio n. 3
0
void Treap::remove(string k)
{
    tNode* aux=findNode(k);
    if(aux==0)
    {
        return;
    }
    cout<<"elemento encontrado para eliminar:"<<aux->getValue()<<endl;
    
    while(!aux->isDummy()){
    cout<<"elemento aux:"<<aux->getValue()<<endl;
    cout<<"elemento left:"<<aux->Left()->getValue()<<endl;
    cout<<"elemento Right:"<<aux->Right()->getValue()<<endl;
    if(aux->isDummy())
    {
        return;
    }
    
    else if(aux->Left()->isDummy()&&aux->Right()->getValue()){
        cout<<"elemento eliminado"<<endl;
        aux->setDummy();
        //cout<<"elemento eliminado"<<endl;
        return;
        //debo eliminar ademàs los dummies con un delete (falta implementar destructor)
    }
    else if(aux->Left()->isDummy())
    {
        rotLeft(aux);
        aux=aux->Left();
        continue;
    }
    else if(aux->Right()->isDummy())
    {
        rotRight(aux);
        aux=aux->Right();
        continue;
    }
    else if(aux->Left()->getPriority()>aux->Right()->getPriority())
    {
        rotRight(aux);
        aux=aux->Right();
        continue;
    }
    else {
        rotLeft(aux);
        aux=aux->Left();
        continue;
    }
    }
}
Esempio n. 4
0
    void Player::handleEvent(SDL_Event e, SDL_Renderer *r, cpSpace *space, Skillmanager *sManager, cpVect & moveVect) {
        //Rotation
        if( e.type == SDL_MOUSEMOTION) {
            int x,y;
            SDL_GetRelativeMouseState(&x,&y);
            if( x<-1 )
                rotLeft();
            if( x>1 )
                rotRight();
        }

        //If the right button was pressed
        if ( e.type == SDL_MOUSEBUTTONDOWN && e.button.button == SDL_BUTTON_RIGHT ) {
            Rpressed = true;
        } else if ( e.type == SDL_MOUSEBUTTONUP && e.button.button == SDL_BUTTON_RIGHT ) {
                Rpressed = false;
                mVel = cpvzero;
        }

        //If the left button was pressed
        if ( e.type == SDL_MOUSEBUTTONDOWN && e.button.button == SDL_BUTTON_LEFT ) {
            Lpressed = true;
        } else if ( e.type == SDL_MOUSEBUTTONUP && e.button.button == SDL_BUTTON_LEFT ) {
            Lpressed = false;
        }

        // If q was pressed
        if ( (e.type == SDL_KEYDOWN) && (e.key.keysym.sym == SDLK_q)) {
                if (sManager->cdCheck(1) == 1 ) {
                    sManager->resetCd(1);
                    mVectp = cpvmult(vectorForward(),50);
                    moveVect = cpvadd(moveVect,mVectp);
                }
        }
    }
Esempio n. 5
0
// partition tree at node with position pos (counting from 0) in the
// sorted sequence of all items, node become new root node.
link partitionR (link currentTree, int pos) {
  int leftSubtreeSize = currentTree->left->size;
  if (leftSubtreeSize > pos) {
    currentTree->left = partitionR (currentTree->left, pos);
    currentTree = rotRight (currentTree) ;
  } else if (leftSubtreeSize < pos) {
    currentTree->right = 
      partitionR (currentTree->right, pos - 1 - leftSubtreeSize);
    currentTree = rotLeft (currentTree) ;    
  }
  return currentTree;
}
Esempio n. 6
0
treeLink insertRoot (treeLink currentLink, Item item) { 

    if (currentLink == emptyTree) {
        return (NEW (item, emptyTree, emptyTree, 1));
    }
    if (less (key (item), key (currentLink->item))) {
        currentLink->left = insertRoot (currentLink->left, item);
        rotRight (currentLink);
    } else if (less (key (currentLink->item), key (item))) {
        currentLink->right = insertRoot (currentLink->right, item);
        rotLeft (currentLink);
    } else {
        currentLink->size--;
    }
    currentLink->size++;
    return (currentLink);
}
Esempio n. 7
0
tNode* Treap::insertNode(tNode* nodo,string k,int v,int p)
{

if(nodo->isDummy())//es dummy
	{
	nodo->unDummy(k,v,p);
	}
else{
	int comparison=cmp(k,nodo->getKey());

	if(comparison==0)
		{
            cout<<"cambia valor"<<endl;
		nodo->setValue(v);
		//cambia valor;
		}	
	else if(comparison==-1)
		{
        cout<<"Bajo a la IZQUIERDA"<<endl;
		nodo->setLeft(insertNode(nodo->Left(),k,v,p));
		if(nodo->Left()->getPriority() < nodo->getPriority())
		{
		cout<<"* ROT RIGHT: "<<nodo->getKey()<<endl;
        nodo=rotRight(nodo);
		
		//rotacion derecha del nodo
		}
        }
	else if (comparison==1)//k> nodo->getKey()
		{
        cout<<"Bajo a la DERECHA"<<endl;
		nodo->setRight(insertNode(nodo->Right(),k,v,p));              
		if (nodo->Right()->getPriority() < nodo->getPriority()) 
		{
        cout<<"* ROT LEFT :"<<nodo->getKey()<<endl;
        nodo=rotLeft(nodo);
		
		//		t=lrot(t);  ROTACION IZQUIERDA          
		}
        }
}
cout<<"aux nodo: ("<<nodo->getKey()<<","<<nodo->getValue()<<","<<nodo->getPriority()<<")"<<endl;
cout<<"LEFT:"<<nodo->Left()->getKey()<<" RIGHT:"<<nodo->Right()->getKey()<<endl;
cout<<endl;
return nodo;
}
Esempio n. 8
0
BNode* BNode::insert( const char *aKey, const char *aValue ) {
	BNode* result = this;
  printf("insert\n");
	if ( !iKey ) {
		iKey = (char*) malloc( strlen( aKey ) + 1 );
		strcpy( iKey, aKey ); 
		iValue = (char*) malloc( strlen( aValue ) + 1 );
		strcpy( iValue, aValue ); 
	} else {
		int leftDepth, rightDepth;
		int cmp = strcmp( aKey, iKey );
		if ( cmp > 0 ) {
			iRight = getRight()->insert(aKey, aValue);
			rightDepth = iRight->iDepth;
			leftDepth = iLeft ? iLeft->iDepth : -1;
			if ( iDepth <= rightDepth ) iDepth = rightDepth + 1;
			if ( rightDepth - leftDepth > 1 ) {
				printf("rd: %d, ld: %d\n", rightDepth, leftDepth);
                                result = rotLeft( this );
			}
		} else if ( cmp < 0 ) {
			iLeft = getLeft()->insert(aKey, aValue);
			leftDepth = iLeft->iDepth;
			rightDepth = iRight ? iRight->iDepth : -1;
			if ( iDepth <= leftDepth ) iDepth = leftDepth + 1;
                        int diff = leftDepth - rightDepth;
                        if ( diff > 1 ) {
				printf("rd: %d, ld: %d\n", rightDepth, leftDepth);
                                result = rotRight( this );
			}
			
		} else {
			free( iValue );
			iValue = (char*) malloc( strlen( aValue ) + 1 );
			strcpy( iValue, aValue );
		}
	}
	return result;
}
Esempio n. 9
0
OvrPanoMenu::OvrPanoMenu( App * app, Oculus360Photos * photos, OvrVRMenuMgr & menuMgr, BitmapFont const & font,
		OvrMetaData & metaData, float fadeOutTime, float radius )
	: VRMenu( MENU_NAME )
	, AppPtr( app )
	, MenuMgr( menuMgr )
	, Font( font )
	, Photos( photos )
	, MetaData( metaData )
	, LoadingIconHandle( 0 )
	, AttributionHandle( 0 )
	, BrowserButtonHandle( 0 )
	, SwipeLeftIndicatorHandle( 0 )
	, SwipeRightIndicatorHandle( 0 )
	, Fader( 1.0f )
	, FadeOutTime( fadeOutTime )
	, currentFadeRate( 0.0f )
	, Radius( radius )
	, ButtonCoolDown( 0.0f )
{	
	currentFadeRate = 1.0f / FadeOutTime;

	// Init with empty root
	Init( menuMgr, font, 0.0f, VRMenuFlags_t() );
	
	// Create Attribution info view
	Array< VRMenuObjectParms const * > parms;
	Array< VRMenuComponent* > comps;
	VRMenuId_t attributionPanelId( ID_CENTER_ROOT.Get() + 10 );

	comps.PushBack( new OvrPanoMenuRootComponent( *this ) );

	Quatf rot( DOWN, 0.0f );
	Vector3f dir( -FWD );
	Posef panelPose( rot, dir * Radius );
	Vector3f panelScale( 1.0f );

	//const Posef textPose( Quatf(), Vector3f( 0.0f, 0.0f, 0.0f ) );

	const VRMenuFontParms fontParms( true, true, false, false, true, 0.525f, 0.45f, 1.0f );
	
	VRMenuObjectParms attrParms( VRMENU_STATIC, comps,
		VRMenuSurfaceParms(), "Attribution Panel", panelPose, panelScale, Posef(), Vector3f( 1.0f ), fontParms, attributionPanelId,
		VRMenuObjectFlags_t( VRMENUOBJECT_DONT_HIT_TEXT ), VRMenuObjectInitFlags_t( VRMENUOBJECT_INIT_FORCE_POSITION ) );

	parms.PushBack( &attrParms );

	AddItems( MenuMgr, Font, parms, GetRootHandle(), false );
	parms.Clear();
	comps.Clear();

	AttributionHandle = HandleForId( MenuMgr, attributionPanelId );
	VRMenuObject * attributionObject = MenuMgr.ToObject( AttributionHandle );
	OVR_ASSERT( attributionObject != NULL );

	//Browser button
	float const ICON_HEIGHT = 80.0f * VRMenuObject::DEFAULT_TEXEL_SCALE;
	Array< VRMenuSurfaceParms > surfParms;

	Posef browserButtonPose( Quatf( ), UP * ICON_HEIGHT * 2.0f );

	comps.PushBack( new OvrDefaultComponent( Vector3f( 0.0f, 0.0f, 0.05f ), 1.05f, 0.25f, 0.0f, Vector4f( 1.0f ), Vector4f( 1.0f ) ) );
	comps.PushBack( new OvrButton_OnUp( this, ID_BROWSER_BUTTON ) );
	comps.PushBack( new OvrSurfaceToggleComponent( ) );
	surfParms.PushBack( VRMenuSurfaceParms ( "browser",
		"assets/nav_home_off.png", SURFACE_TEXTURE_DIFFUSE,
		NULL, SURFACE_TEXTURE_MAX, NULL, SURFACE_TEXTURE_MAX ) );
	surfParms.PushBack( VRMenuSurfaceParms( "browser",
		"assets/nav_home_on.png", SURFACE_TEXTURE_DIFFUSE,
		NULL, SURFACE_TEXTURE_MAX, NULL, SURFACE_TEXTURE_MAX ) );
	VRMenuObjectParms browserButtonParms( VRMENU_BUTTON, comps, surfParms, "",
		browserButtonPose, Vector3f( 1.0f ), Posef( ), Vector3f( 1.0f ), fontParms,
		ID_BROWSER_BUTTON, VRMenuObjectFlags_t( VRMENUOBJECT_DONT_HIT_TEXT ),
		VRMenuObjectInitFlags_t( VRMENUOBJECT_INIT_FORCE_POSITION ) );
	parms.PushBack( &browserButtonParms );

	AddItems( MenuMgr, Font, parms, AttributionHandle, false );
	parms.Clear();
	comps.Clear();
	surfParms.Clear();

	BrowserButtonHandle = attributionObject->ChildHandleForId( MenuMgr, ID_BROWSER_BUTTON );
	VRMenuObject * browserButtonObject = MenuMgr.ToObject( BrowserButtonHandle );
	OVR_ASSERT( browserButtonObject != NULL );
	OVR_UNUSED( browserButtonObject );

	//Favorites button
	Posef favoritesButtonPose( Quatf( ), DOWN * ICON_HEIGHT * 2.0f );

	comps.PushBack( new OvrDefaultComponent( Vector3f( 0.0f, 0.0f, 0.05f ), 1.05f, 0.25f, 0.0f, Vector4f( 1.0f ), Vector4f( 1.0f ) ) );
	comps.PushBack( new OvrButton_OnUp( this, ID_FAVORITES_BUTTON ) );
	comps.PushBack( new OvrSurfaceToggleComponent() );
	
	surfParms.PushBack( VRMenuSurfaceParms( "favorites_off",
		"assets/nav_star_off.png", SURFACE_TEXTURE_DIFFUSE,
		NULL, SURFACE_TEXTURE_MAX, NULL, SURFACE_TEXTURE_MAX ) );

	surfParms.PushBack( VRMenuSurfaceParms( "favorites_on",
		"assets/nav_star_on.png", SURFACE_TEXTURE_DIFFUSE,
		NULL, SURFACE_TEXTURE_MAX, NULL, SURFACE_TEXTURE_MAX ) );

	surfParms.PushBack( VRMenuSurfaceParms( "favorites_active_off",
		"assets/nav_star_active_off.png", SURFACE_TEXTURE_DIFFUSE,
		NULL, SURFACE_TEXTURE_MAX, NULL, SURFACE_TEXTURE_MAX ) );

	surfParms.PushBack( VRMenuSurfaceParms( "favorites_active_on",
		"assets/nav_star_active_on.png", SURFACE_TEXTURE_DIFFUSE,
		NULL, SURFACE_TEXTURE_MAX, NULL, SURFACE_TEXTURE_MAX ) );

	VRMenuObjectParms favoritesButtonParms( VRMENU_BUTTON, comps, surfParms, "",
		favoritesButtonPose, Vector3f( 1.0f ), Posef( ), Vector3f( 1.0f ), fontParms,
		ID_FAVORITES_BUTTON, VRMenuObjectFlags_t( VRMENUOBJECT_DONT_HIT_TEXT ),
		VRMenuObjectInitFlags_t( VRMENUOBJECT_INIT_FORCE_POSITION ) );
	parms.PushBack( &favoritesButtonParms );

	AddItems( MenuMgr, Font, parms, AttributionHandle, false );
	parms.Clear();
	comps.Clear();

	FavoritesButtonHandle = attributionObject->ChildHandleForId( MenuMgr, ID_FAVORITES_BUTTON );
	VRMenuObject * favoritesButtonObject = MenuMgr.ToObject( FavoritesButtonHandle );
	OVR_ASSERT( favoritesButtonObject != NULL );
	OVR_UNUSED( favoritesButtonObject );

	// Swipe icons
	const int numFrames = 10;
	const int numTrails = 3;
	const int numChildren = 5;
	const float swipeFPS = 3.0f;
	const float factor = 1.0f / 8.0f;

	// Right container
	VRMenuId_t swipeRightId( ID_CENTER_ROOT.Get() + 401 );
	Quatf rotRight( DOWN, ( Mathf::TwoPi * factor ) );
	Vector3f rightDir( -FWD * rotRight );	
	comps.PushBack( new OvrTrailsAnimComponent( swipeFPS, true, numFrames, numTrails, numTrails ) );
	VRMenuObjectParms swipeRightRoot( VRMENU_CONTAINER, comps, VRMenuSurfaceParms( ), "",
		Posef( rotRight, rightDir * Radius ), Vector3f( 1.0f ), Posef( ), Vector3f( 1.0f ), fontParms, swipeRightId,
		VRMenuObjectFlags_t( VRMENUOBJECT_DONT_HIT_ALL ), VRMenuObjectInitFlags_t( VRMENUOBJECT_INIT_FORCE_POSITION ) );
	parms.PushBack( &swipeRightRoot );
	AddItems( MenuMgr, Font, parms, AttributionHandle, false );
	parms.Clear();
	comps.Clear();

	SwipeRightIndicatorHandle = attributionObject->ChildHandleForId( MenuMgr, swipeRightId );
	VRMenuObject * swipeRightRootObject = MenuMgr.ToObject( SwipeRightIndicatorHandle );
	OVR_ASSERT( swipeRightRootObject != NULL );

	// Left container
	VRMenuId_t swipeLeftId( ID_CENTER_ROOT.Get( ) + 402 );
	Quatf rotLeft( DOWN, ( Mathf::TwoPi * -factor ) );
	Vector3f leftDir( -FWD * rotLeft );
	comps.PushBack( new OvrTrailsAnimComponent( swipeFPS, true, numFrames, numTrails, numTrails ) );
	VRMenuObjectParms swipeLeftRoot( VRMENU_CONTAINER, comps, VRMenuSurfaceParms( ), "",
		Posef( rotLeft, leftDir * Radius ), Vector3f( 1.0f ), Posef( ), Vector3f( 1.0f ), fontParms, swipeLeftId,
		VRMenuObjectFlags_t( VRMENUOBJECT_DONT_HIT_ALL ), VRMenuObjectInitFlags_t( VRMENUOBJECT_INIT_FORCE_POSITION ) );
	parms.PushBack( &swipeLeftRoot );
	AddItems( MenuMgr, Font, parms, AttributionHandle, false );
	parms.Clear();
	comps.Clear();

	SwipeLeftIndicatorHandle = attributionObject->ChildHandleForId( MenuMgr, swipeLeftId );
	VRMenuObject * swipeLeftRootObject = MenuMgr.ToObject( SwipeLeftIndicatorHandle );
	OVR_ASSERT( swipeLeftRootObject != NULL );
	
	// Arrow frame children
	const char * swipeRightIcon = "assets/nav_arrow_right.png";
	const char * swipeLeftIcon = "assets/nav_arrow_left.png";

	VRMenuSurfaceParms rightIndicatorSurfaceParms( "swipeRightSurface",
		swipeRightIcon, SURFACE_TEXTURE_DIFFUSE,
		NULL, SURFACE_TEXTURE_MAX, NULL, SURFACE_TEXTURE_MAX );

	VRMenuSurfaceParms leftIndicatorSurfaceParms( "swipeLeftSurface",
		swipeLeftIcon, SURFACE_TEXTURE_DIFFUSE,
		NULL, SURFACE_TEXTURE_MAX, NULL, SURFACE_TEXTURE_MAX );
	
	const float surfaceWidth = 25 * VRMenuObject::DEFAULT_TEXEL_SCALE;

	for ( int i = 0; i < numChildren; ++i )
	{
 		//right frame
		const Vector3f rightPos = ( RIGHT * surfaceWidth * i ) - ( FWD * i * 0.1f );
		VRMenuObjectParms swipeRightFrame( VRMENU_STATIC, Array< VRMenuComponent* >(), rightIndicatorSurfaceParms, "",
			Posef( Quatf( ), rightPos ), Vector3f( 1.0f ), Posef( ), Vector3f( 1.0f ), fontParms, VRMenuId_t( ),
			VRMenuObjectFlags_t(), VRMenuObjectInitFlags_t( VRMENUOBJECT_INIT_FORCE_POSITION ) );
		parms.PushBack( &swipeRightFrame );
		AddItems( MenuMgr, Font, parms, SwipeRightIndicatorHandle, false );
		parms.Clear();

		// left frame
		const Vector3f leftPos = ( (-RIGHT) * surfaceWidth * i ) - ( FWD * i * 0.1f );
		VRMenuObjectParms swipeLeftFrame( VRMENU_STATIC, Array< VRMenuComponent* >(), leftIndicatorSurfaceParms, "",
			Posef( Quatf( ), leftPos ), Vector3f( 1.0f ), Posef( ), Vector3f( 1.0f ), fontParms, VRMenuId_t( ),
			VRMenuObjectFlags_t(), VRMenuObjectInitFlags_t( VRMENUOBJECT_INIT_FORCE_POSITION ) );
		parms.PushBack( &swipeLeftFrame );
		AddItems( MenuMgr, Font, parms, SwipeLeftIndicatorHandle, false );
		parms.Clear();
	}

	if ( OvrTrailsAnimComponent* animRightComp = swipeRightRootObject->GetComponentByName< OvrTrailsAnimComponent >( ) )
	{
		animRightComp->Play( );
	}
	
	if ( OvrTrailsAnimComponent* animLeftComp = swipeLeftRootObject->GetComponentByName< OvrTrailsAnimComponent >( ) )
	{
		animLeftComp->Play( );
	}
}