Esempio n. 1
0
void Unit::setPosition(float x, float y) {
	if(_isLoaded) {
		_circle.setPosition(x,y);
		_sprite.setPosition(x,y);
	}
	else {
		_circle.setPosition(x,y);
	}
}
Esempio n. 2
0
void Particles::initialize() {
  int displayxi = int(displayx); 
  int displayyi = int(displayy);
  int radiusi = int(radius);
  int wallwidthi = int(wallwidth);
  srand(time(NULL));
    
  for( int i = 0; i<Nparticles; i++ ) {
    float tempR = rand() % ((displayyi-24)/2);
    float tempAngle = rand() % 360;
    float tempX = -tempR*sin(tempAngle*conv);
    float tempY = tempR*cos(tempAngle*conv);
    sf::Vector2f temp(tempX, tempY);
    sf::Vector2f placeParticles = temp + centerofmap;
   
    particles.setPosition( placeParticles );
    
    sf::Vector2f currentParticle = particles.getPosition();
    sf::Vector2f tempPos(0,0);
    sf::Vector2f disVec(0,0);
    float distance = 0;

    // Need to check if particles overlap during initialization
    // if it does overlap, just move it by some amount
    // We do not need to check if there is just one particle
    if( i==0 ) {
      storeParticles.push_back( particles );
    }
    else { 
      for( it = storeParticles.begin(); it != storeParticles.end(); it++ ) {
	tempPos = (*it).getPosition();
	disVec = currentParticle - tempPos;
	
	distance = sqrt(pow(disVec.x,2) + pow(disVec.y,2) );

	if( distance < 2.2*radius ) deleted++;

	while( distance < 2.2*radius ){
	  (particles).setPosition( rand()%(displayxi-2*wallwidthi-3*radiusi)+(wallwidthi+1.5*radiusi), rand()%(displayyi-3*radiusi-2*wallwidthi)+(wallwidthi+1.5*radiusi) );
	  
	  currentParticle = particles.getPosition();
	  tempPos = (*it).getPosition();
	  disVec = currentParticle - tempPos;
	  distance = sqrt(pow(disVec.x,2) + pow(disVec.y,2) );
	  if( i>=2 ) {
	    for( bit=storeParticles.begin(); bit != it; bit++ ){
	      tempPos = (*bit).getPosition();
	      disVec = currentParticle - tempPos;
	      distance = sqrt( pow(disVec.x,2)+pow(disVec.y,2));
	      if( distance < 2.2*radius ){
		(particles).setPosition( rand()%(displayxi-2*wallwidthi-3*radiusi)+(wallwidthi+1.5*radiusi), rand()%(displayyi-3*radiusi-2*wallwidthi)+(wallwidthi+1.5*radiusi) );
	      }
	    }
	  }
	} 
      }
      storeParticles.push_back(particles);    
    }
  } 
}
Esempio n. 3
0
 Ball(float mX, float mY)
 {
     shape.setPosition(mX, mY);
     shape.setRadius(defRadius);
     shape.setFillColor(defColor);
     shape.setOrigin(defRadius, defRadius);
 }
Esempio n. 4
0
	Pong() : gameWindow(sf::VideoMode(600, 480), "Pong")
	{
		ball.setFillColor(sf::Color::Cyan);
		ball.setPosition(100.0, 100.0);
		ball.setRadius(10.f);

		p1Paddle.setFillColor(sf::Color::Green);
		p1Paddle.setPosition(10.0, 100.0);
		p1Paddle.setSize(sf::Vector2f(10.0, 100.0));

		p2Paddle.setFillColor(sf::Color::Red);
		p2Paddle.setPosition(580.0, 100.0);
		p2Paddle.setSize(sf::Vector2f(10.0, 100.0));

		p1MovingUp = false;
		p1MovingDown = false;
		p2MovingUp = false;
		p2MovingDown = false;

		ballMovement = sf::Vector2f(ballSpeed, ballSpeed);
		font.loadFromFile("arial.ttf");

		p1ScoreText.setPosition(150, 10);
		p1ScoreText.setFont(font);
		p1ScoreText.setString(std::to_string(p1Score));
		p1ScoreText.setColor(sf::Color::Red);
		p1ScoreText.setCharacterSize(24);

		p2ScoreText.setPosition(450, 10);
		p2ScoreText.setFont(font);
		p2ScoreText.setString(std::to_string(p2Score));
		p2ScoreText.setColor(sf::Color::Red);
		p2ScoreText.setCharacterSize(24);
	}
void World::RespawnApple() {
	_msgCallback("Respawning Apple");
	int maxX = _windowSize.x / _blockSize - 2;
	int maxY = _windowSize.y / _blockSize - 2;
	_item = sf::Vector2i(rand() % maxX + 1, rand() % maxY + 1);
	_appleShape.setPosition(_item.x * _blockSize, _item.y * _blockSize);
}
Esempio n. 6
0
/*
 *  Mostra na tela os indicadores básicos do jogo:
 *  vidas restantes, HP e pontuação.
 */
void Jogo::exibeHud()
{
    float x = 0.10 * janela.getSize().x;
    float y = 0.15 * janela.getSize().y;

    /* Desenha vidas extras da nave */
    static sf::CircleShape losango(20.0, 4);
    for (int i = 0; i < nave->getVidas(); i++) {
        double deltaX = 2.5 * losango.getRadius();
        losango.setPosition(x + (i * deltaX), y);
        janela.draw(losango); 
    }
    /* Desenha caixa da lifebar */
    y += 3.0 * losango.getRadius();
    static sf::RectangleShape caixa({200.0, 10.0});
    caixa.setPosition(x, y);
    caixa.setFillColor(sf::Color::Blue);
    janela.draw(caixa);

    /* Desenha lifebar com parcial do HP */
    float k = (float) nave->getHP() / nave->getHPMax();
    sf::RectangleShape lifebar({k * caixa.getSize().x,
                                    caixa.getSize().y});
    lifebar.setPosition(x, y);
    lifebar.setFillColor(k > 0.25 ? sf::Color::Green : sf::Color::Red);
    janela.draw(lifebar);

    /* Imprime pontuação (e, se for o caso, mensagem de pausa) */
    y += 2.5 * lifebar.getSize().y;
    sf::String str = "Score: " + std::to_string(nave->getScore());
    if (pausado) str += " (pausa)";
    sf::Text texto(str, fonte, 20);
    texto.setPosition(x, y);
    janela.draw(texto);
}
Esempio n. 7
0
	void update(sf::Time timeChange)
	{
		sf::Vector2f p1Movement(0, 0);
		sf::Vector2f p2Movement(0, 0);


		if (p1MovingUp)
			p1Movement.y -= paddleSpeed;
		if (p1MovingDown)
			p1Movement.y += paddleSpeed;
		if (p2MovingUp)
			p2Movement.y -= paddleSpeed;
		if (p2MovingDown)
			p2Movement.y += paddleSpeed;

		p1Paddle.move(p1Movement * timeChange.asSeconds());
		p2Paddle.move(p2Movement * timeChange.asSeconds());


		// Check collision
		if (ball.getPosition().y < 0 || ball.getPosition().y > 480){
			ballMovement.y *= -1;
		}
		if (ball.getGlobalBounds().intersects(p1Paddle.getGlobalBounds()) || ball.getGlobalBounds().intersects(p2Paddle.getGlobalBounds())){
			ballMovement.x *= -1;
		}



		// Scoring
		if (ball.getPosition().x > 600){
			// P1 scores
			ball.setPosition(300, 240);
			p1Score++;
			p1ScoreText.setString(std::to_string(p1Score));
		}
		else if (ball.getPosition().x < 0){
			// P2 scores
			ball.setPosition(300, 240);
			p2Score++;
			p2ScoreText.setString(std::to_string(p2Score));
		}

		ball.move(ballMovement * timeChange.asSeconds());


	}
void update(EntityFixture &fixture, const sf::Time &delta) {
    playerUpdater->update(delta);
    velocitiesUpdater->update(delta);
    walker->update(delta);
    poseUpdater->update(delta);
    xformHistorian->update(delta);

    dot.setPosition(fixture.GetInput().getCursorPosition());
}
Esempio n. 9
0
void ColorPalette::update(const sf::Time& dt) {
	if(sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
		double x = Settings::mouse_position.x;
		double y = Settings::mouse_position.y;

		if((angular[0]*x+linear[0]-y)<=0 &&
			(angular[1]*x+linear[1]-y)>=0 &&
			(angular[2]*x+linear[2]-y)<=0) {
			rgb_c.setPosition(x, y);
			identify(rgb, x, y);
			refresh();
		} else if((angular[3]*x+linear[3]-y)<=0 &&
			(angular[4]*x+linear[4]-y)>=0 &&
			(angular[5]*x+linear[5]-y)>=0) {
			bw_c.setPosition(x, y);
		}
	}
}
Esempio n. 10
0
Stone (float x, float y, float a, float b)
{
    velocity.x = x;
    velocity.y = y;
    s.setRadius(radius);
    s.setOrigin(radius,radius);
    s.setFillColor(sf::Color::Black);
    s.setPosition(a,b);

}
Esempio n. 11
0
void set_circle(sf::CircleShape& circle, const float value, const float norm_radius,
				const sf::Vector2f& position, const sf::Color& color)
{
	
	const float radius{sqrt_value_tot_radius(value, norm_radius)};
	
	circle.setRadius(radius);
	circle.setOrigin(radius, radius);
	circle.setPosition(position);
	circle.setFillColor(color);
	
}
Esempio n. 12
0
void ColorPalette::plot(const sf::VertexArray& shape) {
	double l = ColorPalette::dist(shape[0].position.x, shape[0].position.y,
			shape[1].position.x, shape[1].position.y);

	double da = l*(color.r)/255;
	double db = l*(color.g)/255;

	double x = (linear[1]-linear[2]+da-db)/(angular[2]-angular[1]);
	double y = angular[1]*x+linear[1]+da;

	rgb_c.setPosition(x, y);
}
Esempio n. 13
0
    // Costruttore: prende come parametri la posizione iniziale
    // della pallina, sotto forma di due `float`.
    Ball(float mX, float mY)
    {
        // SFML usa un sistema di coordinate avente l'origine
        // posizionata nell'angolo in alto a sinistra della
        // finestra.
        // {Info: coordinate system}

        shape.setPosition(mX, mY);
        shape.setRadius(defRadius);
        shape.setFillColor(defColor);
        shape.setOrigin(defRadius, defRadius);
    }
Esempio n. 14
0
void drawParticles(sf::RenderWindow &window, sf::CircleShape &particle_shape, b2ParticleSystem *particle_system)
{
	for(int i = 0; i < particle_system->GetParticleCount(); i++) //loops through all the particles
	{
		b2Vec2 pos = particle_system->GetPositionBuffer()[i]; //gets the position of the current particle

		if( &pos != NULL ) //if the particle exists
		{
			particle_shape.setPosition( pos.x, pos.y );
			window.draw( particle_shape );
		}
	}
}
Esempio n. 15
0
    void Game::cambiar_posicion_objectos(){

        int x_player;
        int y_player;
        int x_obj;
        int y_obj;

        while(true){

            x_player = rand() % 14;
            y_player = rand() % 10;

            x_obj = rand() % 14;
            y_obj = rand() % 10;

            if(Game::tabla_de_movimientos[y_obj][x_obj] == true & Game::tabla_de_movimientos[y_player][x_player] == true){
                break;
            }
        }

        mPlayerObj.setPosition(x_obj * 50, y_obj * 50);
        mPlayer.setPosition(x_player * 50, y_player * 50);
    }
Esempio n. 16
0
    Polygons():
            _polygons(),
            __polygonsVect()
    {
        _polygons.setRadius(50);
        _polygons.setFillColor(sf::Color::Red);

            for(int i = 3; i < 9;i++)
            {
                _polygons.setPointCount(i);
                _polygons.setPosition(100.0 + (i*99) , 200.0);
                __polygonsVect.push_back(_polygons);
            }

    }
Esempio n. 17
0
    // Fizyka
    void dzialaj(){
        if(pola[x][y+100]==0 &&skok==0)
            {

            y=y+1;}
        else
     {
      y-=skok*0.3;
    }



            x=x+ruch_prawo;
            x=x-ruch_lewo;
            if(skok>0)skok--;




            ksztalt.setPosition(x,y);
        }
Esempio n. 18
0
    cerclesTransparents():
        _mesCercles(),
        __vectCercles()
    {
        sf::Vector2u tailleWindow = _window.getSize();
        unsigned int hauteur = tailleWindow.y;
        unsigned int largeur = tailleWindow.x;
        float rayon = 400;

        for(int i = 0 ; i < 10; i++)
        {
            _mesCercles.setOrigin(rayon, rayon);
            _mesCercles.setPosition(400,400);
            _mesCercles.setRadius(rayon);
            _mesCercles.setFillColor(sf::Color(0.0, 0.0 + (25*i) , 255 - (25*i), 127));
            rayon -= 25;
            __vectCercles.push_back(_mesCercles);
        }

        cout << "Taille du vect --> " <<  __vectCercles.size() << endl;
    }
Esempio n. 19
0
//FUNKTIONSLEICHE
void Renderer::renderfirstderivation(std::vector<double> &firstderivationlocalcopyx, std::vector<double> &firstderivationlocalcopyfx, std::vector<double>::iterator &it3, std::vector<double>::iterator &it4, sf::CircleShape &firstderivationvalue, sf::RenderWindow &window)
{
    it4 = firstderivationlocalcopyfx.begin();
    if (m_1ablanzeigen == true)
    {
        for (it3 = firstderivationlocalcopyx.begin(); it3 < firstderivationlocalcopyx.end(); it3++)
        {
            firstderivationvalue.setPosition(10*(*it3)+m_width/2, -1*(10*(*it4))+m_heigth/2);
            it4++;
            window.draw(firstderivationvalue);
        }
    }
    
    else
    {
        window.clear(sf::Color(255,255,255,255));
        
    }

    *it3 = 0;
    *it4 = 0;
}
int main(int argc, char** argv)
{   sf::RenderWindow window(sf::VideoMode(400, 400), "Myo color picker");
	shape.setPosition(sf::Vector2f(50, 50));    
	shape.setFillColor(sf::Color::Green);
	color_input = true;
    // We catch any exceptions that might occur below -- see the catch statement for more details.
    try {

    // First, we create a Hub with our application identifier. Be sure not to use the com.example namespace when
    // publishing your application. The Hub provides access to one or more Myos.
    myo::Hub hub("com.example.hello-myo");

    std::cout << "Attempting to find a Myo..." << std::endl;

    // Next, we attempt to find a Myo to use. If a Myo is already paired in Myo Connect, this will return that Myo
    // immediately.
    // waitForAnyMyo() takes a timeout value in milliseconds. In this case we will try to find a Myo for 10 seconds, and
    // if that fails, the function will return a null pointer.
    myo::Myo* myo = hub.waitForMyo(10000);

    // If waitForAnyMyo() returned a null pointer, we failed to find a Myo, so exit with an error message.
    if (!myo) {
        throw std::runtime_error("Unable to find a Myo!");
    }

    // We've found a Myo.
    std::cout << "Connected to a Myo armband!" << std::endl << std::endl;

    // Next we construct an instance of our DeviceListener, so that we can register it with the Hub.
    DataCollector collector;

    // Hub::addListener() takes the address of any object whose class inherits from DeviceListener, and will cause
    // Hub::run() to send events to all registered device listeners.
    hub.addListener(&collector);



    // Finally we enter our main loop.
    while (1) {
        // In each iteration of our main loop, we run the Myo event loop for a set number of milliseconds.
        // In this case, we wish to update our display 20 times a second, so we run for 1000/20 milliseconds.
        hub.run(1000/20);
        // After processing events, we call the print() member function we defined above to print out the values we've
        // obtained from any events that have occurred.
        collector.print();
		if(window.isOpen())
		{	        sf::Event event;
			 while (window.pollEvent(event))
			{
			    if (event.type == sf::Event::Closed)
			   {    window.close();
					 return 0;
				}
			
			}

        window.clear();
        window.draw(shape);
        window.display();
		}
    }

    // If a standard exception occurred, we print out its message and exit.
    } catch (const std::exception& e) {
        std::cerr << "Error: " << e.what() << std::endl;
        std::cerr << "Press enter to continue.";
        std::cin.ignore();
        return 1;
    }
}
Esempio n. 21
0
	Ball(float mX, float mY) {
		shape.setPosition(mX, mY);
		shape.setRadius(ballRadius);
		shape.setFillColor(sf::Color::Red);
		shape.setOrigin(ballRadius, ballRadius);
	}
Esempio n. 22
0
void Renderer::renderfunction(std::vector<double> &localcopyx, std::vector<double> &localcopyfx, std::vector<double>::iterator &it, std::vector<double>::iterator &it2, sf::CircleShape &values, sf::RenderWindow &window, std::vector<double> &firstderivationlocalcopyx, std::vector<double> &firstderivationlocalcopyfx, std::vector<double>::iterator &it3, std::vector<double>::iterator &it4, sf::CircleShape &firstderivationvalue)
{
    it2 = localcopyfx.begin();
    it4 = firstderivationlocalcopyfx.begin();
    if (m_stammanzeigen == true && m_1ablanzeigen == true)
    {
        for (it = localcopyx.begin(); it < localcopyx.end(); it++)
        {
            //std::cout << (*it) << std::endl;
            // (xwerte\ywerte)
            values.setPosition(10*(*it)+m_width/2, -1*(10*(*it2))+m_heigth/2);
            it2++;
            window.draw(values);
        }
        
        
        for (it3 = firstderivationlocalcopyx.begin(); it3 < firstderivationlocalcopyx.end(); it3++)
        {
            firstderivationvalue.setPosition(10*(*it3)+m_width/2, -1*(10*(*it4))+m_heigth/2);
            it4++;
            window.draw(firstderivationvalue);
        }
        

    }
    
    else if (m_stammanzeigen == false && m_1ablanzeigen == true)
    {
        for (it3 = firstderivationlocalcopyx.begin(); it3 < firstderivationlocalcopyx.end(); it3++)
        {
            firstderivationvalue.setPosition(10*(*it3)+m_width/2, -1*(10*(*it4))+m_heigth/2);
            it4++;
            window.draw(firstderivationvalue);
        }

    }
    else if (m_stammanzeigen == true && m_1ablanzeigen == false)
    {
        for (it = localcopyx.begin(); it < localcopyx.end(); it++)
        {
            //std::cout << (*it) << std::endl;
            // (xwerte\ywerte)
            values.setPosition(10*(*it)+m_width/2, -1*(10*(*it2))+m_heigth/2);
            it2++;
            window.draw(values);
        }
    
    }
    else
    {
        window.clear(sf::Color(255,255,255,255));
        
    }
    
    
    *it = 0;
    *it2 =0;
    *it3 = 0;
    *it4 = 0;

}
Esempio n. 23
0
int		main()
{
	sf::Clock			clock;
	double				s = 0;
	
	double				viewZoom = 1.0f;

	srand(time(0));

	for (u32 i = 0; i < PN; i++)
	{
		particule[i]._px = rand() % WINX;
		particule[i]._py = rand() % WINY;
		if (INITIAL_SPEED_ACTIVATE)
		{
			particule[i]._mx = ((rand() % INITIAL_SPEED) - INITIAL_SPEED / 2) / INITIAL_SPEED_DIV;
			particule[i]._my = ((rand() % INITIAL_SPEED) - INITIAL_SPEED / 2) / INITIAL_SPEED_DIV;
		}
		else
		{
			particule[i]._mx = 0;
			particule[i]._my = 0;
		}
		particule[i]._mass = PAR_MASS;
		particule[i]._color = PCOLOR;
	}

	planet.setPosition(sf::Vector2f(WINX/2, WINY/2));
	planet.setOrigin(sf::Vector2f(10.0f, 10.0f));
	planet.setFillColor(sf::Color::Blue);

	win.create(sf::VideoMode(WINX, WINY), "ORBITE");
	win.setFramerateLimit(MAXFPS);
	clock.restart();
	while (win.isOpen())
	{
		s = clock.restart().asSeconds();
		s *= SPEED;

		sf::View view = win.getDefaultView();
		view.zoom(viewZoom);

		while (win.pollEvent(eve))
		{
			if (eve.type == sf::Event::Closed)
				win.close();
			if (eve.type == sf::Event::KeyPressed)
			{
				if (eve.key.code == sf::Keyboard::Add)
					viewZoom -= 0.25f;
				else if (eve.key.code == sf::Keyboard::Subtract)
					viewZoom += 0.25f;
				else if (eve.key.code == sf::Keyboard::Space)
				{
					trace.clear();
					for (u32 i = 0; i < PN; i++)
					{
						particule[i]._px = rand() % WINX;
						particule[i]._py = rand() % WINY;
						if (INITIAL_SPEED_ACTIVATE)
						{
							particule[i]._mx = ((rand() % INITIAL_SPEED) - INITIAL_SPEED / 2) / INITIAL_SPEED_DIV;
							particule[i]._my = ((rand() % INITIAL_SPEED) - INITIAL_SPEED / 2) / INITIAL_SPEED_DIV;
						}
						else
						{
							particule[i]._mx = 0;
							particule[i]._my = 0;
						}
						particule[i]._mass = PAR_MASS;
						particule[i]._color = PCOLOR;
					}		
				}
			}
		}
		
		planet.setPosition((sf::Vector2f)sf::Mouse::getPosition(win));
		for (u32 i = 0; i < PN; i++)
		{
			particule[i].updateToPosition(planet.getPosition(), PL_MASS, s);
			part[i].position = sf::Vector2f(particule[i]._px, particule[i]._py);
			part[i].color = particule[i]._color;
			if (ACTIVATE_ORBIT_TRACE)
			{
				sf::Vertex cpy = part[i];
				trace.append(cpy);
			}
		}
		win.setView(view);
		win.clear(sf::Color::Black);
		win.draw(planet);
		win.draw(part);
		win.draw(trace);
		win.display();
	}
	return (0);
}
Esempio n. 24
0
static void drawCrosshair(sf::RenderWindow &window)
{
	crosshair.setPosition(sf::Vector2f(sf::Mouse::getPosition(window)));
	window.draw(crosshair);
}
Esempio n. 25
0
int main(int argc, char* argv[])
{
    if(argc < 2){
        ADDRESS = "localhost";
    }else{
    	std::string line = argv[1];
    	
    	int colon_pos = line.find(":");
    	if(colon_pos != std::string::npos){
    		ADDRESS = line.substr(0, colon_pos);
    		PORT = std::stoi(line.substr(colon_pos + 1, std::string::npos));
    	}else{
    		ADDRESS = line;
    	}
    }
    std::cout << ADDRESS << std::endl;
    std::cout << PORT << std::endl;
    
    //start ros thread
    XInitThreads();
    std::thread ros_thread(ros_stuff);
    
    //Initialize OSC stuff
    UdpTransmitSocket transmit_socket( IpEndpointName( ADDRESS.c_str(), PORT ) );
    
    listener = new LRPacketListener();
    //listener->registerStringCallback(nothing);
    listener->registerTransportCallback(sync);
    listener->registerPlaybackCallback(playbackChanged);
    listener->registerClipUpdateCallback(loadClip);
    receive_socket = new UdpListeningReceiveSocket(IpEndpointName( IpEndpointName::ANY_ADDRESS, PORT ), listener);
    
    //Set up threads
    std::thread listen_thread(listen);

	//interupt quits
    signal(SIGINT, [](int signum){std::cout << "okay" << std::endl; quit = true; receive_socket->Break(); receive_socket->AsynchronousBreak();});
    
    //conductor
    listener->registerTransportCallback(update_baton);
    
    //SFML
    sf::Font font;
	if (!font.loadFromFile("Ubuntu-R.ttf"))
	{
		std::cout << "where's the font?" << std::endl;
	}
	play_shape.rotate(90);
	play_shape.setPosition(700, 10);
	play_shape.setFillColor(sf::Color::Green);
	stop_shape.setPosition(700, 10);
	stop_shape.setFillColor(sf::Color::Red);
	
	for(int i = 0; i < 50; i++){
		
		sf::CircleShape baton(8, 20);
		sf::Color color(255, i*255/50, 0, 51*(i-50)*(i-50)/500);
		baton.setFillColor(color);
		baton.setPosition(400, 300);
		baton_trail.push_back(baton);
	}

	// select the font
	transport_text.setFont(font); // font is a sf::Font
	time_text.setFont(font);
	offset_text.setFont(font);
	debug_text.setFont(font);
	transport_text.setCharacterSize(24); // in pixels, not points!
	time_text.setCharacterSize(24);
	offset_text.setCharacterSize(24);
	debug_text.setCharacterSize(24);
	transport_text.setColor(sf::Color::White);
	time_text.setColor(sf::Color::White);
	offset_text.setColor(sf::Color::White);
	debug_text.setColor(sf::Color::White);
	transport_text.setPosition(10, 10);
	time_text.setPosition(10, 40);
	offset_text.setPosition(10, 70);
	debug_text.setPosition(400, 70);

	// set the string to display
	transport_text.setString("Hello world");
	time_text.setString("waiting...");
	offset_text.setString("no offset");

    //sfml window
    sf::ContextSettings settings;
	settings.antialiasingLevel = 8;
    sf::RenderWindow window(sf::VideoMode(800, 600), "Terpsichore", sf::Style::Default, settings);
    window.setVerticalSyncEnabled(true);
    
        
    //request initial information
    send("/terpsichore", (int)1, transmit_socket);
    
    // run the program as long as the window is open
    while (window.isOpen())
    {
        // check all the window's events that were triggered since the last iteration of the loop
        sf::Event event;
        while (window.pollEvent(event))
        {
            // "close requested" event: we close the window
            if (event.type == sf::Event::Closed){
                window.close();
                quit = true;
                receive_socket->Break(); 
                receive_socket->AsynchronousBreak();
            }
        }
        // clear the window with black color
        window.clear(sf::Color::Black);

        // draw everything here...
        
        // draw the notes of the currently playing clips
        double y = 100.0;
        double scale = 50.0;
        for(std::map<int, Clip*>::iterator clip_it = listener->clips.begin(); clip_it != listener->clips.end(); clip_it++){
        	
        	Clip* c = clip_it->second;
        	for(std::multimap<Position, Note>::iterator note_it = c->notes.begin(); note_it != c->notes.end(); note_it++){
        		Position p = note_it->first;
        		Note n = note_it->second;
        		double x = p.toFloat(listener->transport.timeSignature) * scale + 10;
        		double w = n.duration * scale;
        		double h = n.pitch;
        		
        		sf::RectangleShape noteRect(sf::Vector2f(w, h));
        		noteRect.setFillColor(sf::Color::Blue);
        		noteRect.setOutlineThickness(2);
        		noteRect.setOutlineColor(sf::Color::Cyan);
        		noteRect.setPosition(x, y);
        		window.draw(noteRect); 
        	}
        	y += 80;
        	debug_text.setString(std::to_string(y));
        }
        
        
        // window.draw(...);
        transport_text.setString(transport_string);
        time_text.setString(time_string);
        window.draw(time_text);
        offset_text.setString(offset_string);
        window.draw(offset_text);
        window.draw(debug_text);

		if(playing){
			window.draw(play_shape);
		}else{
			window.draw(stop_shape);
		}
        //draw the baton point;
        for(int i = baton_trail.size() - 1; i >= 0; i--){
	        window.draw(baton_trail.at(i));
        }

        window.draw(transport_text);
        // end the current frame
        window.display();
    }
    
    
    //stopping threads
    std::cout << "attempting to join\n";
    listen_thread.join();
    ros_thread.join();
    
    delete receive_socket;
    delete listener;

    return 0;
}
Esempio n. 26
0
void fixCircle( sf::RenderWindow& window, sf::CircleShape& circ )
{
	sf::Vector2i mousePos = sf::Mouse::getPosition( window );
	circ.setPosition( mousePos.x, mousePos.y );
}