// ------------------------------------------------------ render -------------------------------------------------------------------- // void Scene::render(Image &img){ int w = img.width(); int h = img.height(); Vector right = ((center-eye).cross(up)).normalized(); // right vector double pSize = up.length(); // pixel size as length of up vector Point leftUp(center - (w/2)*pSize*right + (h/2)*pSize*up); // pixel left upper bound double zBuffer[w][h]; cout << "eye: " << eye.x << "," << eye.y << "," << eye.z << endl; cout << "center: " << center.x << "," << center.y << "," << center.z << endl; cout << "up: " << up.x << "," << up.y << "," << up.z << endl; cout << "right: " << right.x << "," << right.y << "," << right.z << endl; cout << "viewSize: " << w << "," << h << endl; cout << "leftUp: " << leftUp.x << "," << leftUp.y << "," << leftUp.z << endl; cout << "pSize: " << pSize << endl; cout << "maxRecursionDepth: " << maxRecursionDepth << endl; cout << "superSamplingFactor: " << superSamplingFactor << endl; cout << "apertureSamples: " << apertureSamples << endl; cout << "apertureRadius: " << apertureRadius << endl; Color color; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { Point pixel = leftUp + (x*pSize*right) - (y*pSize*up); // go to correct x,y position if (rendermode == phong || rendermode == gooch){ img(x,y) = superSample(pixel, right, pSize); } if (rendermode == normal){ Ray ray(eye, ((pixel + right*pSize/2 - up*pSize/2)-eye).normalized()); img(x,y) = traceNormal(ray); } if (rendermode == zbuffer){ Ray ray(eye, ((pixel + right*pSize/2 - up*pSize/2)-eye).normalized()); zBuffer[x][y] = traceZBuffer(ray); } } } if (rendermode == zbuffer){ for (int y = 0; y < h; y++){ for (int x = 0; x < w; x++){ color.set((-1*(zBuffer[x][y]-minZB)/(maxZB-minZB))+1); color.clamp(); img(x,y) = color; } } } }
static void read_mac(char *ifname, n2n_mac_t mac_addr) { int _sock, res; struct ifreq ifr; macstr_t mac_addr_buf; memset(&ifr, 0, sizeof(struct ifreq)); /* Dummy socket, just to make ioctls with */ _sock = socket(PF_INET, SOCK_DGRAM, 0); strcpy(ifr.ifr_name, ifname); res = ioctl(_sock, SIOCGIFHWADDR, &ifr); if (res < 0) { perror("Get hw addr"); } else memcpy(mac_addr, ifr.ifr_ifru.ifru_hwaddr.sa_data, 6); traceNormal("Interface %s has MAC %s", ifname, mac2str(mac_addr_buf, mac_addr)); close(_sock); }