示例#1
0
void RoundedRectItem::createPolygon(void)
{
	polygon.clear();

	if(corners!=NONE_CORNERS && corners!=ALL_CORNERS && this->rect().isValid())
	{
		QRectF rect=this->rect();

		if(isCornerRounded(TOPLEFT_CORNER))
			polygon << calculatePoints(rect.topLeft() + QPointF(radius, radius), 180, 90);
		else
			polygon.append(this->rect().topLeft());

		if(isCornerRounded(TOPRIGHT_CORNER))
			polygon << calculatePoints(this->rect().topRight() + QPointF(-radius, radius), 90, 0);
		else
			polygon.append(this->rect().topRight());

		if(isCornerRounded(BOTTOMRIGHT_CORNER))
			polygon << calculatePoints(this->rect().bottomRight() + QPointF(-radius, -radius), 360, 270);
		else
			polygon.append(this->rect().bottomRight());

		if(isCornerRounded(BOTTOMLEFT_CORNER))
			polygon << calculatePoints(this->rect().bottomLeft() + QPointF(radius, -radius), 270, 180);
		else
			polygon.append(this->rect().bottomLeft());
	}
}
示例#2
0
void level_update() {
	if (scene.tempo <= 0) {
		if (input.backspace->press) {
			sceneLoad(MENU);
		}
		if (input.enter->press && !input.captureText && !input.captureFinish) {
			showTextbox();
		}
		if (input.captureFinish) {
			hideTextbox();
		}
		if (input.textUpdate) {
			calculatePoints(false);
		}
		if (input.tab->press) {
			setDir(-functionDir);
			calculatePoints(true);
		}
	}
	if (zeroHeightTempo > 0) {
		zeroHeightTempo -= game.delta*3;
		if (zeroHeightTempo < 0) {
			zeroHeightTempo = 0;
		}
	}
	dottedTempo += game.delta*3;
	while (dottedTempo >= 1) {
		dottedTempo -= 1;
	}
	if (functionPlot) {
		if (weightTempo < 1) {
			weightTempo += game.delta*8;
			if (weightTempo > 1) weightTempo = 1;
		}
	} else {
		if (weightTempo > 0) {
			weightTempo -= game.delta*2;
			if (weightTempo < 0) weightTempo = 0;
		}
	}
	if (plotTempo > 0) {
		if (weightTempo > 0) {
			plotTempo -= game.delta*8;
			if (plotTempo < 0) plotTempo = 0;
		} else {
			plotTempo = 0;
		}
	}
}
示例#3
0
文件: mesh.cpp 项目: tsong/viewer
Mesh Mesh::subdivide() {
    //calculate new points in subdivided mesh
    calculatePoints();

    Mesh M;

    //each face will become 4 faces in the new mesh
    for (uint i = 0; i < m_faces.size(); i++) {
        Face &f = m_faces[i];
        Vector3f V[4];
        Vector3f N[4];

        //calculate the vertices of the new faces
        V[0] = m_facePoints[i];
        N[0] = m_facePointNormals[i];
        for (uint j = 0; j < 4; j++) {
            V[1] = m_edgePoints[f.edges[j]];
            V[2] = m_vertexPoints[f.vertices[(j+1)%4]];
            V[3] = m_edgePoints[f.edges[(j+1)%4]];

            N[1] = m_edgePointNormals[f.edges[j]];
            N[2] = m_vertexPointNormals[f.vertices[(j+1)%4]];
            N[3] = m_edgePointNormals[f.edges[(j+1)%4]];

            M.addFace(V[0],V[1],V[2],V[3],N);
        }
    }

    return M;
}
int main() {

	int i;

	//init mutexes and condition variables
	initMutAndCond();

	//calculate the points
	calculatePoints();

	//allocate memory for first box
	box = (Box**) malloc(sizeof(Box*));  
	box[0] = (Box*) malloc(sizeof(Box));

	//init first box
	initFirstBox();
	
	boxIdCounter=1; bCounter=0;

	//get first timestamp
	long starting=getTimestamp();

	runBox(box[0]);
	
	printf("\n=======================================\n\n");
	for(i=0;i<boxIdCounter;i++)
	if(box[i]->boxid%1000==0)	
		printf("Box %i: level=%i, center=%G,%G,%G, n=%i\n",
			box[i]->boxid,box[i]->level,box[i]->center[0],box[i]->center[1],
			box[i]->center[2],box[i]->n);
	
	long finishing=getTimestamp();
	printf("Total time: %lu, threads used:%lu\n",finishing-starting,sumOfThreadsUsed);
}
void UBGraphicsTriangle::setOrientation(UBGraphicsTriangleOrientation orientation)
{
    mOrientation = orientation;
    calculatePoints(boundingRect());

    QPolygonF polygon;
    polygon << A1 << B1 << C1;
    setPolygon(polygon);
}
void CreateRoundaboutInteraction::mousePressEvent(QMouseEvent * event)
{
    if (event->buttons() & Qt::LeftButton)
    {
        if (!HaveCenter)
        {
            HaveCenter = true;
            view()->setInteracting(true);
            Center = XY_TO_COORD(event->pos());
        }
        else
        {
            calculatePoints();
            if (Points.size() == 0) return;

            QPointF Prev = Points[0];
            Node* First = g_backend.allocNode(theMain->document()->getDirtyOrOriginLayer(), XY_TO_COORD(Prev.toPoint()));
            Way* R = g_backend.allocWay(theMain->document()->getDirtyOrOriginLayer());
            CommandList* L  = new CommandList(MainWindow::tr("Create Roundabout %1").arg(R->id().numId), R);
            L->add(new AddFeatureCommand(theMain->document()->getDirtyOrOriginLayer(),R,true));
            R->add(First);
            L->add(new AddFeatureCommand(theMain->document()->getDirtyOrOriginLayer(),First,true));
            if (M_PREFS->getAutoSourceTag()) {
                QStringList sl = theMain->document()->getCurrentSourceTags();
                if (sl.size())
                    R->setTag("source", sl.join(";"));
            }
            // "oneway" is implied on roundabouts
            //R->setTag("oneway","yes");
            if (DockData.type->currentIndex() == 0)
                R->setTag("junction","roundabout");
            for (int i = 1; i < Points.size(); i++ ) {
                QPointF Next = Points[i];
                Node* New = g_backend.allocNode(theMain->document()->getDirtyOrOriginLayer(), XY_TO_COORD(Next.toPoint()));
                L->add(new AddFeatureCommand(theMain->document()->getDirtyOrOriginLayer(),New,true));
                R->add(New);
            }
            R->add(First);
            for (FeatureIterator it(document()); !it.isEnd(); ++it) {
                Way* W1 = CAST_WAY(it.get());
                if (W1 && (W1 != R))
                    Way::createJunction(theMain->document(), L, R, W1, true);
            }
            theMain->properties()->setSelection(R);
            document()->addHistory(L);
            view()->setInteracting(false);
            view()->invalidate(true, true, false);
            theMain->launchInteraction(0);
        }
    }
    else
        Interaction::mousePressEvent(event);
}
示例#7
0
bool Visibility::InLOS(int x1, int y1, int x2, int y2)
{
  std::vector<Vector2f> points;
  calculatePoints(x1, y1, x2, y2, points);

  for (unsigned i = 0; i < points.size(); ++i) {
    CTile *tile = CArea::area_control.GetTile(
        points[i].x * TILE_SIZE, points[i].y * TILE_SIZE);
        if (tile && tile->type_id == TILE_TYPE_BLOCK) {
      return false;
    }
  }
    return true;
}
示例#8
0
void Visibility::drawRay(int x1, int y1, int x2, int y2, SDL_Surface *dest)
{
  std::vector<Vector2f> points;
  calculatePoints(x1 / TILE_SIZE, y1 / TILE_SIZE,
      x2 / TILE_SIZE, y2 / TILE_SIZE, points);

  SDL_Surface *point =
      CSurface::OnLoad(data::FindFile("gfx/UI/Target.png").c_str());
  for (unsigned i = 0; i < points.size(); ++i) {
    CSurface::OnDraw(dest, point,
        points[i].x * TILE_SIZE - CCamera::camera_control.GetX(),
        points[i].y * TILE_SIZE - CCamera::camera_control.GetY());
  }
  SDL_FreeSurface(point);
}
void CreateRoundaboutInteraction::paintEvent(QPaintEvent* , QPainter& thePainter)
{
    calculatePoints();

    if (Points.size() == 0) return;

    qreal Precision = DockData.precision->value(); //2.49;
    QBrush SomeBrush(QColor(0xff,0x77,0x11,128));
    QPen TP(SomeBrush,view()->pixelPerM()*Precision/2);

    for (int i = 0; i < Points.size(); i++) {
        QPointF Prev = Points[i];
        QPointF Next = Points[ (i+1)%Points.size() ];
        ::draw(thePainter, TP, (DockData.type->currentIndex() == 0) ? Feature::OneWay : Feature::BothWays, Prev, Next, Precision, view()->projection());
        Prev = Next;
    }
}
示例#10
0
/* choosing a default because otherwise everyone has to
 * choose and ensure that it is same all over, which
 * could be a pain.
 * Bigger todo is to have some way to specify weightage
 * with the servers.
 */
consistent_t consistentCreate(char* serverNames) {
	consistentImpl_t* pC = ALLOCATE_1(consistentImpl_t);

	IfTrue(pC, ERR, "Error allocating memory");

	pC->spread    = SPREAD;

	IfTrue( 0 == parseAndSetServerNames(pC, serverNames), ERR, "Error setting server names");
	IfTrue( 0 == calculatePoints(pC), ERR, "Error calculating points");

	goto OnSuccess;
OnError:
	consistentDelete(pC);
	pC = 0;
OnSuccess:
    return pC;
}
示例#11
0
int AxisBase::toView(double value)
{
    int p_start, p_end;
    calculatePoints(p_start, p_end);

    // add 5% to ensure that everything fits
    double p10 = (m_max - m_min) * 0.05;

    double d = (value - m_min) / (m_max - m_min + p10);

    switch (m_orient)
    {
        case Qt::Vertical:
            return p_end - d * (p_end - p_start);

        case Qt::Horizontal:
            return d * (p_end - p_start) + p_start;
    }

    return 0;
}
示例#12
0
int main()
{
    srand(time(NULL));
    clock_t start = clock();
    int x1,y1,x2,y2,counter=0;
    int i,record=0;
    char tryagain='y';//for restart menu
    char **board;//for create a board
    board=(char **)malloc(7*sizeof(char*));
    for(i=0;i<7;i++) board[i]=(char*)malloc(7*sizeof(char*));
    
    while(tryagain=='y')
    {
        int total_point=0;
        initializeBoard(board);
        while(checkclock(start))
        {
            while(getCandiesCoordinates(&x1,&y1,&x2,&y2));
            if(checkCandies(&x1,&y1,&x2,&y2,board,&counter))
            {
                crushCandies(&x1,&y1,&x2,&y2,board);
                total_point=total_point+calculatePoints(&counter);
                printf("Your total points is %d!\n",total_point);
                display_board(board);  
            }
        }
        fflush(stdin);
        printf("\ntime is up\n");
        if(total_point>record)record=total_point;
        printf("Record is %d\n",record);
        printf("Do you want to play again (y/n) :");
        scanf("%c",&tryagain);
        start = clock();
    }
    printf("\nGood Bye\n");
    system("pause");
    return 0;
}
示例#13
0
void AxisBase::drawAxisModel(QPainter &p)
{
    PlotterBase *plotter = (PlotterBase*)parent();
    QRect rect(plotter->contentsRect());

    int p_start, p_end;
    calculatePoints(p_start, p_end);

    switch (m_orient)
    {
        case Qt::Vertical:
        {
            p.setPen(m_pen);
            p.drawLine(m_offset+2, p_start, m_offset+2, p_end);

            if (m_model)
            {
            }

            break;
        }

        case Qt::Horizontal:
        {
            p.setPen(m_pen);
            p.drawLine(p_start, rect.height()-m_offset, p_end, rect.height()-m_offset);

            if (m_model)
            {
                int count = m_model->columnCount();
				if (count <= 0)
					return;

                int p_offs = (p_end - p_start) / count;
                int p_line_d = p_start + p_offs;

				QRect prevRect;

                for (int i = 0; i < count; i++)
                {
                    double d = (double)i / (double)count;
                    int p_d = d * (p_end - p_start) + p_start + p_offs/2;

                    p.setPen(m_majorPen);
                    p.drawLine(p_d, rect.height()-m_offset+0, p_d, rect.height()-m_offset+4);

                    if (m_majorGridPen != Qt::NoPen)
                    {
                        p.setPen(m_majorGridPen);
                        p.drawLine(p_line_d, rect.top(), p_line_d, rect.height()-m_offset);
                        p_line_d += p_offs;
                    }

                    QString text(m_model->headerData(i, m_orient).toString());
                    QFontMetrics fm(m_font);
                    QRect textRect(fm.boundingRect(text));

                    int w = textRect.width() + 4;
                    QRect drawRect(p_d - w/2, rect.height()-m_offset+3, w, m_offset);

                    // skip paining the text
                    if (prevRect.isValid() && prevRect.intersects(drawRect))
                        continue;
                    prevRect = drawRect;

                    p.setPen(QPen(m_textColor));
                    p.drawText(drawRect, Qt::AlignCenter, text);
                }
            }

            break;
        }

    }

}
示例#14
0
void AxisBase::drawAxisData(QPainter &p)
{
    PlotterBase *plotter = (PlotterBase*)parent();
    QRect rect(plotter->contentsRect());

    double start = m_min;
    double end = m_max;

    int p_start, p_end;
    calculatePoints(p_start, p_end);

    switch (m_orient)
    {
        case Qt::Vertical:
        {
            p.setPen(m_pen);
            p.drawLine(m_offset+2, p_start, m_offset+2, p_end);

            if (m_minor > 1e-100)
            {
                int prevTick = INT_MAX/2;

                for (double i = start; i <= end; i += m_minor)
                {
                    int p_d = toView(i);

                    if (p_d < prevTick-1)
                    {
                        prevTick = p_d;
                        p.setPen(m_minorPen);
                        p.drawLine(m_offset+1, p_d, m_offset+3, p_d);

                        if (m_minorGridPen != Qt::NoPen)
                        {
                            p.setPen(m_minorGridPen);
                            p.drawLine(m_offset+2, p_d, rect.right(), p_d);
                        }
                    }
                }
            }

            if (m_major > 1e-100)
            {
                QRect prevRect;
                int prevTick = INT_MAX/2;

                for (double i = start; i <= end; i += m_major)
                {
                    int p_d = toView(i);

                    if (p_d < prevTick-1)
                    {
                        prevTick = p_d;
                        p.setPen(m_majorPen);
                        p.drawLine(m_offset+0, p_d, m_offset+4, p_d);

                        if (m_majorGridPen != Qt::NoPen)
                        {
                            p.setPen(m_majorGridPen);
                            p.drawLine(m_offset+2, p_d, rect.right(), p_d);
                        }
                    }

                    QString text(QString::number(i));
                    QFontMetrics fm(m_font);
                    QRect textRect(fm.boundingRect(text));

                    int h = textRect.height();
                    QRect drawRect(0, p_d - h/2, m_offset, h);

                    // skip paining the text
                    if (prevRect.isValid() && prevRect.intersects(drawRect))
                        continue;
                    prevRect = drawRect;

                    p.setPen(QPen(m_textColor));
                    p.drawText(drawRect, Qt::AlignRight | Qt::AlignVCenter, text);
                }
            }

            break;
        }

        case Qt::Horizontal:
        {
            p.setPen(m_pen);
            p.drawLine(p_start, rect.height()-m_offset, p_end, rect.height()-m_offset);

            if (m_minor > 1e-100)
            {
                int prevTick = -INT_MAX;

                for (double i = start; i <= end; i += m_minor)
                {
                    int p_d = toView(i);

                    if (p_d > prevTick+1)
                    {
                        prevTick = p_d;
                        p.setPen(m_minorPen);
                        p.drawLine(p_d, rect.height()-m_offset+1, p_d, rect.height()-m_offset+3);

                        if (m_minorGridPen != Qt::NoPen)
                        {
                            p.setPen(m_minorGridPen);
                            p.drawLine(p_d, rect.top(), p_d, rect.height()-m_offset);
                        }
                    }
                }
            }

            if (m_major > 1e-100)
            {
                QRect prevRect;
                int prevTick = -INT_MAX;

                for (double i = start; i <= end; i += m_major)
                {
                    int p_d = toView(i);

                    if (p_d > prevTick+1)
                    {
                        prevTick = p_d;
                        p.setPen(m_majorPen);
                        p.drawLine(p_d, rect.height()-m_offset+0, p_d, rect.height()-m_offset+4);

                        if (m_majorGridPen != Qt::NoPen)
                        {
                            p.setPen(m_majorGridPen);
                            p.drawLine(p_d, rect.top(), p_d, rect.height()-m_offset);
                        }
                    }

                    QString text(QString::number(i));
                    QFontMetrics fm(m_font);
                    QRect textRect(fm.boundingRect(text));

                    int w = textRect.width();
                    QRect drawRect(p_d - w/2, rect.height()-m_offset+3, w, m_offset);

                    // skip paining the text
                    if (prevRect.isValid() && prevRect.intersects(drawRect))
                        continue;
                    prevRect = drawRect;

                    p.setPen(QPen(m_textColor));
                    p.drawText(drawRect, Qt::AlignCenter, text);
                }
            }

            break;

        }
    }
}