예제 #1
0
	void Render::DrawShape(b2Fixture* fixture, const b2Transform& xf, const b2Color& color) {
		switch (fixture->GetType()) {
			case b2Shape::e_circle: {
				b2CircleShape* circle = (b2CircleShape*) fixture->GetShape();

				b2Vec2 center = b2Mul(xf, circle->m_p);
				float32 radius = circle->m_radius;
				b2Vec2 axis = b2Mul(xf.q, b2Vec2(1.0f, 0.0f));

				DrawSolidCircle(center, radius, axis, color);
			}
				break;

			case b2Shape::e_edge: {
				b2EdgeShape* edge = (b2EdgeShape*) fixture->GetShape();
				b2Vec2 v1 = b2Mul(xf, edge->m_vertex1);
				b2Vec2 v2 = b2Mul(xf, edge->m_vertex2);
				DrawSegment(v1, v2, color);
			}
				break;

			case b2Shape::e_chain: {
				b2ChainShape* chain = (b2ChainShape*) fixture->GetShape();
				int32 count = chain->m_count;
				const b2Vec2* vertices = chain->m_vertices;

				b2Vec2 v1 = b2Mul(xf, vertices[0]);
				for (int32 i = 1; i < count; ++i) {
					b2Vec2 v2 = b2Mul(xf, vertices[i]);
					DrawSegment(v1, v2, color);
					DrawCircle(v1, 0.05f, color);
					v1 = v2;
				}
			}
				break;

			case b2Shape::e_polygon: {
				b2PolygonShape* poly = (b2PolygonShape*) fixture->GetShape();
				int32 vertexCount = poly->m_vertexCount;
				b2Assert(vertexCount <= b2_maxPolygonVertices);
				b2Vec2 vertices[b2_maxPolygonVertices];

				for (int32 i = 0; i < vertexCount; ++i) {
					vertices[i] = b2Mul(xf, poly->m_vertices[i]);
				}

				DrawSolidPolygon(vertices, vertexCount, color);
			}
				break;

			default:
				break;
		}
	}
예제 #2
0
파일: Drawer.cpp 프로젝트: toemm/Pong
void Drawer::DrawShape(b2Transform& transf, b2Fixture *fix, b2Color& col)
{
	// The shape contains the vertices/points of the primitive structure
	// The coordinates of the vertices are in local coordinates and need to be transformed
	// Transformation is done via translation and rotation with the b2Transform of the body the shape is living in
	b2Shape *shape = fix->GetShape();

	switch (shape->GetType()) {

	case b2Shape::e_polygon:
		{
			b2PolygonShape *pShape = dynamic_cast<b2PolygonShape *>(shape);
			int vertexCount = pShape->GetVertexCount();
	
			b2Vec2 poly[b2_maxPolygonVertices];

			for (int i = 0; i < vertexCount; i++) {
				poly[i] = b2Mul(transf, pShape->m_vertices[i]);

			}
			DrawSolidPolygon(poly, vertexCount, col);
		}
		break;

	case b2Shape::e_circle:
		{
			b2CircleShape *cShape = dynamic_cast<b2CircleShape *>(shape);
			b2Vec2 cent = b2Mul(transf, cShape->m_p);
			DrawSolidCircle(cent, cShape->m_radius, col);
		}
		break;

	case b2Shape::e_edge:
		{
			b2EdgeShape *eShape = dynamic_cast<b2EdgeShape *>(shape);
			b2Vec2 p1 = b2Mul(transf, eShape->m_vertex1);
			b2Vec2 p2 = b2Mul(transf, eShape->m_vertex2);
			DrawSegment(p1, p2, col);
		}
		break;

	default:
		break;
	}
}
예제 #3
0
파일: debug_draw.cpp 프로젝트: ibawt/ev
void b2DebugDraw::DrawCircle(const b2Vec2& center, float radius,  const b2Color& color )
{
    DrawSolidCircle(center, radius, b2Vec2(0,0), color);
}