diff --git a/src/main.cpp b/src/main.cpp index a4e347f..51564f2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -59,7 +59,8 @@ void *process_cin(void* args) { glm::vec4 &transl = std::get<1>(camera_bodies[i])->pose[3]; transl = 0.9f*transl + 0.1f*glm::vec4(new_loc, 1); // filter - std::get<1>(camera_bodies[i])->color = glm::vec4(i&0x4, i&0x2, i&0x1, 1); + int color_i = i + 1; + std::get<1>(camera_bodies[i])->color = glm::vec4(color_i&0x4, color_i&0x2, color_i&0x1, 1); std::get<2>(camera_bodies[i]) = max_hp; found_match = true; } else if (std::get<1>(camera_bodies[i])) { @@ -94,22 +95,26 @@ static glm::vec4 strafe_y = camera_t[1]; static void cursor_position_callback(GLFWwindow* window, double xpos, double ypos) { float dx = (xpos - prev_cursor_x); float dy = (ypos - prev_cursor_y); + strafe_x = camera_t[0]; + strafe_y = camera_t[1]; prev_cursor_x = xpos; prev_cursor_y = ypos; + if (mouse_pressed) { phi += dx / width * glm::radians(360.0); theta += dy / height * glm::radians(360.0); + double len = glm::length(camera_loc - focal_point); + camera_loc.x = focal_point.x + (len * glm::cos(theta) * glm::cos(-phi)); + camera_loc.y = focal_point.y + (len * glm::sin(theta)); + camera_loc.z = focal_point.z + (-len * glm::cos(theta) * glm::sin(-phi)); } if (scroll_pressed) { - focal_point += strafe_x * (dx / 300) + strafe_y * (dy / 300); + glm::vec4 move_vec = -strafe_x * (dx / 100) + strafe_y * (dy / 100); + focal_point += move_vec; + camera_loc += move_vec; } - double len = glm::length(camera_loc); - camera_loc.x = len * glm::cos(theta) * glm::cos(-phi); - camera_loc.y = len * glm::sin(theta); - camera_loc.z = -len * glm::cos(theta) * glm::sin(-phi); - camera_t = glm::lookAt(camera_loc, focal_point, up); }