PolygonShape::PolygonShape(const Polygon2d& polygon, Material& attrs): m_polygon(polygon) { b2Vec2* vertecies = new b2Vec2[polygon.VerteciesCount()]; const Vertecies& polygonVertecies = polygon.GetVertecies(); for (size_t vertexNo = 0; vertexNo < polygonVertecies.size(); ++vertexNo) { vertecies[vertexNo] = ToBox2dVec(polygonVertecies[vertexNo]); } m_polygonShapePtr = new b2PolygonShape(); m_polygonShapePtr->Set(vertecies, polygon.VerteciesCount()); delete[] vertecies; Construct(m_polygonShapePtr, attrs); }
void D3DRenderContext::RenderSolidPolygon(const Polygon2d& p, const ivec3& color) const { WireGeometryVertex* points = new WireGeometryVertex[p.VerteciesCount() + 1]; for (uint i = 0; i <= p.VerteciesCount(); ++i) { if (i == p.VerteciesCount()) { points[i].x = p[0].x; points[i].y = p[0].y; points[i].z = MAX_ZCHOOORD; points[i].color = D3DCOLOR_XRGB(color.x, color.y, color.z); } else { points[i].x = p[i].x; points[i].y = p[i].y; points[i].z = MAX_ZCHOOORD; points[i].color = D3DCOLOR_XRGB(color.x, color.y, color.z); } } m_d3dDevice->SetFVF(D3DFVF_WIRE_GEOMETRY_VERTEX); m_d3dDevice->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, p.VerteciesCount(), static_cast<void*>(points), sizeof(WireGeometryVertex)); delete[] points; }