Add mouse offset to Input
This commit is contained in:
@@ -1,11 +1,42 @@
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include "inferno/application.h"
|
||||
#include "inferno/event/mouseevent.h"
|
||||
#include "inferno/input.h"
|
||||
#include "inferno/window.h"
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
bool Input::m_firstMousePos = true;
|
||||
float Input::m_xPosLast = 0.0f;
|
||||
float Input::m_yPosLast = 0.0f;
|
||||
float Input::m_xOffset = 0.0f;
|
||||
float Input::m_yOffset = 0.0f;
|
||||
|
||||
void Input::update()
|
||||
{
|
||||
m_xOffset = 0.0f;
|
||||
m_yOffset = 0.0f;
|
||||
}
|
||||
|
||||
bool Input::onMousePosition(MousePositionEvent &e)
|
||||
{
|
||||
// Prevent weird jump on first cursor window enter
|
||||
if(m_firstMousePos) {
|
||||
m_firstMousePos = false;
|
||||
m_xPosLast = e.getXPos();
|
||||
m_yPosLast = e.getYPos();
|
||||
}
|
||||
|
||||
m_xOffset = e.getXPos() - m_xPosLast;
|
||||
// Reversed since y-coordinates range from bottom to top
|
||||
m_yOffset = m_yPosLast - e.getYPos();
|
||||
m_xPosLast = e.getXPos();
|
||||
m_yPosLast = e.getYPos();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Input::isKeyPressed(int key)
|
||||
{
|
||||
GLFWwindow* w = Application::get().getWindow().getWindow();
|
||||
|
||||
@@ -1,20 +1,35 @@
|
||||
#ifndef INPUT_H
|
||||
#define INPUT_H
|
||||
|
||||
#include <utility>
|
||||
#include <utility> // std::pair
|
||||
|
||||
namespace Inferno {
|
||||
|
||||
class MousePositionEvent;
|
||||
|
||||
class Input {
|
||||
public:
|
||||
static void update();
|
||||
|
||||
static bool onMousePosition(MousePositionEvent &e);
|
||||
|
||||
static bool isKeyPressed(int key);
|
||||
static bool isMouseButtonPressed(int button);
|
||||
static std::pair<float, float> getMousePosition();
|
||||
static float getMouseX();
|
||||
static float getMouseY();
|
||||
|
||||
static inline float getXOffset() { return m_xOffset; }
|
||||
static inline float getYOffset() { return m_yOffset; }
|
||||
|
||||
private:
|
||||
static bool m_firstMousePos;
|
||||
static float m_xPosLast;
|
||||
static float m_yPosLast;
|
||||
static float m_xOffset;
|
||||
static float m_yOffset;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // INPUT_H
|
||||
|
||||
Reference in New Issue
Block a user