Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 553 lines (412 sloc) 12.235 kb
e65967f powerpacks now set charging flag correctly
rtv authored
1 #include "stage.hh"
2 #include "worldfile.hh"
3 #include "canvas.hh"
4 #include "texture_manager.hh"
5 using namespace Stg;
6
7 // speech bubble colors
4ccc5cd replaced stg_color_t with Color class and added static named constructor...
rtv authored
8 static const Color BUBBLE_FILL( 1.0, 0.8, 0.8 );// light blue/grey
9 static const Color BUBBLE_BORDER( 0,0,0 ); // black
10 static const Color BUBBLE_TEXT( 0,0,0 ); // black
e65967f powerpacks now set charging flag correctly
rtv authored
11
12 void Model::DrawSelected()
13 {
14 glPushMatrix();
15
16 glTranslatef( pose.x, pose.y, pose.z+0.01 ); // tiny Z offset raises rect above grid
17
18 Pose gpose = GetGlobalPose();
19
20 char buf[64];
21 snprintf( buf, 63, "%s [%.2f %.2f %.2f %.2f]",
22 token, gpose.x, gpose.y, gpose.z, rtod(gpose.a) );
23
24 PushColor( 0,0,0,1 ); // text color black
25 Gl::draw_string( 0.5,0.5,0.5, buf );
26
27 glRotatef( rtod(pose.a), 0,0,1 );
28
29 Gl::pose_shift( geom.pose );
30
31 double dx = geom.size.x / 2.0 * 1.6;
32 double dy = geom.size.y / 2.0 * 1.6;
33
34 PopColor();
35
36 PushColor( 0,1,0,0.4 ); // highlight color blue
37 glRectf( -dx, -dy, dx, dy );
38 PopColor();
39
40 PushColor( 0,1,0,0.8 ); // highlight color blue
41 glLineWidth( 1 );
42 glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
43 glRectf( -dx, -dy, dx, dy );
44 glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
45 PopColor();
46
47 glPopMatrix();
48 }
49
50
51 void Model::DrawTrailFootprint()
52 {
de00f25 more STLing, and viz fixes
rtv authored
53 double darkness = 0;
54 double fade = 0.5 / (double)(trail_length+1);
910541e removed glib2 dependency (after many years of good service. Thanks GLib....
rtv authored
55
56 PushColor( 0,0,0,1 ); // dummy pushL just saving the color
57
de00f25 more STLing, and viz fixes
rtv authored
58 FOR_EACH( it, trail )
910541e removed glib2 dependency (after many years of good service. Thanks GLib....
rtv authored
59 {
60 TrailItem& checkpoint = *it;
61
62 glPushMatrix();
63 Pose pz = checkpoint.pose;
64
65 Gl::pose_shift( pz );
66 Gl::pose_shift( geom.pose );
67
68 darkness += fade;
69 Color c = checkpoint.color;
70 c.a = darkness;
71 glColor4f( c.r, c.g, c.b, c.a );
72
73 blockgroup.DrawFootPrint( geom );
74
75 glPopMatrix();
e65967f powerpacks now set charging flag correctly
rtv authored
76 }
910541e removed glib2 dependency (after many years of good service. Thanks GLib....
rtv authored
77
78 PopColor();
e65967f powerpacks now set charging flag correctly
rtv authored
79 }
80
81 void Model::DrawTrailBlocks()
82 {
83 double timescale = 0.0000001;
84
de00f25 more STLing, and viz fixes
rtv authored
85 FOR_EACH( it, trail )
910541e removed glib2 dependency (after many years of good service. Thanks GLib....
rtv authored
86 {
87 TrailItem& checkpoint = *it;
88
89 glPushMatrix();
90 Pose pz = checkpoint.pose;
91 pz.z = (world->sim_time - checkpoint.time) * timescale;
92
93 Gl::pose_shift( pz );
94 Gl::pose_shift( geom.pose );
95
96 DrawBlocks();
97
98 glPopMatrix();
e65967f powerpacks now set charging flag correctly
rtv authored
99 }
100 }
101
102 void Model::DrawTrailArrows()
103 {
104 double dx = 0.2;
105 double dy = 0.07;
910541e removed glib2 dependency (after many years of good service. Thanks GLib....
rtv authored
106 double timescale = 1e-7;
107
108 PushColor( 0,0,0,1 ); // dummy push
e65967f powerpacks now set charging flag correctly
rtv authored
109
910541e removed glib2 dependency (after many years of good service. Thanks GLib....
rtv authored
110 FOR_EACH( it, trail )
111 {
112 TrailItem& checkpoint = *it;
113
114 glPushMatrix();
115 Pose pz = checkpoint.pose;
116 // set the height proportional to age
117 pz.z = (world->sim_time - checkpoint.time) * timescale;
118
119 Gl::pose_shift( pz );
120 Gl::pose_shift( geom.pose );
121
122 Color& c = checkpoint.color;
123 glColor4f( c.r, c.g, c.b, c.a );
124
125 glBegin( GL_TRIANGLES );
126 glVertex3f( 0, -dy, 0);
127 glVertex3f( dx, 0, 0 );
128 glVertex3f( 0, +dy, 0 );
129 glEnd();
130
131 glPopMatrix();
132 }
133
134 PopColor();
e65967f powerpacks now set charging flag correctly
rtv authored
135 }
136
137 void Model::DrawOriginTree()
138 {
139 DrawPose( GetGlobalPose() );
5dee8f1 more STL-ization. may reduce performance slightly in worlds with few mod...
rtv authored
140
141 FOR_EACH( it, children )
142 (*it)->DrawOriginTree();
e65967f powerpacks now set charging flag correctly
rtv authored
143 }
144
145
146 void Model::DrawBlocksTree( )
147 {
148 PushLocalCoords();
5dee8f1 more STL-ization. may reduce performance slightly in worlds with few mod...
rtv authored
149
150 FOR_EACH( it, children )
151 (*it)->DrawBlocksTree();
152
e65967f powerpacks now set charging flag correctly
rtv authored
153 DrawBlocks();
154 PopCoords();
155 }
156
157 void Model::DrawPose( Pose pose )
158 {
159 PushColor( 0,0,0,1 );
160 glPointSize( 4 );
161
162 glBegin( GL_POINTS );
163 glVertex3f( pose.x, pose.y, pose.z );
164 glEnd();
165
166 PopColor();
167 }
168
169 void Model::DrawBlocks( )
170 {
171 blockgroup.CallDisplayList( this );
172 }
173
174 void Model::DrawBoundingBoxTree()
175 {
176 PushLocalCoords();
5dee8f1 more STL-ization. may reduce performance slightly in worlds with few mod...
rtv authored
177
178 FOR_EACH( it, children )
179 (*it)->DrawBoundingBoxTree();
180
e65967f powerpacks now set charging flag correctly
rtv authored
181 DrawBoundingBox();
182 PopCoords();
183 }
184
185 void Model::DrawBoundingBox()
186 {
187 Gl::pose_shift( geom.pose );
188
189 PushColor( color );
190
191 glBegin( GL_QUAD_STRIP );
192
193 glVertex3f( -geom.size.x/2.0, -geom.size.y/2.0, geom.size.z );
194 glVertex3f( -geom.size.x/2.0, -geom.size.y/2.0, 0 );
195
196 glVertex3f( +geom.size.x/2.0, -geom.size.y/2.0, geom.size.z );
197 glVertex3f( +geom.size.x/2.0, -geom.size.y/2.0, 0 );
198
199 glVertex3f( +geom.size.x/2.0, +geom.size.y/2.0, geom.size.z );
200 glVertex3f( +geom.size.x/2.0, +geom.size.y/2.0, 0 );
201
202 glVertex3f( +geom.size.x/2.0, +geom.size.y/2.0, geom.size.z );
203 glVertex3f( +geom.size.x/2.0, +geom.size.y/2.0, 0 );
204
205 glVertex3f( -geom.size.x/2.0, +geom.size.y/2.0, geom.size.z );
206 glVertex3f( -geom.size.x/2.0, +geom.size.y/2.0, 0 );
207
208 glVertex3f( -geom.size.x/2.0, -geom.size.y/2.0, geom.size.z );
209 glVertex3f( -geom.size.x/2.0, -geom.size.y/2.0, 0 );
210
211 glEnd();
212
213 glBegin( GL_LINES );
214 glVertex2f( -0.02, 0 );
215 glVertex2f( +0.02, 0 );
216
217 glVertex2f( 0, -0.02 );
218 glVertex2f( 0, +0.02 );
219 glEnd();
220
221 PopColor();
222 }
223
224 // move into this model's local coordinate frame
225 void Model::PushLocalCoords()
226 {
227 glPushMatrix();
228
229 if( parent )
230 glTranslatef( 0,0, parent->geom.size.z );
231
232 Gl::pose_shift( pose );
233 }
234
235 void Model::PopCoords()
236 {
237 glPopMatrix();
238 }
239
a9b91ec more STLing
rtv authored
240 void Model::AddVisualizer( Visualizer* cv, bool on_by_default )
e65967f powerpacks now set charging flag correctly
rtv authored
241 {
a9b91ec more STLing
rtv authored
242 if( !cv )
64382ca cleaned up cmdline args
rtv authored
243 return;
244
245 // If there's no GUI, ignore this request
246 if( ! world_gui )
247 return;
5e9262a reworked CustomVisualizer => Visualizer - tweaked API. See ModelLaser fo...
rtv authored
248
e65967f powerpacks now set charging flag correctly
rtv authored
249 //save visual instance
a9b91ec more STLing
rtv authored
250 //cv_list = g_list_append(cv_list, cv );
251 cv_list.push_back( cv );
e65967f powerpacks now set charging flag correctly
rtv authored
252
253 //register option for all instances which share the same name
254 Canvas* canvas = world_gui->GetCanvas();
a9b91ec more STLing
rtv authored
255 std::map< std::string, Option* >::iterator i = canvas->_custom_options.find( cv->GetMenuName() );
e65967f powerpacks now set charging flag correctly
rtv authored
256 if( i == canvas->_custom_options.end() ) {
a9b91ec more STLing
rtv authored
257 Option* op = new Option( cv->GetMenuName(),
258 cv->GetWorldfileName(),
5e9262a reworked CustomVisualizer => Visualizer - tweaked API. See ModelLaser fo...
rtv authored
259 "",
427aa67 working on power models
rtv authored
260 on_by_default,
5e9262a reworked CustomVisualizer => Visualizer - tweaked API. See ModelLaser fo...
rtv authored
261 world_gui );
a9b91ec more STLing
rtv authored
262 canvas->_custom_options[ cv->GetMenuName() ] = op;
4cba3e6 cleaned up vis options and dialog
rtv authored
263 RegisterOption( op );
e65967f powerpacks now set charging flag correctly
rtv authored
264 }
265 }
266
a9b91ec more STLing
rtv authored
267 void Model::RemoveVisualizer( Visualizer* cv )
e65967f powerpacks now set charging flag correctly
rtv authored
268 {
a9b91ec more STLing
rtv authored
269 if( cv )
270 cv_list.erase( remove( cv_list.begin(), cv_list.end(), cv ));
271
e65967f powerpacks now set charging flag correctly
rtv authored
272
273 //TODO unregister option - tricky because there might still be instances attached to different models which have the same name
274 }
275
276
277 void Model::DrawStatusTree( Camera* cam )
278 {
279 PushLocalCoords();
280 DrawStatus( cam );
5dee8f1 more STL-ization. may reduce performance slightly in worlds with few mod...
rtv authored
281 FOR_EACH( it, children )
282 (*it)->DrawStatusTree( cam );
e65967f powerpacks now set charging flag correctly
rtv authored
283 PopCoords();
284 }
285
286 void Model::DrawStatus( Camera* cam )
287 {
288 // quick hack
289 // if( power_pack && power_pack->stored < 0.0 )
290 // {
291 // glPushMatrix();
292 // glTranslatef( 0.3, 0, 0.0 );
293 // DrawImage( TextureManager::getInstance()._mains_texture_id, cam, 0.85 );
294 // glPopMatrix();
295 // }
296
297 if( say_string || power_pack )
298 {
299 float yaw, pitch;
300 pitch = - cam->pitch();
301 yaw = - cam->yaw();
302
303 Pose gpz = GetGlobalPose();
304
305 float robotAngle = -rtod(gpz.a);
306 glPushMatrix();
203687c working on energy monitoring
rtv authored
307
e65967f powerpacks now set charging flag correctly
rtv authored
308 // move above the robot
309 glTranslatef( 0, 0, 0.5 );
310
311 // rotate to face screen
312 glRotatef( robotAngle - yaw, 0,0,1 );
313 glRotatef( -pitch, 1,0,0 );
314
2db3b91 fixed crash bug when a saystring was present without a powerpack
rtv authored
315 if( power_pack )
e65967f powerpacks now set charging flag correctly
rtv authored
316 power_pack->Visualize( cam );
317
318 if( say_string )
319 {
aadcd1b vis stuff
rtv authored
320 glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
321
e65967f powerpacks now set charging flag correctly
rtv authored
322 //get raster positition, add gl_width, then project back to world coords
323 glRasterPos3f( 0, 0, 0 );
324 GLfloat pos[ 4 ];
325 glGetFloatv(GL_CURRENT_RASTER_POSITION, pos);
326
327 GLboolean valid;
328 glGetBooleanv( GL_CURRENT_RASTER_POSITION_VALID, &valid );
329
330 if( valid )
2db3b91 fixed crash bug when a saystring was present without a powerpack
rtv authored
331 {
aadcd1b vis stuff
rtv authored
332 //fl_font( FL_HELVETICA, 12 );
e65967f powerpacks now set charging flag correctly
rtv authored
333 float w = gl_width( this->say_string ); // scaled text width
334 float h = gl_height(); // scaled text height
335
336 GLdouble wx, wy, wz;
337 GLint viewport[4];
338 glGetIntegerv(GL_VIEWPORT, viewport);
339
340 GLdouble modelview[16];
341 glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
342
343 GLdouble projection[16];
344 glGetDoublev(GL_PROJECTION_MATRIX, projection);
345
346 //get width and height in world coords
347 gluUnProject( pos[0] + w, pos[1], pos[2], modelview, projection, viewport, &wx, &wy, &wz );
348 w = wx;
349 gluUnProject( pos[0], pos[1] + h, pos[2], modelview, projection, viewport, &wx, &wy, &wz );
350 h = wy;
351
352 // calculate speech bubble margin
353 const float m = h/10;
354
355 // draw inside of bubble
356 PushColor( BUBBLE_FILL );
357 glPushAttrib( GL_POLYGON_BIT | GL_LINE_BIT );
358 glPolygonMode( GL_FRONT, GL_FILL );
359 glEnable( GL_POLYGON_OFFSET_FILL );
360 glPolygonOffset( 1.0, 1.0 );
361 Gl::draw_octagon( w, h, m );
362 glDisable( GL_POLYGON_OFFSET_FILL );
363 PopColor();
364
365 // draw outline of bubble
366 PushColor( BUBBLE_BORDER );
367 glLineWidth( 1 );
368 glEnable( GL_LINE_SMOOTH );
369 glPolygonMode( GL_FRONT, GL_LINE );
370 Gl::draw_octagon( w, h, m );
371 glPopAttrib();
372 PopColor();
373
374 PushColor( BUBBLE_TEXT );
375 // draw text inside the bubble
aadcd1b vis stuff
rtv authored
376 Gl::draw_string( m, 2.5*m, 0, this->say_string );
e65967f powerpacks now set charging flag correctly
rtv authored
377 PopColor();
378 }
379 }
380 glPopMatrix();
381 }
382
383 if( stall )
384 {
385 DrawImage( TextureManager::getInstance()._stall_texture_id, cam, 0.85 );
386 }
387 }
388
389 void Model::DrawImage( uint32_t texture_id, Camera* cam, float alpha, double width, double height )
390 {
391 float yaw, pitch;
392 pitch = - cam->pitch();
393 yaw = - cam->yaw();
394 float robotAngle = -rtod(pose.a);
395
8b06ea1 fixed broken badges
rtv authored
396 glPolygonMode( GL_FRONT, GL_FILL );
397
e65967f powerpacks now set charging flag correctly
rtv authored
398 glEnable(GL_TEXTURE_2D);
399 glBindTexture( GL_TEXTURE_2D, texture_id );
400
401 glColor4f( 1.0, 1.0, 1.0, alpha );
402 glPushMatrix();
403
404 //position image above the robot
405 glTranslatef( 0.0, 0.0, ModelHeight() + 0.3 );
406
407 // rotate to face screen
408 glRotatef( robotAngle - yaw, 0,0,1 );
409 glRotatef( -pitch - 90, 1,0,0 );
410
411 //draw a square, with the textured image
412 glBegin(GL_QUADS);
413 glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.25f, 0, -0.25f );
414 glTexCoord2f(width, 0.0f); glVertex3f( 0.25f, 0, -0.25f );
415 glTexCoord2f(width, height); glVertex3f( 0.25f, 0, 0.25f );
416 glTexCoord2f(0.0f, height); glVertex3f(-0.25f, 0, 0.25f );
417 glEnd();
418
419 glPopMatrix();
420 glBindTexture( GL_TEXTURE_2D, 0 );
421 glDisable(GL_TEXTURE_2D);
422 }
423
424
425 void Model::DrawFlagList( void )
426 {
2c36066 fixed color bug in flags, and more STLing
rtv authored
427 if( flag_list.size() < 1 )
e65967f powerpacks now set charging flag correctly
rtv authored
428 return;
429
430 PushLocalCoords();
431
432 glPolygonMode( GL_FRONT, GL_FILL );
433
434 GLUquadric* quadric = gluNewQuadric();
435 glTranslatef(0,0,1); // jump up
436 Pose gpose = GetGlobalPose();
437 glRotatef( 180 + rtod(-gpose.a),0,0,1 );
438
2c36066 fixed color bug in flags, and more STLing
rtv authored
439 for( std::list<Flag*>::reverse_iterator it( flag_list.rbegin());
440 it != flag_list.rend();
441 it++ )
442 {
443 Flag* flag = *it;
e65967f powerpacks now set charging flag correctly
rtv authored
444
2c36066 fixed color bug in flags, and more STLing
rtv authored
445 glTranslatef( 0, 0, flag->size/2.0 );
e65967f powerpacks now set charging flag correctly
rtv authored
446
2c36066 fixed color bug in flags, and more STLing
rtv authored
447 flag->Draw( quadric );
448
e65967f powerpacks now set charging flag correctly
rtv authored
449 glTranslatef( 0, 0, flag->size/2.0 );
450 }
451
452
453 gluDeleteQuadric( quadric );
454
455 PopCoords();
456 }
457
458
910541e removed glib2 dependency (after many years of good service. Thanks GLib....
rtv authored
459 // void Model::DrawBlinkenlights()
460 // {
461 // PushLocalCoords();
e65967f powerpacks now set charging flag correctly
rtv authored
462
910541e removed glib2 dependency (after many years of good service. Thanks GLib....
rtv authored
463 // GLUquadric* quadric = gluNewQuadric();
464 // //glTranslatef(0,0,1); // jump up
465 // //Pose gpose = GetGlobalPose();
466 // //glRotatef( 180 + rtod(-gpose.a),0,0,1 );
e65967f powerpacks now set charging flag correctly
rtv authored
467
910541e removed glib2 dependency (after many years of good service. Thanks GLib....
rtv authored
468 // for( unsigned int i=0; i<blinkenlights->len; i++ )
469 // {
470 // stg_blinkenlight_t* b =
471 // (stg_blinkenlight_t*)g_ptr_array_index( blinkenlights, i );
472 // assert(b);
e65967f powerpacks now set charging flag correctly
rtv authored
473
910541e removed glib2 dependency (after many years of good service. Thanks GLib....
rtv authored
474 // glTranslatef( b->pose.x, b->pose.y, b->pose.z );
e65967f powerpacks now set charging flag correctly
rtv authored
475
910541e removed glib2 dependency (after many years of good service. Thanks GLib....
rtv authored
476 // PushColor( b->color );
e65967f powerpacks now set charging flag correctly
rtv authored
477
910541e removed glib2 dependency (after many years of good service. Thanks GLib....
rtv authored
478 // if( b->enabled )
479 // gluQuadricDrawStyle( quadric, GLU_FILL );
480 // else
481 // gluQuadricDrawStyle( quadric, GLU_LINE );
2c36066 fixed color bug in flags, and more STLing
rtv authored
482
910541e removed glib2 dependency (after many years of good service. Thanks GLib....
rtv authored
483 // gluSphere( quadric, b->size/2.0, 8,8 );
e65967f powerpacks now set charging flag correctly
rtv authored
484
910541e removed glib2 dependency (after many years of good service. Thanks GLib....
rtv authored
485 // PopColor();
486 // }
e65967f powerpacks now set charging flag correctly
rtv authored
487
910541e removed glib2 dependency (after many years of good service. Thanks GLib....
rtv authored
488 // gluDeleteQuadric( quadric );
e65967f powerpacks now set charging flag correctly
rtv authored
489
910541e removed glib2 dependency (after many years of good service. Thanks GLib....
rtv authored
490 // PopCoords();
491 // }
e65967f powerpacks now set charging flag correctly
rtv authored
492
493 void Model::DrawPicker( void )
494 {
495 //PRINT_DEBUG1( "Drawing %s", token );
496 PushLocalCoords();
497
498 // draw the boxes
499 blockgroup.DrawSolid( geom );
500
501 // recursively draw the tree below this model
5dee8f1 more STL-ization. may reduce performance slightly in worlds with few mod...
rtv authored
502 FOR_EACH( it, children )
503 (*it)->DrawPicker();
e65967f powerpacks now set charging flag correctly
rtv authored
504
505 PopCoords();
506 }
507
508 void Model::DataVisualize( Camera* cam )
509 {
510 }
511
512 void Model::DataVisualizeTree( Camera* cam )
513 {
514 PushLocalCoords();
515 DataVisualize( cam ); // virtual function overridden by most model types
516
a9b91ec more STLing
rtv authored
517 for( std::list<Visualizer*>::iterator it = cv_list.begin();
518 it != cv_list.end();
519 it++ )
520 {
521 Visualizer* vis = *it;
522 if( world_gui->GetCanvas()->_custom_options[ vis->GetMenuName() ]->isEnabled() )
523 vis->Visualize( this, cam );
524 }
525
e65967f powerpacks now set charging flag correctly
rtv authored
526 // and draw the children
5dee8f1 more STL-ization. may reduce performance slightly in worlds with few mod...
rtv authored
527 FOR_EACH( it, children )
528 (*it)->DataVisualizeTree( cam );
e65967f powerpacks now set charging flag correctly
rtv authored
529
530 PopCoords();
531 }
532
533 void Model::DrawGrid( void )
534 {
535 if ( gui.grid )
536 {
537 PushLocalCoords();
538
539 stg_bounds3d_t vol;
540 vol.x.min = -geom.size.x/2.0;
541 vol.x.max = geom.size.x/2.0;
542 vol.y.min = -geom.size.y/2.0;
543 vol.y.max = geom.size.y/2.0;
544 vol.z.min = 0;
545 vol.z.max = geom.size.z;
546
547 PushColor( 0,0,1,0.4 );
548 Gl::draw_grid(vol);
549 PopColor();
550 PopCoords();
551 }
552 }
Something went wrong with that request. Please try again.