UPD: Adjust size of Minimap

This commit is contained in:
sebastian 2026-02-15 09:50:27 +01:00
parent 10a495c205
commit 66020b9b9a
3 changed files with 24 additions and 5 deletions

View File

@ -39,7 +39,7 @@ private:
public: public:
MasterRenderer() : projectionMatrix(createProjectionMatrix()), entityRenderer(std::make_unique<Renderer>(projectionMatrix)), MasterRenderer() : projectionMatrix(createProjectionMatrix()), entityRenderer(std::make_unique<Renderer>(projectionMatrix)),
terrainRenderer(std::make_unique<TerrainRenderer>(projectionMatrix)), worldSpriteRenderer(std::make_unique<WorldSpriteRenderer>(projectionMatrix)), terrainRenderer(std::make_unique<TerrainRenderer>(projectionMatrix)), worldSpriteRenderer(std::make_unique<WorldSpriteRenderer>(projectionMatrix)),
minimapRenderer(std::make_unique<MinimapRenderer>(600,400)) minimapRenderer(std::make_unique<MinimapRenderer>(200,200))
{ {
glEnable(GL_CULL_FACE); glEnable(GL_CULL_FACE);
glCullFace(GL_BACK); glCullFace(GL_BACK);

View File

@ -62,10 +62,29 @@ void MinimapRenderer::prepareShader() {
bounds.minZ + mapHeight * 0.5f bounds.minZ + mapHeight * 0.5f
); );
glm::mat4 view = glm::lookAt(mapCenter + glm::vec3(0,50,0), mapCenter, glm::vec3(0,0,1)); float fboAspect = static_cast<float>(width) / static_cast<float>(height);
float mapAspect = mapWidth / mapHeight;
float left, right, bottom, top;
float zoom = 1.2f; // >1 = weiter raus, <1 = näher ran float zoom = 1.2f; // >1 = weiter raus, <1 = näher ran
glm::mat4 proj = glm::ortho(-mapWidth * 0.5f * zoom, mapWidth * 0.5f * zoom, -mapHeight * 0.5f * zoom, mapHeight * 0.5f * zoom, -100.f, 100.0f); if (mapAspect > fboAspect) {
// Map breiter als FBO → FBO horizontal voll, vertikal Padding
float adjustedHeight = mapWidth / fboAspect;
left = -mapWidth * 0.5f * zoom;
right = mapWidth * 0.5f * zoom;
bottom = -adjustedHeight * 0.5f * zoom;
top = adjustedHeight * 0.5f * zoom;
} else {
// Map höher als FBO → FBO vertikal voll, horizontal Padding
float adjustedWidth = mapHeight * fboAspect;
left = -adjustedWidth * 0.5f * zoom;
right = adjustedWidth * 0.5f * zoom;
bottom = -mapHeight * 0.5f * zoom;
top = mapHeight * 0.5f * zoom;
}
glm::mat4 view = glm::lookAt(mapCenter + glm::vec3(0,50,0), mapCenter, glm::vec3(0,0,1));
glm::mat4 proj = glm::ortho(left, right, bottom, top, -100.f, 100.f);
minimapShader.loadViewProjectionMatrix(proj * view); minimapShader.loadViewProjectionMatrix(proj * view);
} }

View File

@ -80,8 +80,8 @@ void UILayer::onAttach() {
}); });
auto minimapStyle = LayoutStyle(); auto minimapStyle = LayoutStyle();
minimapStyle.width = SizeValue(600, SizeUnit::Pixels); minimapStyle.width = SizeValue(200, SizeUnit::Pixels);
minimapStyle.height = SizeValue(400.f, SizeUnit::Pixels); minimapStyle.height = SizeValue(200.f, SizeUnit::Pixels);
minimapStyle.margin.top = {10.f, SizeUnit::Pixels}; minimapStyle.margin.top = {10.f, SizeUnit::Pixels};
GLuint minimapTextureID = RenderTargets::instance().getMinimapTexture(); GLuint minimapTextureID = RenderTargets::instance().getMinimapTexture();