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); if (count > 0x2000) count = 0x2000; 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(m_impl->canvas, 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(m_impl->canvas, ctx, count, points, false, true, false, modelUnit); int ienter = findInvisibleEdge(clip); if (ienter == count) { ret = _DrawPolygon(m_impl->canvas, ctx, count, points, false, false, true, modelUnit) || ret; } else { ret = drawPolygonEdge(PolylineAux(this, ctx), count, clip, ienter) || ret; } } return ret; }
void MeshCutting::draw(BOOL displayMode[10]) { // Displays the cut and colored voxels if (displayMode[4]){ for (int i = 0; i < m_cutSurface.size(); i++){ glColor3fv(color[i+1].data()); drawPolygonEdge(m_cutSurface[i]); glColor3fv(color[i].data()); drawPolygonFace(m_cutSurface[i]); } } // Displays the cut and colored mesh cut pieces // Note: have to press F to cut mesh first before this works if (displayMode[5]){ mirrorDraw mirror; mirror.mirrorAxis = 0; //x-axis mirror.mirrorCoord = s_surObj->midPoint()[0]; arrayVec3f origins = getAllMeshOrigin(); for (int i = 0; i < m_cutPieces.size(); i++){ //command::print("Meshcutting.cpp drawing: %d %d\n", i, m_cutPieces[i]->faces.size()); glColor3fv(color[i].data()); glPushMatrix(); glTranslatef(origins[i][0], origins[i][1], origins[i][2]); setRotationCase(coords[i]); drawPolygonFace(m_cutPieces[i]); glPopMatrix(); if (boneArray[i]->m_type == TYPE_SIDE_BONE){ glPushMatrix(); glTranslatef(mirror.mirrorCoord, 0, 0); glScalef(-1, 1, 1); glTranslatef(origins[i][0], origins[i][1], origins[i][2]); setRotationCase(coords[i]); drawPolygonFace(m_cutPieces[i]); glPopMatrix(); } } } }
bool GiGraphics::drawPolygon(const GiContext* ctx, int count, const Point2d* points, bool modelUnit) { if (count < 2 || !points || isStopping()) return false; 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; }