Zde můžete vidět rozdíly mezi vybranou verzí a aktuální verzí dané stránky.
| Následující verze | Předchozí verze | ||
| pitel:izg:lab03 [03. 07. 2012, 11.53:35] – upraveno mimo DokuWiki 127.0.0.1 | pitel:izg:lab03 [30. 12. 2022, 13.43:01] (aktuální) – upraveno mimo DokuWiki 127.0.0.1 | ||
|---|---|---|---|
| Řádek 1: | Řádek 1: | ||
| + | ====== Generování základních objektů v rastru ====== | ||
| + | [[http:// | ||
| + | <file cpp student.cpp> | ||
| + | /////////////////////////////////////////////////////////////////////////////// | ||
| + | // Soubor studentskych funkci | ||
| + | /////////////////////////////////////////////////////////////////////////////// | ||
| + | |||
| + | /////////////////////////////////////////////////////////////////////////////// | ||
| + | // include | ||
| + | |||
| + | #include " | ||
| + | |||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | |||
| + | /////////////////////////////////////////////////////////////////////////////// | ||
| + | // name spaces | ||
| + | |||
| + | using namespace std; | ||
| + | |||
| + | |||
| + | /////////////////////////////////////////////////////////////////////////////// | ||
| + | // do teto casti doplnujte kod pri praci ve cviceni | ||
| + | |||
| + | |||
| + | /////////////////////////////////////////////////////////////////////////////// | ||
| + | // funkce pro vykresleni usecky do frame bufferu, Bresenhamuv algoritmus | ||
| + | // x1, y1 - souradnice pocatecniho bodu usecky | ||
| + | // x2, y2 - koncovy bod usecky | ||
| + | // color - barva vykreslene usecky | ||
| + | |||
| + | void DrawLine(int x1, int y1, int x2, int y2, const S_RGBA & color) | ||
| + | { | ||
| + | bool steep = abs(y1 - y2) > abs(x1 - x2); | ||
| + | if (steep) { | ||
| + | SWAP(x1, y1); | ||
| + | SWAP(x2, y2) | ||
| + | } | ||
| + | if (x1 > x2) { | ||
| + | SWAP(x1, x2); | ||
| + | SWAP(y1, y2); | ||
| + | } | ||
| + | int step_y = 1; | ||
| + | if (y1 > y2) { | ||
| + | step_y = -1; | ||
| + | } | ||
| + | |||
| + | int dx = abs(x2 - x1); | ||
| + | int dy = abs(y2 - y1); | ||
| + | int P = 2 * dy - dx; | ||
| + | int P1 = 2 * dy; | ||
| + | int P2 = P1 - 2 * dx; | ||
| + | int y = y1; | ||
| + | for (int x = x1; x != x2; x++) { | ||
| + | if (steep) { | ||
| + | PutPixel(y, | ||
| + | } else { | ||
| + | PutPixel(x, | ||
| + | } | ||
| + | if (P >= 0) { | ||
| + | P += P2; | ||
| + | y += step_y; | ||
| + | } | ||
| + | else { | ||
| + | P += P1; | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | |||
| + | /////////////////////////////////////////////////////////////////////////////// | ||
| + | // do teto casti doplnujte kod pro domaci ukol | ||
| + | |||
| + | |||
| + | /////////////////////////////////////////////////////////////////////////////// | ||
| + | // funkce pro vykresleni elipsy midpoint algoritmem prerusovanou carou | ||
| + | // cx cy - souradnice stredu elipsy | ||
| + | // px, py - souradnice druheho zadaneho bodu pro vypocet poloos | ||
| + | // FillPixels - pocet pixelu segmentu cary, ktery se vykresli | ||
| + | // SkipPixels - pocet pixelu segmentu cary, ktery se nevykresli | ||
| + | // color - barva vykreslene usecky | ||
| + | void DrawDashedEllipse(int cx, int cy, int px, int py, unsigned FillPixels, unsigned SkipPixels, const S_RGBA & color) | ||
| + | { | ||
| + | if (FillPixels < 1) { | ||
| + | return; //neni co kreslit | ||
| + | } | ||
| + | int rx = abs(px - cx); | ||
| + | int ry = abs(py - cy); | ||
| + | int x = 0; | ||
| + | int y = ry; | ||
| + | int P = ROUND(pow(ry, | ||
| + | unsigned SegmentPixels = FillPixels + SkipPixels; | ||
| + | unsigned RenderPixel = 1; | ||
| + | while (pow(rx, 2) * y > pow(ry, 2) * x ) { | ||
| + | if (RenderPixel <= FillPixels) { | ||
| + | PutPixel(cx + x, cy + y, color); | ||
| + | PutPixel(cx - x, cy + y, color); | ||
| + | PutPixel(cx + x, cy - y, color); | ||
| + | PutPixel(cx - x, cy - y, color); | ||
| + | } | ||
| + | if (RenderPixel++ > SegmentPixels) { | ||
| + | RenderPixel = 1; | ||
| + | } | ||
| + | if (P < 0) { | ||
| + | P += ROUND(pow(ry, | ||
| + | x++; | ||
| + | } else { | ||
| + | P += ROUND(pow(ry, | ||
| + | x++; | ||
| + | y--; | ||
| + | } | ||
| + | } | ||
| + | P = ROUND(pow(ry, | ||
| + | while (y >= 0) { | ||
| + | if (RenderPixel <= FillPixels) { | ||
| + | PutPixel(cx + x, cy + y, color); | ||
| + | PutPixel(cx - x, cy + y, color); | ||
| + | PutPixel(cx + x, cy - y, color); | ||
| + | PutPixel(cx - x, cy - y, color); | ||
| + | } | ||
| + | if (RenderPixel++ > SegmentPixels) { | ||
| + | RenderPixel = 1; | ||
| + | } | ||
| + | if (P < 0) { | ||
| + | P += ROUND(pow(ry, | ||
| + | x++; | ||
| + | y--; | ||
| + | } else { | ||
| + | P += ROUND(pow(rx, | ||
| + | y--; | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | |||
| + | |||
| + | |||
| + | /////////////////////////////////////////////////////////////////////////////// | ||
| + | /////////////////////////////////////////////////////////////////////////////// | ||
| + | </ | ||