예제 #1
0
void graph2_1::paintEvent(QPaintEvent *)
{
    /***********�����α߿���������**************/
    QPainter *painter=new QPainter(this);
    painter->setRenderHint(QPainter::Antialiasing,true);
    painter->drawRect(10,10,380,230);
    QPoint beginPoint(50,200);
    QPoint xEndPoint(xEndX,xEndY);
    QPoint yEndPoint(yEndX,yEndY);
    painter->drawLine(beginPoint,xEndPoint);
    painter->drawLine(beginPoint,yEndPoint);

    //*****************����������ͷ*********/
    int xOffset=13;
    brush.setColor(Qt::black);
    brush.setStyle(Qt::SolidPattern);
    painter->setBrush(brush);

    QPoint xarrowRightPoint(xEndX+xOffset,xEndY);
    QPoint xarrowTopPoint(xEndX,-xOffset*tan(PI/6)+xEndY);
    QPoint xarrowBotPoint(xEndX,xOffset*tan(PI/6)+xEndY);
    static const QPoint xarrowPoints[3] = {
    xarrowRightPoint,xarrowTopPoint,xarrowBotPoint,
    };
    painter->drawPolygon(xarrowPoints,3);

    QPoint yarrowTopPoint(yEndX,yEndY-xOffset);
    QPoint yarrowRightPoint(xOffset*tan(PI/6)+yEndX,yEndY);
    QPoint yarrowLeftPoint(-xOffset*tan(PI/6)+yEndX,yEndY);
    static const QPoint yarrowPoints[3] = {
    yarrowTopPoint,yarrowLeftPoint,yarrowRightPoint,
    };
    painter->drawPolygon(yarrowPoints,3);
    painter->setBrush(Qt::NoBrush);

    /************��ע������**********/
    painter->drawText(xEndX,xEndY+20,tr("HZ"));
    //painter->rotate(270);
    painter->drawText(yEndY,yEndX+20,tr("dB"));
    //painter->rotate(90);


    /*************************/
    QVector<qreal> dashes;
    qreal space = 3;
    dashes << 5 << space << 5 << space;
    pen.setDashPattern(dashes);
    pen.setWidth(2);
    pen.setColor(Qt::blue);
    painter->setPen(pen);

    QPoint point5(90,200);
    QPoint point6(100,155);
    QPoint point7(250,110);
    QPoint point8(300,80);

    painter->drawPath(drawBezierCurve(point5,point6));
    painter->drawPath(drawBezierCurve(point6,point7));
    painter->drawPath(drawBezierCurve(point7,point8));
}
예제 #2
0
void MapBuilder::render(int mouse_x, int mouse_y)
{

    //draw anchor points and mouse control point
    controlPoint1.x = mouse_x;
    controlPoint1.y = mouse_y;
    controlDot1.setPosition(controlPoint1.x,controlPoint1.y);
    engine->Window->draw(controlDot1);

    if(anchor1)
    {
        anchorDot1.setPosition(anchorPoint1.x,anchorPoint1.y);
        engine->Window->draw(anchorDot1);
    }


    if(anchor2)
    {
        anchorDot2.setPosition(anchorPoint2.x,anchorPoint2.y);
        engine->Window->draw(anchorDot2);
    }

    if(anchor1 && anchor2)
    {
       //if both anchors are set
       drawBezierCurve(mouse_x,mouse_y);
    }

    if(drawbox)
        drawBox(mouse_x,mouse_y);


}
예제 #3
0
void drawScene2D()
{
    // setup projection
    glMatrixMode(GL_PROJECTION);
	auto res = resolution.Cast<Gs::Real>();
    auto proj = Gs::ProjectionMatrix4::Planar(res.x, res.y);
    glLoadMatrix_T(proj.Ptr());

    // setup model-view matrix
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    // draw scene
    drawSpline(spline, 0.0f, 6.0f, 500);
    drawBezierCurve(bezierCurve, 100);
}
예제 #4
0
void GLWidget::paintGL()
{
	// clear
	glClear(GL_COLOR_BUFFER_BIT);

	// Koordinatensystem
	glColor3f(0.5,0.5,0.5);
	glBegin(GL_LINES);
	glVertex2f(-1.0, 0.0);
	glVertex2f( 1.0, 0.0);
	glVertex2f( 0.0,-1.0);
	glVertex2f( 0.0, 1.0);
	glEnd();
	glColor3f(1.0,0.0,0.0);

	// Punkte
	glPointSize(7.0);
	glBegin(GL_POINTS);
	for (int i=0; i<points.getCount(); i++) {
		glVertex2f(points.getPointX(i),points.getPointY(i));
	}

	glEnd();

	// Hüllpolygone zeichnen
	glColor3f(0.0,0.0,1.0);

	for (int i=0; i<curveSizes.count(); i++) {
		glBegin(GL_LINE_STRIP);
		for (int j=0; j<curveSizes[i]; j++) {
			glVertex2f(points.getPointX(j+sumCurveSizes(i)),points.getPointY(j+sumCurveSizes(i)));
		}
		glEnd();
	}

	// Kurve
	glColor3f(1.0,1.0,1.0);

	// Kurvenpunkte auf Kurven aufteilen
	Points* pointsArray = new Points[curveSizes.count()];
	for (int j=0; j<curveSizes.count(); j++) {
		for (int i=sumCurveSizes(j); i<sumCurveSizes(j)+curveSizes[j]; i++) {
			pointsArray[j].addPoint(points.getPointX(i), points.getPointY(i));
		}
	}

	// Kurven zeichnen
	for (int i=0; i<curveSizes.count(); i++) {
		drawBezierCurve(pointsArray[i].getCount(), pointsArray[i], this->epsilon_draw);
	}

	// Schnittpunkte zeichnen

	if (doIntersection) {
		glColor3f(0.0,1.0,0.0);
		for (int i=0; i<curveSizes.count(); i++) {
			for (int j=i+1; j<curveSizes.count(); j++) {
				drawIntersect(pointsArray[i], pointsArray[j], this->epsilon_intersection);
			}
		}
	}
	if (doSelfIntersection) {
		glColor3f(1.0,0.0,1.0);
		for (int i=0; i<curveSizes.count(); i++) {
			drawSelfIntersect(pointsArray[i], this->epsilon_intersection);
		}
	}

	delete pointsArray;
}