Skip to content
Snippets Groups Projects
Commit c753b153 authored by Alexander Gauggel's avatar Alexander Gauggel
Browse files

Merge branch '35-kamera-erstellung-und-handling' into 'develop'

Resolve "Kamera - Erstellung und Handling"

Closes #35

See merge request !26
parents 47938552 11e92197
No related branches found
No related tags found
1 merge request!26Resolve "Kamera - Erstellung und Handling"
Pipeline #25187 passed
Showing
with 692 additions and 15 deletions
[submodule "lib/glfw"] [submodule "lib/glfw"]
path = lib/glfw path = lib/glfw
url = https://github.com/glfw/glfw.git url = https://github.com/glfw/glfw.git
[submodule "modules/camera/lib/glm"]
path = modules/camera/lib/glm
url = https://github.com/g-truc/glm.git
...@@ -72,12 +72,15 @@ endif() ...@@ -72,12 +72,15 @@ endif()
# add include directories from dependencies as system includes # add include directories from dependencies as system includes
target_include_directories(vkcv SYSTEM BEFORE PRIVATE ${vkcv_includes}) target_include_directories(vkcv SYSTEM BEFORE PRIVATE ${vkcv_includes})
message(STATUS ${vkcv_includes})
# add the own include directory for public headers # add the own include directory for public headers
target_include_directories(vkcv BEFORE PUBLIC ${vkcv_include}) target_include_directories(vkcv BEFORE PUBLIC ${vkcv_include})
message(STATUS ${vkcv_include})
# link the framework using all required libraries # link the framework using all required libraries
target_link_libraries(vkcv ${vkcv_libraries}) target_link_libraries(vkcv ${vkcv_libraries})
message(STATUS ${vkcv_libraries})
# add sub-projects/examples as targets # add sub-projects/examples as targets
add_subdirectory(projects) add_subdirectory(projects)
......
...@@ -187,7 +187,7 @@ namespace vkcv ...@@ -187,7 +187,7 @@ namespace vkcv
* @brief render a beautiful triangle * @brief render a beautiful triangle
*/ */
void renderTriangle(const PassHandle renderpassHandle, const PipelineHandle pipelineHandle, void renderTriangle(const PassHandle renderpassHandle, const PipelineHandle pipelineHandle,
const int width, const int height); const int width, const int height, const size_t pushConstantSize, const void* pushConstantData);
/** /**
* @brief end recording and present image * @brief end recording and present image
......
...@@ -34,8 +34,9 @@ namespace vkcv { ...@@ -34,8 +34,9 @@ namespace vkcv {
* adds a function handle to the event to be called * adds a function handle to the event to be called
* @param handle of the function * @param handle of the function
*/ */
void add(typename event_function<T...>::type handle) { typename event_function<T...>::type add(typename event_function<T...>::type handle) {
this->m_handles.push_back(handle); this->m_handles.push_back(handle);
return handle;
} }
/** /**
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
struct GLFWwindow; struct GLFWwindow;
namespace vkcv { namespace vkcv {
class Window final { class Window final {
private: private:
GLFWwindow *m_window; GLFWwindow *m_window;
...@@ -32,6 +32,16 @@ namespace vkcv { ...@@ -32,6 +32,16 @@ namespace vkcv {
*/ */
static void onMouseMoveEvent(GLFWwindow *window, double x, double y); static void onMouseMoveEvent(GLFWwindow *window, double x, double y);
/**
* mouseButton callback for mouse buttons
* @param[in] button The [mouse button](@ref buttons) that was pressed or released.
* @param[in] action One of `GLFW_PRESS` or `GLFW_RELEASE`. Future releases may add more actions.
* @param[in] mods Bit field describing which [modifier keys](@ref mods) were held down.
*/
static void onMouseButtonEvent(GLFWwindow *callbackWindow, int button, int action, int mods);
static void onMouseScrollEvent(GLFWwindow *callbackWindow, double xoffset, double yoffset);
/** /**
* resize callback for the resize option of the window * resize callback for the resize option of the window
* @param[in] window The window that was resized. * @param[in] window The window that was resized.
...@@ -81,7 +91,9 @@ namespace vkcv { ...@@ -81,7 +91,9 @@ namespace vkcv {
/** /**
* basic events of the window * basic events of the window
*/ */
event< int, int, int> e_mouseButton;
event< double, double > e_mouseMove; event< double, double > e_mouseMove;
event< double, double > e_mouseScroll;
event< int, int > e_resize; event< int, int > e_resize;
event< int, int, int, int > e_key; event< int, int, int, int > e_key;
...@@ -129,5 +141,5 @@ namespace vkcv { ...@@ -129,5 +141,5 @@ namespace vkcv {
*/ */
virtual ~Window(); virtual ~Window();
}; };
} }
\ No newline at end of file
# Add new modules here: # Add new modules here:
add_subdirectory(camera)
add_subdirectory(testing) add_subdirectory(testing)
cmake_minimum_required(VERSION 3.16)
project(vkcv_camera)
# setting c++ standard for the project
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(vkcv_camera_source ${PROJECT_SOURCE_DIR}/src)
set(vkcv_camera_include ${PROJECT_SOURCE_DIR}/include)
set(vkcv_camera_sources
${vkcv_camera_include}/vkcv/camera/Camera.hpp
${vkcv_camera_source}/vkcv/camera/Camera.cpp
${vkcv_camera_include}/vkcv/camera/TrackballCamera.hpp
${vkcv_camera_source}/vkcv/camera/TrackballCamera.cpp
${vkcv_camera_include}/vkcv/camera/CameraManager.hpp
${vkcv_camera_source}/vkcv/camera/CameraManager.cpp
)
# adding source files to the project
add_library(vkcv_camera STATIC ${vkcv_camera_sources})
# Setup some path variables to load libraries
set(vkcv_camera_lib lib)
set(vkcv_camera_lib_path ${PROJECT_SOURCE_DIR}/${vkcv_camera_lib})
include(config/GLM.cmake)
target_link_libraries(vkcv_camera PUBLIC ${vkcv_camera_libraries} vkcv)
target_include_directories(vkcv_camera SYSTEM BEFORE PRIVATE ${vkcv_camera_includes} ${vkcv_include})
# add the own include directory for public headers
target_include_directories(vkcv_camera BEFORE PUBLIC ${vkcv_camera_include} ${vkcv_camera_includes})
find_package(glm QUIET)
if (glm_FOUND)
list(APPEND vkcv_camera_includes ${GLM_INCLUDE_DIRS})
list(APPEND vkcv_camera_libraries glm)
else()
if (EXISTS "${vkcv_camera_lib_path}/glm")
add_subdirectory(${vkcv_camera_lib}/glm)
list(APPEND vkcv_camera_libraries glm)
else()
message(WARNING "GLM is required..! Update the submodules!")
endif ()
endif ()
#pragma once
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/matrix_access.hpp>
namespace vkcv {
class Camera {
protected:
glm::mat4 m_view;
glm::mat4 m_projection;
int m_width;
int m_height;
float m_near;
float m_far;
float m_fov;
float m_ratio;
glm::vec3 m_up;
glm::vec3 m_position;
float m_cameraSpeed;
float m_pitch;
float m_yaw;
int m_fov_nsteps;
float m_fov_min;
float m_fov_max;
bool m_forward;
bool m_backward;
bool m_left;
bool m_right;
public:
Camera();
virtual ~Camera();
void setPerspective(float fov, float ratio, float near, float far);
const glm::mat4 getView() const;
void getView(glm::vec3 &x, glm::vec3 &y, glm::vec3 &z, glm::vec3 &pos);
glm::mat4 updateView(double deltatime);
void lookAt(glm::vec3 position, glm::vec3 center, glm::vec3 up);
const glm::mat4& getProjection() const;
void setProjection(const glm::mat4 projection);
void getNearFar(float &near, float &far) const;
void setUp(const glm::vec3 &Up);
float getFov() const;
void setFov(float fov);
void changeFov(double fov);
void updateRatio(float ratio);
float getRatio() const;
void setNearFar(float near, float far);
glm::vec3 getFront() const;
glm::vec3 getPosition() const;
void setPosition( glm::vec3 position );
float getPitch() const;
void setPitch(float pitch);
float getYaw() const;
void setYaw(float yaw);
void panView( double xOffset, double yOffset );
void updatePosition(double deltatime);
void moveForward(int action);
void moveBackward(int action);
void moveLeft(int action);
void moveRight(int action);
};
}
#pragma once
#include "TrackballCamera.hpp"
#include "vkcv/Window.hpp"
#include <GLFW/glfw3.h>
#include <functional>
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;
Window &m_window;
Camera m_camera;
float m_width;
float m_height;
// std::shared_ptr<vkcv::TrackballCamera> m_trackball;
bool m_roationActive = false;
double m_lastX ;
double m_lastY ;
void bindCamera();
void keyCallback(int key, int scancode, int action, int mods);
void scrollCallback( double offsetX, double offsetY);
void mouseMoveCallback( double offsetX, double offsetY);
void mouseButtonCallback(int button, int action, int mods);
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));
Camera &getCamera();
};
}
#pragma once
#include "Camera.hpp"
namespace vkcv {
class TrackballCamera : public vkcv::Camera {
public:
TrackballCamera( int width, int height, glm::mat4 projection);
TrackballCamera(int width, int height);
~TrackballCamera();
float getSensitivity() const;
void setSensitivity(float sensitivity);
float getStepSize() const;
void setStepSize(float stepSize);
float getTheta() const;
void setTheta(float theta);
float getPhi() const;
void setPhi(float phi);
float getRadius() const;
void setRadius(float radius);
const glm::vec3& getCenter() const;
void setCenter(const glm::vec3 &center);
private:
float m_sensitivity;
float m_stepSize, m_theta, m_phi, m_radius;
glm::vec3 m_center;
float m_oldX;
float m_oldY;
};
}
\ No newline at end of file
Subproject commit 66062497b104ca7c297321bd0e970869b1e6ece5
#include "vkcv/camera/Camera.hpp"
#include <iostream>
namespace vkcv {
Camera::Camera(){
m_up = glm::vec3(0.0f, -1.0f, 0.0f);
m_position = glm::vec3(0.0f, 0.0f, 0.0f);
m_cameraSpeed = 2.f;
// front
m_pitch = 0.0;
m_yaw = 180.0;
m_fov_nsteps = 100;
m_fov_min = 10;
m_fov_max = 120;
m_forward = false;
m_backward = false;
m_left = false;
m_right = false;
}
Camera::~Camera() = default;
void Camera::lookAt(glm::vec3 position, glm::vec3 center, glm::vec3 up){
m_view = glm::lookAt(position, center, up);
}
glm::mat4 Camera::updateView(double deltatime){
updatePosition(deltatime);
return m_view = glm::lookAt(m_position, m_position + getFront() , m_up);
}
void Camera::getView(glm::vec3 &x, glm::vec3 &y, glm::vec3 &z, glm::vec3 &pos){
x = glm::vec3( glm::row(m_view, 0));
y = glm::vec3( glm::row(m_view, 1));
z = glm::vec3( glm::row(m_view, 2));
pos = glm::vec3( glm::column(m_view, 3));
glm::mat3 mat_inv = glm::inverse( glm::mat3(m_view));
pos = -mat_inv * pos;
}
void Camera::getNearFar( float &near, float &far) const {
near = m_near;
far = m_far;
}
const glm::mat4 Camera::getView() const {
return m_view;
}
const glm::mat4& Camera::getProjection() const {
return m_projection;
}
void Camera::setProjection(const glm::mat4 projection){
m_projection = projection;
}
float Camera::getFov() const {
return m_fov;
}
void Camera::setFov( float fov){
m_fov = fov;
setPerspective( m_fov, m_ratio, m_near, m_far);
}
void Camera::changeFov(double offset){
float fov = m_fov;
float fov_range = m_fov_max - m_fov_min;
float fov_stepsize = glm::radians(fov_range)/m_fov_nsteps;
fov -= (float) offset*fov_stepsize;
if (fov < glm::radians(m_fov_min)) {
fov = glm::radians(m_fov_min);
}
if (fov > glm::radians(m_fov_max)) {
fov = glm::radians(m_fov_max);
}
setFov(fov);
}
void Camera::updateRatio( float ratio){
m_ratio = ratio;
setPerspective( m_fov, m_ratio, m_near, m_far);
}
float Camera::getRatio() const {
return 0.0f;
}
void Camera::setNearFar( float near, float far){
m_near = near;
m_far = far;
setPerspective(m_fov, m_ratio, m_near, m_far);
}
void Camera::setPerspective(float fov, float ratio, float near, float far){
m_fov = fov;
m_ratio = ratio;
m_near = near;
m_far = far;
m_projection = glm::perspective( m_fov, ratio, m_near, m_far);
}
glm::vec3 Camera::getFront() const {
glm::vec3 direction;
direction.x = sin(glm::radians(m_yaw)) * cos(glm::radians(m_pitch));
direction.y = sin(glm::radians(m_pitch));
direction.z = cos(glm::radians(m_yaw)) * cos(glm::radians(m_pitch));
return glm::normalize(direction);
}
glm::vec3 Camera::getPosition() const {
return m_position;
}
void Camera::setPosition( glm::vec3 position ){
m_position = position;
}
void Camera::setUp(const glm::vec3 &up) {
m_up = up;
}
float Camera::getPitch() const {
return m_pitch;
}
void Camera::setPitch(float pitch) {
if (pitch > 89.0f) {
pitch = 89.0f;
}
if (pitch < -89.0f) {
pitch = -89.0f;
}
m_pitch = pitch;
}
float Camera::getYaw() const {
return m_yaw;
}
void Camera::setYaw(float yaw) {
m_yaw = yaw;
}
void Camera::panView(double xOffset, double yOffset) {
m_yaw += xOffset;
m_pitch += yOffset;
}
void Camera::updatePosition(double deltatime ){
m_position += (m_cameraSpeed * getFront() * static_cast<float> (m_forward) * static_cast<float>(deltatime));
m_position -= (m_cameraSpeed * getFront() * static_cast<float> (m_backward) * static_cast<float>(deltatime));
m_position -= (glm::normalize(glm::cross(getFront(), m_up)) * m_cameraSpeed * static_cast<float> (m_left) * static_cast<float>(deltatime));
m_position += (glm::normalize(glm::cross(getFront(), m_up)) * m_cameraSpeed * static_cast<float> (m_right) * static_cast<float>(deltatime));
}
void Camera::moveForward(int action){
m_forward = static_cast<bool>(action);
}
void Camera::moveBackward(int action){
m_backward = static_cast<bool>(action);
}
void Camera::moveLeft(int action){
m_left = static_cast<bool>(action);
}
void Camera::moveRight(int action){
m_right = static_cast<bool>(action);
}
}
\ No newline at end of file
#include <iostream>
#include "vkcv/camera/CameraManager.hpp"
namespace vkcv{
CameraManager::CameraManager(Window &window, float width, float height, glm::vec3 up, glm::vec3 position):
m_window(window), m_width(width), m_height(height)
{
m_camera.setUp(up);
m_camera.setPosition(position);
m_camera.setPerspective( glm::radians(60.0f), m_width / m_height, 0.1f, 10.f);
m_lastX = width/2.0;
m_lastY = height/2.0;
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); });
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);});
}
void CameraManager::mouseButtonCallback(int button, int action, int mods){
if(button == GLFW_MOUSE_BUTTON_2 && m_roationActive == false && action == GLFW_PRESS){
glfwSetInputMode(m_window.getWindow(), GLFW_CURSOR, GLFW_CURSOR_DISABLED);
m_roationActive = true;
}else if(button == GLFW_MOUSE_BUTTON_2 && m_roationActive == true && action == GLFW_RELEASE){
glfwSetInputMode(m_window.getWindow(), GLFW_CURSOR, GLFW_CURSOR_NORMAL);
m_roationActive = false;
}
}
void CameraManager::mouseMoveCallback(double x, double y){
float xoffset = x - m_lastX;
float yoffset = m_lastY - y;
m_lastX = x;
m_lastY = y;
if(!m_roationActive){
return;
}
float sensitivity = 0.05f;
xoffset *= sensitivity;
yoffset *= sensitivity;
m_camera.panView( xoffset , yoffset );
}
void CameraManager::scrollCallback(double offsetX, double offsetY) {
m_camera.changeFov(offsetY);
}
void CameraManager::keyCallback(int key, int scancode, int action, int mods) {
switch (key) {
case GLFW_KEY_W:
m_camera.moveForward(action);
break;
case GLFW_KEY_S:
m_camera.moveBackward(action);
break;
case GLFW_KEY_A:
m_camera.moveLeft(action);
break;
case GLFW_KEY_D:
m_camera.moveRight(action);
break;
case GLFW_KEY_ESCAPE:
glfwSetWindowShouldClose(m_window.getWindow(), 1);
break;
default:
break;
}
}
Camera &CameraManager::getCamera(){
return m_camera;
}
}
\ No newline at end of file
#include "vkcv/camera/TrackballCamera.hpp"
namespace vkcv{
TrackballCamera::TrackballCamera( int width, int height, glm::mat4 projection)
{
setPosition( glm::vec3(0.0f, 0.0f, 5.0) );
m_center = glm::vec3( 0.0f, 0.0f, 0.0f);
m_up = glm::vec3(0.0f, 1.0f, 0.0f);
m_width = width;
m_height = height;
m_sensitivity = 0.010f;
m_stepSize = 0.1f;
m_theta = glm::pi<float>() / 2.0f;
m_phi = 0.f;
m_radius = 1.5;
m_view = glm::lookAt( m_center + getPosition(), m_center, m_up);
m_oldX = width/2.f;
m_oldY = height/2.f;
setProjection(projection);
}
TrackballCamera::TrackballCamera(int width, int height)
{
setPosition( glm::vec3(0.0f, 0.0f, 5.0));
m_center = glm::vec3( 0.0f, 0.0f, 0.0f);
m_up = glm::vec3(0.0f, 1.0f, 0.0f);
m_width = width;
m_height = height;
m_sensitivity = 0.010f;
m_stepSize = 0.1f;
m_theta = glm::pi<float>() / 2.0f;
m_phi = 0.f;
m_radius = 1.5;
m_view = glm::lookAt( m_center + getPosition(), m_center, m_up);
m_oldX = width/2.f;
m_oldY = height/2.f;
m_fov = glm::radians(60.f);
m_ratio = m_width / (float) m_height;
m_near = 0.001f;
m_far = 10.f;
glm::mat4 projection = glm::perspective(m_fov, m_ratio, m_near, m_far);
setProjection(projection);
}
TrackballCamera::~TrackballCamera()
{
}
// TODO: Can be done as events... (mouseMove, mouseDown, mouseUp)
/*void TrackballCamera::update( GLFWwindow* window) {
double x, y;
glfwGetCursorPos( window, &x, &y);
if (glfwGetMouseButton( window, GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS)
{
float changeX = ((float) x - m_oldX) * m_sensitivity;
float changeY = ((float) y - m_oldY) * m_sensitivity;
m_theta -= changeY;
if (m_theta < 0.01f) m_theta = 0.01f;
else if (m_theta > glm::pi<float>() - 0.01f) m_theta = glm::pi<float>() - 0.01f;
m_phi -= changeX;
if (m_phi < 0) m_phi += 2*glm::pi<float>();
else if (m_phi > 2*glm::pi<float>()) m_phi -= 2*glm::pi<float>();
}
m_oldX = (float) x;
m_oldY = (float) y;
if (glfwGetKey( window, GLFW_KEY_UP) == GLFW_PRESS)
m_radius -= m_stepSize;
if (glfwGetKey( window, GLFW_KEY_DOWN) == GLFW_PRESS)
m_radius += m_stepSize;
if (m_radius < 0.1f) m_radius = 0.1f;
m_position.x = m_center.x + m_radius * sin(m_theta) * sin(m_phi);
m_position.y = m_center.y + m_radius * cos(m_theta);
m_position.z = m_center.z + m_radius * sin(m_theta) * cos(m_phi);
m_view = glm::lookAt( m_position, m_center, m_up);
}*/
float TrackballCamera::getSensitivity() const {
return m_sensitivity;
}
void TrackballCamera::setSensitivity(float sensitivity) {
m_sensitivity = sensitivity;
}
float TrackballCamera::getStepSize() const {
return m_stepSize;
}
void TrackballCamera::setStepSize(float stepSize) {
m_stepSize = stepSize;
}
float TrackballCamera::getTheta() const {
return m_theta;
}
void TrackballCamera::setTheta(float theta) {
m_theta = theta;
}
float TrackballCamera::getPhi() const {
return m_phi;
}
void TrackballCamera::setPhi(float phi) {
m_phi = phi;
}
float TrackballCamera::getRadius() const {
return m_radius;
}
void TrackballCamera::setRadius(float radius) {
m_radius = radius;
}
const glm::vec3& TrackballCamera::getCenter() const {
return m_center;
}
void TrackballCamera::setCenter(const glm::vec3 &center) {
m_center = center;
}
}
\ No newline at end of file
...@@ -18,3 +18,4 @@ add_library(vkcv_testing STATIC ${vkcv_testing_sources}) ...@@ -18,3 +18,4 @@ add_library(vkcv_testing STATIC ${vkcv_testing_sources})
# add the own include directory for public headers # add the own include directory for public headers
target_include_directories(vkcv_testing BEFORE PUBLIC ${vkcv_testing_include}) target_include_directories(vkcv_testing BEFORE PUBLIC ${vkcv_testing_include})
...@@ -22,7 +22,7 @@ if(MSVC) ...@@ -22,7 +22,7 @@ if(MSVC)
endif() endif()
# including headers of dependencies and the VkCV framework # including headers of dependencies and the VkCV framework
target_include_directories(first_triangle SYSTEM BEFORE PRIVATE ${vkcv_include} ${vkcv_includes} ${vkcv_testing_include}) target_include_directories(first_triangle SYSTEM BEFORE PRIVATE ${vkcv_include} ${vkcv_includes} ${vkcv_testing_include} ${vkcv_camera_include})
# linking with libraries from all dependencies and the VkCV framework # linking with libraries from all dependencies and the VkCV framework
target_link_libraries(first_triangle vkcv ${vkcv_libraries} vkcv_testing) target_link_libraries(first_triangle vkcv vkcv_testing vkcv_camera)
...@@ -3,11 +3,15 @@ ...@@ -3,11 +3,15 @@
layout(location = 0) out vec3 fragColor; layout(location = 0) out vec3 fragColor;
layout( push_constant ) uniform constants{
mat4 mvp;
};
void main() { void main() {
vec3 positions[3] = { vec3 positions[3] = {
vec3(-0.5, 0.5, 0), vec3(-0.5, 0.5, -1),
vec3( 0.5, 0.5, 0), vec3( 0.5, 0.5, -1),
vec3(0, -0.5, 0) vec3(0, -0.5, -1)
}; };
vec3 colors[3] = { vec3 colors[3] = {
...@@ -16,6 +20,6 @@ void main() { ...@@ -16,6 +20,6 @@ void main() {
vec3(0, 0, 1) vec3(0, 0, 1)
}; };
gl_Position = vec4(positions[gl_VertexIndex], 1.0); gl_Position = mvp * vec4(positions[gl_VertexIndex], 1.0);
fragColor = colors[gl_VertexIndex]; fragColor = colors[gl_VertexIndex];
} }
\ No newline at end of file
No preview for this file type
#include <iostream> #include <iostream>
#include <vkcv/Core.hpp> #include <vkcv/Core.hpp>
#include <vkcv/Window.hpp>
#include <vkcv/ShaderProgram.hpp>
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#include <vkcv/DescriptorConfig.hpp> #include <vkcv/camera/CameraManager.hpp>
#include <chrono>
int main(int argc, const char** argv) { int main(int argc, const char** argv) {
const char* applicationName = "First Triangle"; const char* applicationName = "First Triangle";
...@@ -17,6 +16,8 @@ int main(int argc, const char** argv) { ...@@ -17,6 +16,8 @@ int main(int argc, const char** argv) {
false false
); );
vkcv::CameraManager cameraManager(window, windowWidth, windowHeight);
window.initEvents(); window.initEvents();
vkcv::Core core = vkcv::Core::create( vkcv::Core core = vkcv::Core::create(
...@@ -128,11 +129,18 @@ int main(int argc, const char** argv) { ...@@ -128,11 +129,18 @@ int main(int argc, const char** argv) {
* *
* PipelineHandle trianglePipeline = core.CreatePipeline(trianglePipeline); * PipelineHandle trianglePipeline = core.CreatePipeline(trianglePipeline);
*/ */
auto start = std::chrono::system_clock::now();
while (window.isWindowOpen()) while (window.isWindowOpen())
{ {
core.beginFrame(); core.beginFrame();
core.renderTriangle(trianglePass, trianglePipeline, windowWidth, windowHeight); window.pollEvents();
auto end = std::chrono::system_clock::now();
auto deltatime = end - start;
start = end;
cameraManager.getCamera().updateView(std::chrono::duration<double>(deltatime).count());
const glm::mat4 mvp = cameraManager.getCamera().getProjection() * cameraManager.getCamera().getView();
core.renderTriangle(trianglePass, trianglePipeline, windowWidth, windowHeight, sizeof(mvp), &mvp);
core.endFrame(); core.endFrame();
} }
return 0; return 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment