diff --git a/Input/Input.cpp b/Input/Input.cpp index b79a2c5..c9e26d1 100644 --- a/Input/Input.cpp +++ b/Input/Input.cpp @@ -79,10 +79,11 @@ void Input::handleMovementKeys(Renderer& ren) { glm::vec3 forward; if (ren.flycam) - forward = glm::vec3(glm::sin(ren.cam.theta)*glm::cos(ren.cam.phi), glm::cos(ren.cam.theta), glm::sin(ren.cam.theta)*glm::sin(ren.cam.phi)); - else - 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)); + forward = glm::normalize(glm::vec3(glm::sin(ren.cam.theta)*glm::cos(ren.cam.phi), glm::cos(ren.cam.theta), glm::sin(ren.cam.theta)*glm::sin(ren.cam.phi))); + else { + forward = glm::normalize(glm::vec3(glm::cos(ren.cam.phi), 0.0, glm::sin(ren.cam.phi))); + } + const auto right = glm::normalize(glm::cross(forward, glm::vec3(0.0, 1.0, 0.0))); auto speed = glfwGetKey(in, GLFW_KEY_LEFT_SHIFT)? 2.0f : 1.0f; speed *= ren.speed; @@ -143,7 +144,7 @@ void Input::handleCursorMovement(Renderer& ren, double x, double y) { if (io.WantCaptureMouse) return; - if (!ren.capture_mouse) { + if (ren.in_menu) { io.AddMousePosEvent(x, y); return; } diff --git a/Renderer/Renderer.hpp b/Renderer/Renderer.hpp index 8c5da50..bc47b5b 100644 --- a/Renderer/Renderer.hpp +++ b/Renderer/Renderer.hpp @@ -72,7 +72,7 @@ struct Renderer { float fps; - bool capture_mouse = false; + bool in_menu = false; bool flycam = false; /* time speed */ float time = 0.0; diff --git a/Scene/BSP.cpp b/Scene/BSP.cpp index 14857d7..96b0fc9 100644 --- a/Scene/BSP.cpp +++ b/Scene/BSP.cpp @@ -127,7 +127,8 @@ bool BSP::determine_visibility(const Leaf& cam_leaf, const Leaf& leaf, const std } /* changes handedness by swapping z and y */ -static inline void change_swizzle(glm::vec3& v) { +template +static inline void change_swizzle(T& v) { auto tmp = v.y; v.y = v.z; v.z = tmp; @@ -152,10 +153,22 @@ BSP::BSP(vk::PhysicalDevice phys_dev, vk::Device dev, const std::string& fname) change_swizzle(plane.norm); } copy_data(file_data.data(), nodes, header->nodes); + for (auto& node : nodes) { + change_swizzle(node.bb_mins); + change_swizzle(node.bb_maxes); + } copy_data(file_data.data(), leafs, header->leafs); + for (auto& leaf : leafs) { + change_swizzle(leaf.bb_mins); + change_swizzle(leaf.bb_maxes); + } copy_data(file_data.data(), leaf_faces, header->leaf_faces); copy_data(file_data.data(), leaf_brushes, header->leaf_brushes); copy_data(file_data.data(), models, header->models); + for (auto& model : models) { + change_swizzle(model.bb_mins); + change_swizzle(model.bb_maxes); + } copy_data(file_data.data(), brushes, header->brushes); copy_data(file_data.data(), brush_sides, header->brush_sides); copy_data(file_data.data(), vertices, header->vertices); diff --git a/pléascach.cpp b/pléascach.cpp index d09e5c5..881fce6 100644 --- a/pléascach.cpp +++ b/pléascach.cpp @@ -56,11 +56,17 @@ int main(int argc, char* argv[]) { case InputEvent::Tag::eBUTTON: break; case InputEvent::Tag::eKEY: + if (event.key.key == GLFW_KEY_ESCAPE && event.key.state == GLFW_PRESS) { + ren.in_menu = !ren.in_menu; + in->setCursor(ren.in_menu); + break; + } + + if (ren.in_menu) + break; + if (event.key.key == GLFW_KEY_Q) { return 0; - } else if (event.key.key == GLFW_KEY_ESCAPE && event.key.state == GLFW_PRESS) { - ren.capture_mouse = !ren.capture_mouse; - in->setCursor(!ren.capture_mouse); } else if (event.key.key == GLFW_KEY_R && event.key.state == GLFW_PRESS) { ren.time = 0; } else if (event.key.key == GLFW_KEY_C && event.key.state == GLFW_PRESS) { diff --git a/util/geo.hpp b/util/geo.hpp index e5d4ba5..371b577 100644 --- a/util/geo.hpp +++ b/util/geo.hpp @@ -20,20 +20,21 @@ static glm::vec4 extract_plane(const glm::mat4& mat, int col) { /* extracts frustum from projection matrix */ static std::array frustum(const glm::mat4& mat) { /* Left, Right, Top, Bottom, Back, Front */ - return std::array { + std::array ret; /* { extract_plane(mat, 1), extract_plane(mat, -1), extract_plane(mat, 2), extract_plane(mat, -2), extract_plane(mat, 3), extract_plane(mat, -3), - }; + };*/ - /*for (size_t i = 0; i < 3; i++) + for (size_t i = 0; i < 3; i++) for (size_t j = 0; j < 4; j++) ret[i * 2][j] = mat[j].w + mat[j][i], - ret[i * 2 + 1][j] = mat[j].w - mat[j][i];*/ + ret[i * 2 + 1][j] = mat[j].w - mat[j][i]; + return ret; } static bool box_in_frustum(const std::array& frustum, const glm::vec3 box_verts[8]) {