Skip to content
Snippets Groups Projects
Commit 5792db23 authored by Joseph Walton-Rivers's avatar Joseph Walton-Rivers
Browse files

use NDC for mouse axis

parent 6cc0b228
No related branches found
No related tags found
No related merge requests found
......@@ -55,7 +55,7 @@ camera_type cam_mode = cam_free;
using namespace fggl::input;
using InputManager = std::shared_ptr<fggl::input::Input>;
void process_arcball(fggl::gfx::Window& window, fggl::ecs::ECS& ecs, InputManager input, fggl::ecs::entity_t cam) {
void process_arcball(fggl::ecs::ECS& ecs, InputManager input, fggl::ecs::entity_t cam) {
// see https://asliceofrendering.com/camera/2019/11/30/ArcballCamera/
auto camTransform = ecs.getComponent<fggl::math::Transform>(cam);
auto camComp = ecs.getComponent<fggl::gfx::Camera>(cam);
......@@ -67,8 +67,8 @@ void process_arcball(fggl::gfx::Window& window, fggl::ecs::ECS& ecs, InputManage
glm::vec3 viewDir = -glm::transpose(view)[2];
glm::vec3 rightDir = glm::transpose(view)[0];
float deltaAngleX = ( 2 * M_PI / window.width() );
float deltaAngleY = ( M_PI / window.height() );
float deltaAngleX = ( 2 * M_PI );
float deltaAngleY = ( M_PI );
float xAngle = ( -mouse.axisDelta(fggl::input::MouseAxis::X) ) * deltaAngleX;
float yAngle = ( -mouse.axisDelta(fggl::input::MouseAxis::Y) ) * deltaAngleY;
......@@ -170,14 +170,14 @@ void process_camera(fggl::gfx::Window& window, fggl::ecs::ECS& ecs, InputManager
// scroll wheel
glm::vec3 motion(0.0f);
float delta = input->mouse.axisDelta( fggl::input::MouseAxis::SCROLL_Y );
float delta = input->mouse.axis( fggl::input::MouseAxis::SCROLL_Y );
if ( (glm::length( dir ) < 25.0f && delta < 0.0f) || (glm::length( dir ) > 2.5f && delta > 0.0f) )
motion -= (forward * delta);
camTransform->origin( camTransform->origin() + motion );
if ( cam_mode == cam_arcball || input->mouse.button( fggl::input::MouseButton::MIDDLE ) ) {
process_arcball(window, ecs, input, cam);
process_arcball(ecs, input, cam);
} else if ( cam_mode == cam_free ) {
process_freecam(ecs, input, cam);
}
......
#include "window.hpp"
#include "window_input.hpp"
......@@ -6,8 +5,6 @@
#include <string>
#include <stdexcept>
#include <GLFW/glfw3.h>
using namespace fggl::gfx;
static void glfw_error(int code, const char* description) {
......@@ -24,6 +21,15 @@ static void framebuffer_resize(GLFWwindow* window, int width, int height) {
static void fggl_input_cursor(GLFWwindow* window, double x, double y) {
auto& input = GlfwInputManager::instance();
auto fgglWin = (Window*)glfwGetWindowUserPointer(window);
#ifndef FGGL_INPUT_SCREEN_COORDS
// convert to nice ranges...
x = (x / fgglWin->width() * 2) - 1.0; // [-1, 1]
y = (y / fgglWin->height() * 2) - 1.0; // [-1, 1]
#endif
// inform the input system
input.onMouseMove(x, y);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment