Extend ortho camera
This commit is contained in:
@@ -114,10 +114,11 @@ namespace OpenVulkano
|
||||
}
|
||||
|
||||
public:
|
||||
MovingCubeAppImpl() : m_camera(90, 16, 9, 0.1, 1000)
|
||||
MovingCubeAppImpl() : m_camera(90)
|
||||
{
|
||||
m_morphableCameraControl.Init(&m_camera);
|
||||
m_cameraControl.Init(&m_camera);
|
||||
m_camera.SetZoom(50);
|
||||
}
|
||||
|
||||
void Init() override
|
||||
|
||||
@@ -25,7 +25,8 @@ namespace OpenVulkano::Scene
|
||||
Math::Vector4f m_camPosition{};
|
||||
float m_nearPlane, m_farPlane, m_width, m_height;
|
||||
float m_fov = 0, m_aspect = 0, m_scaleFactor = 0, m_perPixelScaleFactor = 0;
|
||||
std::array<uint8_t, 16> m_userData{};
|
||||
float m_contentScaleFactor = 1, m_zoom = 1; // For use with ortho camera
|
||||
std::array<uint8_t, 8> m_userData{};
|
||||
|
||||
Camera() : m_nearPlane(0), m_farPlane(0), m_width(0), m_height(0) {}
|
||||
|
||||
@@ -81,6 +82,17 @@ namespace OpenVulkano::Scene
|
||||
return m_farPlane;
|
||||
}
|
||||
|
||||
void SetContentScaleFactor(float contentScale = 1)
|
||||
{
|
||||
m_contentScaleFactor = 1.0f / contentScale;
|
||||
}
|
||||
|
||||
[[nodiscard]] float GetContentScaleFactor() const { return 1.0f / m_contentScaleFactor; }
|
||||
|
||||
void SetZoom(float zoom) { m_zoom = 1.0f / zoom; }
|
||||
|
||||
[[nodiscard]] float GetZoom() const { return 1.0f / m_zoom; }
|
||||
|
||||
virtual void UpdateProjectionMatrix() = 0;
|
||||
|
||||
void UpdateViewProjectionMatrix()
|
||||
@@ -141,7 +153,7 @@ namespace OpenVulkano::Scene
|
||||
* 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, 16>& GetUserData() { return m_userData; }
|
||||
[[nodiscard]] std::array<uint8_t, 8>& GetUserData() { return m_userData; }
|
||||
|
||||
[[nodiscard]] float GetPixelScaleFactor() const { return m_perPixelScaleFactor; }
|
||||
};
|
||||
@@ -245,7 +257,8 @@ namespace OpenVulkano::Scene
|
||||
public:
|
||||
void UpdateProjectionMatrix() final
|
||||
{
|
||||
const float widthHalf = m_width * 0.5f, heightHalf = m_height * 0.5f;
|
||||
const float scale = 0.5f * m_contentScaleFactor * m_zoom;
|
||||
const float widthHalf = m_width * scale, heightHalf = m_height * scale;
|
||||
m_projection = Math::Utils::orthoRH_ZO(-widthHalf, widthHalf, -heightHalf, heightHalf, m_nearPlane, m_farPlane);
|
||||
UpdateViewProjectionMatrix();
|
||||
}
|
||||
|
||||
@@ -25,15 +25,15 @@ namespace OpenVulkano::Scene
|
||||
PerspectiveCamera::UpdateProjectionMatrix();
|
||||
if (m_morphState != 0)
|
||||
{
|
||||
float aspectH = m_aspect;
|
||||
float aspectV = 1;
|
||||
const float scale = 0.5f * m_contentScaleFactor * m_zoom;
|
||||
const float widthHalf = m_width * scale, heightHalf = m_height * scale;
|
||||
m_orthoMatrix = Math::Utils::orthoRH_ZO(-widthHalf, widthHalf, -heightHalf, heightHalf, m_nearPlane, m_farPlane);
|
||||
if (m_morphState == 1)
|
||||
{
|
||||
m_projection = Math::Utils::orthoRH_ZO(-aspectH, aspectH, -aspectV, aspectV, m_nearPlane, m_farPlane);
|
||||
m_projection = m_orthoMatrix;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_orthoMatrix = Math::Utils::orthoRH_ZO(-aspectH, aspectH, -aspectV, aspectV, m_nearPlane, m_farPlane);
|
||||
m_projection = BlendMatrices(m_projection, m_orthoMatrix, m_morphState);
|
||||
}
|
||||
UpdateViewProjectionMatrix();
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace OpenVulkano::Scene
|
||||
Math::Matrix4f m_orthoMatrix;
|
||||
|
||||
public:
|
||||
MorphableCamera(float fovDegrees, float width, float height, float nearPlane, float farPlane)
|
||||
MorphableCamera(float fovDegrees, float nearPlane = 0.1f, float farPlane = 1000.0f, float width = 16, float height = 9)
|
||||
: PerspectiveCamera(fovDegrees, nearPlane, farPlane, width, height), m_morphState(0.0f)
|
||||
{
|
||||
UpdateProjectionMatrix();
|
||||
|
||||
Reference in New Issue
Block a user