/* put your name here, just in case **** Project 1: Ray Tracing CS4451A, Spring 2005 */ #include #include #include /* ------------ typedefs -------------- */ typedef struct { double r,g,b; } RGB; class image { int xsize,ysize; // resolution RGB *rgb; // pixel intensities public: image ( int m, int n ); // allocates image of specified size RGB &pixel ( int i, int j ); // access to a specific pixel friend ostream &operator<< ( ostream &ofs, image i ); // dumps image as a ppm file }; /* ----------- functionality of image class ---------- */ image::image ( int m, int n ) : xsize(m), ysize(n) { rgb = new RGB[m*n]; } /* ----------------------- */ RGB &image::pixel ( int i, int j ) { return rgb[i+xsize*j]; } /* ----------------------- */ int clampnround ( double x ) { if (x>255) x = 255; if (x<0) x = 0; return (int)floor(x+.5); } ostream &operator<< ( ostream &ofs, RGB c ) { return ofs << clampnround(255*c.r) << " " << clampnround(255*c.g) << " " << clampnround(255*c.b) << " " << endl; } ostream &operator<< ( ostream &ofs, image i ) { int x,y; ofs << "P3" << endl; ofs << i.xsize << " " << i.ysize << endl; ofs << "255" << endl; for ( y=i.ysize-1; y>=0; y-- ) for ( x=0; x