@@ -22,8 +22,20 @@ Main record responsible for minimap to mainscreen (mm2ms) conversion.
2222 ZoomQuads: array [0..100] of TQuad;
2323 PlayerBoxes: array [0..100] of TBox;
2424 Projector: TMM2MSProjector;
25+ Normalization: record
26+ Projector: TMM2MSProjector;
27+ Base: TPoint;
28+ end;
2529 end;
2630
31+ procedure TMM2MS.Setup();
32+ begin
33+ Self.Projector.SetupProjection();
34+ Self.Normalization.Projector.SetupProjection();
35+ Self.Normalization.Projector.UpdateZoom(0);
36+ Self.Normalization.Base := Self.Normalization.Projector.Run([0, 0, 0], [0, 0, 0]);
37+ end;
38+
2739(*
2840## MM2MS.Run
2941```pascal
@@ -437,6 +449,70 @@ begin
437449 Result := Minimap.FacePoint(Self.Point2MM(pt, 0, Minimap.GetCompassAngle(False)).ToPoint(), randomness);
438450end;
439451
452+ (*
453+ ## MainScreen.NormalizeDistance
454+ ```pascal
455+ function TRSMainScreen.NormalizeDistance(dist: Integer; accuracy: Single = 1.05): Integer;
456+ ```
457+ Converts a distance acquired from the **fixed client* and **default zoom** to the
458+ current mainscreen.
459+
460+ Example:
461+ ```pascal
462+ // 20 pixels on the fixed client and default zoom(50) is currently x pixels at the current zoom & client size.
463+ WriteLn(MainScreen.TranslateDistance(20));
464+ ```
465+ *)
466+ function TRSMainScreen.NormalizeDistance(dist: Integer; accuracy: Single = 1.05): Integer;
467+ function _SearchUp(value: Single; target: Single; inc: Single): Single;
468+ var
469+ pt: TPoint;
470+ begin
471+ while True do
472+ begin
473+ pt := MM2MS.Normalization.Projector.Run([value, 0, 0], [0, 0, 0]);
474+ if MM2MS.Normalization.Base.DistanceTo(pt) > target then
475+ Exit(value);
476+
477+ value *= inc;
478+ end;
479+ end;
480+
481+ function _SearchDown(value: Single; target: Single; dec: Single): Single;
482+ var
483+ pt: TPoint;
484+ begin
485+ while True do
486+ begin
487+ pt := MM2MS.Normalization.Projector.Run([value, 0, 0], [0, 0, 0]);
488+ if MM2MS.Normalization.Base.DistanceTo(pt) < target then
489+ Exit(value);
490+
491+ value /= dec;
492+ end;
493+ end;
494+
495+ var
496+ lo, hi, mean: Single;
497+ begin
498+ if dist = 0 then Exit;
499+
500+ hi := _SearchUp(0.1, dist, 1.50);
501+ lo := _SearchDown(hi, dist, 1.50);
502+
503+ hi := _SearchUp(lo, dist, accuracy);
504+ lo := _SearchDown(hi, dist, accuracy);
505+
506+ mean := lo + ((hi - lo) / 2);
507+
508+ with Minimap.Center do
509+ Result := Round(
510+ Minimap.Vector2MS([X, Y, 0], 0).DistanceTo(
511+ Minimap.Vector2MS([X + mean, Y, 0], 0)
512+ ));
513+
514+ if Result < 1 then Result := 1;
515+ end;
440516
441517
442518(*
0 commit comments