00001 // This is core/vgui/vrml/vgui_vrml_tableau.cxx 00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE 00003 #pragma implementation 00004 #endif 00005 //: 00006 // \file 00007 // \author Philip C. Pritchett, RRG, University of Oxford 00008 // \date 17 Sep 1999 00009 //----------------------------------------------------------------------------- 00010 00011 #include "vgui_vrml_tableau.h" 00012 00013 #include <Qv/QvVrmlFile.h> 00014 #include <Qv/QvVisitor.h> 00015 00016 #include <vcl_iostream.h> 00017 00018 #include <vul/vul_file.h> 00019 00020 #include <vgui/vgui_gl.h> 00021 #include <vgui/vgui_glu.h> 00022 #include <vgui/vgui_event.h> 00023 00024 #include "vgui_vrml_texture_map.h" 00025 #include "vgui_vrml_draw_visitor.h" 00026 00027 00028 vgui_vrml_tableau::vgui_vrml_tableau(const char* filename, bool scale) 00029 : rescale_model( true) 00030 { 00031 vrml = new QvVrmlFile(filename); 00032 drawer = new vgui_vrml_draw_visitor; 00033 vgui_vrml_texture_map::vrml_dirname = vul_file::dirname(vrml->get_filename()); 00034 00035 00036 if (scale) vrml->compute_centroid_radius(); 00037 00038 setup_dl = GL_INVALID_VALUE; 00039 } 00040 00041 00042 vgui_vrml_tableau::~vgui_vrml_tableau() 00043 { 00044 delete vrml; 00045 delete drawer; 00046 } 00047 00048 void vgui_vrml_tableau::invalidate_vrml() 00049 { 00050 setup_dl = GL_INVALID_VALUE; 00051 post_redraw(); 00052 } 00053 00054 vcl_string vgui_vrml_tableau::type_name() const 00055 { 00056 return "vgui_vrml_tableau"; 00057 } 00058 00059 vcl_string vgui_vrml_tableau::pretty_name() const 00060 { 00061 vcl_string fn = vrml?(vrml->get_filename()):"null"; 00062 return type_name() + "[" + fn + "]"; 00063 } 00064 00065 vcl_string vgui_vrml_tableau::file_name() const 00066 { 00067 if (vrml) 00068 return vrml->get_filename(); 00069 00070 return type_name(); 00071 } 00072 00073 00074 bool vgui_vrml_tableau::handle(const vgui_event &e) 00075 { 00076 #ifdef DEBUG 00077 vcl_cerr << "vgui_vrml_tableau::draw\n"; 00078 #endif 00079 00080 if (!glIsEnabled(GL_LIGHTING)) 00081 glColor3f(1,1,1); 00082 00083 int mode = 1; 00084 if (mode == 0 /*e.user == &vgui_3D::wireframe*/) 00085 { 00086 #ifdef DEBUG 00087 vcl_cerr << "vgui_vrml_tableau wireframe\n"; 00088 #endif 00089 if (drawer->get_gl_mode() != vgui_vrml_draw_visitor::wireframe) 00090 { 00091 drawer->set_gl_mode(vgui_vrml_draw_visitor::wireframe); 00092 setup_dl = GL_INVALID_VALUE; 00093 } 00094 } 00095 else if (mode == 1 /*e.user == &vgui_3D::textured*/) 00096 { 00097 #ifdef DEBUG 00098 vcl_cerr << "vgui_vrml_tableau textured\n"; 00099 #endif 00100 if (drawer->get_gl_mode() != vgui_vrml_draw_visitor::textured) 00101 { 00102 drawer->set_gl_mode(vgui_vrml_draw_visitor::textured); 00103 setup_dl = GL_INVALID_VALUE; 00104 } 00105 } 00106 00107 00108 if (e.type != vgui_DRAW) 00109 return false; 00110 00111 // 00112 float scale = 10.0f / vrml->radius; 00113 00114 if ( rescale_model) 00115 { 00116 glScalef(scale, scale, scale); 00117 glTranslatef(-vrml->centroid[0], -vrml->centroid[1], -vrml->centroid[2]); 00118 } 00119 00120 //extern void projective_skew(float*); 00121 //projective_skew(token.trans); 00122 00123 if (setup_dl == GL_INVALID_VALUE) 00124 { 00125 #ifdef DEBUG 00126 vcl_cerr << "vgui_vrml_tableau generating display list\n"; 00127 #endif 00128 00129 setup_dl = glGenLists(1); 00130 glNewList(setup_dl, GL_COMPILE_AND_EXECUTE); 00131 00132 vrml->traverse(drawer); 00133 00134 glEndList(); 00135 } 00136 else 00137 { 00138 #ifdef DEBUG 00139 vcl_cerr << "vgui_vrml_tableau using display list\n"; 00140 #endif 00141 glCallList(setup_dl); 00142 } 00143 00144 return true; 00145 }