Cleaned up input with IMGUI while using mouse look
This commit is contained in:
parent
6d353814fc
commit
703fe88fa6
@ -67,11 +67,16 @@ Input::Input(INPUT_PTR in) : in(in) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
glfwSetInputMode(in, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
void Input::setCursor(bool enabled) {
|
||||||
|
glfwSetInputMode(in, GLFW_CURSOR, enabled? GLFW_CURSOR_NORMAL : GLFW_CURSOR_DISABLED);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Input::handleMovementKeys(Renderer& ren) {
|
void Input::handleMovementKeys(Renderer& ren) {
|
||||||
|
if (ImGui::GetIO().WantCaptureKeyboard)
|
||||||
|
return;
|
||||||
|
|
||||||
const auto forward = glm::vec3(glm::cos(ren.cam.phi), 0.0, glm::sin(ren.cam.phi));
|
const auto forward = glm::vec3(glm::cos(ren.cam.phi), 0.0, glm::sin(ren.cam.phi));
|
||||||
const auto right = glm::cross(forward, glm::vec3(0.0, 1.0, 0.0));
|
const auto right = glm::cross(forward, glm::vec3(0.0, 1.0, 0.0));
|
||||||
const auto speed = glfwGetKey(in, GLFW_KEY_LEFT_SHIFT)? 2.0f : 1.0f;
|
const auto speed = glfwGetKey(in, GLFW_KEY_LEFT_SHIFT)? 2.0f : 1.0f;
|
||||||
@ -129,6 +134,15 @@ void Input::handleCursorMovement(Renderer& ren, double x, double y) {
|
|||||||
int rel_mouse_x = static_cast<int>(x) - last_mouse.x;
|
int rel_mouse_x = static_cast<int>(x) - last_mouse.x;
|
||||||
int rel_mouse_y = static_cast<int>(y) - last_mouse.y;
|
int rel_mouse_y = static_cast<int>(y) - last_mouse.y;
|
||||||
|
|
||||||
|
auto& io = ImGui::GetIO();
|
||||||
|
if (io.WantCaptureMouse)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!ren.capture_mouse) {
|
||||||
|
io.AddMousePosEvent(x, y);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ren.cam.phi += rel_mouse_x / 100.0;
|
ren.cam.phi += rel_mouse_x / 100.0;
|
||||||
ren.cam.theta += rel_mouse_y / 100.0;
|
ren.cam.theta += rel_mouse_y / 100.0;
|
||||||
|
|
||||||
|
|||||||
@ -72,5 +72,7 @@ struct Input {
|
|||||||
void handleMovementKeys(Renderer& ren);
|
void handleMovementKeys(Renderer& ren);
|
||||||
void handleCursorMovement(Renderer& ren, double x, double y);
|
void handleCursorMovement(Renderer& ren, double x, double y);
|
||||||
|
|
||||||
|
void setCursor(bool enabled);
|
||||||
|
|
||||||
bool shouldClose();
|
bool shouldClose();
|
||||||
};
|
};
|
||||||
@ -61,4 +61,6 @@ struct Renderer {
|
|||||||
std::unique_ptr<UI> ui;
|
std::unique_ptr<UI> ui;
|
||||||
|
|
||||||
Camera cam {};
|
Camera cam {};
|
||||||
|
|
||||||
|
bool capture_mouse = false;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -91,7 +91,7 @@ void UI::newFrame() {
|
|||||||
|
|
||||||
ImGui::Text("FPS: %f", info.fps);
|
ImGui::Text("FPS: %f", info.fps);
|
||||||
ImGui::SliderAngle("Theta", &info.cam.theta, 0.01, 179.9);
|
ImGui::SliderAngle("Theta", &info.cam.theta, 0.01, 179.9);
|
||||||
ImGui::SliderAngle("Phi", &info.cam.phi);
|
ImGui::SliderAngle("Phi", &info.cam.phi, 0.0, 360.0, "%.0f def");
|
||||||
ImGui::SliderFloat("cam.x", &info.cam.pos.x, -1e2, 1e2);
|
ImGui::SliderFloat("cam.x", &info.cam.pos.x, -1e2, 1e2);
|
||||||
ImGui::SliderFloat("cam.y", &info.cam.pos.y, -1e2, 1e2);
|
ImGui::SliderFloat("cam.y", &info.cam.pos.y, -1e2, 1e2);
|
||||||
ImGui::SliderFloat("cam.z", &info.cam.pos.z, -1e2, 1e2);
|
ImGui::SliderFloat("cam.z", &info.cam.pos.z, -1e2, 1e2);
|
||||||
|
|||||||
@ -40,6 +40,12 @@ int main(int argc, char* argv[]) {
|
|||||||
break;
|
break;
|
||||||
case InputEvent::Tag::eBUTTON:
|
case InputEvent::Tag::eBUTTON:
|
||||||
break;
|
break;
|
||||||
|
case InputEvent::Tag::eKEY:
|
||||||
|
if (event.key.key == GLFW_KEY_ESCAPE && event.key.state == GLFW_PRESS) {
|
||||||
|
ren.capture_mouse = !ren.capture_mouse;
|
||||||
|
in->setCursor(!ren.capture_mouse);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user