Results 1 to 4 of 4

Thread: Compass angle mod

  1. #1
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    7,421
    Mentioned
    268 Post(s)
    Quoted
    1442 Post(s)

    Default Compass angle mod

    Hiya. After looking over the coordinates we use to determine the compass angle I found the central X value is off by a single pixel which is causes our slightly inaccurate result of finding the angle, so I've fixed it up and the result is much more (as can be) precise.

    Simba Code:
    function getCompassAngle(): Extended;
    var
      Angles: Array [0..2] of Extended;
      Vectors: Array [0..2] of TVector;
      I: Integer;
      SouthPoint: TPoint;
      TPA: TPointArray;
    begin
      Result := -1;
      FindColors(TPA, 920735, 545, 4, 576, 36); //Searches for red of South, East, and West points on compass.
      RAaSTPA(TPA, 7); // the point are small clusters of pixels, so by doing this, we are left with four points: the three cardinal points, and the center of the red arrow on the compass.
      SortTPAFrom(TPA, Point(561, 20)); //Sort from center of the compass, so the first point in the array is the point that is the center of the red arrow.
      InvertTPA(TPA); //Invert the array so that the arrow's center point is now at the end of the array and out of the way.
      if (Length(TPA) <> 4) then //If we don't have four points, something has gone wrong.
        Exit;
      for I := 0 to 2 do //Creates normalized vectors from center of compass to three cardinal points.
        Vectors[i] := CreateVector(Point(561, 20), TPA[i], True); //Creates normalized vectors from center of compass out to the cardinal points.
      Angles[0] := AngleBetween(Vectors[0], Vectors[1]); //Stores the angle between vectors 0 and 1 in Angles[0].
      Angles[1] := AngleBetween(Vectors[0], Vectors[2]); //Stores the angle between vectors 0 and 2 in Angles[1].
      Angles[2] := AngleBetween(Vectors[1], Vectors[2]); //Stores the angle between vectors 1 and 2 in Angles[2].
      for I := 0 to 2 do //This loop determines which point is the southern point of the compass.
      begin
        if (Angles[i] > pi) then //If the angle is greater than pi radians (180 degrees),
          Angles[i] := MATH_2PI - Angles[i]; //We subtract it from 2pi radians (360 degrees) to get something like a reference angle.
        if (Angles[i] >= 2) then //If the angle is greater than 2 radians, then we know that the two vectors this angle is between
        begin //are the East and West point vectors.
          case I of //The vector that is not those two is the South point vector.
            0: SouthPoint := TPA[2];
            1: SouthPoint := TPA[1];
            2: SouthPoint := TPA[0];
          end;
        end;
      end;
      Result := FixRad((ArcTan2(-(SouthPoint.y - 20), SouthPoint.x - 561) + MATH_PIOVER2));
      Result := Degrees(FixD(Result));
    end;

    It's almost not worth making a thread but it wouldn't be fair if I kept it just to myself. Also, this will give you a result in degrees right away rather than radians. Don't forget to fit this into your makeCompass() function.
    Last edited by Flight; 01-18-2014 at 04:26 PM.

    Current projects:
    [ AeroGuardians (GotR minigame), Motherlode Miner, Blast furnace ]

    "I won't fall in your gravity. Open your eyes,
    you're the Earth and I'm the sky..."


  2. #2
    Join Date
    Dec 2011
    Location
    Hyrule
    Posts
    8,662
    Mentioned
    179 Post(s)
    Quoted
    1870 Post(s)

  3. #3
    Join Date
    Feb 2006
    Posts
    3,044
    Mentioned
    4 Post(s)
    Quoted
    21 Post(s)

    Default

    Is SRL OSR developed anymore? Who maintains GitHub etc..

    ~Home

  4. #4
    Join Date
    Dec 2011
    Location
    Hyrule
    Posts
    8,662
    Mentioned
    179 Post(s)
    Quoted
    1870 Post(s)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •