From 7d7ed5367cb2690f4018b00abf42f03efb78decc Mon Sep 17 00:00:00 2001 From: MitchellHansen Date: Sat, 14 Jan 2017 15:40:23 -0800 Subject: [PATCH] Fixed the held keys, now occasionally a key will stick though --- src/Camera.cpp | 16 ++++++++-------- src/Input.cpp | 4 ++-- src/main.cpp | 29 +++++++---------------------- 3 files changed, 17 insertions(+), 32 deletions(-) diff --git a/src/Camera.cpp b/src/Camera.cpp index 0b938a0..01a9d4b 100644 --- a/src/Camera.cpp +++ b/src/Camera.cpp @@ -93,31 +93,31 @@ void Camera::recieve_event(VrEventPublisher* publisher, std::unique_ptr(event.get()); - float speed = 1.0f; + default_impulse = 1.0f; if (held_event->code == sf::Keyboard::LShift) { - speed = 0.2f; + default_impulse = 0.2f; } else if (held_event->code == sf::Keyboard::C) { look_at_center(); } else if (held_event->code == sf::Keyboard::Q) { - add_relative_impulse(Camera::DIRECTION::DOWN, speed); + add_relative_impulse(Camera::DIRECTION::DOWN, default_impulse); } else if (held_event->code == sf::Keyboard::E) { - add_relative_impulse(Camera::DIRECTION::UP, speed); + add_relative_impulse(Camera::DIRECTION::UP, default_impulse); } else if (held_event->code == sf::Keyboard::W) { - add_relative_impulse(Camera::DIRECTION::FORWARD, speed); + add_relative_impulse(Camera::DIRECTION::FORWARD, default_impulse); } else if (held_event->code == sf::Keyboard::S) { - add_relative_impulse(Camera::DIRECTION::REARWARD, speed); + add_relative_impulse(Camera::DIRECTION::REARWARD, default_impulse); } else if (held_event->code == sf::Keyboard::A) { - add_relative_impulse(Camera::DIRECTION::LEFT, speed); + add_relative_impulse(Camera::DIRECTION::LEFT, default_impulse); } else if (held_event->code == sf::Keyboard::D) { - add_relative_impulse(Camera::DIRECTION::RIGHT, speed); + add_relative_impulse(Camera::DIRECTION::RIGHT, default_impulse); } else if (held_event->code == sf::Keyboard::T) { set_position(sf::Vector3f(50, 50, 50)); diff --git a/src/Input.cpp b/src/Input.cpp index dbafc28..b24347b 100644 --- a/src/Input.cpp +++ b/src/Input.cpp @@ -46,7 +46,7 @@ void Input::handle_held_keys() { } else if (event->type == vr::Event::KeyReleased) { vr::KeyReleased *e = static_cast(event.get()); - std::remove(held_keys.begin(), held_keys.end(), e->code); + held_keys.erase(std::remove(held_keys.begin(), held_keys.end(), e->code), held_keys.end()); } else if (event->type == vr::Event::MouseButtonPressed) { vr::MouseButtonPressed *e = static_cast(event.get()); @@ -54,7 +54,7 @@ void Input::handle_held_keys() { } else if (event->type == vr::Event::MouseButtonReleased) { vr::MouseButtonReleased *e = static_cast(event.get()); - std::remove(held_mouse_buttons.begin(), held_mouse_buttons.end(), e->button); + held_keys.erase(std::remove(held_keys.begin(), held_keys.end(), e->button), held_keys.end()); } } diff --git a/src/main.cpp b/src/main.cpp index aa1e2d7..0f59683 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,7 @@ -#include "GL_Testing.h" + +// This has to be up here or else glew will complain +#include "GL_Testing.h" + #ifdef linux #include #include @@ -17,28 +20,22 @@ # include #include #include - #endif #pragma once #include #include -#include -#include - - #include #include "Old_Map.h" #include "util.hpp" #include "RayCaster.h" #include "Hardware_Caster.h" #include "Vector4.hpp" -#include +#include "Camera.h" #include "Software_Caster.h" #include "Input.h" #include "Pub_Sub.h" - const int WINDOW_X = 1920; const int WINDOW_Y = 1080; const int WORK_SIZE = WINDOW_X * WINDOW_Y; @@ -164,18 +161,6 @@ int main() { sf::Event event; while (window.pollEvent(event)) { - if (event.type == sf::Event::Closed) - window.close(); - - if (event.type == sf::Event::KeyPressed) { - std::cout << event.key.code << std::endl; - } - if (event.type == sf::Event::KeyReleased) { - std::cout << event.key.code << std::endl; - } - - - if (event.type == sf::Event::KeyPressed) { if (event.key.code == sf::Keyboard::M) { if (mouse_enabled) @@ -208,8 +193,8 @@ int main() { sf::Mouse::setPosition(fixed); prev_pos = sf::Mouse::getPosition(); camera->slew_camera(sf::Vector2f( - deltas.y / 300.0f, - deltas.x / 300.0f + deltas.y / 600.0f, + deltas.x / 600.0f )); } }