Skip to content
Snippets Groups Projects
Verified Commit fec73717 authored by Tobias Frisch's avatar Tobias Frisch
Browse files

Merge branch '34-resizing-event' of...

Merge branch '34-resizing-event' of gitlab.uni-koblenz.de:vulkan2021/vkcv-framework into 34-resizing-event
parents 38098a4a 2406d39c
No related branches found
No related tags found
1 merge request!43Resolve "Resizing-Event"
Pipeline #25425 failed
...@@ -63,7 +63,7 @@ namespace vkcv { ...@@ -63,7 +63,7 @@ namespace vkcv {
void changeFov(double fov); void changeFov(double fov);
void updateRatio(float ratio); void updateRatio(int width, int height);
float getRatio() const; float getRatio() const;
......
...@@ -9,10 +9,11 @@ namespace vkcv{ ...@@ -9,10 +9,11 @@ namespace vkcv{
class CameraManager{ class CameraManager{
private: private:
std::function<void(int, int, int, int)> m_keyHandle; std::function<void(int, int, int, int)> e_keyHandle;
std::function<void(double, double)> m_mouseMoveHandle; std::function<void(double, double)> e_mouseMoveHandle;
std::function<void(double, double)> m_mouseScrollHandle; std::function<void(double, double)> e_mouseScrollHandle;
std::function<void(int, int, int)> m_mouseButtonHandle; std::function<void(int, int, int)> e_mouseButtonHandle;
std::function<void(int, int)> e_resizeHandle;
Window &m_window; Window &m_window;
Camera m_camera; Camera m_camera;
...@@ -29,6 +30,7 @@ namespace vkcv{ ...@@ -29,6 +30,7 @@ namespace vkcv{
void scrollCallback( double offsetX, double offsetY); void scrollCallback( double offsetX, double offsetY);
void mouseMoveCallback( double offsetX, double offsetY); void mouseMoveCallback( double offsetX, double offsetY);
void mouseButtonCallback(int button, int action, int mods); void mouseButtonCallback(int button, int action, int mods);
void resizeCallback(int width, int height);
public: public:
CameraManager(Window &window, float width, float height, glm::vec3 up = glm::vec3(0.0f,-1.0f,0.0f), glm::vec3 position = glm::vec3(0.0f,0.0f,0.0f)); CameraManager(Window &window, float width, float height, glm::vec3 up = glm::vec3(0.0f,-1.0f,0.0f), glm::vec3 position = glm::vec3(0.0f,0.0f,0.0f));
......
...@@ -82,8 +82,10 @@ namespace vkcv { ...@@ -82,8 +82,10 @@ namespace vkcv {
setFov(fov); setFov(fov);
} }
void Camera::updateRatio( float ratio){ void Camera::updateRatio( int width, int height){
m_ratio = ratio; m_width = width;
m_height = height;
m_ratio = static_cast<float>(width)/height;
setPerspective( m_fov, m_ratio, m_near, m_far); setPerspective( m_fov, m_ratio, m_near, m_far);
} }
......
...@@ -15,10 +15,11 @@ namespace vkcv{ ...@@ -15,10 +15,11 @@ namespace vkcv{
} }
void CameraManager::bindCamera(){ void CameraManager::bindCamera(){
m_keyHandle = m_window.e_key.add( [&](int key, int scancode, int action, int mods) { this->keyCallback(key, scancode, action, mods); }); e_keyHandle = m_window.e_key.add( [&](int key, int scancode, int action, int mods) { this->keyCallback(key, scancode, action, mods); });
m_mouseMoveHandle = m_window.e_mouseMove.add( [&]( double offsetX, double offsetY) {this->mouseMoveCallback( offsetX, offsetY);} ); e_mouseMoveHandle = m_window.e_mouseMove.add( [&]( double offsetX, double offsetY) {this->mouseMoveCallback( offsetX, offsetY);} );
m_mouseScrollHandle = m_window.e_mouseScroll.add([&](double offsetX, double offsetY) {this->scrollCallback( offsetX, offsetY);} ); e_mouseScrollHandle = m_window.e_mouseScroll.add([&](double offsetX, double offsetY) {this->scrollCallback( offsetX, offsetY);} );
m_mouseButtonHandle = m_window.e_mouseButton.add([&] (int button, int action, int mods) {this->mouseButtonCallback( button, action, mods);}); e_mouseButtonHandle = m_window.e_mouseButton.add([&] (int button, int action, int mods) {this->mouseButtonCallback( button, action, mods);});
e_resizeHandle = m_window.e_resize.add([&] (int width, int height) {this->resizeCallback( width, height);});
} }
void CameraManager::mouseButtonCallback(int button, int action, int mods){ void CameraManager::mouseButtonCallback(int button, int action, int mods){
...@@ -75,6 +76,11 @@ namespace vkcv{ ...@@ -75,6 +76,11 @@ namespace vkcv{
break; break;
} }
} }
void CameraManager::resizeCallback(int width, int height){
m_camera.updateRatio(width, height);
}
Camera &CameraManager::getCamera(){ Camera &CameraManager::getCamera(){
return m_camera; return m_camera;
} }
......
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