Crafter.Graphics/src/module/Crafter.Graphics-Camera.cppm

63 lines
2.1 KiB
Text
Raw Normal View History

2025-05-07 19:21:51 +02:00
/*
Crafter®.Graphics
Copyright (C) 2025 Catcrafts®
Catcrafts.net
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
2025-04-26 23:05:11 +02:00
module;
#include <cstdint>
export module Crafter.Graphics:Camera;
2025-04-27 00:05:21 +02:00
import :VulkanBuffer;
2025-05-04 05:15:31 +02:00
import Crafter.Math;
2025-05-05 06:00:35 +02:00
import Crafter.Event;
2025-04-26 23:05:11 +02:00
namespace Crafter {
2025-06-13 23:59:36 +02:00
/**
* @brief 3D camera with projection and view matrices
* @example examples/VulkanCube/main.cpp
*/
2025-05-25 23:04:56 +02:00
export class Camera {
2025-04-27 22:16:56 +02:00
public:
2025-05-05 05:14:47 +02:00
MatrixRowMajor<float, 4, 4, 1> projection;
MatrixRowMajor<float, 4, 4, 1> view;
MatrixRowMajor<float, 4, 4, 1> projectionView;
2025-05-05 06:00:35 +02:00
Event<void> onUpdate;
2025-06-13 23:59:36 +02:00
/**
* @param fov Field of view in radians.
* @param aspectRatio Aspect ratio of the camera (width / height).
* @param near Near clipping plane.
* @param far Far clipping plane.
* @example examples/VulkanCube/main.cpp
*/
2025-05-04 05:15:31 +02:00
Camera(float fov, float aspectRatio, float near, float far);
2025-06-13 23:59:36 +02:00
/**
* @brief calculates the projectionView matrix by multiplying the projection and view matricies.
*/
2025-05-05 05:14:47 +02:00
void Update();
2025-06-13 23:59:36 +02:00
/**
* @brief Converts screen-space coordinates to a 3D world-space ray.
* @param x The x-coordinate on the screen (in pixels).
* @param y The y-coordinate on the screen (in pixels).
* @return A normalized 3D direction vector representing the ray from the camera.
*/
2025-06-10 22:47:47 +02:00
Vector<float, 3> ToRay(uint32_t x, uint32_t y);
2025-04-26 23:05:11 +02:00
};
}