weh
This commit is contained in:
parent
5b7f400b7b
commit
2fa8e016da
12
flake.lock
12
flake.lock
|
@ -2,11 +2,11 @@
|
|||
"nodes": {
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1729293761,
|
||||
"narHash": "sha256-bkAI9eZGSR+RqM/ZpBV7eZAwHtek9oPC7Ma2TFN0FnQ=",
|
||||
"lastModified": 1729632202,
|
||||
"narHash": "sha256-BqWFOqG9Iuzf5wm9dyVWPeH1SPxSjCxo3inUSnYqxaQ=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "f1812eb562c2253492e7f2f0122b40177e46826c",
|
||||
"rev": "5a95c26209c2e136ef7da309824f562253b5fd7a",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -58,11 +58,11 @@
|
|||
"nixpkgs": "nixpkgs_2"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1729242555,
|
||||
"narHash": "sha256-6jWSWxv2crIXmYSEb3LEVsFkCkyVHNllk61X4uhqfCs=",
|
||||
"lastModified": 1729613947,
|
||||
"narHash": "sha256-XGOvuIPW1XRfPgHtGYXd5MAmJzZtOuwlfKDgxX5KT3s=",
|
||||
"owner": "numtide",
|
||||
"repo": "treefmt-nix",
|
||||
"rev": "d986489c1c757f6921a48c1439f19bfb9b8ecab5",
|
||||
"rev": "aac86347fb5063960eccb19493e0cadcdb4205ca",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
|
58
src/main.cpp
58
src/main.cpp
|
@ -200,6 +200,8 @@ class VulkanApp {
|
|||
bool mFramebufferResized = false; ///< Flag indicating if the framebuffer was resized
|
||||
u32 mCurrentFrame = 0; ///< Index of the current frame being rendered
|
||||
|
||||
glm::mat4 mView; ///< View matrix
|
||||
|
||||
/**
|
||||
* @brief Struct to store queue family indices.
|
||||
*
|
||||
|
@ -240,6 +242,40 @@ class VulkanApp {
|
|||
alignas(16) glm::mat4 proj; ///< Projection matrix
|
||||
};
|
||||
|
||||
struct Camera {
|
||||
glm::dvec3 position;
|
||||
glm::dvec3 front;
|
||||
glm::dvec3 up;
|
||||
f64 speed {};
|
||||
|
||||
Camera() : position(2.0, 2.0, 2.0), front(0.0, 0.0, 0.0), up(0.0, 0.0, 1.0) {}
|
||||
|
||||
[[nodiscard]] fn getViewMatrix() const -> glm::mat4 { return glm::lookAt(position, front, up); }
|
||||
|
||||
fn moveForward(f64 deltaTime) -> void { position += speed * front * deltaTime; }
|
||||
|
||||
fn moveBackward(f64 deltaTime) -> void { position -= speed * front * deltaTime; }
|
||||
|
||||
fn moveLeft(f64 deltaTime) -> void {
|
||||
position -= glm::normalize(glm::cross(front, up)) * speed * deltaTime;
|
||||
}
|
||||
|
||||
fn moveRight(f64 deltaTime) -> void {
|
||||
position += glm::normalize(glm::cross(front, up)) * speed * deltaTime;
|
||||
}
|
||||
};
|
||||
|
||||
static fn processInput(vkfw::Window& window, Camera& camera, const f64& deltaTime) -> void {
|
||||
if (window.getKey(vkfw::Key::eW) == vkfw::eTrue)
|
||||
camera.moveForward(deltaTime);
|
||||
if (window.getKey(vkfw::Key::eA) == vkfw::eTrue)
|
||||
camera.moveLeft(deltaTime);
|
||||
if (window.getKey(vkfw::Key::eS) == vkfw::eTrue)
|
||||
camera.moveBackward(deltaTime);
|
||||
if (window.getKey(vkfw::Key::eD) == vkfw::eTrue)
|
||||
camera.moveRight(deltaTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Update the FPS counter in the window title.
|
||||
*
|
||||
|
@ -415,8 +451,25 @@ class VulkanApp {
|
|||
* polls for events and draws frames until the window is closed.
|
||||
*/
|
||||
fn mainLoop() -> void {
|
||||
Camera camera;
|
||||
|
||||
// Set initial time variables
|
||||
f64 lastFrame = 0.0;
|
||||
f64 deltaTime = 0.0;
|
||||
|
||||
// While the window is open,
|
||||
while (!mWindow->shouldClose()) {
|
||||
// Calculate time between frames
|
||||
f64 currentFrame = vkfw::getTime();
|
||||
deltaTime = currentFrame - lastFrame;
|
||||
lastFrame = currentFrame;
|
||||
|
||||
// Process input for camera movement
|
||||
processInput(mWindow.get(), camera, deltaTime);
|
||||
|
||||
// Create view matrix from camera
|
||||
mView = camera.getViewMatrix();
|
||||
|
||||
// Update the FPS counter
|
||||
updateFPS(mWindow.get(), "Vulkan");
|
||||
|
||||
|
@ -2087,14 +2140,13 @@ class VulkanApp {
|
|||
// Model matrix - glm::rotate(matrix, angle, axis)
|
||||
.model = glm::rotate(glm::mat4(1.0F), time * glm::radians(90.0F), glm::vec3(0.0F, 0.0F, 1.0F)),
|
||||
// View matrix - glm::lookAt(eye, center, up)
|
||||
.view =
|
||||
glm::lookAt(glm::vec3(2.0F, 2.0F, 2.0F), glm::vec3(0.0F, 0.0F, 0.0F), glm::vec3(0.0F, 0.0F, 1.0F)),
|
||||
.view = mView,
|
||||
// Projection matrix - glm::perspective(fov, aspect, near, far)
|
||||
.proj = glm::perspective(
|
||||
glm::radians(45.0F),
|
||||
static_cast<f32>(mSwapChainExtent.width) / static_cast<f32>(mSwapChainExtent.height),
|
||||
0.1F,
|
||||
10.0F
|
||||
100.0F
|
||||
)
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue