예제 #1
0
		/**
			Append a quad to a vertexarray. This version takes Vertexcolors
		*/
		inline void AppendQuad(sf::VertexArray& vA, const sf::FloatRect& Pos, sf::Color c) {
			sf::Vertex vs[4];
			SetQuadPos(vs, Pos);
			SetQuadColor(vs, c);

			vA.append(vs[0]);
			vA.append(vs[1]);
			vA.append(vs[2]);
			vA.append(vs[3]);
		}
예제 #2
0
		/**
			Append a quad to a vertexarray. This version takes Texturecoordinates
		*/
		inline void AppendQuad(sf::VertexArray& vA, const sf::FloatRect& Pos, geom::irect coords) {
			sf::Vertex vs[4];
			SetQuadPos(vs, Pos);
			SetQuadTex(vs, coords);

			vA.append(vs[0]);
			vA.append(vs[1]);
			vA.append(vs[2]);
			vA.append(vs[3]);
		}
예제 #3
0
    void Sprite2VertexArray(const sf::Sprite & sprite,sf::VertexArray & vertices)
    {
        sf::IntRect texBox = sprite.getTextureRect();
        sf::FloatRect box = sprite.getGlobalBounds();

		vertices.append(sf::Vertex(sf::Vector2f(box.left, box.top), sf::Vector2f((float)texBox.left, (float)texBox.top)));
		vertices.append(sf::Vertex(sf::Vector2f(box.left, box.top + box.height), sf::Vector2f((float)texBox.left, (float)(texBox.top + texBox.height))));
		vertices.append(sf::Vertex(sf::Vector2f(box.left + box.width, box.top + box.height), sf::Vector2f((float)(texBox.left + texBox.width), (float)(texBox.top + texBox.height))));
		vertices.append(sf::Vertex(sf::Vector2f(box.left + box.width, box.top), sf::Vector2f((float)(texBox.left + texBox.width), (float)texBox.top)));
    }
예제 #4
0
void fTilemap::drawTile(int tileIndex, sf::VertexArray &vertices) const 
	{	
		// posición en coordenadas globales de la esquina superior izquierda del tile
		sf::Vector2f tilePos = sf::Vector2f((tileIndex%_width)*_tileWidth, (tileIndex/_width)*_tileHeight);
		
		// coordenadas de textura de la esquina superior izquierda del tile
		sf::Vector2f tileCoords = sf::Vector2f(((_tiles[tileIndex]-1)%(_texture->getSize().x/_tileWidth))*_tileWidth, ((_tiles[tileIndex]-1)/(_texture->getSize().x/_tileWidth))*_tileHeight);
		
		// posición de los vertices del triángulo superior del tile
		vertices.append(sf::Vertex(sf::Vector2f(tilePos.x, tilePos.y+_tileHeight), sf::Color::White, sf::Vector2f(tileCoords.x, tileCoords.y+_tileHeight)));
		vertices.append(sf::Vertex(sf::Vector2f(tilePos.x+_tileWidth, tilePos.y), sf::Color::White, sf::Vector2f(tileCoords.x + _tileWidth, tileCoords.y)));
		vertices.append(sf::Vertex(sf::Vector2f(tilePos.x, tilePos.y), sf::Color::White, sf::Vector2f(tileCoords.x, tileCoords.y)));
		
		// posición de los vertices del triángulo inferior del tile
		vertices.append(sf::Vertex(sf::Vector2f(tilePos.x, tilePos.y+_tileHeight), sf::Color::White, sf::Vector2f(tileCoords.x, tileCoords.y+_tileHeight)));
		vertices.append(sf::Vertex(sf::Vector2f(tilePos.x+_tileWidth, tilePos.y+_tileHeight), sf::Color::White, sf::Vector2f(tileCoords.x+_tileWidth, tileCoords.y+_tileHeight)));
		vertices.append(sf::Vertex(sf::Vector2f(tilePos.x+_tileWidth, tilePos.y), sf::Color::White,  sf::Vector2f(tileCoords.x + _tileWidth, tileCoords.y)));
	}
예제 #5
0
void drawPoint( pair <sf::Vector2i, int> & pnt) {
	sf::Vertex vertex;
	vertex.color = sf::Color::Black;
	for (int i = pnt.first.x; i < pnt.first.x + pnt.second; i++) {
		for (int j = pnt.first.y; j < pnt.first.y + pnt.second; j++) {
			vertex.position = sf::Vector2f(i, j);
			draw_arr.append(vertex);
		}
	}
	cout << draw_arr.getVertexCount() << endl;
}
static void plot(sf::VertexArray& va, int x, int y, float c, const sf::Color& color)
{
    const sf::Color newColor(static_cast<sf::Uint8>(color.r * c),
                             static_cast<sf::Uint8>(color.g * c),
                             static_cast<sf::Uint8>(color.b * c));

    const sf::Vertex vertex(sf::Vector2f(static_cast<float>(x),
                                         static_cast<float>(y)),
                            newColor);

    va.append(vertex);
}
예제 #7
0
파일: gax.cpp 프로젝트: jokoon/eio
void
computeCatmullRomPoints
    (const T& P1, const T& P2, const T& P3, const T& P4,
        unsigned int numSeg, sf::VertexArray & line_points){
    line_points.append(P2);
    for (unsigned int j = 0; j < numSeg; ++j)
    {
        float  t = (float)j/(float)numSeg;
        float t2 = t*t;
        float t3 = t*t2;
        T P = 0.5f*
        ((-t3+2.f*t2-t)*P1 +
         (3.f*t3-5.f*t2+2.f)*P2 +
         (-3.f*t3+4.f*t2+t)*P3 +
         (t3-t2)*P4);
        //        addpoint2(P);
        //        line_points.append(P);
        line_points.append(P);
    }
    line_points.append(P3);
}
void draw_box_old(sf::VertexArray& verts, const sf::FloatRect& rect, float thickness = 4.0f, const sf::Color color = sf::Color::Green) {
	float left = rect.left;
	float top = rect.top;
	float right = rect.left + rect.width;
	float bottom = rect.top + rect.height;
	// Add a quad for the current character
	verts.append(Vertex(Vector2f(left, top), color)); verts.append(Vertex(Vector2f(left, bottom), color));
	verts.append(Vertex(Vector2f(left, top), color)); verts.append(Vertex(Vector2f(right, top), color));
	verts.append(Vertex(Vector2f(right, bottom), color)); verts.append(Vertex(Vector2f(left, bottom), color));
	verts.append(Vertex(Vector2f(right, bottom), color)); verts.append(Vertex(Vector2f(right, top), color));
}
예제 #9
0
파일: main.cpp 프로젝트: Draguld/orbite
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);
}
예제 #10
0
		/**
			Append a line to a vertexarray ( 2 vertices).
		*/
		inline void AppendLine(sf::VertexArray& vA, const sf::Vector2f& start, const sf::Vector2f& end, const sf::Color& c) {
			vA.append(sf::Vertex(start, c));
			vA.append(sf::Vertex(end, c));
		}