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

Merge branch '35-kamera-erstellung-und-handling' of...

Merge branch '35-kamera-erstellung-und-handling' of gitlab.uni-koblenz.de:vulkan2021/vkcv-framework into 35-kamera-erstellung-und-handling
parents f95d9d9f f9be0060
No related branches found
No related tags found
1 merge request!26Resolve "Kamera - Erstellung und Handling"
Pipeline #25041 failed
...@@ -164,7 +164,7 @@ namespace vkcv ...@@ -164,7 +164,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
......
...@@ -8,15 +8,22 @@ namespace vkcv { ...@@ -8,15 +8,22 @@ namespace vkcv {
class Camera { class Camera {
protected: protected:
glm::mat4 m_view, m_projection; glm::mat4 m_view;
glm::mat4 m_projection;
int m_width, m_height;
int m_width;
float m_oldX, m_oldY, int m_height;
m_near, m_far,
m_fov, m_ratio; float m_oldX;
float m_oldY;
glm::vec3 m_position, m_direction, m_up; float m_near;
float m_far;
float m_fov;
float m_ratio;
glm::vec3 m_position;
glm::vec3 m_direction;
glm::vec3 m_up;
public: public:
Camera(); 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
...@@ -24,7 +24,7 @@ int main(int argc, const char** argv) { ...@@ -24,7 +24,7 @@ int main(int argc, const char** argv) {
std::shared_ptr<vkcv::TrackballCamera> trackball; std::shared_ptr<vkcv::TrackballCamera> trackball;
camera.setPerspective( glm::radians(60.0f), windowWidth / (float)windowHeight, 0.1f, 10.f); camera.setPerspective( glm::radians(60.0f), windowWidth / (float)windowHeight, 0.1f, 10.f);
glm::vec3 up(0.0f, 1.0f, 0.0f); glm::vec3 up(0.0f, 1.0f, 0.0f);
glm::vec3 position(1.0f, 0.0f, 0.0f); glm::vec3 position(0.0f, 0.0f, 0.0f);
glm::vec3 front(0.0f, 0.0f, -1.0f); glm::vec3 front(0.0f, 0.0f, -1.0f);
glm::vec3 center = position + front; glm::vec3 center = position + front;
camera.lookAt(position, center, up); camera.lookAt(position, center, up);
...@@ -41,7 +41,7 @@ int main(int argc, const char** argv) { ...@@ -41,7 +41,7 @@ int main(int argc, const char** argv) {
// showing basic usage lambda events of window // showing basic usage lambda events of window
window.e_mouseMove.add([&](double x, double y) { window.e_mouseMove.add([&](double x, double y) {
std::cout << "movement: " << x << " , " << y << std::endl; //std::cout << "movement: " << x << " , " << y << std::endl;
if (firstMouse) { if (firstMouse) {
lastX = x; lastX = x;
...@@ -77,7 +77,7 @@ int main(int argc, const char** argv) { ...@@ -77,7 +77,7 @@ int main(int argc, const char** argv) {
center = position + front; center = position + front;
camera.lookAt(position, center, up); camera.lookAt(position, center, up);
std::cout << "New center: " << center.x << ", " << center.y << ", " << center.z << std::endl; //std::cout << "New center: " << center.x << ", " << center.y << ", " << center.z << std::endl;
}); });
window.e_mouseScroll.add([&](double xoffset, double yoffset) { window.e_mouseScroll.add([&](double xoffset, double yoffset) {
...@@ -90,37 +90,37 @@ int main(int argc, const char** argv) { ...@@ -90,37 +90,37 @@ int main(int argc, const char** argv) {
fov = 45.0f; fov = 45.0f;
} }
camera.setFov(fov); camera.setFov(fov);
std::cout << "New FOV: " << fov << std::endl; //std::cout << "New FOV: " << fov << std::endl;
}); });
window.e_key.add([&](int key, int scancode, int action, int mods) { window.e_key.add([&](int key, int scancode, int action, int mods) {
switch (key) { switch (key) {
case GLFW_KEY_W: case GLFW_KEY_W:
std::cout << "Move forward" << std::endl; //std::cout << "Move forward" << std::endl;
position += cameraSpeed * front; position += cameraSpeed * front;
center = position + front; center = position + front;
camera.lookAt(position, center, up); camera.lookAt(position, center, up);
break; break;
case GLFW_KEY_S: case GLFW_KEY_S:
std::cout << "Move left" << std::endl; //std::cout << "Move left" << std::endl;
position -= cameraSpeed * front; position -= cameraSpeed * front;
center = position + front; center = position + front;
camera.lookAt(position, center, up); camera.lookAt(position, center, up);
break; break;
case GLFW_KEY_A: case GLFW_KEY_A:
std::cout << "Move backward" << std::endl; //std::cout << "Move backward" << std::endl;
position -= glm::normalize(glm::cross(front, up)) * cameraSpeed; position -= glm::normalize(glm::cross(front, up)) * cameraSpeed;
center = position + front; center = position + front;
camera.lookAt(position, center, up); camera.lookAt(position, center, up);
break; break;
case GLFW_KEY_D: case GLFW_KEY_D:
std::cout << "Move right" << std::endl; //std::cout << "Move right" << std::endl;
position += glm::normalize(glm::cross(front, up)) * cameraSpeed; position += glm::normalize(glm::cross(front, up)) * cameraSpeed;
center = position + front; center = position + front;
camera.lookAt(position, center, up); camera.lookAt(position, center, up);
break; break;
default: default:
std::cout << "this key is not supported yet: " << std::endl; __nop;//std::cout << "this key is not supported yet: " << std::endl;
} }
}); });
...@@ -211,7 +211,10 @@ int main(int argc, const char** argv) { ...@@ -211,7 +211,10 @@ int main(int argc, const char** argv) {
while (window.isWindowOpen()) while (window.isWindowOpen())
{ {
core.beginFrame(); core.beginFrame();
core.renderTriangle(trianglePass, trianglePipeline, windowWidth, windowHeight);
const glm::mat4 mvp = camera.getProjection() * camera.getView();
core.renderTriangle(trianglePass, trianglePipeline, windowWidth, windowHeight, sizeof(mvp), &mvp);
core.endFrame(); core.endFrame();
} }
return 0; return 0;
......
...@@ -167,7 +167,8 @@ namespace vkcv ...@@ -167,7 +167,8 @@ namespace vkcv
} }
void Core::renderTriangle(const PassHandle renderpassHandle, const PipelineHandle pipelineHandle, void Core::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) {
if (m_currentSwapchainImageIndex == std::numeric_limits<uint32_t>::max()) { if (m_currentSwapchainImageIndex == std::numeric_limits<uint32_t>::max()) {
return; return;
} }
...@@ -184,7 +185,9 @@ namespace vkcv ...@@ -184,7 +185,9 @@ namespace vkcv
m_CommandResources.commandBuffer.beginRenderPass(beginInfo, subpassContents, {}); m_CommandResources.commandBuffer.beginRenderPass(beginInfo, subpassContents, {});
const vk::Pipeline pipeline = m_PipelineManager->getVkPipeline(pipelineHandle); const vk::Pipeline pipeline = m_PipelineManager->getVkPipeline(pipelineHandle);
const vk::PipelineLayout pipelineLayout = m_PipelineManager->getVkPipelineLayout(pipelineHandle);
m_CommandResources.commandBuffer.bindPipeline(vk::PipelineBindPoint::eGraphics, pipeline, {}); m_CommandResources.commandBuffer.bindPipeline(vk::PipelineBindPoint::eGraphics, pipeline, {});
m_CommandResources.commandBuffer.pushConstants(pipelineLayout, vk::ShaderStageFlagBits::eAll, 0, pushConstantSize, pushConstantData);
m_CommandResources.commandBuffer.draw(3, 1, 0, 0, {}); m_CommandResources.commandBuffer.draw(3, 1, 0, 0, {});
m_CommandResources.commandBuffer.endRenderPass(); m_CommandResources.commandBuffer.endRenderPass();
} }
......
...@@ -140,14 +140,14 @@ namespace vkcv ...@@ -140,14 +140,14 @@ namespace vkcv
{ 1.f,1.f,1.f,1.f } { 1.f,1.f,1.f,1.f }
); );
const size_t matrixPushConstantSize = 4 * 4 * sizeof(float);
const vk::PushConstantRange pushConstantRange(vk::ShaderStageFlagBits::eAll, 0, matrixPushConstantSize);
// pipeline layout // pipeline layout
vk::PipelineLayoutCreateInfo pipelineLayoutCreateInfo( vk::PipelineLayoutCreateInfo pipelineLayoutCreateInfo(
{}, {},
0, {},
{}, (pushConstantRange));
0,
{}
);
vk::PipelineLayout vkPipelineLayout{}; vk::PipelineLayout vkPipelineLayout{};
if (m_Device.createPipelineLayout(&pipelineLayoutCreateInfo, nullptr, &vkPipelineLayout) != vk::Result::eSuccess) if (m_Device.createPipelineLayout(&pipelineLayoutCreateInfo, nullptr, &vkPipelineLayout) != vk::Result::eSuccess)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment