C++: como usar o 'vector'?

Cambalinho

Power Member
Código:
void DrawPolygon(HDC HDCDestination, vector<POINT> points, HPEN LineColor, HBRUSH PlaneColor)
{
    HPEN hOldPen = (HPEN)SelectObject(HDCDestination, LineColor);
    HBRUSH hOldBrush = (HBRUSH)SelectObject(HDCDestination, PlaneColor);
    points[0]=GetLineZZero(points[0],points[1]);
    points[4]=GetLineZZero(points[4],points[3]);
    Polygon(HDCDestination,points.data(),points.size());
    SelectObject(HDCDestination, hOldPen);
    SelectObject(HDCDestination, hOldBrush);
}
porque a linha: "points[0]=GetLineZZero(points[0],points[1]);" tenho este erro: "could not convert 'points.std::vector<tagPOINT>::operator[](0)' from '__gnu_cxx::__alloc_traits<std::allocator<tagPOINT>, tagPOINT>::value_type' {aka 'tagPOINT'} to 'position'"
que erro eu fiz?
não posso usar o vector dessa forma?
 
fiz 1 erro que já notei...
troquei os tipos de variaveis sem notar e consegui corrir:
Código:
position GetLineZZero(position Origin, position Destination)
{

    position LinePoint;
    int dx = abs(Destination.Pos3DX-Origin.Pos3DX), sx = Origin.Pos3DX<Destination.Pos3DX ? 1 : -1;
    int dy = abs(Destination.Pos3DY-Origin.Pos3DY), sy = Origin.Pos3DY<Destination.Pos3DY ? 1 : -1;
    int dz = abs(Destination.Pos3DZ-Origin.Pos3DZ), sz = Origin.Pos3DZ<Destination.Pos3DZ ? 1 : -1;
    int dm =std::max( { dx, dy, dz } ), i = dm; /* maximum difference */
    Destination.Pos3DX = Destination.Pos3DY = Destination.Pos3DZ = dm/2; /* error offset */

    do
    {
        Destination.Pos3DX -= dx; if (Destination.Pos3DX < 0) { Destination.Pos3DX += dm; Origin.Pos3DX += sx; }
        Destination.Pos3DY -= dy; if (Destination.Pos3DY < 0) { Destination.Pos3DY += dm; Origin.Pos3DY += sy; }
        Destination.Pos3DZ -= dz; if (Destination.Pos3DZ < 0) { Destination.Pos3DZ += dm; Origin.Pos3DZ += sz; }
        LinePoint.Pos3DX=Origin.Pos3DX;
        LinePoint.Pos3DY=Origin.Pos3DY;
        LinePoint.Pos3DZ=Origin.Pos3DZ;
        if(LinePoint.Pos3DZ<=0) break;

        i--;
    }while(i>0);
    return LinePoint;
}

void DrawPolygon(HDC HDCDestination, vector<position> points, HPEN LineColor, HBRUSH PlaneColor)
{
    if(points[1].Pos3DZ<0) return;
    RECT fd;
    GetClientRect(GetConsoleWindow(), &fd);
    HPEN hOldPen = (HPEN)SelectObject(HDCDestination, LineColor);
    HBRUSH hOldBrush = (HBRUSH)SelectObject(HDCDestination, PlaneColor);
    if(points[0].Pos3DZ<0)
    {
        points[0]=GetLineZZero(points[0],points[1]);
        points[3]=GetLineZZero(points[3],points[2]);
    }

    vector<POINT> polygon;
    for(int index=0; index<points.size(); index++)
    {
        polygon.push_back(points[index].Perspective(300,{fd.right/2, fd.bottom/2 }));
    }
    Polygon(HDCDestination,polygon.data(),points.size());
    SelectObject(HDCDestination, hOldPen);
    SelectObject(HDCDestination, hOldBrush);
}
muito obrigado!!!
 
Back
Topo