Triangle.h

Go to the documentation of this file.
00001 #ifndef TRIANGLE_H
00002 #define TRIANGLE_H
00003 
00011 #ifndef NDEBUG
00012 # ifndef BUILDING_DOX
00013 #   include <iostream>
00014 # endif
00015 #endif
00016 
00020 struct Vertex {
00021     float x;  
00022     float y;  
00023     float z;  
00024     
00028     Vertex() {}
00029     
00035     Vertex(float ix, float iy, float iz):
00036         x(ix),
00037         y(iy),
00038         z(iz)
00039         {}
00040 
00044     Vertex(float coords[3]):
00045         x(coords[0]),
00046         y(coords[1]),
00047         z(coords[2])
00048         {}
00049 };
00050 
00051 #ifndef NDEBUG
00052 
00059 inline std::ostream& operator<< (std::ostream &out, const Vertex &vertex) {
00060   out << "(" <<
00061       vertex.x << ", " <<
00062       vertex.y << ", " <<
00063       vertex.z << ")";
00064   return out;
00065 }
00066 #endif
00067 
00072 struct Color {
00073     float r;  
00074     float g;  
00075     float b;  
00076 
00082     Color(float cr, float cg, float cb):
00083       r(cr),
00084       g(cg),
00085       b(cb)
00086       {}
00087 
00091     Color( float rgb[] ):
00092       r(rgb[0]),
00093       g(rgb[1]),
00094       b(rgb[2])
00095       {}
00096     
00100     Color():
00101         r(0.0),
00102         g(0.0),
00103         b(0.0)
00104         {}
00105 };
00106 
00114 inline Color& operator+= (Color &dest, const Color &src) {
00115   dest.r += src.r;
00116   dest.g += src.g;
00117   dest.b += src.b;
00118   return dest;
00119 }
00120 
00128 inline Color& operator*= (Color &dest, const Color &src) {
00129   dest.r *= src.r;
00130   dest.g *= src.g;
00131   dest.b *= src.b;
00132   return dest;
00133 }
00134 
00142 inline Color& operator*= (Color &c, float ratio) {
00143   c.r *= ratio;
00144   c.g *= ratio;
00145   c.b *= ratio;
00146   return c;
00147 }
00148 
00156 inline Color operator* (Color c, float ratio) {
00157   c *= ratio;
00158   return c;
00159 }
00160 
00168 inline bool operator== (const Color &a, const Color &b) {
00169   return
00170       a.r == b.r &&
00171       a.g == b.g &&
00172       a.b == b.b;
00173 }
00174 
00175 #ifndef NDEBUG
00176 
00183 inline std::ostream& operator<< (std::ostream &out, const Color &color) {
00184   out << "RGB(" <<
00185       color.r << ", " <<
00186       color.g << ", " <<
00187       color.b << ")";
00188   return out;
00189 }
00190 #endif
00191 
00196 struct Triangle
00197 {
00198     Vertex vertex[3];     
00199     Color emission;       
00200     Color reflectivity;   
00201     Color radiosity;      
00202     Color radiosityLast;  
00203 
00208     static Vertex centerOf(const Triangle &t)
00209     {
00210       float x = (t.vertex[0].x+t.vertex[1].x+t.vertex[2].x)/3.0f;
00211       float y = (t.vertex[0].y+t.vertex[1].y+t.vertex[2].y)/3.0f;
00212       float z = (t.vertex[0].z+t.vertex[1].z+t.vertex[2].z)/3.0f;
00213       return(Vertex(x,y,z));
00214     }
00215 };
00216 
00217 #ifndef NDEBUG
00218 
00225 inline std::ostream& operator<< (std::ostream &out, const Triangle &t) {
00226   out << "Triangle:" << std::endl << "  " <<
00227       t.vertex[0] << " " << std::endl << "  " <<
00228       t.vertex[1] << " " << std::endl << "  " <<
00229       t.vertex[2] << " " << std::endl << "  " <<
00230       "    Emission: " << t.emission << std::endl << "  " <<
00231       "Reflectivity: " << t.reflectivity << std::endl << "  " <<
00232       "   Radiosity: " << t.radiosity << std::endl <<
00233       std::endl;
00234   return out;
00235 }
00236 #endif
00237 
00238 #endif // TRIANGLE_H

Generated on Thu Dec 6 19:33:11 2007 for Radiosity Renderer and Visualizer by  doxygen 1.5.2