Cursors now works!
This commit is contained in:
parent
c64b7b4bde
commit
6d353814fc
@ -9,6 +9,8 @@
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include <imgui/imgui_impl_glfw.h>
|
||||
|
||||
bool Input::shouldClose() {
|
||||
return glfwWindowShouldClose(in);
|
||||
}
|
||||
@ -65,6 +67,8 @@ Input::Input(INPUT_PTR in) : in(in) {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
glfwSetInputMode(in, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
||||
}
|
||||
|
||||
void Input::handleMovementKeys(Renderer& ren) {
|
||||
@ -108,6 +112,28 @@ void Input::handleMovementKeys(Renderer& ren) {
|
||||
ren.cam.pos += right * 0.1f * speed;
|
||||
}
|
||||
|
||||
if(glfwGetKey(in, GLFW_KEY_SPACE)) {
|
||||
ren.cam.pos.y += 0.1;
|
||||
}
|
||||
|
||||
if(glfwGetKey(in, GLFW_KEY_LEFT_CONTROL)) {
|
||||
ren.cam.pos.y -= 0.1;
|
||||
}
|
||||
|
||||
ren.cam.theta = glm::clamp(ren.cam.theta, 0.01f, glm::pi<float>() - 0.01f);
|
||||
ren.cam.phi = glm::mod(ren.cam.phi, glm::two_pi<float>());
|
||||
}
|
||||
|
||||
|
||||
void Input::handleCursorMovement(Renderer& ren, double x, double y) {
|
||||
int rel_mouse_x = static_cast<int>(x) - last_mouse.x;
|
||||
int rel_mouse_y = static_cast<int>(y) - last_mouse.y;
|
||||
|
||||
ren.cam.phi += rel_mouse_x / 100.0;
|
||||
ren.cam.theta += rel_mouse_y / 100.0;
|
||||
|
||||
last_mouse = glm::vec2(x,y);
|
||||
|
||||
ren.cam.theta = glm::clamp(ren.cam.theta, 0.01f, glm::pi<float>() - 0.01f);
|
||||
ren.cam.phi = glm::mod(ren.cam.phi, glm::two_pi<float>());
|
||||
}
|
||||
@ -7,6 +7,8 @@
|
||||
#include <queue>
|
||||
#include <util/int.hpp>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
enum InputModifierBit {
|
||||
eNONE = 0x00,
|
||||
eSHIFT = 0x01,
|
||||
@ -61,11 +63,14 @@ struct Input {
|
||||
|
||||
INPUT_PTR in;
|
||||
|
||||
glm::vec2 last_mouse = glm::vec2(0.0f, 0.0f);
|
||||
|
||||
void poll();
|
||||
|
||||
std::queue<InputEvent> queue;
|
||||
|
||||
void handleMovementKeys(Renderer& ren);
|
||||
void handleCursorMovement(Renderer& ren, double x, double y);
|
||||
|
||||
bool shouldClose();
|
||||
};
|
||||
@ -5,6 +5,7 @@
|
||||
|
||||
#include <util/int.hpp>
|
||||
|
||||
#include <memory>
|
||||
|
||||
struct Buffer;
|
||||
struct Image;
|
||||
|
||||
@ -191,7 +191,7 @@ Renderer::Renderer(Window& win) : win(win) {
|
||||
|
||||
/* initialize models */
|
||||
// models.push_back(std::make_shared<Model>(phys_dev, dev, "assets/models/dragon.gltf"));
|
||||
models.push_back(std::make_shared<Model>(phys_dev, dev, "assets/models/monk.gltf"));
|
||||
models.push_back(std::make_shared<Model>(phys_dev, dev, "assets/models/dragon.gltf"));
|
||||
|
||||
Log::debug("#%zu vertex indices\n", models[0]->indices.size());
|
||||
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
|
||||
#include <Scene/Camera.hpp>
|
||||
|
||||
UI::UI(Renderer* ren) : dev(ren->dev), info{ .cam = ren->cam } {
|
||||
UI::UI(Renderer* ren) : info{ .cam = ren->cam }, dev(ren->dev) {
|
||||
IMGUI_CHECKVERSION();
|
||||
ImGui::CreateContext();
|
||||
|
||||
@ -71,7 +71,7 @@ UI::UI(Renderer* ren) : dev(ren->dev), info{ .cam = ren->cam } {
|
||||
.pCommandBuffers = &imgui_cmd_buffer.command_buffer,
|
||||
}, imgui_fence);
|
||||
|
||||
ren->dev.waitForFences(imgui_fence, vk::True, UINT64_MAX);
|
||||
(void)ren->dev.waitForFences(imgui_fence, vk::True, UINT64_MAX);
|
||||
|
||||
ren->dev.destroyFence(imgui_fence);
|
||||
|
||||
|
||||
@ -13,6 +13,6 @@ layout (set = 0, binding = 1) uniform sampler2D tex;
|
||||
|
||||
void main() {
|
||||
//FragColor = vec4(1.0);
|
||||
FragColor = texture(tex, texCoord);
|
||||
FragColor = texture(tex, texCoord) * vec4(norm, 1.0);
|
||||
// FragColor = vec4(texCoord, 0.0, 1.0);
|
||||
}
|
||||
Binary file not shown.
@ -36,6 +36,7 @@ int main(int argc, char* argv[]) {
|
||||
win.close();
|
||||
break;
|
||||
case InputEvent::Tag::eCURSOR:
|
||||
in->handleCursorMovement(ren, event.pos.x, event.pos.y);
|
||||
break;
|
||||
case InputEvent::Tag::eBUTTON:
|
||||
break;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user