Advertisement
WarPie90

Simba 2.0 - four point compass angle solve

Dec 18th, 2024 (edited)
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.38 KB | None | 0 0
  1. (*
  2.   This is about as accurate as we can get with the tiny OSRS compass
  3.   Takes into account N,W,S and E dials to compute an average angle to counter NN pixelation.
  4. *)
  5. function CompassAngle(): Single;
  6. var
  7.   middle: TPoint := [Target.Width-160,22];
  8.   bounds: TBox   := Box(middle, 14, 14);
  9.   north,south,west,east: TPoint;
  10.   Nclr, dials, southarr, westarr, eastarr: TPointArray;
  11.   n,w,e,s,x,y: Single;
  12. begin
  13.   dials := Target.FindColor(920735,  1, bounds);
  14.   Nclr  := Target.FindColor(1911089, 1, bounds);
  15.  
  16.   dials := dials.ExtractDist(middle, 10,9999);
  17.   north := Nclr.ExtractDist(middle, 0,20).Mean();
  18.  
  19.   southarr := dials.ExtractDist(north, 20,9999);
  20.   south    := southarr.FurthestPoint(middle);
  21.  
  22.   dials  := dials.Remove(southarr);
  23.   for dials in dials.Cluster(3) do
  24.     if CrossProduct(dials.Mean(), north, south) > 0 then
  25.       westarr := dials
  26.     else
  27.       eastarr := dials;
  28.  
  29.   west := westarr.FurthestPoint(eastarr.Mean());
  30.   east := eastarr.FurthestPoint(westarr.Mean());
  31.  
  32.   n := ArcTan2(north.y-middle.y, north.x-middle.x)+PI/2;
  33.   s := ArcTan2(south.y-middle.y, south.x-middle.x)-PI/2;
  34.   w := ArcTan2(west.y-middle.y, west.x-middle.x)+PI;
  35.   e := ArcTan2(east.y-middle.y, east.x-middle.x);
  36.  
  37.   x := Cos(s) + Cos(e) + Cos(w) + Cos(n);
  38.   y := Sin(s) + Sin(e) + Sin(w) + Sin(n);
  39.  
  40.   Result := RadToDeg(ArcTan2(y/4, x/4));
  41.   if Result < 0 then Result := Result + 360;
  42. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement