# HG changeset patch # User John Tsiombikas # Date 1400941373 -10800 # Node ID d38e13d6063c726744c9d51ef6bc5d636320c468 # Parent e2d9bf168a416d10b617f841c844f14e219aafde foo diff -r e2d9bf168a41 -r d38e13d6063c liberebus/src/erebus.cc --- a/liberebus/src/erebus.cc Sat May 24 06:12:57 2014 +0300 +++ b/liberebus/src/erebus.cc Sat May 24 17:22:53 2014 +0300 @@ -34,6 +34,11 @@ int cur_pixel_x, cur_pixel_y; Rect cur_rect; int cur_sample; + + // interactive input + std::vector keystate; + std::vector bnstate; + int mouse_pos[2]; }; static void render_pixel(struct erebus *ctx, int x, int y, int sample); @@ -205,6 +210,30 @@ return 0; } +bool erb_input_keyboard(struct erebus *ctx, int key, bool pressed) +{ + if(!ctx) return false; + if(ctx->keystate.size() <= key) ctx->keystate.resize(key < 256 ? 256 : key + 1); + + ctx->keystate[key] = pressed; + return false; +} + +bool erb_input_mouse_button(struct erebus *ctx, int bn, bool pressed, int x, int y) +{ + if(!ctx) return false; + if(ctx->bnstate.size() <= bn) ctx->bnstate.resize(bn < 32 ? 32 : bn + 1); + + ctx->bnstate[bn] = pressed; + ctx->mouse_pos[0] = x; + ctx->mouse_pos[1] = y; +} + +bool erb_input_mouse_motion(struct erebus *ctx, int x, int y); +bool erb_input_6dof_button(struct erebus *ctx, int bn, bool pressed); +bool erb_input_6dof_motion(struct erebus *ctx, float x, float y, float z); + + } // extern "C" float randf(float low, float high) diff -r e2d9bf168a41 -r d38e13d6063c liberebus/src/erebus.h --- a/liberebus/src/erebus.h Sat May 24 06:12:57 2014 +0300 +++ b/liberebus/src/erebus.h Sat May 24 17:22:53 2014 +0300 @@ -39,6 +39,12 @@ int erb_load_scene(struct erebus *ctx, const char *fname); +bool erb_input_keyboard(struct erebus *ctx, int key, bool pressed); +bool erb_input_mouse_button(struct erebus *ctx, int bn, bool pressed, int x, int y); +bool erb_input_mouse_motion(struct erebus *ctx, int x, int y); +bool erb_input_6dof_button(struct erebus *ctx, int bn, bool pressed); +bool erb_input_6dof_motion(struct erebus *ctx, float x, float y, float z); + #ifdef __cplusplus } #endif diff -r e2d9bf168a41 -r d38e13d6063c src/main.cc --- a/src/main.cc Sat May 24 06:12:57 2014 +0300 +++ b/src/main.cc Sat May 24 17:22:53 2014 +0300 @@ -12,7 +12,11 @@ static void display(); static void reshape(int x, int y); static void keyb(unsigned char key, int x, int y); +static void keyb_up(unsigned char key, int x, int y); static void mouse(int bn, int st, int x, int y); +static void motion(int x, int y); +static void sball_button(int bn, int st); +static void sball_motion(int x, int y, int z); static int next_pow2(int x); static int width, height, rtex_width, rtex_height; @@ -32,7 +36,11 @@ glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(keyb); + glutKeyboardUpFunc(keyb_up); glutMouseFunc(mouse); + glutMotionFunc(motion); + glutSpaceballButtonFunc(sball_button); + glutSpaceballMotionFunc(sball_motion); if(!init()) { return 1; @@ -169,10 +177,45 @@ erb_begin_frame(erb, 0); break; } + + if(erb_input_keyboard(key, true)) { + glutPostRedisplay(); + } +} + +static void keyb_up(unsigned char key, int x, int y) +{ + if(erb_input_keyboard(key, false)) { + glutPostRedisplay(); + } } static void mouse(int bn, int st, int x, int y) { + if(erb_input_mouse_button(bn - GLUT_LEFT_BUTTON, st == GLUT_DOWN, x, y)) { + glutPostRedisplay(); + } +} + +static void motion(int x, int y) +{ + if(erb_input_mouse_move(x, y)) { + glutPostRedisplay(); + } +} + +static void sball_button(int bn, int state) +{ + if(erb_input_6dof_button(bn, state == GLUT_DOWN)) { + glutPostRedisplay(); + } +} + +static void sball_motion(int x, int y, int z) +{ + if(erb_input_6dof_motion(x / 65536.0, y / 65536.0, z / 65536.0)) { + glutPostRedisplay(); + } } static int next_pow2(int x)