More lazy rendering stuff
This commit is contained in:
@@ -15,7 +15,7 @@ namespace OpenVulkano
|
|||||||
public:
|
public:
|
||||||
uint64_t frameId = 0;
|
uint64_t frameId = 0;
|
||||||
double frameTime = 1;
|
double frameTime = 1;
|
||||||
bool shouldDraw = true;
|
bool needsRedraw = true;
|
||||||
|
|
||||||
FrameMetadata() = default;
|
FrameMetadata() = default;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -26,17 +26,23 @@ namespace OpenVulkano
|
|||||||
{
|
{
|
||||||
if (!GetCamera()) return;
|
if (!GetCamera()) return;
|
||||||
Input::InputManager* input = Input::InputManager::GetInstance();
|
Input::InputManager* input = Input::InputManager::GetInstance();
|
||||||
|
float inYaw = input->GetAxis(m_actionLookSide);
|
||||||
|
float inPitch = input->GetAxis(m_actionLookUp);;
|
||||||
Math::Vector4f_SIMD position = GetCamera()->GetPosition();
|
Math::Vector4f_SIMD position = GetCamera()->GetPosition();
|
||||||
yaw += input->GetAxis(m_actionLookSide);
|
bool updated = false;
|
||||||
pitch += input->GetAxis(m_actionLookUp);
|
|
||||||
|
|
||||||
pitch = std::min(1.5f, std::max(-1.5f, pitch));
|
if (inYaw != 0 || inPitch != 0)
|
||||||
|
{
|
||||||
|
yaw += inYaw;
|
||||||
|
pitch = std::min(1.5f, std::max(-1.5f, pitch + inPitch));
|
||||||
|
|
||||||
Math::Matrix4f rotateY = Math::Utils::rotate(yaw, Math::Vector3f_SIMD(0, 1, 0));
|
Math::Matrix4f rotateY = Math::Utils::rotate(yaw, Math::Vector3f_SIMD(0, 1, 0));
|
||||||
Math::Vector4f x = rotateY * Math::Vector4f(1, 0, 0, 0);
|
Math::Vector4f x = rotateY * Math::Vector4f(1, 0, 0, 0);
|
||||||
Math::Matrix4f rotateX = Math::Utils::rotate(pitch, Math::Vector3f_SIMD(x));
|
Math::Matrix4f rotateX = Math::Utils::rotate(pitch, Math::Vector3f_SIMD(x));
|
||||||
position = rotateX * rotateY * Math::Vector4f_SIMD(0, 0, 3, 0);
|
position = rotateX * rotateY * Math::Vector4f_SIMD(0, 0, 3, 0);
|
||||||
position += m_pivotPoint;
|
position += m_pivotPoint;
|
||||||
|
updated = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Move the camera and the pivot point
|
// Move the camera and the pivot point
|
||||||
Math::Vector3f_SIMD vec(input->GetAxis(m_actionSide), input->GetAxis(m_actionUp), -input->GetAxis(m_actionForward));
|
Math::Vector3f_SIMD vec(input->GetAxis(m_actionSide), input->GetAxis(m_actionUp), -input->GetAxis(m_actionForward));
|
||||||
@@ -52,12 +58,17 @@ namespace OpenVulkano
|
|||||||
const Math::Vector4f_SIMD movement(vec, 0);
|
const Math::Vector4f_SIMD movement(vec, 0);
|
||||||
position += movement;
|
position += movement;
|
||||||
m_pivotPoint += movement;
|
m_pivotPoint += movement;
|
||||||
|
updated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the camera view
|
if (updated)
|
||||||
GetCamera()->SetViewMatrix(Math::Utils::lookAt(reinterpret_cast<Math::Vector3f_SIMD&>(position),
|
{
|
||||||
reinterpret_cast<Math::Vector3f_SIMD&>(m_pivotPoint),
|
// Update the camera view
|
||||||
Math::Vector3f_SIMD(0,1,0)));
|
GetCamera()->SetViewMatrix(Math::Utils::lookAt(reinterpret_cast<Math::Vector3f_SIMD&>(position),
|
||||||
|
reinterpret_cast<Math::Vector3f_SIMD&>(m_pivotPoint),
|
||||||
|
Math::Vector3f_SIMD(0, 1, 0)));
|
||||||
|
CURRENT_FRAME.needsRedraw = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArcballCameraController::SetActive()
|
void ArcballCameraController::SetActive()
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include "MapCameraController.hpp"
|
#include "MapCameraController.hpp"
|
||||||
#include "Input/InputManager.hpp"
|
#include "Input/InputManager.hpp"
|
||||||
#include "Scene/Camera.hpp"
|
#include "Scene/Camera.hpp"
|
||||||
|
#include "Base/FrameMetadata.hpp"
|
||||||
|
|
||||||
namespace OpenVulkano
|
namespace OpenVulkano
|
||||||
{
|
{
|
||||||
@@ -22,7 +23,9 @@ namespace OpenVulkano
|
|||||||
{
|
{
|
||||||
if (!GetCamera()) return;
|
if (!GetCamera()) return;
|
||||||
auto input = Input::InputManager::GetInstance();
|
auto input = Input::InputManager::GetInstance();
|
||||||
Math::Vector3f_SIMD vec = m_dirUp * input->GetAxis(m_actionUp) + m_dirSide * input->GetAxis(m_actionSide);
|
float up = input->GetAxis(m_actionUp);
|
||||||
|
float side = input->GetAxis(m_actionSide);
|
||||||
|
Math::Vector3f_SIMD vec = m_dirUp * up + m_dirSide * side;
|
||||||
vec /= GetCamera()->GetZoom();
|
vec /= GetCamera()->GetZoom();
|
||||||
vec /= GetCamera()->GetContentScaleFactor();
|
vec /= GetCamera()->GetContentScaleFactor();
|
||||||
|
|
||||||
@@ -35,7 +38,11 @@ namespace OpenVulkano
|
|||||||
GetCamera()->UpdateProjectionMatrix();
|
GetCamera()->UpdateProjectionMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
GetCamera()->SetMatrix(Math::Utils::translate(vec) * GetCamera()->GetMatrix());
|
if (zoom != 0 || up != 0 || side != 0)
|
||||||
|
{
|
||||||
|
GetCamera()->SetMatrix(Math::Utils::translate(vec) * GetCamera()->GetMatrix());
|
||||||
|
CURRENT_FRAME.needsRedraw = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapCameraController::SetDefaultKeybindings()
|
void MapCameraController::SetDefaultKeybindings()
|
||||||
|
|||||||
@@ -141,12 +141,12 @@ namespace OpenVulkano
|
|||||||
{
|
{
|
||||||
Input::InputManager::GetInstance()->Tick();
|
Input::InputManager::GetInstance()->Tick();
|
||||||
app->Tick();
|
app->Tick();
|
||||||
if (CURRENT_FRAME.shouldDraw) renderer->Tick();
|
if (CURRENT_FRAME.needsRedraw) renderer->Tick();
|
||||||
frameTimer.Tick();
|
frameTimer.Tick();
|
||||||
UpdateFps();
|
UpdateFps();
|
||||||
CURRENT_FRAME.frameId = frameCount;
|
CURRENT_FRAME.frameId = frameCount;
|
||||||
CURRENT_FRAME.frameTime = frameTimer.GetTickSeconds();
|
CURRENT_FRAME.frameTime = frameTimer.GetTickSeconds();
|
||||||
CURRENT_FRAME.shouldDraw = !EngineConfiguration::GetEngineConfiguration()->GetLazyRendering();
|
CURRENT_FRAME.needsRedraw = !EngineConfiguration::GetEngineConfiguration()->GetLazyRendering();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user