basic camera movement

This commit is contained in:
2023-06-05 13:15:27 +02:00
parent b72f4a7673
commit faf544f997
3 changed files with 8 additions and 5 deletions

View File

@@ -31,6 +31,8 @@ private:
std::unique_ptr<shader::WorldShader> m_WorldShader;
std::unique_ptr<shader::EntityShader> m_EntityShader;
Vec2i m_WindowSize;
Vec3f m_BackgroundColor;
Camera m_Camera {};

View File

@@ -82,6 +82,7 @@ void Renderer::Resize(int width, int height) {
m_WorldShader->SetProjectionMatrix(m_Camera.projectionMatrix);
m_EntityShader->Start();
m_WorldShader->SetProjectionMatrix(m_Camera.projectionMatrix);
m_WindowSize = {width, height};
glViewport(0, 0, width, height);
}
@@ -90,14 +91,14 @@ void Renderer::SetZoom(float zoom) {
}
void Renderer::SetCamMovement(const Vec2f& mov) {
m_Camera.CamPos.x -= mov.x / m_Camera.CamPos.y * 5000.0f;
m_Camera.CamPos.z -= mov.y / m_Camera.CamPos.y * 5000.0f;
SetCamPos(m_Camera.CamPos);
Vec2f cursor = {static_cast<float>(m_WindowSize.x) / 2.0f - mov.x, static_cast<float>(m_WindowSize.y) / 2.0f - mov.y};
Vec2f worldMovement = GetCursorWorldPos(cursor, m_WindowSize.x, m_WindowSize.y);
SetCamPos({worldMovement.x, m_Camera.CamPos.y, worldMovement.y});
}
void Renderer::SetCamPos(const Vec3f& newPos) {
m_Camera.CamPos = newPos;
m_Camera.viewMatrix = maths::Look(m_Camera.CamPos, {0, -1, -0.0001}, {0, 1, 0});
m_Camera.viewMatrix = maths::Look(m_Camera.CamPos, {0, -1, -0.000000001}, {0, 1, 0});
m_Camera.InvViewMatrix = maths::Inverse(m_Camera.viewMatrix);
m_WorldShader->Start();
m_WorldShader->SetViewMatrix(m_Camera.viewMatrix);

View File

@@ -53,7 +53,7 @@ void WorldRenderer::Update() {
ImVec2 mouseDelta = ImGui::GetIO().MouseDelta;
const float relativeX = mouseDelta.x / (float)Display::GetWindowWidth() * 2;
const float relativeY = mouseDelta.y / (float)Display::GetWindowHeight() * 2;
MoveCam(relativeX, relativeY);
MoveCam(mouseDelta.x, mouseDelta.y);
}
if (io.MouseWheel != 0) {
ChangeZoom(io.MouseWheel);