X-Git-Url: https://eleni.mutantstargoat.com/git/?p=demo;a=blobdiff_plain;f=src%2Fmain.cc;h=4d77441ffdb89e5a103a4a4259dffb519a3f32b9;hp=4e6677adbe09132acd32c9cc8c8bd65e3ce0ef4b;hb=369d75c73bf926a6dbcf4d740c8664bbb401602a;hpb=0da7a98f74d00bfa6cf0d47fd7cf0f687eeba5f6 diff --git a/src/main.cc b/src/main.cc index 4e6677a..4d77441 100644 --- a/src/main.cc +++ b/src/main.cc @@ -30,9 +30,13 @@ GLFWwindow *win; int win_w = 800; int win_h = 600; -Camera *camera; +OrbitCamera *camera; /* variables */ +static float phi = 25; +static float theta = 0; +static float dist = 4; + // TODO: remove just for test: static Scene scene; @@ -90,7 +94,8 @@ static bool init() return false; } - camera = new Camera(25, 25, 4, 45); + camera = new OrbitCamera; + camera->set_orbit_params(phi, theta, dist); if(!scene.load("data/spot/spot_control_mesh.obj")) { fprintf(stderr, "Failed to load scene.\n"); @@ -127,34 +132,37 @@ static void key_clbk(GLFWwindow *win, int key, int scancode, int action, int mod } static double prev_x, prev_y; -static int bnstate[8]; +static int button; static void motion_clbk(GLFWwindow *win, double x, double y) { - int dx = x - prev_x; - int dy = y - prev_y; + switch(button) { + case GLFW_MOUSE_BUTTON_LEFT: + theta += x - prev_x; + phi += y - prev_y; + + if(phi < -90) + phi = -90; + if(phi > 90) + phi = 90; + + break; + + case GLFW_MOUSE_BUTTON_RIGHT: + dist *= (y - prev_y) * 0.01 + 1; + if(dist < 0.0) { + dist = 0.0; + } + break; + } prev_x = x; prev_y = y; - - if(!dx && !dy) return; - - if(bnstate[0]) { - camera->theta += dx * 0.5; - camera->phi += dy * 0.5; - - if(camera->phi < -90) camera->phi = -90; - if(camera->phi > 90) camera->phi = 90; - } - if(bnstate[2]) { - camera->distance += dy * 0.1; - if(camera->distance < 0.0) camera->distance = 0.0; - } } static void mouse_clbk(GLFWwindow *win, int bn, int action, int mods) { - bnstate[bn - GLFW_MOUSE_BUTTON_LEFT] = action == GLFW_PRESS ? 1 : 0; + button = bn; glfwGetCursorPos(win, &prev_x, &prev_y); }