44 if (c->
world->dirty) {
47 c->
world->dirty =
false;
59 showBBoxes(
"Debug/Bounding boxes",
"show_boundingboxes",
"^b", false, world),
60 showBlocks(
"Blocks",
"show_blocks",
"b", true, world),
61 showBlur(
"Trails/Blur",
"show_trailblur",
"^d", false, world),
62 showClock(
"Clock",
"show_clock",
"c", true, world),
63 showData(
"Data",
"show_data",
"d", false, world),
64 showFlags(
"Flags",
"show_flags",
"l", true, world),
65 showFollow(
"Follow",
"show_follow",
"f", false, world),
66 showFootprints(
"Footprints",
"show_footprints",
"o", false, world),
67 showGrid(
"Grid",
"show_grid",
"g", true, world),
68 showOccupancy(
"Debug/Occupancy",
"show_occupancy",
"^o", false, world),
70 showStatus(
"Status",
"show_status",
"s", true, world),
71 showTrailArrows(
"Trails/Rising Arrows",
"show_trailarrows",
"^a", false, world),
72 showTrailRise(
"Trails/Rising blocks",
"show_trailrise",
"^r", false, world),
73 showTrails(
"Trails/Fast",
"show_trailfast",
"^f", false, world),
74 showVoxels(
"Debug/Voxels",
"show_voxels",
"^v", false, world),
75 pCamOn(
"Perspective camera",
"pcam_on",
"r", false, world),
76 visualizeAll(
"Selected only",
"vis_all",
"v", false, world),
85 mode( FL_RGB |FL_DOUBLE|FL_DEPTH| FL_MULTISAMPLE | FL_ALPHA );
102 glClearColor(0.7, 0.7, 0.8, 1.0);
103 glDisable(GL_LIGHTING);
104 glEnable(GL_DEPTH_TEST);
105 glDepthFunc(GL_LESS);
111 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
112 glEnable(GL_LINE_SMOOTH);
113 glHint(GL_LINE_SMOOTH_HINT, GL_FASTEST);
114 glDepthMask(GL_TRUE);
115 glEnable(GL_TEXTURE_2D);
116 glEnableClientState(GL_VERTEX_ARRAY);
117 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
120 gl_font(FL_HELVETICA, 12);
124 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
133 if (fullpath ==
"") {
143 if (fullpath ==
"") {
177 int even = (i + j) % 2;
178 checkImage[i][j][0] = (GLubyte)255 - 10 * even;
179 checkImage[i][j][1] = (GLubyte)255 - 10 * even;
185 glBindTexture(GL_TEXTURE_2D,
checkTex);
187 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
188 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
189 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
190 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
192 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, checkImageWidth, checkImageHeight, 0, GL_RGBA,
207 glClearColor(1, 1, 1, 1);
208 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
213 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
214 glDisable(GL_DITHER);
224 uint8_t rByte, gByte, bByte, aByte;
225 uint32_t modelId = mod->
id;
227 gByte = modelId >> 8;
228 bByte = modelId >> 16;
229 aByte = modelId >> 24;
234 glColor4ub(rByte, gByte, bByte, aByte);
244 glGetIntegerv(GL_VIEWPORT, viewport);
249 glReadPixels(x, viewport[3] - y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &rgbaByte[0]);
251 modelId = rgbaByte[0];
252 modelId |= rgbaByte[1] << 8;
253 modelId |= rgbaByte[2] << 16;
268 glClearColor(0.7, 0.7, 0.8, 1.0);
323 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
332 glGetIntegerv(GL_VIEWPORT, viewport);
334 GLdouble modelview[16];
335 glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
337 GLdouble projection[16];
338 glGetDoublev(GL_PROJECTION_MATRIX, projection);
341 glReadPixels(px, h() - py, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &pz);
342 gluUnProject(px, w() - py, pz, modelview, projection, viewport, wx, wy, wz);
354 camera.
scale(Fl::event_dy(), Fl::event_x(), w(), Fl::event_y(), h());
361 if (Fl::event_state(FL_META)) {
362 puts(
"TODO: HANDLE HISTORY");
370 if (Fl::event_state(FL_CTRL))
372 int dx = Fl::event_x() -
startx;
373 int dy = Fl::event_y() -
starty;
384 }
else if (Fl::event_state(FL_ALT)) {
385 int dx = Fl::event_x() -
startx;
386 int dy = Fl::event_y() -
starty;
407 switch (Fl::event_button()) {
414 if (Fl::event_state(FL_SHIFT)) {
448 int dx = Fl::event_x() -
startx;
449 int dy = Fl::event_y() -
starty;
451 if (Fl::event_state(FL_BUTTON1) && Fl::event_state(FL_CTRL) ==
false) {
475 }
else if (Fl::event_state(FL_BUTTON3)
476 || (Fl::event_state(FL_BUTTON1) && Fl::event_state(FL_CTRL))) {
482 mod->
AddToPose(0, 0, 0, 0.05 * (dx + dy));
487 int dx = Fl::event_x() -
startx;
488 int dy = Fl::event_y() -
starty;
524 switch (Fl::event_key()) {
570 return Fl_Gl_Window::handle(event);
580 glViewport(0, 0, W, H);
591 printf(
"removing model %s from canvas list\n", mod->
Token());
599 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
601 glEnable(GL_POLYGON_OFFSET_FILL);
602 glPolygonOffset(2.0, 2.0);
605 glEnable(GL_TEXTURE_2D);
606 glBindTexture(GL_TEXTURE_2D,
checkTex);
607 glColor3f(1.0, 1.0, 1.0);
610 glTexCoord2f(bounds.
x.
min / 2.0, bounds.
y.
min / 2.0);
611 glVertex2f(bounds.
x.
min, bounds.
y.
min);
612 glTexCoord2f(bounds.
x.
max / 2.0, bounds.
y.
min / 2.0);
613 glVertex2f(bounds.
x.
max, bounds.
y.
min);
614 glTexCoord2f(bounds.
x.
max / 2.0, bounds.
y.
max / 2.0);
615 glVertex2f(bounds.
x.
max, bounds.
y.
max);
616 glTexCoord2f(bounds.
x.
min / 2.0, bounds.
y.
max / 2.0);
617 glVertex2f(bounds.
x.
min, bounds.
y.
max);
620 glDisable(GL_TEXTURE_2D);
623 glDisable(GL_POLYGON_OFFSET_FILL);
636 if (skip > 2 && skip % 2)
644 for (
double i = 0; i < bounds.
x.
max; i += skip) {
645 snprintf(str, 16,
"%d", (
int)i);
649 for (
double i = 0; i >= bounds.
x.
min; i -= skip) {
650 snprintf(str, 16,
"%d", (
int)i);
654 for (
double i = 0; i < bounds.
y.
max; i += skip) {
655 snprintf(str, 16,
"%d", (
int)i);
659 for (
double i = 0; i >= bounds.
y.
min; i -= skip) {
660 snprintf(str, 16,
"%d", (
int)i);
672 glEnable(GL_POLYGON_OFFSET_FILL);
673 glPolygonOffset(2.0, 2.0);
675 glColor4f(1.0, 1.0, 1.0, 1.0);
678 glVertex2f(bounds.
x.
min, bounds.
y.
min);
679 glVertex2f(bounds.
x.
max, bounds.
y.
min);
680 glVertex2f(bounds.
x.
max, bounds.
y.
max);
681 glVertex2f(bounds.
x.
min, bounds.
y.
max);
688 (*it)->DrawBlocksTree();
693 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
702 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
707 float max_x = 0, max_y = 0, min_x = 0, min_y = 0;
715 float tmp_min_x = pose.
x - geom.
size.
x / 2.0;
716 float tmp_max_x = pose.
x + geom.
size.
x / 2.0;
717 float tmp_min_y = pose.
y - geom.
size.
y / 2.0;
718 float tmp_max_y = pose.
y + geom.
size.
y / 2.0;
720 if (tmp_min_x < min_x)
722 if (tmp_max_x > max_x)
724 if (tmp_min_y < min_y)
726 if (tmp_max_y > max_y)
731 float x = (min_x + max_x) / 2.0;
732 float y = (min_y + max_y) / 2.0;
734 float scale_x = w() / (max_x - min_x) * 0.9;
735 float scale_y = h() / (max_y - min_y) * 0.9;
749 const meters_t a_dist = hypot(y - a_pose.
y, x - a_pose.
x);
750 const meters_t b_dist = hypot(y - b_pose.
y, x - b_pose.
x);
752 return (a_dist < b_dist);
781 glEnable(GL_DEPTH_TEST);
784 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
795 glScalef(scale, scale, 1.0);
799 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
822 glBegin(GL_LINE_STRIP);
837 glScalef(scale, scale, 1.0);
841 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
862 glBegin(GL_LINE_STRIP);
881 glDisable(GL_DEPTH_TEST);
884 (*it)->DrawTrailFootprint();
886 glEnable(GL_DEPTH_TEST);
890 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
891 glBegin(GL_TRIANGLES);
894 (*it)->DrawFlagList();
901 (*it)->DrawTrailArrows();
905 (*it)->DrawTrailBlocks();
917 (*it)->DrawSelected();
946 glTranslatef(0, 0, 0.1);
949 (*it)->DrawStatusTree(&
camera);
955 glDisable(GL_DEPTH_TEST);
960 glVertex2f(pts[0], pts[1]);
961 glVertex2f(pts[2], pts[3]);
965 glEnable(GL_DEPTH_TEST);
971 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
974 glMatrixMode(GL_PROJECTION);
977 glOrtho(0, w(), 0, h(), -100, 100);
978 glMatrixMode(GL_MODELVIEW);
982 glDisable(GL_DEPTH_TEST);
986 clockstr.append(
" [FOLLOW MODE]");
988 float txtWidth = gl_width(clockstr.c_str());
991 int txtHeight = gl_height();
993 const int margin = 5;
995 width = txtWidth + 2 * margin;
996 height = txtHeight + 2 * margin;
1000 glRectf(0, 0, width, height);
1021 glEnable(GL_DEPTH_TEST);
1025 glMatrixMode(GL_PROJECTION);
1027 glMatrixMode(GL_MODELVIEW);
1039 glMatrixMode(GL_PROJECTION);
1042 glOrtho(0, w(), 0, h(), -100, 100);
1043 glMatrixMode(GL_MODELVIEW);
1047 glDisable(GL_DEPTH_TEST);
1052 glEnable(GL_DEPTH_TEST);
1054 glMatrixMode(GL_PROJECTION);
1056 glMatrixMode(GL_MODELVIEW);
1070 static std::vector<uint8_t> pixels;
1071 pixels.resize(width * height * depth);
1075 glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, &pixels[0]);
1077 static uint32_t count = 0;
1079 snprintf(filename, 63,
"stage-%06d.png", count++);
1081 FILE *fp = fopen(filename,
"wb");
1087 png_structp pp = png_create_write_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
1089 png_infop info = png_create_info_struct(pp);
1093 png_init_io(pp, fp);
1096 png_bytep *rowpointers =
new png_bytep[height];
1097 for (
int i = 0; i < height; i++)
1098 rowpointers[i] = &pixels[(height - 1 - i) * width * depth];
1100 png_set_rows(pp, info, rowpointers);
1102 png_set_IHDR(pp, info, width, height, 8, PNG_COLOR_TYPE_RGBA, PNG_INTERLACE_NONE,
1103 PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
1105 png_write_png(pp, info, PNG_TRANSFORM_IDENTITY, NULL);
1108 png_destroy_write_struct(&pp, &info);
1112 printf(
"Saved %s\n", filename);
1113 delete[] rowpointers;
1127 canvas->invalidate();
1236 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
1256 Fl_Gl_Window::resize(X, Y, W, H);
std::list< Model * > models_sorted
std::vector< point_int_t > rt_candidate_cells
void DrawOccupancy() const
Bounds y
volume extent along y axis, initially zero
GLuint loadTexture(const char *filename)
load a texture on the GPU, returned value is the texture ID, or 0 for failure
void Save(Worldfile *wf, int sec)
virtual void Draw(void) const =0
double Resolution() const
double max
largest value in range, initially zero
Pose GetGlobalPose() const
The Stage library uses its own namespace.
static const int checkImageWidth
void setPose(double x, double y)
static bool texture_load_done
void setDirtyBuffer(void)
virtual void DrawPicker()
bool operator()(const Model *a, const Model *b) const
void AddToPose(const Pose &pose)
void Load(Worldfile *wf, int sec)
void forward(double amount)
static TextureManager & getInstance(void)
void EraseAll(T thing, C &cont)
double min
smallest value in range, initially zero
virtual int handle(int event)
void createMenuItems(Fl_Menu_Bar *menu, std::string path)
void setPose(double x, double y, double z)
Canvas(WorldGui *world, int x, int y, int width, int height)
PerspectiveCamera perspective_camera
void DataVisualizeTree(Camera *cam)
void PushColor(Color col)
void Save(Worldfile *wf, int sec)
void Save(Worldfile *wf, int section)
void WriteInt(int entity, const char *name, int value)
void scale(double scale, double shift_x=0, double h=0, double shift_y=0, double w=0)
static GLubyte checkImage[checkImageHeight][checkImageWidth][4]
void FixViewport(int W, int H)
int screenshot_frame_skip
void CanvasToWorld(int px, int py, double *wx, double *wy, double *wz)
usec_t sim_time
the current sim time in this world in microseconds
const bounds3d_t & GetExtent() const
void addPitch(double pitch)
virtual void SetProjection(double pixels_width, double pixels_height, double y_min, double y_max)
void createMenuItem(Fl_Menu_Bar *menu, std::string path)
void RemoveModel(Model *mod)
std::vector< point_int_t > rt_cells
std::list< Model * > selected_models
void addPitch(double pitch)
DistFuncObj(meters_t x, meters_t y)
virtual void SetProjection(void) const =0
void draw_string(float x, float y, float z, const char *string)
static Model * LookupId(uint32_t id)
Bounds x
volume extent along x axis, intially zero
static std::string findFile(const std::string &filename)
void menuCallback(Fl_Callback *cb, Fl_Widget *w)
bool paused
if true, the simulation is stopped
virtual void PushColor(Color col)
dummy implementations to be overloaded by GUI subclasses
void Push(double r, double g, double b, double a=1.0)
Model * getModel(int x, int y)
void strafe(double amount)
void AddModel(Model *mod)
void setScale(double scale)
static void perspectiveCb(Fl_Widget *w, void *p)
void Save(Worldfile *wf, int section)
static const int checkImageHeight
std::list< float * > ray_list
List of rays traced for debug visualization.
void Load(Worldfile *wf, int section)
void Load(Worldfile *wf, int sec)
void DrawBoundingBoxTree()
void Load(Worldfile *wf, int section)
bool dirtyBuffer(void) const
int ReadInt(int entity, const char *name, int value)
class Stg::Model::GuiState gui
radians_t a
rotation about the z axis.
unsigned long frames_rendered_count
void setAspect(double aspect)
update vertical fov based on window aspect and current horizontal fov
void move(double x, double y, double z)
msec_t interval
(even if it is now unselected).
class Stg::Canvas::GlColorStack colorstack
void move(double x, double y)
virtual void SetProjection(void) const
bool selected(Model *mod)
void resize(int X, int Y, int W, int H)
virtual void renderFrame()
virtual std::string ClockString() const
const char * Token() const
static void TimerCallback(Canvas *canvas)
void unSelect(Model *mod)