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 
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, float *data, size_t len, size_t offset,
25  float min, float max)
26 {
27  float sample_spacing = w / (float)len;
28  float yscale = h / (max - min);
29 
30  // printf( "min %.2f max %.2f\n", min, max );
31 
32  glBegin(GL_LINE_STRIP);
33 
34  for (unsigned int i = 0; i < len; i++)
35  glVertex3f(x + (float)i * sample_spacing, y + (data[(i + offset) % len] - min) * yscale, 0.01);
36 
37  glEnd();
38 
39  glColor3f(0, 0, 0);
40  char buf[64];
41  snprintf(buf, 63, "%.2f", min);
42  Gl::draw_string(x, y, 0, buf);
43  snprintf(buf, 63, "%.2f", max);
44  Gl::draw_string(x, y + h - fl_height(), 0, buf);
45 }
46 
47 void Stg::Gl::draw_array(float x, float y, float w, float h, float *data, size_t len, size_t offset)
48 {
49  // wild initial bounds
50  float smallest = 1e16;
51  float largest = -1e16;
52 
53  for (size_t i = 0; i < len; i++) {
54  smallest = std::min(smallest, data[i]);
55  largest = std::max(largest, data[i]);
56  }
57 
58  draw_array(x, y, w, h, data, len, offset, smallest, largest);
59 }
60 
61 void Stg::Gl::draw_string(float x, float y, float z, const char *str)
62 {
63  glRasterPos3f(x, y, z);
64 
65  GLboolean b;
66  glGetBooleanv(GL_CURRENT_RASTER_POSITION_VALID, &b);
67 
68  // printf( "[%.2f %.2f %.2f] %d string %u %s\n", x,y,z, (int)b, (unsigned
69  // int)strlen(str), str );
70 
71  if (b)
72  gl_draw(str); // fltk function
73 }
74 
75 void Stg::Gl::draw_string_multiline(float x, float y, float w, float h, const char *str,
76  Fl_Align align)
77 {
78  // printf( "[%.2f %.2f %.2f] string %u %s\n", x,y,z,(unsigned int)strlen(str),
79  // 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 void Stg::Gl::draw_centered_rect(float x, float y, float dx, float dy)
121 {
122  glRectf(x - 0.5 * dx, y - 0.5 * dy, x + 0.5 * dx, y + 0.5 * dy);
123 }
124 
125 void Stg::Gl::draw_vector(double x, double y, double z)
126 {
127  glBegin(GL_LINES);
128  glVertex3f(0, 0, 0);
129  glVertex3f(x, y, z);
130  glEnd();
131 }
132 
133 void Stg::Gl::draw_origin(double len)
134 {
135  draw_vector(len, 0, 0);
136  draw_vector(0, len, 0);
137  draw_vector(0, 0, len);
138 }
139 
141 {
142  glBegin(GL_LINES);
143 
144  for (double i = floor(vol.x.min); i < vol.x.max; i++) {
145  glVertex2f(i, vol.y.min);
146  glVertex2f(i, vol.y.max);
147  }
148 
149  for (double i = floor(vol.y.min); i < vol.y.max; i++) {
150  glVertex2f(vol.x.min, i);
151  glVertex2f(vol.x.max, i);
152  }
153 
154  glEnd();
155 
156  char str[16];
157 
158  for (double i = floor(vol.x.min); i < vol.x.max; i++) {
159  snprintf(str, 16, "%d", (int)i);
160  draw_string(i, 0, 0.00, str);
161  }
162 
163  for (double i = floor(vol.y.min); i < vol.y.max; i++) {
164  snprintf(str, 16, "%d", (int)i);
165  draw_string(0, i, 0.00, str);
166  }
167 }
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:429
double max
largest value in range, initially zero
Definition: stage.hh:412
The Stage library uses its own namespace.
Definition: canvas.hh:8
double min
smallest value in range, initially zero
Definition: stage.hh:410
void draw_origin(double len)
Definition: gl.cc:133
void draw_string_multiline(float x, float y, float w, float h, const char *string, Fl_Align align)
Definition: gl.cc:75
meters_t z
location in 3 axes
Definition: stage.hh:259
meters_t y
Definition: stage.hh:259
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:120
double rtod(double r)
Definition: stage.hh:151
void draw_grid(bounds3d_t vol)
Definition: gl.cc:140
void draw_vector(double x, double y, double z)
Definition: gl.cc:125
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:61
Bounds x
volume extent along x axis, intially zero
Definition: stage.hh:427
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:260
meters_t x
Definition: stage.hh:259


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 Feb 28 2022 23:48:55