本文整理汇总了C++中DebugDraw::DrawPolygon方法的典型用法代码示例。如果您正苦于以下问题:C++ DebugDraw::DrawPolygon方法的具体用法?C++ DebugDraw::DrawPolygon怎么用?C++ DebugDraw::DrawPolygon使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DebugDraw
的用法示例。
在下文中一共展示了DebugDraw::DrawPolygon方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DrawFixture
//Rotina que chama os métodos de desenho da classe DebugDraw para desenhar os objetos da cena
void DrawFixture(b2Fixture* fixture, b2Color color)
{
const b2Transform& xf = fixture->GetBody()->GetTransform();
switch (fixture->GetType())
{
case b2Shape::e_circle:
{
b2CircleShape* circle = (b2CircleShape*)fixture->GetShape();
b2Vec2 center = b2Mul(xf, circle->m_p);
float32 radius = circle->m_radius;
renderer.DrawCircle(center, radius, color);
}
break;
case b2Shape::e_polygon:
{
b2PolygonShape* poly = (b2PolygonShape*)fixture->GetShape();
int32 vertexCount = poly->m_count;
b2Assert(vertexCount <= b2_maxPolygonVertices);
b2Vec2 vertices[b2_maxPolygonVertices];
for (int32 i = 0; i < vertexCount; ++i)
{
vertices[i] = b2Mul(xf, poly->m_vertices[i]);
}
renderer.DrawPolygon(vertices, vertexCount, color);
}
break;
case b2Shape::e_edge:
{
b2EdgeShape* edge = (b2EdgeShape*)fixture->GetShape();
int32 vertexCount;
b2Vec2 vertices[b2_maxPolygonVertices];
int i=0;
if (edge->m_hasVertex0)
{
vertices[i] = b2Mul(xf, edge->m_vertex0);
i++;
}
vertices[i] = b2Mul(xf, edge->m_vertex1); i++;
vertices[i] = b2Mul(xf, edge->m_vertex2); i++;
if (edge->m_hasVertex3)
{
vertices[i] = b2Mul(xf, edge->m_vertex3);
i++;
}
vertexCount = i;
renderer.DrawPolygon(vertices, vertexCount, color);
}
break;
}
}
示例2: DrawShape
//Rotina que chama os métodos de desenho da classe DebugDraw para desenhar os objetos da cena
void DrawShape(b2Fixture* fixture, b2Color color)
{
const b2Transform& xf = fixture->GetBody()->GetTransform();
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));
float angle = xf.q.GetAngle();
renderer.DrawSolidCircle(center, radius, axis, color);
DrawSprite((radius*1.44)*2,center.x,center.y,0.0,RadianosParaGraus(angle)); //este 1.44 foi um cálculo q eu fiz para encaixar... o ideal é que o circulo tenha o raio da imagem
}
break;
case b2Shape::e_polygon:
{
b2PolygonShape* poly = (b2PolygonShape*)fixture->GetShape();
int32 vertexCount = poly->m_count;
b2Assert(vertexCount <= b2_maxPolygonVertices);
b2Vec2 vertices[b2_maxPolygonVertices];
for (int32 i = 0; i < vertexCount; ++i)
{
vertices[i] = b2Mul(xf, poly->m_vertices[i]);
}
renderer.DrawPolygon(vertices, vertexCount, color);
}
break;
case b2Shape::e_edge:
{
b2EdgeShape* edge = (b2EdgeShape*)fixture->GetShape();
int32 vertexCount;
b2Vec2 vertices[b2_maxPolygonVertices];
int i=0;
if (edge->m_hasVertex0)
{
vertices[i] = b2Mul(xf, edge->m_vertex0);
i++;
}
vertices[i] = b2Mul(xf, edge->m_vertex1); i++;
vertices[i] = b2Mul(xf, edge->m_vertex2); i++;
if (edge->m_hasVertex3)
{
vertices[i] = b2Mul(xf, edge->m_vertex3);
i++;
}
vertexCount = i;
renderer.DrawPolygon(vertices, vertexCount, 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]);
renderer.DrawSegment(v1, v2, color);
renderer.DrawCircle(v1, 0.05f, color);
v1 = v2;
}
}
break;
}
}