MorphableCamera class
This commit is contained in:
32
openVulkanoCpp/Scene/MorphableCamera.cpp
Normal file
32
openVulkanoCpp/Scene/MorphableCamera.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include "MorphableCamera.hpp"
|
||||
|
||||
namespace OpenVulkano::Scene
|
||||
{
|
||||
namespace
|
||||
{
|
||||
Math::Matrix4f BlendMatrices(const Math::Matrix4f& mat1, const Math::Matrix4f& mat2, float t)
|
||||
{
|
||||
Math::Matrix4f result;
|
||||
for (int i = 0; i < 4; ++i)
|
||||
{
|
||||
for (int j = 0; j < 4; ++j) { result[i][j] = glm::mix(mat1[i][j], mat2[i][j], t); }
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
void MorphableCamera::UpdateProjectionMatrix()
|
||||
{
|
||||
PerspectiveCamera::UpdateProjectionMatrix();
|
||||
float aspectH = m_aspect;
|
||||
float aspectV = 1;
|
||||
m_orthoMatrix = Math::Utils::orthoRH_ZO(-aspectH, aspectH, -aspectV, aspectV, m_nearPlane, m_farPlane);
|
||||
m_projection = BlendMatrices(m_projection, m_orthoMatrix, m_morphState);
|
||||
UpdateViewProjectionMatrix();
|
||||
}
|
||||
}
|
||||
33
openVulkanoCpp/Scene/MorphableCamera.hpp
Normal file
33
openVulkanoCpp/Scene/MorphableCamera.hpp
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "Camera.hpp"
|
||||
#include "Math/Math.hpp"
|
||||
|
||||
namespace OpenVulkano::Scene
|
||||
{
|
||||
class MorphableCamera : public PerspectiveCamera
|
||||
{
|
||||
float m_morphState;
|
||||
Math::Matrix4f m_orthoMatrix;
|
||||
|
||||
public:
|
||||
MorphableCamera(float fovDegrees, float width, float height, float nearPlane, float farPlane)
|
||||
: PerspectiveCamera(fovDegrees, nearPlane, farPlane, width, height), m_morphState(0.0f)
|
||||
{
|
||||
UpdateProjectionMatrix();
|
||||
}
|
||||
|
||||
void SetMorphState(float state)
|
||||
{
|
||||
m_morphState = Math::Utils::clamp(state, 0.0f, 1.0f);
|
||||
UpdateProjectionMatrix();
|
||||
}
|
||||
|
||||
void UpdateProjectionMatrix() override;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user