Skip to content

Commit

Permalink
add mousemovement callback method to application_solar
Browse files Browse the repository at this point in the history
  • Loading branch information
wobakj committed Oct 19, 2016
1 parent 25f7630 commit 1820f67
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 1 deletion.
3 changes: 3 additions & 0 deletions application/include/application_solar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class ApplicationSolar : public Application {
void updateProjection();
// react to key input
void keyCallback(int key, int scancode, int action, int mods);
//handle delta mouse movement input
void mouseCallback(double pos_x, double pos_y);

// draw all objects
void render() const;

Expand Down
5 changes: 5 additions & 0 deletions application/source/application_solar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ void ApplicationSolar::keyCallback(int key, int scancode, int action, int mods)
}
}

//handle delta mouse movement input
void ApplicationSolar::mouseCallback(double pos_x, double pos_y) {
// mouse handling
}

// load shader programs
void ApplicationSolar::initializeShaderPrograms() {
// store shader program objects in container
Expand Down
5 changes: 4 additions & 1 deletion framework/include/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ class Application {
virtual void updateProjection() = 0;
// react to key input
inline virtual void keyCallback(int key, int scancode, int action, int mods) {};
//
//handle delta mouse movement input
inline virtual void mouseCallback(double pos_x, double pos_y) {};

// give shader programs to launcher
virtual std::map<std::string, shader_program>& getShaderPrograms();
// draw all objects
virtual void render() const = 0;
Expand Down
3 changes: 3 additions & 0 deletions framework/include/launcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class Launcher {
void update_shader_programs(bool throwing);
// handle key input
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods);
//handle mouse movement input
void mouse_callback(GLFWwindow* window, double pos_x, double pos_y);

// calculate fps and show in window title
void show_fps();
// free resources
Expand Down
12 changes: 12 additions & 0 deletions framework/source/launcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ void Launcher::initialize() {
glfwSetKeyCallback(m_window, key_func);
// allow free mouse movement
glfwSetInputMode(m_window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
auto mouse_func = [](GLFWwindow* w, double a, double b) {
static_cast<Launcher*>(glfwGetWindowUserPointer(w))->mouse_callback(w, a, b);
};
glfwSetCursorPosCallback(m_window, mouse_func);
// allow free mouse movement
// register resizing function
auto resize_func = [](GLFWwindow* w, int a, int b) {
static_cast<Launcher*>(glfwGetWindowUserPointer(w))->update_projection(w, a, b);
Expand Down Expand Up @@ -201,6 +206,13 @@ void Launcher::key_callback(GLFWwindow* m_window, int key, int scancode, int act
m_application->keyCallback(key, scancode, action, mods);
}

//handle mouse movement input
void Launcher::mouse_callback(GLFWwindow* window, double pos_x, double pos_y) {
m_application->mouseCallback(pos_x, pos_y);
// reset cursor pos to receive position delta next frame
glfwSetCursorPos(m_window, 0.0, 0.0);
}

// calculate fps and show in m_window title
void Launcher::show_fps() {
++m_frames_per_second;
Expand Down

0 comments on commit 1820f67

Please sign in to comment.