//---------------------------------------- void ofxBox2dBody::draw() { ofPushMatrix(); b2Vec2 p = body->GetPosition(); p *= OFX_BOX2D_SCALE; ofTranslate(p.x, p.y); float angle = body->GetAngle(); ofRotate(ofRadToDeg(angle)); for (b2Fixture* f=body->GetFixtureList(); f; f = f->GetNext()) { switch (f->GetType()) { case b2Shape::e_circle: { b2CircleShape* shape = dynamic_cast<b2CircleShape*>(f->GetShape()); b2Vec2 position = shape->m_p; float radius = shape->m_radius; _drawCircle(position, radius); break; } case b2Shape::e_polygon: { b2PolygonShape* shape = dynamic_cast<b2PolygonShape*>(f->GetShape()); _drawPolygon(shape->m_vertices, shape->m_count); break; } default: break; } } ofPopMatrix(); }
bool GiGraphics::drawPolygon(const GiContext* ctx, int count, const Point2d* points, bool modelUnit) { if (m_impl->drawRefcnt == 0 || count < 2 || points == NULL) return false; GiLock lock (&m_impl->drawRefcnt); count = count > 0x2000 ? 0x2000 : count; ctx = ctx ? ctx : &(m_impl->ctx); bool ret = false; const Box2d extent (count, points); // 模型坐标范围 if (!DRAW_RECT(m_impl, modelUnit).isIntersect(extent)) // 全部在显示区域外 return false; if (DRAW_MAXR(m_impl, modelUnit).contains(extent)) // 全部在显示区域内 { ret = _drawPolygon(ctx, count, points, true, true, true, modelUnit); } else // 部分在显示区域内 { PolygonClip clip (m_impl->rectDraw); if (!clip.clip(count, points, &S2D(xf(), modelUnit))) // 多边形剪裁 return false; count = clip.getCount(); points = clip.getPoints(); ret = _drawPolygon(ctx, count, points, false, true, false, modelUnit); int ienter = findInvisibleEdge(clip); if (ienter == count) { ret = _drawPolygon(ctx, count, points, false, false, true, modelUnit) || ret; } else { ret = drawPolygonEdge(PolylineAux(this, ctx), count, clip, ienter) || ret; } } return ret; }