diff options
author | Thomas Dinges <blender@dingto.org> | 2014-02-14 04:15:07 +0400 |
---|---|---|
committer | Thomas Dinges <blender@dingto.org> | 2014-02-14 04:17:01 +0400 |
commit | b09684567e6029211cbbe06e93209989bb5fc804 (patch) | |
tree | 89e8e2cc1ae62895c07dcbfbabeec43136680211 /intern/cycles/util | |
parent | 5621e63d36c525f6acd744e2ddae3a73f2c3b453 (diff) |
Cycles Standalone: The camera can now be moved and rotated with LMB/RMB mouse key.
ToDo: Add controls for forward/backward movement.
Diffstat (limited to 'intern/cycles/util')
-rw-r--r-- | intern/cycles/util/util_view.cpp | 53 | ||||
-rw-r--r-- | intern/cycles/util/util_view.h | 3 |
2 files changed, 52 insertions, 4 deletions
diff --git a/intern/cycles/util/util_view.cpp b/intern/cycles/util/util_view.cpp index 7a9019b0b0a..de655d9d41e 100644 --- a/intern/cycles/util/util_view.cpp +++ b/intern/cycles/util/util_view.cpp @@ -38,9 +38,13 @@ struct View { ViewResizeFunc resize; ViewDisplayFunc display; ViewKeyboardFunc keyboard; + ViewMotionFunc motion; bool first_display; bool redraw; + + int mouseX, mouseY; + int mouseBut0, mouseBut2; int width, height; } V; @@ -95,11 +99,14 @@ void view_display_help() view_display_text(x1+20, y2-20, "Cycles Renderer"); view_display_text(x1+20, y2-40, "(C) 2011-2014 Blender Foundation"); - view_display_text(x1+20, y2-80, "Help:"); - view_display_text(x1+20, y2-100, "h: Toggle this help message"); + view_display_text(x1+20, y2-80, "Controls:"); + view_display_text(x1+20, y2-100, "h: Show/Hide this help message"); view_display_text(x1+20, y2-120, "r: Restart the render"); view_display_text(x1+20, y2-140, "q: Quit the program"); view_display_text(x1+20, y2-160, "esc: Cancel the render"); + + view_display_text(x1+20, y2-190, "LMB: Move camera"); + view_display_text(x1+20, y2-210, "RMB: Rotate camera"); glColor3f(1.0f, 1.0f, 1.0f); } @@ -164,6 +171,43 @@ static void view_keyboard(unsigned char key, int x, int y) } } +static void view_mouse(int button, int state, int x, int y) +{ + if(button == 0) { + if(state == GLUT_DOWN) { + V.mouseX = x; + V.mouseY = y; + V.mouseBut0 = 1; + } + else if(state == GLUT_UP) { + V.mouseBut0 = 0; + } + } + else if(button == 2) { + if(state == GLUT_DOWN) { + V.mouseX = x; + V.mouseY = y; + V.mouseBut2 = 1; + } + else if(state == GLUT_UP) { + V.mouseBut2 = 0; + } + } +} + +static void view_motion(int x, int y) +{ + const int but = V.mouseBut0? 0:2; + const int distX = x - V.mouseX; + const int distY = y - V.mouseY; + + if(V.motion) + V.motion(distX, distY, but); + + V.mouseX = x; + V.mouseY = y; +} + static void view_idle(void) { if(V.redraw) { @@ -177,7 +221,7 @@ static void view_idle(void) void view_main_loop(const char *title, int width, int height, ViewInitFunc initf, ViewExitFunc exitf, ViewResizeFunc resize, ViewDisplayFunc display, - ViewKeyboardFunc keyboard) + ViewKeyboardFunc keyboard, ViewMotionFunc motion) { const char *name = "app"; char *argv = (char*)name; @@ -193,6 +237,7 @@ void view_main_loop(const char *title, int width, int height, V.resize = resize; V.display = display; V.keyboard = keyboard; + V.motion = motion; glutInit(&argc, &argv); glutInitWindowSize(width, height); @@ -210,6 +255,8 @@ void view_main_loop(const char *title, int width, int height, glutIdleFunc(view_idle); glutReshapeFunc(view_reshape); glutKeyboardFunc(view_keyboard); + glutMouseFunc(view_mouse); + glutMotionFunc(view_motion); glutMainLoop(); } diff --git a/intern/cycles/util/util_view.h b/intern/cycles/util/util_view.h index a0d0d492790..65d890eb6af 100644 --- a/intern/cycles/util/util_view.h +++ b/intern/cycles/util/util_view.h @@ -27,11 +27,12 @@ typedef void (*ViewExitFunc)(void); typedef void (*ViewResizeFunc)(int width, int height); typedef void (*ViewDisplayFunc)(void); typedef void (*ViewKeyboardFunc)(unsigned char key); +typedef void (*ViewMotionFunc)(int x, int y, int button); void view_main_loop(const char *title, int width, int height, ViewInitFunc initf, ViewExitFunc exitf, ViewResizeFunc resize, ViewDisplayFunc display, - ViewKeyboardFunc keyboard); + ViewKeyboardFunc keyboard, ViewMotionFunc motion); void view_display_info(const char *info); void view_display_help(); |