Expose ui scaling and orientation

This commit is contained in:
Georg Hagen
2024-07-27 14:30:59 +02:00
parent 6a1a76f4d1
commit eb81c777bf
7 changed files with 45 additions and 43 deletions

View File

@@ -17,7 +17,7 @@ namespace OpenVulkano::Scene
{
public:
ICloseable* renderCamera = nullptr;
static constexpr inline size_t SIZE = sizeof(Math::Matrix4f) * 3 + sizeof(Math::Vector4f) + sizeof(float) * 8 + 16;
static constexpr inline size_t SIZE = sizeof(Math::Matrix4f) * 3 + sizeof(Math::Vector4f) + sizeof(float) * 12;
static constexpr inline DescriptorSetLayoutBinding DESCRIPTOR_SET_LAYOUT_BINDING = { 0, DescriptorSetLayoutBinding::Type::TYPE_UNIFORM_BUFFER_DYNAMIC, 1, ShaderProgramType::ALL_GRAPHICS };
protected:
@@ -26,7 +26,8 @@ namespace OpenVulkano::Scene
float m_nearPlane, m_farPlane, m_width, m_height;
float m_fov = 0, m_aspect = 0, m_scaleFactor = 0, m_perPixelScaleFactor = 0;
float m_contentScaleFactor = 1, m_zoom = 1; // For use with ortho camera
std::array<uint8_t, 8> m_userData{};
float m_interfaceOrientation = 0;
float m_padding = 0; //Unused
Camera() : m_nearPlane(0), m_farPlane(0), m_width(0), m_height(0) {}
@@ -55,32 +56,19 @@ namespace OpenVulkano::Scene
virtual void SetSize(const float width, const float height)
{
if (m_width == width && m_height == height) return;
if (m_width == width && m_height == height) [[likely]] return;
m_width = width;
m_height = height;
UpdateProjectionMatrix();
}
void SetNearPlane(float nearPlane)
{
m_nearPlane = nearPlane;
}
void SetNearPlane(float nearPlane) { m_nearPlane = nearPlane; }
void SetFarPlane(float farPlane)
{
m_farPlane = farPlane;
}
void SetFarPlane(float farPlane) { m_farPlane = farPlane; }
[[nodiscard]] float NearPlane() const { return m_nearPlane; }
[[nodiscard]] float NearPlane() const
{
return m_nearPlane;
}
[[nodiscard]] float FarPlane() const
{
return m_farPlane;
}
[[nodiscard]] float FarPlane() const { return m_farPlane; }
void SetContentScaleFactor(float contentScale = 1)
{
@@ -88,6 +76,10 @@ namespace OpenVulkano::Scene
}
[[nodiscard]] float GetContentScaleFactor() const { return 1.0f / m_contentScaleFactor; }
void SetInterfaceOrientation(float orientation) { m_interfaceOrientation = orientation; }
float GetInterfaceOrientation() const { return m_interfaceOrientation; }
void SetZoom(float zoom) { m_zoom = 1.0f / zoom; }
@@ -126,10 +118,7 @@ namespace OpenVulkano::Scene
return m_viewProjection;
}
[[nodiscard]] const Math::Vector4f& GetPosition() const
{
return m_camPosition;
}
[[nodiscard]] const Math::Vector4f& GetPosition() const { return m_camPosition; }
[[nodiscard]] Math::Vector3f GetRightVector() const
{
@@ -155,12 +144,6 @@ namespace OpenVulkano::Scene
return {m_viewProjection};
}
/**
* The 16 byte of user data can be used to transmit additional data about the camera to the shader.
* @return reference to the custom data array
*/
[[nodiscard]] std::array<uint8_t, 8>& GetUserData() { return m_userData; }
[[nodiscard]] float GetScaleFactor() const { return m_scaleFactor; }
[[nodiscard]] float GetPixelScaleFactor() const { return m_perPixelScaleFactor; }
@@ -202,6 +185,7 @@ namespace OpenVulkano::Scene
void SetSize(const float width, const float height) override
{
if (m_width == width && m_height == height) [[likely]] return;
m_aspect = width / height;
Camera::SetSize(width, height);
m_perPixelScaleFactor = m_height / m_scaleFactor;
@@ -235,20 +219,14 @@ namespace OpenVulkano::Scene
m_perPixelScaleFactor = m_height / m_scaleFactor;
}
[[nodiscard]] float GetFov() const
{
return Math::Utils::degrees(m_fov);
}
[[nodiscard]] float GetFov() const { return Math::Utils::degrees(m_fov); }
[[nodiscard]] float GetFovX() const
{
return 2.0f * atanf(tanf(GetFov() * 0.5f) * m_aspect);
}
[[nodiscard]] float GetFovRad() const
{
return m_fov;
}
[[nodiscard]] float GetFovRad() const { return m_fov; }
[[nodiscard]] float GetFovXRad() const
{