3 #include <OpenGL/glu.h> 10 #include "hrpsys/util/ThreadedObject.h" 11 #include "hrpsys/util/LogManagerBase.h" 12 #include "hrpsys/util/GLsceneBase.h" 13 #include "hrpsys/util/GLcamera.h" 14 #include "hrpsys/util/GLlink.h" 20 scene(i_scene), log(i_log), throbj(i_throbj),
22 pan(
M_PI/4), tilt(
M_PI/16), radius(5),
23 isShiftPressed(false), isControlPressed(false),
24 xCenter(0), yCenter(0), zCenter(0.8),
25 showingHelp(false), initialized(false)
42 instructions.push_back(
"p: pause/resume background thread");
60 char *argv[] = {(
char *)
"dummy"};
61 glutInit(&argc, argv);
63 if(SDL_Init(SDL_INIT_VIDEO)<0) {
64 fprintf(stderr,
"failed to initialize SDL.\n");
68 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1);
69 SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL,1);
71 int flag = SDL_HWSURFACE | SDL_GL_DOUBLEBUFFER | SDL_OPENGL;
72 if (resizable) flag |= SDL_RESIZABLE;
75 fprintf(stderr,
"failed to set video mode to %dx%dx32.\n",
width,
height);
79 SDL_WM_SetCaption(
"hrpsys viewer", NULL);
80 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY,SDL_DEFAULT_REPEAT_INTERVAL);
92 if (ratio < 0.0) ratio = 0.0;
93 if (ratio > 1.0) ratio = 1.0;
100 while(SDL_PollEvent(&event)){
108 switch(event.key.keysym.sym){
136 scene->toggleRobotState();
165 scene->showFloorGrid(!
scene->showFloorGrid());
168 scene->defaultLights(!
scene->defaultLights());
204 switch(event.key.keysym.sym){
216 case SDL_MOUSEBUTTONDOWN:
217 switch(event.button.button){
218 case SDL_BUTTON_LEFT:
226 case SDL_BUTTON_MIDDLE:
228 case SDL_BUTTON_RIGHT:
230 case SDL_BUTTON_WHEELUP:
240 case SDL_BUTTON_WHEELDOWN:
250 case SDL_MOUSEBUTTONUP:
251 switch(event.button.button){
252 case SDL_BUTTON_LEFT:
254 case SDL_BUTTON_MIDDLE:
256 case SDL_BUTTON_RIGHT:
258 case SDL_BUTTON_WHEELUP:
260 case SDL_BUTTON_WHEELDOWN:
264 case SDL_MOUSEMOTION:
266 int dx =
event.motion.xrel;
267 int dy =
event.motion.yrel;
268 if (event.motion.state&SDL_BUTTON(SDL_BUTTON_LEFT)){
282 }
else if (event.motion.state&SDL_BUTTON(SDL_BUTTON_RIGHT)){
290 case SDL_VIDEORESIZE:
291 width =
event.resize.w;
293 SDL_SetVideoMode(
width,
height,32,SDL_HWSURFACE | SDL_GL_DOUBLEBUFFER | SDL_OPENGL | SDL_RESIZABLE);
303 for (
unsigned int i=0;
i<strlen(str);
i++){
304 glutBitmapCharacter(GLUT_BITMAP_9_BY_15, str[
i]);
310 if (
scene->getDefaultCamera() ==
scene->getCamera()){
327 scene->getCamera()->setViewTarget(x,y,z);
328 scene->getCamera()->setViewPoint(xEye, yEye, zEye);
332 glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);
339 SDL_GL_SwapBuffers();
348 double startT = SDL_GetTicks();
352 double dt = SDL_GetTicks() - startT;
354 SDL_Delay(1000.0/30 - dt);
361 pan = atan2(T[6], T[2]);
362 tilt = atan2(T[10], sqrt(T[2]*T[2]+T[6]*T[6]));
#define SLIDER_SIDE_MARGIN
void setSize(int w, int h)
virtual bool record(double i_fps)=0
SDLwindow(GLsceneBase *i_scene, LogManagerBase *i_lm, ThreadedObject *i_throbj=NULL)
bool init(int w=0, int h=0, bool resizable=true)
hrp::Matrix33 getRotation()
void setView(double T[16])
png_infop png_uint_32 * width
hrp::Vector3 getPosition()
png_infop png_uint_32 png_uint_32 * height
virtual void move(double ratio)=0
virtual void next(int delta)=0
double sliderRatio(double x)
bool buttonPressedInSliderArea
static void drawString(const char *str)
HRP_UTIL_EXPORT Vector3 rpyFromRot(const Matrix33 &m)
std::vector< std::string > instructions
virtual void prev(int delta)=0
#define SLIDER_AREA_HEIGHT
png_infop png_uint_32 flag
std::vector< std::string > helpcommand