gl.cc
Go to the documentation of this file.
1 
2 #include "stage.hh"
3 using namespace Stg;
4 
5 // transform the current coordinate frame by the given pose
6 void Stg::Gl::coord_shift( double x, double y, double z, double a )
7 {
8  glTranslatef( x,y,z );
9  glRotatef( rtod(a), 0,0,1 );
10 }
11 
12 // transform the current coordinate frame by the given pose
13 void Stg::Gl::pose_shift( const Pose &pose )
14 {
15  coord_shift( pose.x, pose.y, pose.z, pose.a );
16 }
17 
18 void Stg::Gl::pose_inverse_shift( const Pose &pose )
19 {
20  coord_shift( 0,0,0, -pose.a );
21  coord_shift( -pose.x, -pose.y, -pose.z, 0 );
22 }
23 
24 void Stg::Gl::draw_array( float x, float y, float w, float h,
25  float* data, size_t len, size_t offset,
26  float min, float max )
27 {
28  float sample_spacing = w / (float)len;
29  float yscale = h / (max-min);
30 
31  //printf( "min %.2f max %.2f\n", min, max );
32 
33  glBegin( GL_LINE_STRIP );
34 
35  for( unsigned int i=0; i<len; i++ )
36  glVertex3f( x + (float)i*sample_spacing, y+(data[(i+offset)%len]-min)*yscale, 0.01 );
37 
38  glEnd();
39 
40  glColor3f( 0,0,0 );
41  char buf[64];
42  snprintf( buf, 63, "%.2f", min );
43  Gl::draw_string( x,y,0,buf );
44  snprintf( buf, 63, "%.2f", max );
45  Gl::draw_string( x,y+h-fl_height(),0,buf );
46 
47 }
48 
49 void Stg::Gl::draw_array( float x, float y, float w, float h,
50  float* data, size_t len, size_t offset )
51 {
52  // wild initial bounds
53  float smallest = 1e16;
54  float largest = -1e16;
55 
56  for( size_t i=0; i<len; i++ )
57  {
58  smallest = std::min( smallest, data[i] );
59  largest = std::max( largest, data[i] );
60  }
61 
62  draw_array( x,y,w,h,data,len,offset,smallest,largest );
63 }
64 
65 void Stg::Gl::draw_string( float x, float y, float z, const char *str )
66 {
67  glRasterPos3f( x, y, z );
68 
69  GLboolean b;
70  glGetBooleanv( GL_CURRENT_RASTER_POSITION_VALID, &b );
71 
72  //printf( "[%.2f %.2f %.2f] %d string %u %s\n", x,y,z, (int)b, (unsigned int)strlen(str), str );
73 
74  if( b ) gl_draw( str ); // fltk function
75 }
76 
77 void Stg::Gl::draw_string_multiline( float x, float y, float w, float h, const char *str, Fl_Align align )
78 {
79  //printf( "[%.2f %.2f %.2f] string %u %s\n", x,y,z,(unsigned int)strlen(str), str );
80  gl_draw(str, x, y, w, h, align ); // fltk function
81 }
82 
83 void Stg::Gl::draw_speech_bubble( float x, float y, float z, const char* str )
84 {
85  draw_string( x, y, z, str );
86 }
87 
88 // draw an octagon with center rectangle dimensions w/h
89 // and outside margin m
90 void Stg::Gl::draw_octagon( float w, float h, float m )
91 {
92  glBegin(GL_POLYGON);
93  glVertex2f( m+w, 0 );
94  glVertex2f( w+2*m, m );
95  glVertex2f( w+2*m, h+m );
96  glVertex2f( m+w, h+2*m );
97  glVertex2f( m, h+2*m );
98  glVertex2f( 0, h+m );
99  glVertex2f( 0, m );
100  glVertex2f( m, 0 );
101  glEnd();
102 }
103 
104 // draw an octagon with center rectangle dimensions w/h
105 // and outside margin m
106 void Stg::Gl::draw_octagon( float x, float y, float w, float h, float m )
107 {
108  glBegin(GL_POLYGON);
109  glVertex2f( x + m+w, y );
110  glVertex2f( x+w+2*m, y+m );
111  glVertex2f( x+w+2*m, y+h+m );
112  glVertex2f( x+m+w, y+h+2*m );
113  glVertex2f( x+m, y+h+2*m );
114  glVertex2f( x, y+h+m );
115  glVertex2f( x, y+m );
116  glVertex2f( x+m, y );
117  glEnd();
118 }
119 
120 
121 void Stg::Gl::draw_centered_rect( float x, float y, float dx, float dy )
122 {
123  glRectf( x-0.5*dx, y-0.5*dy, x+0.5*dx, y+0.5*dy );
124 }
125 
126 void Stg::Gl::draw_vector( double x, double y, double z )
127 {
128  glBegin( GL_LINES );
129  glVertex3f( 0,0,0 );
130  glVertex3f( x,y,z );
131  glEnd();
132 }
133 
134 void Stg::Gl::draw_origin( double len )
135 {
136  draw_vector( len,0,0 );
137  draw_vector( 0,len,0 );
138  draw_vector( 0,0,len );
139 }
140 
142 {
143  glBegin(GL_LINES);
144 
145  for( double i = floor(vol.x.min); i < vol.x.max; i++)
146  {
147  glVertex2f( i, vol.y.min );
148  glVertex2f( i, vol.y.max );
149  }
150 
151  for( double i = floor(vol.y.min); i < vol.y.max; i++)
152  {
153  glVertex2f( vol.x.min, i );
154  glVertex2f( vol.x.max, i );
155  }
156 
157  glEnd();
158 
159  char str[16];
160 
161  for( double i = floor(vol.x.min); i < vol.x.max; i++)
162  {
163  snprintf( str, 16, "%d", (int)i );
164  draw_string( i, 0, 0.00, str );
165  }
166 
167  for( double i = floor(vol.y.min); i < vol.y.max; i++)
168  {
169  snprintf( str, 16, "%d", (int)i );
170  draw_string( 0, i, 0.00, str );
171  }
172 }
173 
174 
void coord_shift(double x, double y, double z, double a)
Definition: gl.cc:6
Bounds y
volume extent along y axis, initially zero
Definition: stage.hh:453
double max
largest value in range, initially zero
Definition: stage.hh:435
The Stage library uses its own namespace.
Definition: canvas.hh:8
double min
smallest value in range, initially zero
Definition: stage.hh:433
void draw_origin(double len)
Definition: gl.cc:134
void draw_string_multiline(float x, float y, float w, float h, const char *string, Fl_Align align)
Definition: gl.cc:77
meters_t z
location in 3 axes
Definition: stage.hh:251
meters_t y
Definition: stage.hh:251
void pose_inverse_shift(const Pose &pose)
Definition: gl.cc:18
void draw_array(float x, float y, float w, float h, float *data, size_t len, size_t offset, float min, float max)
Definition: gl.cc:24
void draw_centered_rect(float x, float y, float dx, float dy)
Definition: gl.cc:121
double rtod(double r)
Definition: stage.hh:148
void draw_grid(bounds3d_t vol)
Definition: gl.cc:141
void draw_vector(double x, double y, double z)
Definition: gl.cc:126
void pose_shift(const Pose &pose)
Definition: gl.cc:13
void draw_string(float x, float y, float z, const char *string)
Definition: gl.cc:65
Bounds x
volume extent along x axis, intially zero
Definition: stage.hh:451
void draw_speech_bubble(float x, float y, float z, const char *str)
Definition: gl.cc:83
void draw_octagon(float w, float h, float m)
Definition: gl.cc:90
radians_t a
rotation about the z axis.
Definition: stage.hh:252
meters_t x
Definition: stage.hh:251


stage
Author(s): Richard Vaughan , Brian Gerkey , Reed Hedges , Andrew Howard , Toby Collett , Pooya Karimian , Jeremy Asher , Alex Couture-Beil , Geoff Biggs , Rich Mattes , Abbas Sadat
autogenerated on Mon Jun 10 2019 15:06:09