Skip to content

Commit

Permalink
Refactor follow mode tranformation code; Fix edge opacity in non-foll…
Browse files Browse the repository at this point in the history
…ow mode
  • Loading branch information
LiZhenhuan1019 committed Aug 28, 2022
1 parent 65fc88a commit 94c893d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
12 changes: 6 additions & 6 deletions source/BattleMiniMap/src/Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ public static Vec2 WorldToWidget(this IMiniMap miniMap, Vec2 p)
{
var camera = (MissionState.Current.Listener as MissionScreen).CombatCamera;
var position = camera.Position.AsVec2;
var direction = camera.Direction.AsVec2.Normalized().LeftVec();
var relativePosition = (p - position).TransformToLocalUnitF(direction);
return new Vec2(-relativePosition.y, relativePosition.x) * config.GetFollowModeScale() / 100f * config.WidgetWidth + new Vec2(config.WidgetWidth / 2f, config.WidgetWidth / 2f);
var direction = camera.Direction.AsVec2.Normalized();
var relativePosition = direction.TransformToLocalUnitF(p - position);
return new Vec2(relativePosition.x, -relativePosition.y) * config.GetFollowModeScale() / 100f * config.WidgetWidth + new Vec2(config.WidgetWidth / 2f, config.WidgetWidth / 2f);
}
else
{
Expand All @@ -97,12 +97,12 @@ public static Vec2 WidgetToWorld(this IMiniMap miniMap, Vec2 p)
{
p -= new Vec2(config.WidgetWidth / 2f, config.WidgetWidth / 2f);
p = p * 100f / config.GetFollowModeScale() / config.WidgetWidth;
var relativePosition = new Vec2(-p.y, -p.x);
var relativePosition = new Vec2(p.x, -p.y);

var camera = (MissionState.Current.Listener as MissionScreen).CombatCamera;
var position = camera.Position.AsVec2;
var direction = camera.Direction.AsVec2.Normalized().LeftVec();
return relativePosition.TransformToParentUnitF(direction) + position;
var direction = camera.Direction.AsVec2.Normalized();
return direction.TransformToParentUnitF(relativePosition) + position;
}
else
{
Expand Down
23 changes: 15 additions & 8 deletions source/BattleMiniMap/src/View/Map/BattleMiniMapView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,26 @@ public override void OnMissionScreenTick(float dt)

private void UpdateDynamicScale(float dt)
{
if (!_dataSource.IsEnabled || !BattleMiniMapConfig.Get().FollowMode || !BattleMiniMapConfig.Get().EnableDynamicScale)
if (!_dataSource.IsEnabled)
return;
if (!MissionSharedLibrary.Utilities.Utility.IsAgentDead(MissionScreen.LastFollowedAgent))

if (!BattleMiniMapConfig.Get().FollowMode || !BattleMiniMapConfig.Get().EnableDynamicScale)
{
var speed = MissionScreen.LastFollowedAgent.Velocity.Length;
_targetDynamicScale = 1 / MathF.Lerp(1f, 3f, speed / 50);
_targetDynamicScale = 1;
}
else
{
_targetDynamicScale = 1;
_targetDynamicScale *= 1 / MathF.Lerp(1f, 2f,
(MissionScreen.CombatCamera.Position.z - MiniMap.Instance.WaterLevel) / 120);
if (!MissionSharedLibrary.Utilities.Utility.IsAgentDead(MissionScreen.LastFollowedAgent))
{
var speed = MissionScreen.LastFollowedAgent.Velocity.Length;
_targetDynamicScale = 1 / MathF.Lerp(1f, 3f, speed / 50);
}
else
{
_targetDynamicScale = 1;
_targetDynamicScale *= 1 / MathF.Lerp(1f, 3f,
(MissionScreen.CombatCamera.Position.z - MiniMap.Instance.WaterLevel) / 120);
}
}

BattleMiniMapConfig.DynamicScale = MathF.Lerp(_targetDynamicScale, BattleMiniMapConfig.DynamicScale,
Expand Down
2 changes: 1 addition & 1 deletion source/BattleMiniMap/src/View/MapTerrain/GdiMiniMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public int GetEdgeAlpha(int w, int h, float edgeOpacityFactor)
var factor = edgeOpacityFactor * 2 + 2;
var x = MathF.Clamp(Math.Abs((float)w / BitmapWidth - 0.5f) * 2, 0, 1);
var y = MathF.Clamp(Math.Abs((float)h / BitmapHeight - 0.5f) * 2, 0, 1);
return (int)(MathF.Pow(MathF.Max(1 - MathF.Pow(x, factor) - MathF.Pow(y, factor), 0f), 1 / (factor + 2)) * 255);
return (int)(MathF.Pow(MathF.Max(1 - MathF.Pow(x, factor) - MathF.Pow(y, factor), 0f), (1f - edgeOpacityFactor / 2)) * 255);
}
}
}

0 comments on commit 94c893d

Please sign in to comment.