SceneHandler::SceneHandler(std::shared_ptr<sf::RenderWindow> window)
	: m_window(window)
	, m_isPathActive(false)
	, m_isObstacleActive(false)
	, m_leader(nullptr)
{
	m_unitTexture.loadFromFile("unit.png");


	sf::RectangleShape shape1(sf::Vector2f(300.0f, 150.0f));
	shape1.setPosition(150.0f, 400.0f);
	shape1.setFillColor(sf::Color::Black);
	m_obstacles.push_back(shape1);

	/*sf::RectangleShape shape2(sf::Vector2f(120.0f, 200.0f));
	shape2.setPosition(500.0f, 70.0f);
	shape2.setFillColor(sf::Color::Black);
	m_obstacles.push_back(shape2);*/

	sf::RectangleShape shape3(sf::Vector2f(340.0f, 70.0f));
	shape3.setPosition(800.0f, 500.0f);
	shape3.setFillColor(sf::Color::Black);
	m_obstacles.push_back(shape3);

	m_ankers.push_back(createAnger(Vec2(-10.f, 30.0f)));
	m_ankers.push_back(createAnger(Vec2(0.f, 50.0f)));
	m_ankers.push_back(createAnger(Vec2(-50.f, 50.0f)));
	m_ankers.push_back(createAnger(Vec2(-70.f, 30.0f)));
	m_ankers.push_back(createAnger(Vec2(-70.f, 0.0f)));
	m_ankers.push_back(createAnger(Vec2(-70.f, -30.0f)));
	m_ankers.push_back(createAnger(Vec2(-50.f, -50.0f)));

}
Beispiel #2
0
  void ScalarFiniteElement<D> ::
  CalcDShape (const IntegrationPoint & ip, 
	      FlatMatrixFixWidth<D> dshape) const
  
  {
    static bool firsttime = true;
    if (firsttime)
      {
	cout << "WARNING: CalcDShape not overloaded for class, using numerical differentiation " << typeid(this).name() << ", ndof = " << ndof << endl;
        firsttime = false;
      }
    
    int nd = GetNDof();
    int sdim = D;

    double eps = 2e-5;
    ArrayMem<double, 100> hm1(nd), hm2(nd), hm3(nd), hm4(nd);
    FlatVector<> 
      shape1(nd, &hm1[0]), 
      shape2(nd, &hm2[0]), 
      shape3(nd, &hm3[0]), 
      shape4(nd, &hm4[0]);

    for (int i = 0; i < sdim; i++)
      {
	IntegrationPoint ip1 = ip;
	IntegrationPoint ip2 = ip;
        ip1(i) -= eps;
        ip2(i) += eps;
	CalcShape (ip1, shape1);
	CalcShape (ip2, shape2);

        ip1(i) -= eps;
        ip2(i) += eps;
	CalcShape (ip1, shape3);
	CalcShape (ip2, shape4);

	for (int j = 0; j < nd; j++)
	  dshape(j, i) = 
	    2/(3*eps) * (shape2(j) - shape1(j)) 
	    -1/(12*eps) * (shape4(j) - shape3(j));
      }
  }
Beispiel #3
0
void			Resum::drawBorder(const sf::Vector2f &pos)
{
  sf::RectangleShape	shape(sf::Vector2f(1000, 500));
  sf::RectangleShape	shape2(sf::Vector2f(1000, 10));
  sf::RectangleShape	shape3(sf::Vector2f(1000, 3));
  
  shape.setPosition(pos.x - 500, pos.y + 300);
  shape2.setPosition(pos.x - 500, pos.y + 300);
  shape.setFillColor(sf::Color(20, 121, 17));
  shape2.setFillColor(sf::Color(8, 57, 6));
  _window->draw(shape);
  _window->draw(shape2);

  shape3.setFillColor(sf::Color(8, 57, 6));
  shape3.setPosition(pos.x - 500, pos.y + 360);
  _window->draw(shape3);
}
 tensor3 upsampling2d(const tensor3& in_vol) const
 {
     tensor3 out_vol(shape3(
         in_vol.shape().depth_,
         in_vol.shape().height_ * scale_factor_.height_,
         in_vol.shape().width_ * scale_factor_.width_), 0);
     for (std::size_t z = 0; z < in_vol.shape().depth_; ++z)
     {
         for (std::size_t y = 0; y < out_vol.shape().height_; ++y)
         {
             std::size_t y_in = y / scale_factor_.height_;
             for (std::size_t x = 0; x < out_vol.shape().width_; ++x)
             {
                 std::size_t x_in = x / scale_factor_.width_;
                 out_vol.set(z, y, x, in_vol.get(z, y_in, x_in));
             }
         }
     }
     return out_vol;
 }
Beispiel #5
0
int			main(int ac, char **av) {
    SocketTCPClient	client;
    sf::RenderWindow	window(sf::VideoMode(800, 800), "SFML color game");
    sf::CircleShape	shape(400.f);
    sf::CircleShape	shape2(300.f);
    sf::CircleShape	shape3(200.f);
    sf::Color		color;
    sf::Color		color2;
    sf::Color		color3;
    FDSet		fdSet;
    char		buff[1024];
    std::string		entry;
    int			nbRead;
    sf::Event		event;
    struct timeval	tv;

    if (ac != 4)
    {
	std::cout << "./client host port name" << std::endl;
	return (0);
    }
    client.start();
    client.connectToServer(av[1], atoi(av[2]));
    color = sf::Color::Red;
    color2 = sf::Color::Yellow;
    color3 = sf::Color::Green;
    shape.setFillColor(color);
    shape2.setFillColor(color2);
    shape3.setFillColor(color3);
    while (window.isOpen())
    {
	fdSet.zero();
	fdSet.set(&client);
	fdSet.set(0);
	tv.tv_sec = 1;
	tv.tv_usec = 0;
	if (!Select::call(&fdSet, NULL, &tv))
	{
	    std::cout << "Client : Socket managment failed" << std::endl;
	    return (-1);
	}
	if (fdSet.isset(&client))
	{
	    memset(buff, 0, 1024);		
	    if ((nbRead = client.receive(buff, 1024)) == 0)
	    {
		client.close();
		std::cout << "Server left" << std::endl;
		return 0;
	    }
	    buff[nbRead] = 0;
	    if (std::string(buff) == "BIENVENU")
	    {
		client.send(("player|" + std::string(av[3])).c_str(), 7 + std::string(av[3]).length());
	    }
	    else if (std::string(buff) == "kick")
	    {
		std::cout << "You are kicked by server" << std::endl;
		return (0);
	    }
	    else if (std::string(buff) == "1")
	    {
		color = sf::Color::Blue;
		color2 = sf::Color::Red;
		color3 = sf::Color::Yellow;

		shape.setFillColor(color);
		shape2.setFillColor(color2);
		shape3.setFillColor(color3);

	    }
	    else if (std::string(buff) == "2")
	    {
		color = sf::Color::Black;
		color2 = sf::Color::White;
		color3 = sf::Color::Blue;

		shape.setFillColor(color);
		shape2.setFillColor(color2);
		shape3.setFillColor(color3);

	    }
	    else if (std::string(buff) == "3")
	    {
		color = sf::Color::Red;
		color2 = sf::Color::Yellow;
		color3 = sf::Color::Green;
		shape.setFillColor(color);
		shape2.setFillColor(color2);
		shape3.setFillColor(color3);

	    }
	    std::cout << "msg : " << buff << std::endl;
	}	
	if (fdSet.isset(0))
	{
	    std::getline(std::cin, entry);
	    client.send(entry.c_str(), entry.length());
	}	
	while (window.pollEvent(event))
	{
	    if (event.type == sf::Event::Closed)
		window.close();
	}
	window.clear();
	window.draw(shape);
	window.draw(shape2);
	window.draw(shape3);
	window.display();
    }
}
Beispiel #6
0
void TestShapePainting::testPaintOrder()
{
    // the stacking order determines the painting order so things on top
    // get their paint called last.
    // Each shape has a zIndex and within the children a container has
    // it determines the stacking order. Its important to realize that
    // the zIndex is thus local to a container, if you have layer1 and layer2
    // with both various child shapes the stacking order of the layer shapes
    // is most important, then within this the child shape index is used.

    class OrderedMockShape : public MockShape {
    public:
        OrderedMockShape(QList<MockShape*> &list) : order(list) {}
        void paint(QPainter &painter, const KViewConverter &converter) {
            order.append(this);
            MockShape::paint(painter, converter);
        }
        QList<MockShape*> &order;
    };

    QList<MockShape*> order;

    MockContainer top;
    top.setZIndex(2);
    OrderedMockShape shape1(order);
    shape1.setZIndex(5);
    OrderedMockShape shape2(order);
    shape2.setZIndex(0);
    top.addShape(&shape1);
    top.addShape(&shape2);

    MockContainer bottom;
    bottom.setZIndex(1);
    OrderedMockShape shape3(order);
    shape3.setZIndex(-1);
    OrderedMockShape shape4(order);
    shape4.setZIndex(9);
    bottom.addShape(&shape3);
    bottom.addShape(&shape4);

    MockCanvas canvas;
    KShapeManager manager(&canvas);
    manager.addShape(&top);
    manager.addShape(&bottom);
    QCOMPARE(manager.shapes().count(), 6);

    QImage image(100, 100,  QImage::Format_Mono);
    QPainter painter(&image);
    KViewConverter vc;
    manager.paint(painter, vc, false);
    QCOMPARE(top.paintedCount, 1);
    QCOMPARE(bottom.paintedCount, 1);
    QCOMPARE(shape1.paintedCount, 1);
    QCOMPARE(shape2.paintedCount, 1);
    QCOMPARE(shape3.paintedCount, 1);
    QCOMPARE(shape4.paintedCount, 1);

    QCOMPARE(order.count(), 4);
    QVERIFY(order[0] == &shape3); // lowest first
    QVERIFY(order[1] == &shape4);
    QVERIFY(order[2] == &shape2);
    QVERIFY(order[3] == &shape1);

    // again, with clipping.
    order.clear();
    painter.setClipRect(0, 0, 100, 100);
    manager.paint(painter, vc, false);
    QCOMPARE(top.paintedCount, 2);
    QCOMPARE(bottom.paintedCount, 2);
    QCOMPARE(shape1.paintedCount, 2);
    QCOMPARE(shape2.paintedCount, 2);
    QCOMPARE(shape3.paintedCount, 2);
    QCOMPARE(shape4.paintedCount, 2);

    QCOMPARE(order.count(), 4);
    QVERIFY(order[0] == &shape3); // lowest first
    QVERIFY(order[1] == &shape4);
    QVERIFY(order[2] == &shape2);
    QVERIFY(order[3] == &shape1);

    order.clear();
    
    MockContainer root;
    root.setZIndex(0);
    
    MockContainer branch1;
    branch1.setZIndex(1);
    OrderedMockShape child1_1(order);
    child1_1.setZIndex(1);
    OrderedMockShape child1_2(order);
    child1_2.setZIndex(2);
    branch1.addShape(&child1_1);
    branch1.addShape(&child1_2);
    
    MockContainer branch2;
    branch2.setZIndex(2);
    OrderedMockShape child2_1(order);
    child2_1.setZIndex(1);
    OrderedMockShape child2_2(order);
    child2_2.setZIndex(2);
    branch2.addShape(&child2_1);
    branch2.addShape(&child2_2);
 
    root.addShape(&branch1);
    root.addShape(&branch2);
    
    QList<KShape*> sortedShapes;
    sortedShapes.append(&root);
    sortedShapes.append(&branch1);
    sortedShapes.append(&branch2);
    sortedShapes.append(branch1.shapes());
    sortedShapes.append(branch2.shapes());
    
    qSort(sortedShapes.begin(), sortedShapes.end(), KShape::compareShapeZIndex);
    QCOMPARE(sortedShapes.count(), 7);
    QVERIFY(sortedShapes[0] == &root);
    QVERIFY(sortedShapes[1] == &branch1);
    QVERIFY(sortedShapes[2] == &child1_1);
    QVERIFY(sortedShapes[3] == &child1_2);
    QVERIFY(sortedShapes[4] == &branch2);
    QVERIFY(sortedShapes[5] == &child2_1);
    QVERIFY(sortedShapes[6] == &child2_2);
}
Beispiel #7
0
TEST(SAVE, SaveGraph)
{
	std::string expect_pbfile = testdir + "/graph.pb";
	std::string got_pbfile = "got_graph.pb";
	cortenn::Graph graph;
	std::vector<ade::TensptrT> roots;

	pbm::PathedMapT labels;
	// subtree one
	ade::Shape shape({3, 7});
	ade::TensptrT osrc(new MockTensor(shape));

	ade::Shape shape2({7, 3});
	ade::TensptrT osrc2(new MockTensor(shape2));

	labels[osrc] = {"global", "osrc"};
	labels[osrc2] = {"global", "osrc2"};

	{
		ade::TensptrT src(new MockTensor(shape));

		ade::Shape shape3({3, 1, 7});
		ade::TensptrT src2(new MockTensor(shape3));

		ade::TensptrT dest(ade::Functor::get(ade::Opcode{"-", 0}, {
			{src2, ade::identity},
			{ade::TensptrT(ade::Functor::get(ade::Opcode{"@", 1}, {
				{ade::TensptrT(ade::Functor::get(ade::Opcode{"/", 2}, {
					{ade::TensptrT(ade::Functor::get(ade::Opcode{"neg", 3}, {
						{osrc, ade::identity},
					})), ade::identity},
					{ade::TensptrT(ade::Functor::get(ade::Opcode{"+", 4}, {
						{ade::TensptrT(
							ade::Functor::get(ade::Opcode{"sin", 5}, {
							{src, ade::identity}})), ade::identity},
						{src, ade::identity},
					})), ade::identity}
				})), ade::permute({1, 0})},
				{osrc2, ade::identity}
			})), ade::permute({1, 2, 0})},
		}));
		roots.push_back(dest);

		labels[src] = {"subtree", "src"};
		labels[src2] = {"subtree", "src2"};
		labels[dest] = {"subtree", "dest"};
	}

	// subtree two
	{
		ade::Shape mshape({3, 3});
		ade::TensptrT src(new MockTensor(mshape));

		ade::TensptrT src2(new MockTensor(mshape));

		ade::TensptrT src3(new MockTensor(mshape));

		ade::TensptrT dest(ade::Functor::get(ade::Opcode{"-", 0}, {
			{src, ade::identity},
			{ade::TensptrT(ade::Functor::get(ade::Opcode{"*", 6}, {
				{ade::TensptrT(ade::Functor::get(ade::Opcode{"abs", 7}, {
					{src, ade::identity},
				})), ade::identity},
				{ade::TensptrT(ade::Functor::get(ade::Opcode{"exp", 8}, {
					{src2, ade::identity},
				})), ade::identity},
				{ade::TensptrT(ade::Functor::get(ade::Opcode{"neg", 3}, {
					{src3, ade::identity},
				})), ade::identity},
			})), ade::identity},
		}));
		roots.push_back(dest);

		labels[src] = {"subtree2", "src"};
		labels[src2] = {"subtree2", "src2"};
		labels[src3] = {"subtree2", "src3"};
		labels[dest] = {"subtree2", "dest"};
	}

	pbm::GraphSaver<TestSaver> saver;
	for (auto& root : roots)
	{
		root->accept(saver);
	}

	saver.save(graph, labels);

	{
		std::fstream gotstr(got_pbfile,
			std::ios::out | std::ios::trunc | std::ios::binary);
		ASSERT_TRUE(gotstr.is_open());
		ASSERT_TRUE(graph.SerializeToOstream(&gotstr));
	}

	std::fstream expect_ifs(expect_pbfile, std::ios::in | std::ios::binary);
	std::fstream got_ifs(got_pbfile, std::ios::in | std::ios::binary);
	ASSERT_TRUE(expect_ifs.is_open());
	ASSERT_TRUE(got_ifs.is_open());

	std::string expect;
	std::string got;
	// skip the first line (it contains timestamp)
	expect_ifs >> expect;
	got_ifs >> got;
	for (size_t lineno = 1; expect_ifs && got_ifs; ++lineno)
	{
		expect_ifs >> expect;
		got_ifs >> got;
		EXPECT_STREQ(expect.c_str(), got.c_str()) << "line number " << lineno;
	}
}