basic camera movement
This commit is contained in:
@@ -31,6 +31,8 @@ private:
|
|||||||
std::unique_ptr<shader::WorldShader> m_WorldShader;
|
std::unique_ptr<shader::WorldShader> m_WorldShader;
|
||||||
std::unique_ptr<shader::EntityShader> m_EntityShader;
|
std::unique_ptr<shader::EntityShader> m_EntityShader;
|
||||||
|
|
||||||
|
Vec2i m_WindowSize;
|
||||||
|
|
||||||
Vec3f m_BackgroundColor;
|
Vec3f m_BackgroundColor;
|
||||||
|
|
||||||
Camera m_Camera {};
|
Camera m_Camera {};
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ void Renderer::Resize(int width, int height) {
|
|||||||
m_WorldShader->SetProjectionMatrix(m_Camera.projectionMatrix);
|
m_WorldShader->SetProjectionMatrix(m_Camera.projectionMatrix);
|
||||||
m_EntityShader->Start();
|
m_EntityShader->Start();
|
||||||
m_WorldShader->SetProjectionMatrix(m_Camera.projectionMatrix);
|
m_WorldShader->SetProjectionMatrix(m_Camera.projectionMatrix);
|
||||||
|
m_WindowSize = {width, height};
|
||||||
glViewport(0, 0, width, height);
|
glViewport(0, 0, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,14 +91,14 @@ void Renderer::SetZoom(float zoom) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::SetCamMovement(const Vec2f& mov) {
|
void Renderer::SetCamMovement(const Vec2f& mov) {
|
||||||
m_Camera.CamPos.x -= mov.x / m_Camera.CamPos.y * 5000.0f;
|
Vec2f cursor = {static_cast<float>(m_WindowSize.x) / 2.0f - mov.x, static_cast<float>(m_WindowSize.y) / 2.0f - mov.y};
|
||||||
m_Camera.CamPos.z -= mov.y / m_Camera.CamPos.y * 5000.0f;
|
Vec2f worldMovement = GetCursorWorldPos(cursor, m_WindowSize.x, m_WindowSize.y);
|
||||||
SetCamPos(m_Camera.CamPos);
|
SetCamPos({worldMovement.x, m_Camera.CamPos.y, worldMovement.y});
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::SetCamPos(const Vec3f& newPos) {
|
void Renderer::SetCamPos(const Vec3f& newPos) {
|
||||||
m_Camera.CamPos = 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_Camera.InvViewMatrix = maths::Inverse(m_Camera.viewMatrix);
|
||||||
m_WorldShader->Start();
|
m_WorldShader->Start();
|
||||||
m_WorldShader->SetViewMatrix(m_Camera.viewMatrix);
|
m_WorldShader->SetViewMatrix(m_Camera.viewMatrix);
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ void WorldRenderer::Update() {
|
|||||||
ImVec2 mouseDelta = ImGui::GetIO().MouseDelta;
|
ImVec2 mouseDelta = ImGui::GetIO().MouseDelta;
|
||||||
const float relativeX = mouseDelta.x / (float)Display::GetWindowWidth() * 2;
|
const float relativeX = mouseDelta.x / (float)Display::GetWindowWidth() * 2;
|
||||||
const float relativeY = mouseDelta.y / (float)Display::GetWindowHeight() * 2;
|
const float relativeY = mouseDelta.y / (float)Display::GetWindowHeight() * 2;
|
||||||
MoveCam(relativeX, relativeY);
|
MoveCam(mouseDelta.x, mouseDelta.y);
|
||||||
}
|
}
|
||||||
if (io.MouseWheel != 0) {
|
if (io.MouseWheel != 0) {
|
||||||
ChangeZoom(io.MouseWheel);
|
ChangeZoom(io.MouseWheel);
|
||||||
|
|||||||
Reference in New Issue
Block a user