Skip to content
Snippets Groups Projects
Commit 2406d39c authored by Sebastian Gaida's avatar Sebastian Gaida
Browse files

[#34] added resizing event to camera

parent 07a8d7b8
Branches
Tags
1 merge request!43Resolve "Resizing-Event"
Pipeline #25422 passed
......@@ -63,7 +63,7 @@ namespace vkcv {
void changeFov(double fov);
void updateRatio(float ratio);
void updateRatio(int width, int height);
float getRatio() const;
......
......@@ -9,10 +9,11 @@ namespace vkcv{
class CameraManager{
private:
std::function<void(int, int, int, int)> m_keyHandle;
std::function<void(double, double)> m_mouseMoveHandle;
std::function<void(double, double)> m_mouseScrollHandle;
std::function<void(int, int, int)> m_mouseButtonHandle;
std::function<void(int, int, int, int)> e_keyHandle;
std::function<void(double, double)> e_mouseMoveHandle;
std::function<void(double, double)> e_mouseScrollHandle;
std::function<void(int, int, int)> e_mouseButtonHandle;
std::function<void(int, int)> e_resizeHandle;
Window &m_window;
Camera m_camera;
......@@ -29,6 +30,7 @@ namespace vkcv{
void scrollCallback( double offsetX, double offsetY);
void mouseMoveCallback( double offsetX, double offsetY);
void mouseButtonCallback(int button, int action, int mods);
void resizeCallback(int width, int height);
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));
......
......@@ -82,8 +82,10 @@ namespace vkcv {
setFov(fov);
}
void Camera::updateRatio( float ratio){
m_ratio = ratio;
void Camera::updateRatio( int width, int height){
m_width = width;
m_height = height;
m_ratio = static_cast<float>(width)/height;
setPerspective( m_fov, m_ratio, m_near, m_far);
}
......
......@@ -15,10 +15,11 @@ namespace vkcv{
}
void CameraManager::bindCamera(){
m_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);} );
m_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_keyHandle = m_window.e_key.add( [&](int key, int scancode, int action, int mods) { this->keyCallback(key, scancode, action, mods); });
e_mouseMoveHandle = m_window.e_mouseMove.add( [&]( double offsetX, double offsetY) {this->mouseMoveCallback( offsetX, offsetY);} );
e_mouseScrollHandle = m_window.e_mouseScroll.add([&](double offsetX, double offsetY) {this->scrollCallback( offsetX, offsetY);} );
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){
......@@ -75,6 +76,11 @@ namespace vkcv{
break;
}
}
void CameraManager::resizeCallback(int width, int height){
m_camera.updateRatio(width, height);
}
Camera &CameraManager::getCamera(){
return m_camera;
}
......
......@@ -18,14 +18,6 @@ int main(int argc, const char** argv) {
vkcv::CameraManager cameraManager(window, static_cast<float>(window.getWidth()), static_cast<float>(window.getHeight()));
window.initEvents();
window.e_resize.add([&cameraManager](int width, int height) {
auto& camera = cameraManager.getCamera();
float near;
float far;
camera.getNearFar(near, far);
const float aspectRatio = static_cast<float>(width) / height;
camera.setPerspective(camera.getFov(), aspectRatio, near, far);
});
vkcv::Core core = vkcv::Core::create(
window,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment