Skip to content

Commit

Permalink
rendering: fixed icons not working properly when distance to ground w…
Browse files Browse the repository at this point in the history
…as 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
  • Loading branch information
tvo committed Jan 18, 2010
1 parent d5ab989 commit 0c4e070
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
11 changes: 5 additions & 6 deletions rts/Rendering/UnitModels/UnitDrawer.cpp
Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion rts/Rendering/UnitModels/UnitDrawer.h
Expand Up @@ -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;
Expand Down

0 comments on commit 0c4e070

Please sign in to comment.