00001 #ifndef GTEX_UTIL_H_IS_INCLUDED
00002 #define GTEX_UTIL_H_IS_INCLUDED
00003
00004 #include "geom/gl_view.H"
00005 #include "geom/world.H"
00006 #include "geom/show_tris.H"
00007 #include "mesh/edge_strip.H"
00008 #include "mesh/stripcb.H"
00009 #include "mesh/lmesh.H"
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 namespace TexUnit {
00020 enum tex_stage_t { APP=0, PAPER, PERLIN, REF_IMG };
00021 };
00022
00023 class TriStrip;
00024
00025
00026
00027
00028
00029
00030 class GLStripCB : public StripCB {
00031 public:
00032
00033
00034 virtual void begin_faces(TriStrip*) { glBegin(GL_TRIANGLE_STRIP); }
00035 virtual void end_faces (TriStrip*) { glEnd(); }
00036
00037 virtual void begin_edges(EdgeStrip*) { glBegin(GL_LINE_STRIP); }
00038 virtual void end_edges (EdgeStrip*) { glEnd(); }
00039
00040 virtual void begin_verts(VertStrip*) { glBegin(GL_POINTS); }
00041 virtual void end_verts (VertStrip*) { glEnd(); }
00042
00043
00044
00045
00046 virtual void faceCB(CBvert* v, CBface*) { glVertex3dv(v->loc().data()); }
00047 virtual void edgeCB(CBvert* v, CBedge*) { glVertex3dv(v->loc().data()); }
00048 virtual void vertCB(CBvert* v) { glVertex3dv(v->loc().data()); }
00049 };
00050
00051
00052
00053
00054
00055
00056
00057
00058 class VertNormStripCB : public GLStripCB {
00059 public:
00060 virtual void faceCB(CBvert* v, CBface* f) {
00061 glNormal3dv(f->vert_normal(v).data());
00062 glVertex3dv(v->loc().data());
00063 }
00064 };
00065
00066
00067
00068
00069 namespace GtexUtil {
00070
00071 inline str_ptr toon_path() {
00072 return Config::JOT_ROOT() + "nprdata/toon_textures/";
00073 }
00074 inline str_ptr toon_name(Cstr_ptr& name) { return toon_path() + name; }
00075
00076
00077 inline void
00078 setup_material(APPEAR* a)
00079 {
00080
00081 assert(a);
00082 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT,
00083 float4(a->ambient_color(),a->transp()));
00084 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE,
00085 float4(a->color(),a->transp()));
00086 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR,
00087 float4(a->specular_color(),a->transp()));
00088 glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, (GLfloat)a->shininess());
00089 }
00090
00091
00092 inline void
00093 draw_strip(
00094 EdgeStrip& strip,
00095 double width,
00096 CCOLOR& color,
00097 double alpha=1,
00098 StripCB* cb=0
00099 )
00100 {
00101 VIEWptr v = VIEW::peek();
00102 GL_VIEW::init_line_smooth(GLfloat(v->line_scale()*width), GL_CURRENT_BIT);
00103
00104 glDisable(GL_LIGHTING);
00105 GL_COL(color, alpha);
00106
00107 GLStripCB glcb;
00108 strip.draw(cb ? cb : &glcb);
00109
00110 GL_VIEW::end_line_smooth();
00111 }
00112 inline void draw_strip(EdgeStrip& strip, double width=1, StripCB* cb=0) {
00113 return draw_strip(strip, width, Color::black, 1, cb);
00114 }
00115
00116
00117 inline SHOW_TRIS::Triangle tri(Bface* f) {
00118 return f ?
00119 SHOW_TRIS::Triangle(f->v1()->wloc(),f->v2()->wloc(),f->v3()->wloc()) :
00120 SHOW_TRIS::Triangle();
00121 }
00122
00123 inline GELptr show_tris(CBface_list& faces, CCOLOR& col=Color::yellow) {
00124 SHOW_TRISptr tris = new SHOW_TRIS();
00125 for (int i=0; i<faces.num(); i++) {
00126 tris->add(tri(faces[i]));
00127 }
00128 tris->set_fill_color(col);
00129 WORLD::create(tris,false);
00130 return tris;
00131 }
00132
00133
00134 inline GELptr show(
00135 Bedge* e,
00136 double width=2,
00137 CCOLOR& col=Color::blue,
00138 double alpha=1,
00139 bool depth_test=true
00140 ) {
00141 if (!e) return 0;
00142 return WORLD::show(
00143 e->v1()->wloc(), e->v2()->wloc(), width, col, alpha, depth_test
00144 );
00145 }
00146
00147
00148 inline GELlist show(
00149 CBedge_list& edges,
00150 double width=2,
00151 CCOLOR& col=Color::blue,
00152 double alpha=1,
00153 bool depth_test=true
00154 ) {
00155 GELlist ret(edges.num());
00156 for (int i=0; i<edges.num(); i++)
00157 ret += show(edges[i], width, col, alpha, depth_test);
00158 return ret;
00159 }
00160 };
00161
00162 #endif // GTEX_UTIL_H_IS_INCLUDED
00163
00164