Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (*
- This is about as accurate as we can get with the tiny OSRS compass
- Takes into account N,W,S and E dials to compute an average angle to counter NN pixelation.
- *)
- function CompassAngle(): Single;
- var
- middle: TPoint := [Target.Width-160,22];
- bounds: TBox := Box(middle, 14, 14);
- north,south,west,east: TPoint;
- Nclr, dials, southarr, westarr, eastarr: TPointArray;
- n,w,e,s,x,y: Single;
- begin
- dials := Target.FindColor(920735, 1, bounds);
- Nclr := Target.FindColor(1911089, 1, bounds);
- dials := dials.ExtractDist(middle, 10,9999);
- north := Nclr.ExtractDist(middle, 0,20).Mean();
- southarr := dials.ExtractDist(north, 20,9999);
- south := southarr.FurthestPoint(middle);
- dials := dials.Remove(southarr);
- for dials in dials.Cluster(3) do
- if CrossProduct(dials.Mean(), north, south) > 0 then
- westarr := dials
- else
- eastarr := dials;
- west := westarr.FurthestPoint(eastarr.Mean());
- east := eastarr.FurthestPoint(westarr.Mean());
- n := ArcTan2(north.y-middle.y, north.x-middle.x)+PI/2;
- s := ArcTan2(south.y-middle.y, south.x-middle.x)-PI/2;
- w := ArcTan2(west.y-middle.y, west.x-middle.x)+PI;
- e := ArcTan2(east.y-middle.y, east.x-middle.x);
- x := Cos(s) + Cos(e) + Cos(w) + Cos(n);
- y := Sin(s) + Sin(e) + Sin(w) + Sin(n);
- Result := RadToDeg(ArcTan2(y/4, x/4));
- if Result < 0 then Result := Result + 360;
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement