00001 /** 00002 *\file main.cpp 00003 * 00004 *\brief 00005 * 00006 *\author Xianming Chen 00007 * 00008 */ 00009 00010 #include "Canvas.h" 00011 #include "color.h" 00012 #include "xmath.h" 00013 #include "TriangleMesh.h" 00014 00015 #include <iostream> 00016 #include <sstream> 00017 #include <iomanip> 00018 00019 00020 using namespace columbia; 00021 00022 int main() 00023 { 00024 try 00025 { 00026 Canvas canvas; 00027 canvas.filename = "budaha4.ppm"; 00028 TriangleMesh msh("budaha4.obj"); 00029 00030 for(int f = 0; f < msh.total_triangles; ++f) 00031 { 00032 int i = msh.F[f].i, j = msh.F[f].j, k = msh.F[f].k; 00033 canvas.WireTriangle(msh.V[i], White, msh.V[j], White, msh.V[k], White); 00034 } 00035 00036 00037 canvas.WritePPM(); 00038 } 00039 catch(char const* msg) 00040 { 00041 std :: cerr << msg << std :: endl; 00042 } 00043 00044 00045 return 0; 00046 } 00047 00048 00049 // void draw_pixel(Canvas& canvas, int x, int y, int scale, RGB const& col) 00050 // { 00051 // canvas.SolidRectangle(x*scale, y*scale, (x+1)*scale, (y+1)*scale, col); 00052 // } 00053 00054 00055 // const int frames = 200; 00056 // const int radius = 20; 00057 // const int x0 = -canvas.hReso/2 + radius; 00058 // const int y0 = -canvas.vReso/2 + radius; 00059 // int step_x = 5; 00060 // int step_y = 7; 00061 00062 // int x = x0, y = y0; 00063 00064 // for(int i = 0; i<frames; i++) 00065 // { 00066 // ostringstream os; 00067 // os << setfill('0') << setw(4) << i; 00068 // canvas.filename = "frame" + os.str() + ".ppm"; 00069 00070 // canvas.Clear(Blue); 00071 // canvas.SolidCircle(x, y, radius, Magenta); 00072 // canvas.WritePPM(); 00073 00074 // // update circle's center: (x, y) 00075 // x += step_x, y += step_y; 00076 // if(x + radius >= canvas.hReso/2) // move out of right boundary 00077 // { 00078 // x = canvas.hReso / 2 - 1 - 2 * (x+radius - canvas.hReso/2) - radius; // bounce back 00079 // step_x = - step_x; // will move left 00080 // } 00081 // else if(x - radius < -canvas.hReso/2) // move out of left boundary 00082 // { 00083 // x = -canvas.hReso/2 + 2 * (-canvas.hReso/2 - (x - radius)) + radius; // bounce back 00084 // step_x = - step_x; // will move right 00085 // } 00086 00087 // if(y + radius >= canvas.vReso/2) // move out of upper boundary 00088 // { 00089 // y = canvas.vReso / 2 -1 - 2 * (y+radius - canvas.vReso/2) - radius; // bounce back 00090 // step_y = - step_y; // will move down 00091 // } 00092 // else if(y - radius < -canvas.vReso/2) // move out of bottom boundary 00093 // { 00094 // y = -canvas.vReso/2 + 2 * (-canvas.vReso/2 - (y - radius)) + radius; // bounce back 00095 // step_y = - step_y; // will move up. 00096 // } 00097 // } 00098 00099 00100 // canvas.SolidRectangle(0,0, 200, 200, Red); 00101 // canvas.SolidTriangle(0, 200, White, 200, 200, White, 100, 250, White); 00102 00103 // canvas.SolidTriangle(-50, 100, White, -200, 100, White, -125, 200, White); 00104 // canvas.SolidTriangle(-250, 250, White, -200, 100, White, -125, 200, White); 00105 00106 // // p = 2a sin(theta) 00107 // int x1, y1; 00108 00109 // for(int theta = 0; theta <= 360; theta += 5) 00110 // { 00111 // double ang = theta * pi / 180; 00112 // double rho = 200 * sin(2 * ang); 00113 // int x2 = columbia::round(rho * cos(ang)), y2 = columbia::round(rho * sin(ang)); 00114 // if(theta != 0) 00115 // canvas.ScanLineSegment(x1, y1, White, x2, y2, White); 00116 // x1 = x2, y1 = y2; 00117 // } 00118 00119 00120 // canvas.SolidTriangle(-150, 250, Yellow, -100, 100, Yellow, -125, 200, Yellow); 00121 00122 00123 00124 00125 // canvas.Clear(White); 00126 00127 // canvas.filename = "scanline.ppm"; 00128 00129 // { 00130 // Canvas canvas1616(16,16); 00131 // multimap<int,int> pixels; 00132 // canvas1616.ScanLineSegment(0, 0,White, 16, 16,White, &pixels); 00133 00134 // // show thesse pixeles 00135 // for (multimap<int, int>::iterator it = pixels.begin(); it != pixels.end(); ++it) 00136 // { 00137 // draw_pixel(canvas, it->second, it->first, 16, Red); 00138 // } 00139 // } 00140 00141 00142 // { 00143 // Canvas canvas1616(16,16); 00144 // multimap<int,int> pixels; 00145 // canvas1616.ScanLineSegment(0, 0, White, 6, 12,White, &pixels); 00146 00147 // // show thesse pixeles 00148 // for (multimap<int, int>::iterator it = pixels.begin(); it != pixels.end(); ++it) 00149 // { 00150 // draw_pixel(canvas, it->second, it->first, 16, Blue); 00151 // } 00152 // } 00153 00154 00155 // { 00156 // Canvas canvas1616(16,16); 00157 // multimap<int,int> pixels; 00158 // canvas1616.ScanLineSegment(0, 0, White, 12, 6,White, &pixels); 00159 00160 // // show thesse pixeles 00161 // for (multimap<int, int>::iterator it = pixels.begin(); it != pixels.end(); ++it) 00162 // { 00163 // draw_pixel(canvas, it->second, it->first, 16, Green); 00164 // } 00165 // } 00166 00167 // { 00168 // Canvas canvas1616(16,16); 00169 // multimap<int,int> pixels; 00170 // canvas1616.ScanLineSegment(0, 0, White, 12, -6,White, &pixels); 00171 00172 // // show thesse pixeles 00173 // for (multimap<int, int>::iterator it = pixels.begin(); it != pixels.end(); ++it) 00174 // { 00175 // draw_pixel(canvas, it->second, it->first, 16, Green); 00176 // } 00177 // } 00178 00179 // canvas.ScanLineSegment(0,0,Red, 12*16, -6*16, Red); 00180 // canvas.ScanLineSegment(0,0,Red, 12*16, 6*16, Red); 00181 // canvas.ScanLineSegment(0,0,Red, 6*16, 12*16, Red); 00182 // canvas.ScanLineSegment(0,0,Red, 16*16, 16*16, Green); 00183 00184 // for(int y = - 256; y <= 256; y += 16) 00185 // { 00186 // canvas.ScanLineSegment( - 256, y, Black, 256, y, Black); 00187 // } 00188 // for(int x = -256; x <= 256; x += 16) 00189 // { 00190 // canvas.ScanLineSegment(x, -256, Black, x, 256, Black); 00191 // } 00192 00193 // canvas.SolidCircle(-16*16, -16*16, 5, Black); 00194 // canvas.SolidCircle(16*16, 16*16, 5, Black); 00195 // canvas.SolidCircle(12*16, 6*16, 5, Black); 00196 // canvas.SolidCircle(12*16, -6*16, 5, Black); 00197 // canvas.SolidCircle(6*16, 12*16, 5, Black); 00198 // canvas.SolidCircle(0, 0, 5, Black); 00199
1.3.6