Uživatelské nástroje

Nástroje pro tento web


pitel:izg:lab03

Rozdíly

Zde můžete vidět rozdíly mezi vybranou verzí a aktuální verzí dané stránky.

Odkaz na výstup diff

Následující verze
Předchozí verze
pitel:izg:lab03 [03. 07. 2012, 11.53:35] – upraveno mimo DokuWiki 127.0.0.1pitel: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://www.flickr.com/photos/pitel/2320249169/|{{ http://farm4.static.flickr.com/3042/2320249169_288aa1d69b_o.png }}]]
  
 +<file cpp student.cpp>
 +///////////////////////////////////////////////////////////////////////////////
 +// Soubor studentskych funkci
 +///////////////////////////////////////////////////////////////////////////////
 +
 +///////////////////////////////////////////////////////////////////////////////
 +// include 
 +
 +#include "main.h"
 +
 +#include <assert.h>
 +#include <math.h>
 +#include <stdlib.h>
 +#include <iostream>
 +#include <vector>
 +
 +
 +///////////////////////////////////////////////////////////////////////////////
 +// 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, x, color);
 + } else {
 + PutPixel(x, y, color);
 + }
 + 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, 2) - pow(rx, 2) * ry + pow(rx, 2) / 4);
 + 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, 2) * (2 * x + 3));
 + x++;
 + } else {
 + P += ROUND(pow(ry, 2) * (2 * x + 3) + pow(rx, 2) * (2 - 2 * y));
 + x++;
 + y--;
 + }
 + }
 + P = ROUND(pow(ry, 2) * (x + 0.5) * (x + 0.5) + pow(rx, 2) * (y - 1) * (y - 1) - pow(rx, 2) * pow(ry, 2));
 + 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, 2) * (2 * x + 2) + pow(rx, 2) * (3 - 2 * y));
 + x++;
 + y--;
 + } else {
 + P += ROUND(pow(rx, 2) * (3 - 2 * y));
 + y--;
 + }
 + }
 +}
 +
 +
 +
 +///////////////////////////////////////////////////////////////////////////////
 +///////////////////////////////////////////////////////////////////////////////
 +</file>
/var/www/wiki/data/attic/pitel/izg/lab03.1341316415.txt.bz2 · Poslední úprava: 30. 12. 2022, 13.43:01 (upraveno mimo DokuWiki)