00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 #ifndef INVT_HAVE_LIBGLUT
00049
00050 #include "Robots/LoBot/ui/LoDrawable.H"
00051 #include "Robots/LoBot/misc/LoExcept.H"
00052
00053 namespace lobot {
00054
00055 Drawable::Drawable()
00056 {
00057 throw missing_libs(MISSING_OPENGL) ;
00058 }
00059
00060
00061 void Drawable::gl_init(){}
00062 void Drawable::add_hook(const Drawable::RenderHook&){}
00063 void Drawable::render(){}
00064 void Drawable::render_me(){}
00065 void Drawable::zoom_by(float){}
00066 void Drawable::pan(int, int, int, int){}
00067 void Drawable::reset_zoom_pan(){}
00068 void Drawable::keypress(unsigned char){}
00069 void Drawable::unit_view_volume() const {}
00070 void Drawable::text_view_volume() const {}
00071 void Drawable::restore_view_volume() const {}
00072
00073 void Drawable::gl_cleanup(){}
00074 Drawable::~Drawable(){}
00075
00076 }
00077
00078 #else // pthreads, OpenGL and GLUT available ==> the real McCoy
00079
00080
00081
00082
00083 #include "Robots/LoBot/ui/LoDrawable.H"
00084 #include "Robots/LoBot/config/LoConfigHelpers.H"
00085 #include "Robots/LoBot/misc/LoExcept.H"
00086 #include "Robots/LoBot/util/LoString.H"
00087
00088
00089 #include <GL/glu.h>
00090 #include <GL/gl.h>
00091
00092
00093 #include <vector>
00094
00095
00096
00097 namespace lobot {
00098
00099
00100
00101 Drawable::Drawable(const std::string& name, const Geometry& g)
00102 : m_name(name), m_geometry(g),
00103 m_border(true), m_border_color(1.0f, 1.0f, 0.0f)
00104 {}
00105
00106 Drawable::Geometry::Geometry(int xx, int yy, int w, int h)
00107 : x(xx), y(yy), width(w), height(h)
00108 {}
00109
00110 Drawable::Geometry::Geometry(const std::string& geometry)
00111 {
00112 std::vector<int> g = string_to_vector<int>(geometry) ;
00113 if (g.size() < 4)
00114 throw customization_error(BAD_GEOMETRY_SPEC) ;
00115
00116 x = g[0] ;
00117 y = g[1] ;
00118 width = g[2] ;
00119 height = g[3] ;
00120 }
00121
00122 void Drawable::gl_init(){}
00123
00124 void Drawable::add_hook(const Drawable::RenderHook& h)
00125 {
00126 AutoMutex M(m_hooks_mutex) ;
00127 m_hooks.push_back(h) ;
00128 }
00129
00130
00131
00132 void Drawable::render()
00133 {
00134 render_me() ;
00135
00136
00137 AutoMutex M(m_hooks_mutex) ;
00138 std::for_each(m_hooks.begin(), m_hooks.end(), trigger_hook) ;
00139 }
00140
00141 void Drawable::trigger_hook(const Drawable::RenderHook& h)
00142 {
00143 h.first(h.second) ;
00144 }
00145
00146
00147
00148 void Drawable::render_me(){}
00149 void Drawable::zoom_by(float){}
00150 void Drawable::pan(int, int, int, int){}
00151 void Drawable::reset_zoom_pan(){}
00152 void Drawable::keypress(unsigned char){}
00153
00154
00155
00156
00157
00158 void Drawable::unit_view_volume() const
00159 {
00160 glMatrixMode(GL_PROJECTION) ;
00161 glPushMatrix() ;
00162 glLoadIdentity() ;
00163 gluOrtho2D(-1, 1, -1, 1) ;
00164
00165 glMatrixMode(GL_MODELVIEW) ;
00166 glPushMatrix() ;
00167 glLoadIdentity() ;
00168 glRotatef(get_conf("laser_viz", "lrf_direction", 90.0f), 0, 0, 1) ;
00169 }
00170
00171
00172
00173 void Drawable::text_view_volume() const
00174 {
00175 glMatrixMode(GL_PROJECTION) ;
00176 glPushMatrix() ;
00177 glLoadIdentity() ;
00178 gluOrtho2D(0, m_geometry.width, 0, m_geometry.height) ;
00179
00180 glMatrixMode(GL_MODELVIEW) ;
00181 glPushMatrix() ;
00182 glLoadIdentity() ;
00183 glRotatef(180, 0, 0, 1) ;
00184 glRotatef(180, 0, 1, 0) ;
00185 glTranslatef(0, -m_geometry.height, 0) ;
00186 }
00187
00188
00189 void Drawable::setup_view_volume(float L, float R, float B, float T) const
00190 {
00191 glMatrixMode(GL_PROJECTION) ;
00192 glPushMatrix() ;
00193 glLoadIdentity() ;
00194 gluOrtho2D(L, R, B, T) ;
00195
00196 glMatrixMode(GL_MODELVIEW) ;
00197 glPushMatrix() ;
00198 glLoadIdentity() ;
00199 }
00200
00201
00202 void Drawable::restore_view_volume() const
00203 {
00204 glMatrixMode(GL_PROJECTION) ;
00205 glPopMatrix() ;
00206
00207 glMatrixMode(GL_MODELVIEW) ;
00208 glPopMatrix() ;
00209 }
00210
00211
00212
00213 void Drawable::gl_cleanup(){}
00214 Drawable::~Drawable(){}
00215
00216
00217
00218 }
00219
00220 #endif // #if !defined(INVT_HAVE_LIBPTHREAD) || !defined(INVT_HAVE_LIBGLUT)
00221
00222
00223
00224
00225