Results 1 to 15 of 15

Thread: Vectors (AeroLib and Reflection)

  1. #1
    Join Date
    Jan 2016
    Posts
    14
    Mentioned
    0 Post(s)
    Quoted
    12 Post(s)

    Default Vectors (AeroLib and Reflection)

    I was just wondering, what's the best way to create a vector (containing coordinates in the world) to mark down a area in RS (With or without using Aerolib)? Also, what would be the best way to detect if a character is within this vector, using whatever suggested method.

    I would like to use this for a lot of my potential scripts (miner, fisher, etc).
    Last edited by Immortan; 01-10-2016 at 04:00 PM.

  2. #2
    Join Date
    Oct 2006
    Posts
    6,752
    Mentioned
    95 Post(s)
    Quoted
    532 Post(s)

    Default

    Uh, not sure if you understand what a vector is? It's something with magnitude and direction. Usually used in force type problems/equations.. So I'm not sure what you are asking
    “The long-lived and those who will die soonest lose the same thing. The present is all that they can give up, since that is all you have, and what you do not have, you cannot lose.” - Marcus Aurelius

  3. #3
    Join Date
    Jan 2016
    Posts
    14
    Mentioned
    0 Post(s)
    Quoted
    12 Post(s)

    Default

    Quote Originally Posted by Kyle View Post
    Uh, not sure if you understand what a vector is? It's something with magnitude and direction. Usually used in force type problems/equations.. So I'm not sure what you are asking
    Oh, I am talking about like a list of points that could be used to designate an area in RS. I get that, that's the definition for like physics and math, but I am using the CS definition which states that it is simply an array. Anyways, sorry for the confusion.

    Actually, I just realized that I just tried to use both definitions simultaneously, which just caused confusion.
    Last edited by Immortan; 01-10-2016 at 03:59 PM.

  4. #4
    Join Date
    Dec 2007
    Posts
    289
    Mentioned
    4 Post(s)
    Quoted
    86 Post(s)

    Default

    Quote Originally Posted by Immortan View Post
    Oh, I am talking about like a list of points that could be used to designate an area in RS. I get that, that's the definition for like physics and math, but I am using the CS definition which states that it is simply an array.
    Uhh... coordinates?

    If you're not using reflection take a look at RSWalker for determining your position on the worldmap.

    Reflection has walking built into the include. Explore it here: https://github.com/Elfyyy/OSR-Reflection
    You'll likely be most interested in:
    https://github.com/Elfyyy/OSR-Reflec.../Mapwalk.simba
    https://github.com/Elfyyy/OSR-Reflec...alPlayer.simba
    https://github.com/Elfyyy/OSR-Reflec...ore/Tile.simba

  5. #5
    Join Date
    Jan 2016
    Posts
    14
    Mentioned
    0 Post(s)
    Quoted
    12 Post(s)

    Default

    Quote Originally Posted by honeyhoney View Post
    Uhh... coordinates?

    If you're not using reflection take a look at RSWalker for determining your position on the worldmap.

    Reflection has walking built into the include. Explore it here: https://github.com/Elfyyy/OSR-Reflection
    You'll likely be most interested in:
    https://github.com/Elfyyy/OSR-Reflec.../Mapwalk.simba
    https://github.com/Elfyyy/OSR-Reflec...alPlayer.simba
    https://github.com/Elfyyy/OSR-Reflec...ore/Tile.simba
    This may be something I can use (able to calculate location of character). What I am mainly looking for, is something that can mark say a 4 x 4 location and be able check if the the player entity is within that area, and perhaps some other entities.
    Last edited by Immortan; 01-10-2016 at 04:09 PM.

  6. #6
    Join Date
    Dec 2007
    Posts
    289
    Mentioned
    4 Post(s)
    Quoted
    86 Post(s)

    Default

    Quote Originally Posted by Immortan View Post
    This may be something I can use (able to calculate location of character). What I am mainly looking for, is something that can mark say a 4 x 4 location and be able check if the the player entity is within that area, and perhaps some other entities.
    Once you've got the position of your player (ie. the coordinates) you can then calculate whether this position is within an area.

    Coordinates are stored as the TPoint data type.
    You can define an area using two TPoints (top left of the area, bottom right of the area). This area is stored as a TBox data type.
    There is a function in Simba called PointInBox that returns true/false depending on whether the point is within the box.

    As I said, to define a TBox you need two TPoints. You can just check the position of your player at both of these points to get these.

  7. #7
    Join Date
    Jan 2016
    Posts
    14
    Mentioned
    0 Post(s)
    Quoted
    12 Post(s)

    Default

    Quote Originally Posted by honeyhoney View Post
    Once you've got the position of your player (ie. the coordinates) you can then calculate whether this position is within an area.

    Coordinates are stored as the TPoint data type.
    You can define an area using two TPoints (top left of the area, bottom right of the area). This area is stored as a TBox data type.
    There is a function in Simba called PointInBox that returns true/false depending on whether the point is within the box.

    As I said, to define a TBox you need two TPoints. You can just check the position of your player at both of these points to get these.
    What about irregular shapes? What would be most efficient here? An idea that comes to mind is to just create multiple TBox objects and designate that as the same area, but would this be efficient? I'll look into the libraries anyhow.
    Last edited by Immortan; 01-10-2016 at 04:17 PM.

  8. #8
    Join Date
    Dec 2007
    Posts
    289
    Mentioned
    4 Post(s)
    Quoted
    86 Post(s)

    Default

    Quote Originally Posted by Immortan View Post
    What about irregular shapes? What would be most efficient here? An idea that comes to mind is to just combine TBox objects and designate that as one area, but would this be efficient? I'll look into the libraries anyhow.
    Checking if a point is in a polygon is a super interesting problem that a lot of people come up against
    Give this a read: https://en.wikipedia.org/wiki/Point_in_polygon

    Most people tend to stick to TBoxes (including combining a few as you suggested) for their areas. For our purpose you can generally get away with rectangular search areas. Of course the results using a TBox over a polygon are approximate, but again, generally accurate enough for our needs.

    Edit: completely forgot about this but as Harrier mentions, take a look at SimbaExt (an include that provides some additional functions) and you can find implementations of the algorithms discussed in the wikipedia article above.

    Code:
    {* 
     Check if a point is within a polygon/shape by the given outline points (poly)
     The points must be in order, as if you would draw a line trough each point.
     @note: Ray casting combined with Winding number algorithm
    *}
    function InPoly(x,y:Integer; const Poly:TPointArray): Boolean; Inline; 
    var
      WN,H,i,j:Integer;
      RC:Boolean;
    begin
      WN := 0;
      H := High(poly);
      j := H;
      RC := False;
      for i:=0 to H do begin
        if ((Poly[i].x = x) and (Poly[i].y = y)) then
          Exit(True);
        if ((poly[i].y < y) and (poly[j].y >= y) or (poly[j].y < y) and (poly[i].y >= y)) then
          if (poly[i].x+(y-poly[i].y) / (poly[j].y-poly[i].y) * (poly[j].x-poly[i].x) < x) then
             RC := Not(RC);
        if (poly[i].y <= y) then begin
          if (poly[j].y > y) then
            if (((poly[j].x-poly[i].x)*(y-poly[i].y)-(x-poly[i].x)*(poly[j].y-poly[i].y)) > 0) then
              Inc(WN);
        end else
          if poly[j].y <= y then
            if (((poly[j].x-poly[i].x)*(y-poly[i].y)-(x-poly[i].x)*(poly[j].y-poly[i].y)) < 0) then
              Dec(WN);
        j := i;
      end;
      Result := (WN <> 0) or (rc);
    end;
    
    
    {* 
     Check if a point is within a polygon/shape by the given outline points (poly)
     The points must be in order, as if you would draw a line trough each point.
     @note: Ray casting algorithm
    *}
    function InPolyR(x,y:Integer; const Poly:TPointArray): Boolean; Inline; 
    var j,i,H: Integer;
    begin
      H := High(poly);
      j := H;
      Result := False;
      for i:=0 to H do begin
        if ((poly[i].y < y) and (poly[j].y >= y) or (poly[j].y < y) and (poly[i].y >= y)) then
          if (poly[i].x+(y-poly[i].y) / (poly[j].y-poly[i].y) * (poly[j].x-poly[i].x) < x) then
            Result := not(Result);
        j := i;
      end;
    end;
    
    
    {* 
     Check if a point is within a polygon/shape by the given outline points (poly)
     The points must be in order, as if you would draw a line trough each point.
     @note: Winding number algorithm
    *}
    function InPolyW(x,y:Integer; const Poly:TPointArray): Boolean; Inline; 
    var
      wn,H,i,j:Integer;
    begin
      wn := 0;
      H := High(poly);
      j := H;
      for i:=0 to H do begin
        //if ((Poly[i].x = x) and (Poly[i].y = y)) then
        //  Exit(True);
        if (poly[i].y <= y) then begin
          if (poly[j].y > y) then
            if (((poly[j].x-poly[i].x)*(y-poly[i].y)-(x-poly[i].x)*(poly[j].y-poly[i].y)) > 0) then
              Inc(wn);
        end else
          if poly[j].y <= y then
            if (((poly[j].x-poly[i].x)*(y-poly[i].y)-(x-poly[i].x)*(poly[j].y-poly[i].y)) < 0) then
              Dec(wn);
        j := i;
      end;
      Result := (wn <> 0);
    end;
    Source: https://github.com/WarPie/SimbaExt/b...e/CoreMath.pas

  9. #9
    Join Date
    Mar 2013
    Posts
    1,010
    Mentioned
    35 Post(s)
    Quoted
    620 Post(s)

    Default

    Quote Originally Posted by Immortan View Post
    What about irregular shapes? What would be most efficient here? An idea that comes to mind is to just create multiple TBox objects and designate that as the same area, but would this be efficient? I'll look into the libraries anyhow.
    Look at SimbaEx
    #slack4admin2016
    <slacky> I will build a wall
    <slacky> I will ban reflection and OGL hooking until we know what the hell is going on

  10. #10
    Join Date
    Jan 2016
    Posts
    14
    Mentioned
    0 Post(s)
    Quoted
    12 Post(s)

    Default

    Quote Originally Posted by honeyhoney View Post
    Checking if a point is in a polygon is a super interesting problem that a lot of people come up against
    Give this a read: https://en.wikipedia.org/wiki/Point_in_polygon

    Most people tend to stick to TBoxes (including combining a few as you suggested) for their areas. For our purpose you can generally get away with rectangular search areas. Of course the results using a TBox over a polygon are approximate, but again, generally accurate enough for our needs.
    Alright, I am okay with the idea using 1 or 2 Tbox objects for my areas. I'll stick with this.

  11. #11
    Join Date
    Dec 2007
    Posts
    289
    Mentioned
    4 Post(s)
    Quoted
    86 Post(s)

    Default

    Quote Originally Posted by Immortan View Post
    Alright, I am okay with the idea using 1 or 2 Tbox objects for my areas. I'll stick with this.
    Keeping it simple is a great way to start. If you find you need more specific search bounds then you can revisit this thread

  12. #12
    Join Date
    Jan 2016
    Posts
    14
    Mentioned
    0 Post(s)
    Quoted
    12 Post(s)

    Default

    Quote Originally Posted by honeyhoney View Post
    Checking if a point is in a polygon is a super interesting problem that a lot of people come up against
    Give this a read: https://en.wikipedia.org/wiki/Point_in_polygon

    Most people tend to stick to TBoxes (including combining a few as you suggested) for their areas. For our purpose you can generally get away with rectangular search areas. Of course the results using a TBox over a polygon are approximate, but again, generally accurate enough for our needs.

    Edit: completely forgot about this but as Harrier mentions, take a look at SimbaExt (an include that provides some additional functions) and you can find implementations of the algorithms discussed in the wikipedia article above.

    Code:
    {* 
     Check if a point is within a polygon/shape by the given outline points (poly)
     The points must be in order, as if you would draw a line trough each point.
     @note: Ray casting combined with Winding number algorithm
    *}
    function InPoly(x,y:Integer; const Poly:TPointArray): Boolean; Inline; 
    var
      WN,H,i,j:Integer;
      RC:Boolean;
    begin
      WN := 0;
      H := High(poly);
      j := H;
      RC := False;
      for i:=0 to H do begin
        if ((Poly[i].x = x) and (Poly[i].y = y)) then
          Exit(True);
        if ((poly[i].y < y) and (poly[j].y >= y) or (poly[j].y < y) and (poly[i].y >= y)) then
          if (poly[i].x+(y-poly[i].y) / (poly[j].y-poly[i].y) * (poly[j].x-poly[i].x) < x) then
             RC := Not(RC);
        if (poly[i].y <= y) then begin
          if (poly[j].y > y) then
            if (((poly[j].x-poly[i].x)*(y-poly[i].y)-(x-poly[i].x)*(poly[j].y-poly[i].y)) > 0) then
              Inc(WN);
        end else
          if poly[j].y <= y then
            if (((poly[j].x-poly[i].x)*(y-poly[i].y)-(x-poly[i].x)*(poly[j].y-poly[i].y)) < 0) then
              Dec(WN);
        j := i;
      end;
      Result := (WN <> 0) or (rc);
    end;
    
    
    {* 
     Check if a point is within a polygon/shape by the given outline points (poly)
     The points must be in order, as if you would draw a line trough each point.
     @note: Ray casting algorithm
    *}
    function InPolyR(x,y:Integer; const Poly:TPointArray): Boolean; Inline; 
    var j,i,H: Integer;
    begin
      H := High(poly);
      j := H;
      Result := False;
      for i:=0 to H do begin
        if ((poly[i].y < y) and (poly[j].y >= y) or (poly[j].y < y) and (poly[i].y >= y)) then
          if (poly[i].x+(y-poly[i].y) / (poly[j].y-poly[i].y) * (poly[j].x-poly[i].x) < x) then
            Result := not(Result);
        j := i;
      end;
    end;
    
    
    {* 
     Check if a point is within a polygon/shape by the given outline points (poly)
     The points must be in order, as if you would draw a line trough each point.
     @note: Winding number algorithm
    *}
    function InPolyW(x,y:Integer; const Poly:TPointArray): Boolean; Inline; 
    var
      wn,H,i,j:Integer;
    begin
      wn := 0;
      H := High(poly);
      j := H;
      for i:=0 to H do begin
        //if ((Poly[i].x = x) and (Poly[i].y = y)) then
        //  Exit(True);
        if (poly[i].y <= y) then begin
          if (poly[j].y > y) then
            if (((poly[j].x-poly[i].x)*(y-poly[i].y)-(x-poly[i].x)*(poly[j].y-poly[i].y)) > 0) then
              Inc(wn);
        end else
          if poly[j].y <= y then
            if (((poly[j].x-poly[i].x)*(y-poly[i].y)-(x-poly[i].x)*(poly[j].y-poly[i].y)) < 0) then
              Dec(wn);
        j := i;
      end;
      Result := (wn <> 0);
    end;
    Source: https://github.com/WarPie/SimbaExt/b...e/CoreMath.pas
    Thanks for all the info! This seems to be all I need.

  13. #13
    Join Date
    Dec 2013
    Location
    Pitcairn Island
    Posts
    288
    Mentioned
    20 Post(s)
    Quoted
    166 Post(s)

    Default

    Quote Originally Posted by Immortan View Post
    Thanks for all the info! This seems to be all I need.
    This is already in the reflection include so you don't need any additional code: https://github.com/Elfyyy/OSR-Reflec...Tile.simba#L90

  14. #14
    Join Date
    Apr 2013
    Posts
    680
    Mentioned
    13 Post(s)
    Quoted
    341 Post(s)

    Default

    There is a cheap and nasty way, not exactly what you asked. it may help or be food for thought.

    Reflect.Tiles.DistanceFromTile(Point(3333, 4444)) < 10;

    Should you be within less the '10' squares from the target. You can pick a middle point, i have seen polygon used for NPC inside an area, but i'm not sure about the character.

    You can always use and statement to attack multiple of these., but at that point it is too complicated and you should probabbly try learn polygons.

    <------------------>



  15. #15
    Join Date
    Dec 2010
    Posts
    483
    Mentioned
    30 Post(s)
    Quoted
    328 Post(s)

    Default

    Quote Originally Posted by Kyle View Post
    Uh, not sure if you understand what a vector is? It's something with magnitude and direction. Usually used in force type problems/equations.. So I'm not sure what you are asking
    I think he's referencing a vector in the way they are used in C++ and some other native languages. Its essentially a List. An array with added functionality.

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
  •