Cycles Standalone: The camera can now be moved and rotated with LMB/RMB mouse key.
ToDo: Add controls for forward/backward movement.
This commit is contained in:
parent
5621e63d36
commit
b09684567e
Notes:
blender-bot
2023-02-14 11:11:04 +01:00
Referenced by issue #38647, "Make Duplicates Real" crashes in Solid mode.
|
@ -29,6 +29,7 @@
|
|||
#include "util_progress.h"
|
||||
#include "util_string.h"
|
||||
#include "util_time.h"
|
||||
#include "util_transform.h"
|
||||
|
||||
#ifdef WITH_CYCLES_STANDALONE_GUI
|
||||
#include "util_view.h"
|
||||
|
@ -179,6 +180,30 @@ static void display()
|
|||
display_info(options.session->progress);
|
||||
}
|
||||
|
||||
static void motion(int x, int y, int button)
|
||||
{
|
||||
/* Translate */
|
||||
if(button == 0) {
|
||||
float3 translate = make_float3(x*0.01, y*0.01, 0.0f);
|
||||
options.session->scene->camera->matrix = options.session->scene->camera->matrix * transform_translate(translate);
|
||||
}
|
||||
|
||||
/* Rotate */
|
||||
else if(button == 2) {
|
||||
float4 r1= make_float4(x*0.1, 0.0f, 1.0f, 0.0f);
|
||||
options.session->scene->camera->matrix = options.session->scene->camera->matrix * transform_rotate(r1.x*M_PI/180.0f, make_float3(r1.y, r1.z, r1.w));
|
||||
|
||||
float4 r2 = make_float4(y*0.1, 1.0f, 0.0, 0.0f);
|
||||
options.session->scene->camera->matrix = options.session->scene->camera->matrix * transform_rotate(r2.x*M_PI/180.0f, make_float3(r2.y, r2.z, r2.w));
|
||||
}
|
||||
|
||||
/* Update and Reset */
|
||||
options.session->scene->camera->need_update = true;
|
||||
options.session->scene->camera->need_device_update = true;
|
||||
|
||||
options.session->reset(session_buffer_params(), options.session_params.samples);
|
||||
}
|
||||
|
||||
static void resize(int width, int height)
|
||||
{
|
||||
options.width = width;
|
||||
|
@ -326,6 +351,9 @@ static void options_parse(int argc, const char **argv)
|
|||
fprintf(stderr, "No file path specified\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* For smoother Viewport */
|
||||
options.session_params.start_resolution = 64;
|
||||
|
||||
/* load scene */
|
||||
scene_init(options.width, options.height);
|
||||
|
@ -353,7 +381,7 @@ int main(int argc, const char **argv)
|
|||
|
||||
/* init/exit are callback so they run while GL is initialized */
|
||||
view_main_loop(title.c_str(), options.width, options.height,
|
||||
session_init, session_exit, resize, display, keyboard);
|
||||
session_init, session_exit, resize, display, keyboard, motion);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue