示例#1
0
void Sierpinski::draw(RenderTarget& target, RenderStates states) const{
	ConvexShape triangle;
  	triangle.setPointCount(3);
  	triangle.setPoint(0, C);
	triangle.setPoint(1, A);
	triangle.setPoint(2, B);
	target.draw(triangle, states);
	
	if (depth == 1){
		return;
	}
	
	/* Define the three new triangles by point and length */
	Vector2f a, b, c, temp1, temp2;
	a.x = (C.x + B.x)/2;
	a.y = (C.y + B.y)/2;
	
	b.x = (C.x + A.x)/2;
	b.y = (C.y + A.y)/2;
	
	c.x = (A.x + B.x)/2;
	c.y = A.y;
	
	double length = sqrt(pow(C.x - A.x, 2) + pow(C.y - A.y, 2))/2;
	
	/* a is the small triangle to the right */
	temp1.x = a.x + length;
	temp1.y = a.y;
	temp2.x = a.x + length/2;
	temp2.y = a.y + (length/2 * sqrt(3));
	Sierpinski child1(temp2, a, temp1, depth - 1);
	target.draw(child1, states);	
	
	/* b is the small triangle to the left */
	temp1.x = b.x - length;
	temp1.y = b.y;
	temp2.x = b.x - length/2;
	temp2.y = b.y + (length/2 * sqrt(3));
	Sierpinski child2(temp2, temp1, b ,depth - 1);	
	target.draw(child2, states);	
	
	/* c is the small triangle on the top */
	temp1.x = c.x + length/2;
	temp1.y = c.y - (length/2 * sqrt(3));
	temp2.x = c.x - length/2;
	temp2.y = c.y - (length/2 * sqrt(3));
	Sierpinski child3(c, temp2, temp1, depth - 1);
	target.draw(child3, states);		
	
	return;
}
示例#2
0
void SFMLRenderer::DrawSolidPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color){

	ConvexShape poligono;
	
	poligono.setPointCount(vertexCount);

	for(int i=0;i<vertexCount;++i){		
		poligono.setPoint(i,Vector2f(vertices[i].x, vertices[i].y));		
	}

	poligono.setFillColor(box2d2SFMLColor(color));
	
	wnd->draw(poligono);

}
示例#3
0
void Other::draw(RenderTarget& target, RenderStates states) const {
	ConvexShape rectangle;
  	rectangle.setPointCount(4);
  	rectangle.setPoint(0, A);
	rectangle.setPoint(1, B);
	rectangle.setPoint(2, C);
	rectangle.setPoint(3, D);
	rectangle.setFillColor(Color(55 + (depth*depth), 55 + (depth*depth), 55 + (depth*depth)));
	target.draw(rectangle, states);
	
	if (depth == 1){
		return;
	}
	
	/* Skeliton for two new squares */
	double length = sqrt(pow(A.x - B.x, 2) + pow(A.y - B.y, 2))/2;
	Vector2f upper, right, temp1, temp2, temp3;
	upper.x = (A.x + B.x)/2;
	upper.y = A.y;
	right.x = C.x;
	right.y = (B.x + C.x)/2 + length;
	
	/* Defining upper square */
	temp1.x = upper.x - length;
	temp1.y = upper.y - length;
	temp2.x = upper.x;
	temp2.y = upper.y - length;
	temp3.x = upper.x - length;
	temp3.y = upper.y;
	Other child1(temp1, temp2, upper, temp3, depth - 1);
	target.draw(child1, states);
	
	/* Defining right square */
	temp1.x = right.x + length;
	temp1.y = right.y;
	temp2.x = right.x + length;
	temp2.y = right.y + length;
	temp3.x = right.x;
	temp3.y = right.y + length;
	Other child2(right, temp1, temp2, temp3, depth - 1);
	target.draw(child2, states);
	
	return;
}