/*! \fn void QPaintEngine::drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode) Reimplement this virtual function to draw the polygon defined by the \a pointCount first points in \a points, using mode \a mode. \note At least one of the drawPolygon() functions must be reimplemented. */ void QPaintEngine::drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode) { Q_ASSERT_X(qt_polygon_recursion != this, "QPaintEngine::drawPolygon", "At least one drawPolygon function must be implemented"); qt_polygon_recursion = this; Q_ASSERT(sizeof(QT_Point) == sizeof(QPoint)); QVarLengthArray<QT_Point> p(pointCount); for (int i = 0; i < pointCount; ++i) { p[i].x = qRound(points[i].x()); p[i].y = qRound(points[i].y()); } drawPolygon((QPoint *)p.data(), pointCount, mode); qt_polygon_recursion = 0; }
void OpenGLRenderer::drawCircle(float aCenterX, float aCenterY, float aRadius, int aLineSegments, bool aIsFilled) { int vertexSize = 2; int vertexCount = aLineSegments; std::vector<float> vertices; float rotationAmount = (360.0f / aLineSegments); for (float i = 0; i < 359.99f; i+= rotationAmount) { vertices.push_back(aCenterX + (cosf((M_PI * i / 180.0)) * aRadius)); vertices.push_back(aCenterY + (sinf((M_PI * i / 180.0)) * aRadius)); } drawPolygon(aIsFilled ? GL_TRIANGLE_FAN : GL_LINE_LOOP, &vertices[0], vertexSize, vertexCount); }
bool GiGraphics::drawRoundRect(const GiContext* ctx, const Box2d& rect, float rx, float ry, bool modelUnit) { if (rect.isEmpty() || isStopping()) return false; bool ret = false; if (ry < _MGZERO) ry = rx; if (!DRAW_RECT(m_impl, modelUnit).isIntersect(rect)) // 全部在显示区域外 return false; if (rx < _MGZERO) { Point2d points[4] = { rect.leftBottom(), rect.rightBottom(), rect.rightTop(), rect.leftTop() }; return drawPolygon(ctx, 4, points); } else { Point2d pxs[16]; mgcurv::roundRectToBeziers(pxs, rect, rx, ry); S2D(xf(), modelUnit).transformPoints(16, pxs); ret = rawBeginPath(); if (ret) { rawMoveTo(pxs[0].x, pxs[0].y); rawBezierTo(pxs[1].x, pxs[1].y, pxs[2].x, pxs[2].y, pxs[3].x, pxs[3].y); rawLineTo(pxs[4].x, pxs[4].y); rawBezierTo(pxs[5].x, pxs[5].y, pxs[6].x, pxs[6].y, pxs[7].x, pxs[7].y); rawLineTo(pxs[8].x, pxs[8].y); rawBezierTo(pxs[9].x, pxs[9].y, pxs[10].x, pxs[10].y, pxs[11].x, pxs[11].y); rawLineTo(pxs[12].x, pxs[12].y); rawBezierTo(pxs[13].x, pxs[13].y, pxs[14].x, pxs[14].y, pxs[15].x, pxs[15].y); rawClosePath(); ret = rawEndPath(ctx, true); } } return ret; }
bool Block::init() { if ( !cocos2d::Node::init() ) { return false; } this->scheduleUpdate(); // air Point b[] = {Point(0,0),Point(0,size),Point(size,size),Point(size,0)}; auto d = DrawNode::create(); d->drawPolygon(b, 4, colorAir(), 0, colorAir()); //addChild(d, -1); return 1; }
void OpenGLRenderer::drawCircle(float x, float y, float aRadius, bool aIsFilled, int aLineSegments ) { int vertexSize = 2; int vertexCount = aLineSegments; float * vertices = new float[vertexCount * vertexSize]; float rotationAmount = (360.0f / aLineSegments); int count = 0; for (float i = 0; i < 359.99f; i+= rotationAmount) { vertices[count++] = x + (cosf((PI * i / 180.0)) * aRadius); vertices[count++] = y + (sinf((PI * i / 180.0)) * aRadius); } drawPolygon(aIsFilled ? GL_TRIANGLE_FAN : GL_LINE_LOOP, vertices, vertexSize, vertexCount); }
void KeyboardLayoutWidget::drawRectangle(QPainter* painter, QColor color, int angle, int xkb_x, int xkb_y, int xkb_width, int xkb_height, unsigned int radius) { if (angle == 0) { int x, y, width, height; bool filled; if (color.isValid()) { filled = TRUE; } else { color = Qt::gray; filled = FALSE; } x = xkbToPixmapCoord (xkb_x); y = xkbToPixmapCoord (xkb_y); width = xkbToPixmapCoord (xkb_x + xkb_width) - x; height = xkbToPixmapCoord (xkb_y + xkb_height) - y; drawCurveRectangle (painter, filled, color, x, y, width, height, xkbToPixmapDouble (radius)); } else { XkbPointRec points[4]; int x, y; points[0].x = xkb_x; points[0].y = xkb_y; rotateCoordinate (xkb_x, xkb_y, xkb_x + xkb_width, xkb_y, angle, &x, &y); points[1].x = x; points[1].y = y; rotateCoordinate (xkb_x, xkb_y, xkb_x + xkb_width, xkb_y + xkb_height, angle, &x, &y); points[2].x = x; points[2].y = y; rotateCoordinate (xkb_x, xkb_y, xkb_x, xkb_y + xkb_height, angle, &x, &y); points[3].x = x; points[3].y = y; /* the points we've calculated are relative to 0,0 */ drawPolygon (painter, color, 0, 0, points, 4, radius); } }
void Slice::draw(int layer){ GLfloat green[4]={0.0,1.0,0.0,1.0}; GLfloat blue[4]={0.0,0.0,1.0,1.0}; GLfloat fCurrentColor[4]; // Get the current color glGetFloatv(GL_CURRENT_COLOR, fCurrentColor); if(layer<this->triLayer.size()){ //draw faces // for(int i=0; i<this->triLayer.at(layer)->size(); i++){ // glBegin(GL_TRIANGLES); // glNormal3f(this->triLayer.at(layer)->at(i)->getNormal()->x(),this->triLayer.at(layer)->at(i)->getNormal()->y(),this->triLayer.at(layer)->at(i)->getNormal()->z()); // glVertex3f(this->triLayer.at(layer)->at(i)->getEdge1()->getStart()->x(), this->triLayer.at(layer)->at(i)->getEdge1()->getStart()->y(), this->triLayer.at(layer)->at(i)->getEdge1()->getStart()->z()); // glVertex3f(this->triLayer.at(layer)->at(i)->getEdge2()->getStart()->x(), this->triLayer.at(layer)->at(i)->getEdge2()->getStart()->y(), this->triLayer.at(layer)->at(i)->getEdge2()->getStart()->z()); // glVertex3f(this->triLayer.at(layer)->at(i)->getEdge3()->getStart()->x(), this->triLayer.at(layer)->at(i)->getEdge3()->getStart()->y(), this->triLayer.at(layer)->at(i)->getEdge3()->getStart()->z()); // glEnd( ); // } // //draw edges glDisable(GL_LIGHTING); glColor4fv(green); glLineWidth(1.0); glDepthMask(false); // glBegin(GL_LINES); // for(int i=0; i<this->edgeLayer.at(layer)->size(); i++){ // for(int j=0; j<this->edgeLayer.at(layer)->at(i)->size(); j++){ // glVertex3f(this->edgeLayer.at(layer)->at(i)->at(j)->getStart()->x(), this->edgeLayer.at(layer)->at(i)->at(j)->getStart()->y(), this->edgeLayer.at(layer)->at(i)->at(j)->getStart()->z()); // glVertex3f(this->edgeLayer.at(layer)->at(i)->at(j)->getStop()->x(), this->edgeLayer.at(layer)->at(i)->at(j)->getStop()->y(), this->edgeLayer.at(layer)->at(i)->at(j)->getStop()->z()); // } // } // glEnd( ); //draw intersection points glColor4fv(blue); glPointSize(5.0f); glBegin(GL_POINTS); for(int i=0; i<this->pointLayer.at(layer)->size(); i++){ for(int j=0; j<this->pointLayer.at(layer)->at(i)->size(); j++){ glColor4f(1.0-(float)j/(float)this->pointLayer.at(layer)->at(i)->size(),(float)j/(float)this->pointLayer.at(layer)->at(i)->size(),0.0,1.0); glVertex3f(this->pointLayer.at(layer)->at(i)->at(j).x(), this->pointLayer.at(layer)->at(i)->at(j).y(), this->pointLayer.at(layer)->at(i)->at(j).z() ); } } glEnd(); drawPolygon((Polygons&)this->polygonLayer.at(layer),layer); glDepthMask(true); glEnable(GL_LIGHTING); } glColor4fv(fCurrentColor); }
void Viewport::drawObj(Object* obj){ if(obj->getNCoordsSize() == 0) return; switch(obj->getType()){ case ObjType::OBJECT: break; case ObjType::POINT: drawPoint(obj); break; case ObjType::LINE: drawLine(obj); break; case ObjType::POLYGON: drawPolygon(obj); break; } }
void Face::render(Pixel* px, Matrix* transform, Color *color, Matrix *zBuffer) { Vertex* v1 = getVertex(1); Vertex* v2 = getVertex(2); Vertex* v3 = getVertex(3); //put vertices into window coordinates (directly from local coordinates) v1 = v1->multiply(transform); v2 = v2->multiply(transform); v3 = v3->multiply(transform); Vertex* temp = v1->homogenize(); delete v1; v1 = temp; temp = v2->homogenize(); delete v2; v2 = temp; temp = v3->homogenize(); delete v3; v3 = temp; v1->setRed(color->getRed()); v1->setGreen(color->getGreen()); v1->setBlue(color->getBlue()); v2->setRed(color->getRed()); v2->setGreen(color->getGreen()); v2->setBlue(color->getBlue()); v3->setRed(color->getRed()); v3->setGreen(color->getGreen()); v3->setBlue(color->getBlue()); //draw the wireframe of the triangle /* drawLine(px, v1, v2); drawLine(px, v2, v3); drawLine(px, v3, v1);*/ //Render the face(polygon) drawPolygon(px, zBuffer, color, v1, v2, v3); delete v1; delete v2; delete v3; }
/** * NewDrawNode */ NewDrawNodeTest::NewDrawNodeTest() { auto s = Director::getInstance()->getWinSize(); auto parent = Node::create(); parent->setPosition(s.width/2, s.height/2); addChild(parent); auto rectNode = DrawNode::create(); Vec2 rectangle[4]; rectangle[0] = Vec2(-50, -50); rectangle[1] = Vec2(50, -50); rectangle[2] = Vec2(50, 50); rectangle[3] = Vec2(-50, 50); Color4F white(1, 1, 1, 1); rectNode->drawPolygon(rectangle, 4, white, 1, white); parent->addChild(rectNode); }
void Design::render(Patterns &patterns) { Common::MemoryReadStream in(_data, _len); bool needRender = true; while (needRender) { byte fillType = in.readByte(); byte borderThickness = in.readByte(); byte borderFillType = in.readByte(); int type = in.readByte(); if (in.eos()) break; debug(8, "fill: %d borderFill: %d border: %d type: %d", fillType, borderFillType, borderThickness, type); switch (type) { case 4: drawRect(_surface, in, patterns, fillType, borderThickness, borderFillType); break; case 8: drawRoundRect(_surface, in, patterns, fillType, borderThickness, borderFillType); break; case 12: drawOval(_surface, in, patterns, fillType, borderThickness, borderFillType); break; case 16: case 20: drawPolygon(_surface, in, patterns, fillType, borderThickness, borderFillType); break; case 24: drawBitmap(_surface, in); break; default: warning("Unknown type => %d", type); break; } //g_system->copyRectToScreen(_surface->getPixels(), _surface->pitch, 0, 0, _surface->w, _surface->h); //((WageEngine *)g_engine)->processEvents(); //g_system->updateScreen(); //g_system->delayMillis(500); } }
void drawLine(float _x0, float _y0, float _x1, float _y1, float _r, uint32_t _abgr, float _fth = 1.0f) { float dx = _x1 - _x0; float dy = _y1 - _y0; float d = sqrtf(dx * dx + dy * dy); if (d > 0.0001f) { d = 1.0f / d; dx *= d; dy *= d; } float nx = dy; float ny = -dx; float verts[4 * 2]; _r -= _fth; _r *= 0.5f; if (_r < 0.01f) { _r = 0.01f; } dx *= _r; dy *= _r; nx *= _r; ny *= _r; verts[0] = _x0 - dx - nx; verts[1] = _y0 - dy - ny; verts[2] = _x0 - dx + nx; verts[3] = _y0 - dy + ny; verts[4] = _x1 + dx + nx; verts[5] = _y1 + dy + ny; verts[6] = _x1 + dx - nx; verts[7] = _y1 + dy - ny; drawPolygon(verts, 4, _fth, _abgr); }
void Server::threadedFunction() { while( isThreadRunning() != 0 ){ if( lock() ){ if(polygons.size() > 0){ cout << "Server: Drawing polygon\n"; unlock(); wait(mutex); drawPolygon( polygons.front() ); }else{ unlock(); wait(mutex); //Increment semaphore one token so in next check this thread //will not sleep release(mutex); } } } }
void myDisplay_Draw_Polygon_On_Windows_function(std::vector<Point2D_int> draw2DPointSet) { //用描点法画出直线来 glColor3f(1.0, 0.0, 0.0); // 决定要画的线的颜色 glBegin(GL_POINTS); // 初始化要裁剪的区域 clippedWidowsInit(); // 生成数据 std::vector<Point2D> polygon; for (auto m : drawPolygonSet) { polygon.push_back(m); } drawPolygon(polygon, false, draw2DPointSet); glEnd(); }
void drawPolygons( float *tp, int *pp) { float d[nbFaces]; int i,j,p; int sp[nbFaces] = { 0,1,2,3,4,5 }; float t; int tt; // First calculate mid z position of faces for (i=0;i<nbFaces;++i) { d[i] = 0.0; for (j=0;j<4;++j) d[i] += tp[3*faces[4*i+j]+2]; } // Sort the faces for (i=0;i<nbFaces-1;++i) { for (j=i;j<nbFaces;++j) { if (d[i]<d[j]) { t = d[j]; d[j] = d[i]; d[i] = t; tt = sp[j]; sp[j] = sp[i]; sp[i] = tt; } } } // Draw back to front for (p=0;p<nbFaces;++p) { // Sorted Face Index int pi = sp[p]; int p0 = faces[4*pi+0]; int p1 = faces[4*pi+1]; int p2 = faces[4*pi+2]; int p3 = faces[4*pi+3]; drawPolygon( pp[2*p0+0], pp[2*p0+1], pp[2*p1+0], pp[2*p1+1], pp[2*p2+0], pp[2*p2+1], pp[2*p3+0], pp[2*p3+1], faces_color[pi]); } }
sr_Error updateScreen(sr_Screen * sc) { sr_Element * elem = sc->elements; while(elem!=NULL) { if(elem->class >= maxSrElement) return ERR_INVALID_SR_ELEMENT; switch(elem->class) { case isSrPolygon: drawPolygon(sc, (sr_Polygon *)elem); break; case isSrCircle: drawCircle(sc, (sr_Circle *)elem); break; case isSrPoint: drawPoint(sc, (sr_Point *)elem); break; case isSrShape: ((sr_Shape *)elem)->draw(sc, *((sr_Shape *)elem)); break; case isSrText: drawText(sc, (sr_Text *)elem); break; case isSrObject: drawObject(sc, (sr_Object *)elem); break; default: break; } elem = elem->next; } return ERR_NO_ERR; }
int polygonBinding(lua_State *L) { Sint16* polyBufferX; Sint16* polyBufferY; if (!(lua_gettop(L) == 2 && lua_istable(L,-1) && lua_istable(L,-2))) { programError("Invalid arguments for polygon"); return 0; } int size = (int)lua_objlen(L,-1), i=0; polyBufferY = (Sint16*)malloc(size * sizeof(Sint16)); lua_pushnil(L); while(lua_next(L,-2) != 0) { polyBufferY[i++] = (Sint16)lua_tonumber(L,-1); lua_pop(L,1); if (i > size) break; } lua_pop(L,1); if (size != (int)lua_objlen(L,-1)) { programError("Array size mismatch in call to polygon"); return 0; } polyBufferX = (Sint16*)malloc(size * sizeof(Sint16)); lua_pushnil(L); i=0; while(lua_next(L,-2) != 0) { polyBufferX[i++] = (Sint16)lua_tonumber(L,-1); lua_pop(L,1); if (i > size) break; } drawPolygon(l81.fb, polyBufferX, polyBufferY, size, l81.r, l81.g, l81.b, l81.alpha, l81.filled); free(polyBufferX); free(polyBufferY); return 0; }
/* * Draws a square. */ void drawCube(int a, int b, int c, int d) { GLfloat x1 = 0.0; GLfloat x2 = 1.0; GLfloat y1 = 0.0; GLfloat y2 = 1.0; GLfloat z1 = 0.0; GLfloat z2 = 1.0; float ratio = 1.0; tuple points = { { x1, y1, z1 }, { x2, y1, z1 }, { x2, y2, z1 }, { x1, y2, z1 }, { x1, y1, x2 }, { x2, y1, x2 }, { x2, y2, x2 }, { x1, y2, x2 } }; drawPolygon(points, ratio, a, b, c, d); }
void FrameHeadGadget::drawPlayingHead(QPainter &p, const QColor &lightColor, const QColor &darkColor) { int currentFrame = getCurrentFrame(); int yy = index2y(currentFrame); std::vector<QPointF> pts; int xa = 12; // m_a; int xx = xa; // m_a pts.push_back(QPointF(xx, yy)); pts.push_back(QPointF(xx + 10, yy)); pts.push_back(QPointF(xx + 13, yy + 1)); pts.push_back(QPointF(xx + 17, yy + 5)); pts.push_back(QPointF(xx + 13, yy + 9)); pts.push_back(QPointF(xx + 10, yy + 10)); pts.push_back(QPointF(xx, yy + 10)); drawPolygon(p, pts, true, lightColor); p.setPen(darkColor); for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) p.drawPoint(xx + 3 + i * 2, yy + 2 + j * 2); p.fillRect(QRect(xx - 7, yy + 1, 7, 9), QBrush(lightColor)); p.setPen(darkColor); p.drawLine(xx - 9, yy + 5, xx - 8, yy + 5); p.setPen(Qt::black); p.drawLine(xx - 7, yy, xx - 1, yy); p.drawLine(xx - 7, yy + 10, xx - 1, yy + 10); p.setPen(Qt::black); xx = xa - 6; p.drawPoint(xx - 4, yy + 5); p.drawRect(QRect(xx - 6, yy, 4, 4)); p.drawRect(QRect(xx - 6, yy + 6, 4, 4)); p.fillRect(QRect(xx - 5, yy + 1, 3, 3), QBrush(lightColor)); p.fillRect(QRect(xx - 5, yy + 7, 3, 3), QBrush(lightColor)); }
static void drawLine(float x0, float y0, float x1, float y1, float r, float fth, unsigned int col) { float dx = x1-x0; float dy = y1-y0; float d = sqrtf(dx*dx+dy*dy); float nx; float ny; float verts[4*2]; if (d > 0.0001f) { d = 1.0f/d; dx *= d; dy *= d; } nx = dy; ny = -dx; r -= fth; r *= 0.5f; if (r < 0.01f) r = 0.01f; dx *= r; dy *= r; nx *= r; ny *= r; verts[0] = x0-dx-nx; verts[1] = y0-dy-ny; verts[2] = x0-dx+nx; verts[3] = y0-dy+ny; verts[4] = x1+dx+nx; verts[5] = y1+dy+ny; verts[6] = x1+dx-nx; verts[7] = y1+dy-ny; drawPolygon(verts, 4, fth, col); }
void drawPlayer(point pos, short angle, bool doExhaust) { //At angle = 0, player faces to the right. point vertex, port, starboard, exhaust; point myShip[4]; vertex = rotPoint(pos, angle, makePoint(pos.x+6, pos.y)); port = rotPoint(pos, angle, makePoint(pos.x-5, pos.y-5)); starboard = rotPoint(pos, angle, makePoint(pos.x-5, pos.y+5)); exhaust = rotPoint(pos, angle, makePoint(pos.x-3, pos.y)); myShip[0] = vertex; myShip[1] = port; myShip[2] = exhaust; myShip[3] = starboard; if(getSetting() >= 1) { drawFilledPolygon(myShip, 4, PLAYER_SHADE); } else { drawPolygon(myShip, 4, PLAYER_SHADE); } if(doExhaust) { if(isExhaustOn) { drawPlayerExhaust(pos, angle); } isExhaustOn ^= 1; //Flip the bit. } }
/*! Draws the first \a rectCount rectangles in the buffer \a rects. The default implementation of this function calls drawPath() or drawPolygon() depending on the feature set of the paint engine. */ void QPaintEngine::drawRects(const QRectF *rects, int rectCount) { if (hasFeature(PainterPaths) && !state->penNeedsResolving() && !state->brushNeedsResolving()) { for (int i=0; i<rectCount; ++i) { QPainterPath path; path.addRect(rects[i]); if (path.isEmpty()) continue; drawPath(path); } } else { for (int i=0; i<rectCount; ++i) { QRectF rf = rects[i]; QPointF pts[4] = { QPointF(rf.x(), rf.y()), QPointF(rf.x() + rf.width(), rf.y()), QPointF(rf.x() + rf.width(), rf.y() + rf.height()), QPointF(rf.x(), rf.y() + rf.height()) }; drawPolygon(pts, 4, ConvexMode); } } }
void SkyQPainter::drawSkyPolygon(LineList* list) { SkyList *points = list->points(); bool isVisible, isVisibleLast; SkyPoint* pLast = points->last(); QPointF oLast = m_proj->toScreen( pLast, true, &isVisibleLast ); // & with the result of checkVisibility to clip away things below horizon isVisibleLast &= m_proj->checkVisibility(pLast); QPolygonF polygon; for ( int i = 0; i < points->size(); ++i ) { SkyPoint* pThis = points->at( i ); QPointF oThis = m_proj->toScreen( pThis, true, &isVisible ); // & with the result of checkVisibility to clip away things below horizon isVisible &= m_proj->checkVisibility(pThis); if ( isVisible && isVisibleLast ) { polygon << oThis; } else if ( isVisibleLast ) { QPointF oMid = m_proj->clipLine( pLast, pThis ); polygon << oMid; } else if ( isVisible ) { QPointF oMid = m_proj->clipLine( pThis, pLast ); polygon << oMid; polygon << oThis; } pLast = pThis; oLast = oThis; isVisibleLast = isVisible; } if ( polygon.size() ) drawPolygon(polygon); }
void drawEntireBody(){ // Draw our hinged object // Push the current transformation matrix on the stack glPushMatrix(); glPushMatrix(); { glTranslatef(bodyPositionX, 0.0, 0.0); // Scale to size of body glScalef(BODY_WIDTH, BODY_LENGTH, 1.0); // Set the colour to green glColor3f(0.0, 1.0, 0.0); // Draw the body Point bodyPoints[] = { // top left, right points {-NECK_WIDTH/2, 0.5f}, {NECK_WIDTH/2, 0.5f}, // middle right point {BELLY_WIDTH/2, -0.4f}, // bottom right point {BOTTOM_WIDTH/2, -0.7f}, // bottom left point {-BOTTOM_WIDTH/2, -0.7f}, // middle left point {-BELLY_WIDTH/2, -0.4f}}; drawPolygon(6, bodyPoints); drawArm(); drawLeg(1.0, leg1Rotation, foot1Rotation); drawLeg(-1.0, leg2Rotation, foot2Rotation); drawHead(); } glPopMatrix(); // Retrieve the previous state of the transformation stack glPopMatrix(); }
Mat BodyModel::generateMat() { _mask = Mat::zeros(_img_heigh, _img_width, CV_8UC3); // draw waist drawPolygon(_right_waist, _left_waist, _right_hip, _left_hip); // draw chest drawPolygon(_right_shoulder, _left_shoulder, _right_waist, _left_waist); // draw neck drawPolygon(Point(_center_x + _neck_width, _center_y - _neck_heigh), Point(_center_x - _neck_width, _center_y - _neck_heigh), Point(_center_x + _neck_width, _center_y), Point(_center_x - _neck_width, _center_y)); // draw left arm drawPolygon(_left_shoulder, _left_arm_lower, _left_elbow_upper, _left_elbow_lower); // draw left hand drawBodyShape(_left_elbow_upper, _left_elbow_lower, _left_hand_upper, _left_hand_lower, -5); // draw right arm drawPolygon(_right_shoulder, _right_arm_lower, _right_elbow_upper, _right_elbow_lower); // draw right hand drawBodyShape(_right_elbow_upper, _right_elbow_lower, _right_hand_upper, _right_hand_lower, 5); // draw head drawCircle(_head_center, _head_radius); // draw left leg drawPolygon(_left_hip, _mid_hip, _left_knee, _left_knee_inner); // draw right leg drawPolygon(_right_hip, _mid_hip, _right_knee, _right_knee_inner); // draw left limb drawBodyShape(_left_knee, _left_knee_inner, _left_footrope, _left_heel, -10); // draw right limb drawBodyShape(_right_knee, _right_knee_inner, _right_footrope, _right_heel, 10); // draw left foot drawTriangle(_left_heel, _left_toe, _left_heel_upper); // draw right foot drawTriangle(_right_heel, _right_toe, _right_heel_upper); // draw shoulder drawTriangle(_right_shoulder, _left_shoulder, Point(_center_x, _center_y - _shoulder_heigh)); return _mask; }
void drawArm(){ glPushMatrix(); { // Move the arm into the hinge position glTranslatef(0.1, ARM_SCALE/2, 0.0); // Rotate the arm along the hinge glRotatef(armRotation, 0.0, 0.0, 1.0); // Scale the arm down from the size of the body glScalef(ARM_SCALE, ARM_SCALE, 1.0); // Translate the arm to its true position glTranslatef(0.0, -ARM_SCALE + 0.1, 0.0); glColor3f(0.0, 0.0, 1.0); Point armPoints[] = { // top left point {-ARM_WIDTH_TOP/2, ARM_LENGTH/2}, // top right point {ARM_WIDTH_TOP/2, ARM_LENGTH/2}, // bottom right point {ARM_WIDTH_BOTTOM/2, -ARM_LENGTH/2}, // bottom left point {-ARM_WIDTH_BOTTOM/2, -ARM_LENGTH/2}}; drawPolygon(4, armPoints); } glPopMatrix(); // Draw the shoulder joint glPushMatrix(); { glTranslatef(0.1, ARM_SCALE/2, 0.0); glScalef(LEG_SCALE * 0.1, LEG_SCALE * 0.1, 1.0); glColor3f(1.0, 1.0, 1.0); drawCircle(1.0); } glPopMatrix(); }
void Viewport::drawObj(Object* obj){ if(obj->getType() != ObjType::OBJECT3D && obj->getNCoordsSize() == 0) return; switch(obj->getType()){ case ObjType::OBJECT: break; case ObjType::POINT: drawPoint(obj); break; case ObjType::LINE: drawLine(obj); break; case ObjType::POLYGON: drawPolygon(obj); break; case ObjType::BEZIER_CURVE: case ObjType::BSPLINE_CURVE: drawCurve(obj); break; case ObjType::OBJECT3D: drawObj3D((Object3D*) obj); } }
/* cube - takes an array of 8 vertices, and draws 6 faces * with drawPolygon, making up a box */ void cube(float v[8][3]) //function for drawing cube (taken from Avenue) { glColor3fv(cols[0]); drawPolygon(0, 3, 2, 1, v); glColor3fv(cols[0]); drawPolygon(1, 0, 4, 5, v); glColor3fv(cols[1]); drawPolygon(5, 1, 2, 6, v); glColor3fv(cols[0]); drawPolygon(2, 3, 7, 6, v); glColor3fv(cols[0]); drawPolygon(6, 5, 4, 7, v); glColor3fv(cols[1]); drawPolygon(4, 0, 3, 7, v); }
//draws the cube given the vertices //corrected for back face culling void genshapeClass::cube(float v[8][3]) { glColor3fv(cols[1]); drawPolygon(0, 3, 2, 1, v); glColor3fv(cols[2]); drawPolygon(5 ,4, 0, 1, v); glColor3fv(cols[3]); drawPolygon(5, 1, 2, 6, v); glColor3fv(cols[4]); drawPolygon(2, 3, 7, 6, v); glColor3fv(cols[5]); drawPolygon(7, 4, 5, 6, v); glColor3fv(cols[0]); drawPolygon(7, 3, 0, 4, v); }
void BoardModelPrivate::addPoint(const QPoint& point) { Q_Q(BoardModel); if (sender() == m_rival.get()) { if (m_rival->owner() != m_steps->getCurrentOwner()) return; } else { if (m_rival->owner() == m_steps->getCurrentOwner()) return; } Graph& graph = *m_graph; GraphPoint& currentPoint = graph[point]; if (currentPoint.owner() != Owner::NONE || currentPoint.isCaptured()) return; const Owner current = m_steps->getCurrentOwner(); currentPoint.setOwner(current); m_steps->addPoint(point); PolygonFinder findPolygon(graph, current); //O(n) const PolyList& polyList = findPolygon(point); const auto& points = m_steps->getPoints(StepQueue::other(current)); if (points.empty() || polyList.empty()) { continueStep(); emitStatus(); emit q->pointAdded(point); return; } const Owner otherOwner = StepQueue::other(current); const auto& otherOwnerPoints = m_steps->getPoints(otherOwner); for (const QPoint& p : otherOwnerPoints) { GraphPoint& gpoint = graph[p]; if (gpoint.isCaptured()) continue; for (const Polygon_ptr& polygon : polyList) { if (polygon->contains(p)) { if (gpoint.owner() == otherOwner) { polygon->setFilled(true); m_steps->addCaptured(); } gpoint.capture(); break; } } } for (Graph::iterator itr = graph.begin(), itrEnd = graph.end(); itr != itrEnd; ++itr) { if (itr->isCaptured() || itr->owner() != Owner::NONE) continue; for (const Polygon_ptr& polygon : polyList) { const QPoint& newPoint = itr.point(); if (polygon->contains(newPoint) && polygon->isFilled()) { itr->capture(); m_steps->addEmptyCaptured(); break; } } } drawPolygon(polyList); continueStep(); emitStatus(); emit q->pointAdded(point); }