// We define this function to print the current values that were updated by the on...() functions above.
    void print()
    {
        // Clear the current line
        std::cout << '\r';

        // Print out the orientation. Orientation data is always available, even if no arm is currently recognized.
        std::cout << '[' << std::string(roll_w, '*') << std::string(18 - roll_w, ' ') << ']'
                  << '[' << std::string(pitch_w, '*') << std::string(18 - pitch_w, ' ') << ']'
                  << '[' << std::string(yaw_w, '*') << std::string(18 - yaw_w, ' ') << ']'<< std::endl;
		if(color_input == true)
		{	shape.setFillColor(sf::Color((roll_w*10.75), ((270+pitch_w)*10.75), ((90 +yaw_w)*10.75)));
		}	
		
        if (onArm) {
            // Print out the currently recognized pose and which arm Myo is being worn on.

            // Pose::toString() provides the human-readable name of a pose. We can also output a Pose directly to an
            // output stream (e.g. std::cout << currentPose;). In this case we want to get the pose name's length so
            // that we can fill the rest of the field with spaces below, so we obtain it as a string using toString().
            std::string poseString = currentPose.toString();

            std::cout << '[' << (whichArm == myo::armLeft ? "L" : "R") << ']'
                      << '[' << poseString << std::string(14 - poseString.size(), ' ') << ']';
        } else {
            // Print out a placeholder for the arm and pose when Myo doesn't currently know which arm it's on.
            std::cout << "[?]" << '[' << std::string(14, ' ') << ']';
        }

        std::cout << std::flush;
    }
Пример #2
0
 Ball(float mX, float mY)
 {
     shape.setPosition(mX, mY);
     shape.setRadius(defRadius);
     shape.setFillColor(defColor);
     shape.setOrigin(defRadius, defRadius);
 }
Пример #3
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);
	}
Пример #4
0
void ColorPalette::refresh(void) {
	selected.setFillColor(color);
	label.setColor(color);

	label.setString(ColorPalette::interpret(color, str));

	rgb_c.setOutlineColor(Utility::Color::getInverseColor(color));
	bw_c.setOutlineColor(Utility::Color::getInverseColor(color));
}
Пример #5
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);

}
Пример #6
0
static void init(sf::RenderWindow &window)
{
	window.setMouseCursorVisible(false);
	window.setVerticalSyncEnabled(true);

	crosshair.setFillColor(sf::Color(0, 0, 0, 0));
	crosshair.setOutlineColor(sf::Color(0, 0, 0));
	crosshair.setOutlineThickness(2.0f);

	srand(static_cast<unsigned>(time(0)));
}
Пример #7
0
		void createGeometry() {
			fill = type == Type::Follower ? sf::Color(198, 156, 109, 255) : sf::Color(0, 191, 243, 255);
			outline = type == Type::Follower ?  sf::Color(166, 124, 82, 255) : sf::Color(64, 140, 203, 255);

			geometry.setRadius(radius);
			geometry.setPointCount(6);
			geometry.setFillColor(fill);
			geometry.setOutlineColor(outline);
			geometry.setOutlineThickness(2);
			geometry.setOrigin(radius, radius);
		}
Пример #8
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);
    }
Пример #9
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);
	
}
Пример #10
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);
            }

    }
Пример #11
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;
    }
int main()
{

	WSADATA wsaData;
	SOCKET ConnectSocket = INVALID_SOCKET;
	struct addrinfo *result = NULL,
		*ptr = NULL,
		hints;
	char sendbuf[DEFAULT_BUFLEN];
	int iResult;
	int recvbuflen = DEFAULT_BUFLEN;


	// Initialize Winsock
	iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
	if (iResult != 0)
	{
		printf("WSAStartup failed with error: %d\n", iResult);
		return 1;
	}

	ZeroMemory(&hints, sizeof(hints));
	hints.ai_family = AF_UNSPEC;
	hints.ai_socktype = SOCK_STREAM;
	hints.ai_protocol = IPPROTO_TCP;

	// Resolve the server address and port
	iResult = getaddrinfo("localhost", DEFAULT_PORT, &hints, &result);
	if (iResult != 0)
	{
		printf("getaddrinfo failed with error: %d\n", iResult);
		WSACleanup();
		return 1;
	}

	// Attempt to connect to an address until one succeeds
	for (ptr = result; ptr != NULL; ptr = ptr->ai_next)
	{
		// Create a SOCKET for connecting to server
		ConnectSocket = socket(ptr->ai_family, ptr->ai_socktype, ptr->ai_protocol);
		if (ConnectSocket == INVALID_SOCKET)
		{
			printf("socket failed with error: %ld\n", WSAGetLastError());
			WSACleanup();
			return 1;
		}

		// Connect to server.
		iResult = connect(ConnectSocket, ptr->ai_addr, (int)ptr->ai_addrlen);
		if (iResult == SOCKET_ERROR)
		{
			closesocket(ConnectSocket);
			ConnectSocket = INVALID_SOCKET;
			continue;
		}
		break;
	}

	freeaddrinfo(result);

	if (ConnectSocket == INVALID_SOCKET)
	{
		printf("Unable to connect to server!\n");
		WSACleanup();
		return 1;
	}

	std::thread th(ReceiveThread, ConnectSocket);
	th.detach();
	std::thread th1(SendThread, ConnectSocket);
	th1.detach();
	
	sf::RenderWindow window(sf::VideoMode(800, 200), "SFML works!");
	shape.setFillColor(sf::Color::Green);
	
	sf::Event event;

	while (window.isOpen())
	{
		while (window.pollEvent(event))
		{	
			switch (event.type)// check the type of the event...
			{
			case sf::Event::Closed:
				window.close();
				break;
			case sf::Event::KeyPressed:
				movementMutex.lock();
				if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
					movement-=5;
				if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
					movement+=5;
				movementMutex.unlock();
					break;
			default:
				break;
			}

		}

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

	return 0;
}
TEST_F(EntityFixture, PlayerTest) {
    GetInput().assignKey(sf::Keyboard::W, Input::Up);
    GetInput().assignKey(sf::Keyboard::A, Input::Left);
    GetInput().assignKey(sf::Keyboard::S, Input::Down);
    GetInput().assignKey(sf::Keyboard::D, Input::Right);
    GetInput().assignMouseButton(sf::Mouse::Left, Input::Shoot);
    GetInput().setMouseLock(true);
    GetWindow().setMouseCursorVisible(false);

    dot.setFillColor(sf::Color::Red);

    // Add behaviors
    playerUpdater = da::BehaviorPtr(new PlayerUpdater(GetView(), GetInput()));
    GetManager().addBehavior(playerUpdater);
    GetManager().addBehavior(velocitiesUpdater);
    GetManager().addBehavior(walker);
    GetManager().addBehavior(poseUpdater);
    GetManager().addBehavior(xformHistorian);

    // Add spatial
    GetRenderer().registerSpatial<SpriteSpatial>();

    // Create entity
    entity = GetManager().create();
    entity->addAttribute(new da::Transform);
    entity->addAttribute(new da::Depth);

    da::TexturePtr texture = GetContent().load<sf::Texture>("mans.png");
    entity->addAttribute(new Sprite(texture));
    entity->addAttribute(new TransformHistory);
    entity->addAttribute(new Collider);
    entity->addAttribute(new Velocities);

    Poses *poses = new Poses;

    Pose pose(6);
    for (unsigned int j = 0; j < DirectionCount; j++) {
        for (unsigned int i = 0; i < pose.getFrameCount(); i++) {
            Pose::Frame frame = {
                sf::IntRect(i * 16, j * 24, 16, 24),
                sf::Vector2f(8, 20)
            };

            pose.setFrame((CardinalDirection)j, i, frame);
        }
    }
    poses->addPose("walk", pose);

    poses->isLoop = true;
    poses->timePerFrame = sf::seconds(0.25f);
    poses->setPose("walk", 0);
    entity->addAttribute(poses);

    Player *player = new Player;
    player->walkSpeed = 100.f;
    player->viewDistance = 40.f;
    entity->addAttribute(player);

    GetManager().refresh(entity);

    Run(update, emptyHandler, draw);
}
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;
    }
}
Пример #15
0
	Ball(float mX, float mY) {
		shape.setPosition(mX, mY);
		shape.setRadius(ballRadius);
		shape.setFillColor(sf::Color::Red);
		shape.setOrigin(ballRadius, ballRadius);
	}
Пример #16
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;
}
Пример #17
0
 // Set my general, Maybe roll this into constructor
 inline void set_owner(OgrePlayer *player)
 {
     owner = player;
     circ.setFillColor(owner->get_color());
 }
Пример #18
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);
}
Пример #19
0
void Unit::setFillColor(sf::Color color) {
	_circle.setFillColor(color);
}