From 0c4e070c3dbb490518e651c4ab0e4929b46b3331 Mon Sep 17 00:00:00 2001 From: Tobi Vollebregt Date: Mon, 18 Jan 2010 13:33:41 +0100 Subject: [PATCH] rendering: fixed icons not working properly when distance to ground was used in particular, this fixes: * distance property of the icons not being honoured when using distance to ground, instead of distance to unit * no icons at all showing up in mods that have average icon distance far from 1, when using distance to ground --- rts/Rendering/UnitModels/UnitDrawer.cpp | 11 +++++------ rts/Rendering/UnitModels/UnitDrawer.h | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/rts/Rendering/UnitModels/UnitDrawer.cpp b/rts/Rendering/UnitModels/UnitDrawer.cpp index 0a4ac552c8c..2c72e3efefa 100644 --- a/rts/Rendering/UnitModels/UnitDrawer.cpp +++ b/rts/Rendering/UnitModels/UnitDrawer.cpp @@ -228,14 +228,13 @@ void CUnitDrawer::Update(void) distToGroundForIcons_useMethod = camHandler->GetCurrentController().GetUseDistToGroundForIcons(); if (distToGroundForIcons_useMethod) { - const float3& camPos = camHandler->GetCurrentController().GetPos(); + const float3& camPos = camera->pos; // use the height at the current camera position //const float groundHeight = ground->GetHeight(camPos.x, camPos.z); // use the middle between the highest and lowest position on the map as average const float groundHeight = (readmap->currMinHeight + readmap->currMaxHeight) / 2; const float overGround = camPos.y - groundHeight; - //distToGroundForIcons_areIcons = (overGround > unitIconDist * 30); - distToGroundForIcons_areIcons = (overGround*overGround > iconLength); + distToGroundForIcons_sqGroundCamDist = overGround * overGround; } } @@ -2002,13 +2001,13 @@ void CUnitDrawer::DrawFeatureStatic(CFeature* feature) bool CUnitDrawer::DrawAsIcon(const CUnit& unit, const float sqUnitCamDist) const { + const float sqIconDistMult = unit.unitDef->iconType->GetDistanceSqr(); + const float realIconLength = iconLength * sqIconDistMult; bool asIcon = false; if (distToGroundForIcons_useMethod) { - asIcon = distToGroundForIcons_areIcons; + asIcon = (distToGroundForIcons_sqGroundCamDist > realIconLength); } else { - const float iconDistMult = unit.unitDef->iconType->GetDistance(); - const float realIconLength = iconLength * (iconDistMult * iconDistMult); asIcon = (sqUnitCamDist > realIconLength); } diff --git a/rts/Rendering/UnitModels/UnitDrawer.h b/rts/Rendering/UnitModels/UnitDrawer.h index 7c0ac720091..a0eaa4f85af 100644 --- a/rts/Rendering/UnitModels/UnitDrawer.h +++ b/rts/Rendering/UnitModels/UnitDrawer.h @@ -178,7 +178,7 @@ class CUnitDrawer /// Returns true if the given unit should be drawn as icon in the current frame. bool DrawAsIcon(const CUnit& unit, const float sqUnitCamDist) const; bool distToGroundForIcons_useMethod; - bool distToGroundForIcons_areIcons; + float distToGroundForIcons_sqGroundCamDist; }; extern CUnitDrawer* unitDrawer;