better cam controls
This commit is contained in:
@@ -56,7 +56,7 @@ public:
|
|||||||
|
|
||||||
void SetZoom(float zoom);
|
void SetZoom(float zoom);
|
||||||
void SetCamAngularMovement(const Vec2f& mov);
|
void SetCamAngularMovement(const Vec2f& mov);
|
||||||
void SetCamMovement(const Vec2f& mov);
|
void SetCamMovement(const Vec2f& lastCursorPos, const Vec2f& currentCursorPos);
|
||||||
void SetCamLook(const Vec2f& worldPos);
|
void SetCamLook(const Vec2f& worldPos);
|
||||||
|
|
||||||
void SetBackgroundColor(const Vec3f& color) { m_BackgroundColor = color; }
|
void SetBackgroundColor(const Vec3f& color) { m_BackgroundColor = color; }
|
||||||
|
|||||||
@@ -98,10 +98,11 @@ void Renderer::SetCamAngularMovement(const Vec2f& mov) {
|
|||||||
SetCamLook(m_Camera.CamLook);
|
SetCamLook(m_Camera.CamLook);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::SetCamMovement(const Vec2f& mov) {
|
void Renderer::SetCamMovement(const Vec2f& lastCursorPos, const Vec2f& currentCursorPos) {
|
||||||
Vec2f cursor = { static_cast<float>(m_WindowSize.x) / 2.0f - mov.x, static_cast<float>(m_WindowSize.y) / 2.0f - mov.y };
|
Vec2f worldLastCursorPos = GetCursorWorldPos(lastCursorPos, m_WindowSize.x, m_WindowSize.y);
|
||||||
Vec2f worldMovement = GetCursorWorldPos(cursor, m_WindowSize.x, m_WindowSize.y);
|
Vec2f worldCurrentCursorPos = GetCursorWorldPos(currentCursorPos, m_WindowSize.x, m_WindowSize.y);
|
||||||
SetCamLook(worldMovement);
|
Vec2f movement = worldCurrentCursorPos - worldLastCursorPos;
|
||||||
|
SetCamLook(m_Camera.CamLook - movement);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::SetCamPos(const Vec3f& newPos) {
|
void Renderer::SetCamPos(const Vec3f& newPos) {
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ void WorldRenderer::LoadModels() {
|
|||||||
|
|
||||||
WorldRenderer::WorldRenderer(game::World* world, client::ClientGame* client) : m_Client(client), m_Renderer(m_Client->GetRenderer()), m_World(world), m_Zoom(0.1) {
|
WorldRenderer::WorldRenderer(game::World* world, client::ClientGame* client) : m_Client(client), m_Renderer(m_Client->GetRenderer()), m_World(world), m_Zoom(0.1) {
|
||||||
m_Renderer->SetZoom(m_Zoom);
|
m_Renderer->SetZoom(m_Zoom);
|
||||||
m_Renderer->SetCamMovement({});
|
|
||||||
m_TowerPlacePopup = std::make_unique<gui::TowerPlacePopup>(m_Client->GetClient());
|
m_TowerPlacePopup = std::make_unique<gui::TowerPlacePopup>(m_Client->GetClient());
|
||||||
m_TowerUpgradePopup = std::make_unique<gui::TowerUpgradePopup>(m_Client->GetClient());
|
m_TowerUpgradePopup = std::make_unique<gui::TowerUpgradePopup>(m_Client->GetClient());
|
||||||
m_MobTooltip = std::make_unique<gui::MobTooltip>(m_Client->GetClient());
|
m_MobTooltip = std::make_unique<gui::MobTooltip>(m_Client->GetClient());
|
||||||
@@ -52,8 +51,9 @@ void WorldRenderer::Update() {
|
|||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
|
||||||
if (io.MouseDown[0] && !ImGui::IsAnyItemActive() && !ImGui::IsAnyItemHovered()) {
|
if (io.MouseDown[0] && !ImGui::IsAnyItemActive() && !ImGui::IsAnyItemHovered()) {
|
||||||
|
ImVec2 mousePos = ImGui::GetIO().MousePos;
|
||||||
ImVec2 mouseDelta = ImGui::GetIO().MouseDelta;
|
ImVec2 mouseDelta = ImGui::GetIO().MouseDelta;
|
||||||
m_Renderer->SetCamMovement({ mouseDelta.x, mouseDelta.y });
|
m_Renderer->SetCamMovement({mousePos.x - mouseDelta.x, mousePos.y - mouseDelta.y}, { mousePos.x, mousePos.y });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (io.MouseDown[1] && !ImGui::IsAnyItemActive() && !ImGui::IsAnyItemHovered()) {
|
if (io.MouseDown[1] && !ImGui::IsAnyItemActive() && !ImGui::IsAnyItemHovered()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user