69 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			C++
		
	
	
	
			
		
		
	
	
			69 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			C++
		
	
	
	
#include <glm/glm.hpp>
 | 
						|
 | 
						|
#include "callbacks.h"
 | 
						|
#include "interface.h"
 | 
						|
 | 
						|
namespace Callbacks {
 | 
						|
   Scene* scene_ = nullptr;
 | 
						|
};
 | 
						|
 | 
						|
void Callbacks::Register(GLFWwindow* window, Scene* scene)
 | 
						|
{
 | 
						|
   scene_ = scene;
 | 
						|
 | 
						|
   glfwSetKeyCallback(window, Keyboard);
 | 
						|
   glfwSetCursorPosCallback(window, MouseCursor);
 | 
						|
   glfwSetMouseButtonCallback(window, MouseButton);
 | 
						|
   glfwSetFramebufferSizeCallback(window, Resize);
 | 
						|
}
 | 
						|
 | 
						|
//This function gets called when a key is pressed
 | 
						|
void Callbacks::Keyboard(GLFWwindow* window, int key, int scancode, int action, int mods)
 | 
						|
{
 | 
						|
   //std::cout << "key : " << key << ", " << char(key) << ", scancode: " << scancode << ", action: " << action << ", mods: " << mods << std::endl;
 | 
						|
 | 
						|
   if (action == GLFW_PRESS)
 | 
						|
   {
 | 
						|
      switch (key)
 | 
						|
      {
 | 
						|
      case 'r':
 | 
						|
      case 'R':
 | 
						|
         if (scene_) {
 | 
						|
            scene_->ReloadShader();
 | 
						|
         }
 | 
						|
         break;
 | 
						|
      case GLFW_KEY_ESCAPE:
 | 
						|
         glfwSetWindowShouldClose(window, GLFW_TRUE);
 | 
						|
         break;
 | 
						|
      }
 | 
						|
   }
 | 
						|
}
 | 
						|
 | 
						|
//This function gets called when the mouse moves over the window.
 | 
						|
void Callbacks::MouseCursor(GLFWwindow* window, double x, double y)
 | 
						|
{
 | 
						|
   //std::cout << "cursor pos: " << x << ", " << y << std::endl;
 | 
						|
}
 | 
						|
 | 
						|
//This function gets called when a mouse button is pressed.
 | 
						|
void Callbacks::MouseButton(GLFWwindow* window, int button, int action, int mods)
 | 
						|
{
 | 
						|
   //std::cout << "button : "<< button << ", action: " << action << ", mods: " << mods << std::endl;
 | 
						|
}
 | 
						|
 | 
						|
void Callbacks::Resize(GLFWwindow* window, int width, int height)
 | 
						|
{
 | 
						|
   Window* viewport = Interface::GetWindowByName(scene_->windows_, "Viewport");
 | 
						|
 | 
						|
   scene_->window_width = static_cast<int>(viewport->size.x);
 | 
						|
   scene_->window_height = static_cast<int>(viewport->size.y);
 | 
						|
   
 | 
						|
   scene_->OnScreenResize(viewport);
 | 
						|
 | 
						|
   //Set aspect ratio used in view matrix calculation
 | 
						|
   // scene_->window_width = width;
 | 
						|
   // scene_->window_height = height;
 | 
						|
   // scene_->Scene::UpdateCamera();
 | 
						|
   //Scene::Camera::Aspect = float(width) / float(height);
 | 
						|
   //Scene::Camera::UpdateP();
 | 
						|
} |