dulux-oz
February 29th, 2016, 03:06
Part 1
Introduction
This thread has been created for the expressed purpose of discussing and developing a Line-Of-Sight (LOS) system for use within our games. It has come about from a discussion in August 2013 around the creation of Custom Pointers and some further thoughts and correspondence since then. The original discussion can be found in Posts #16-19 of this thread (https://www.fantasygrounds.com/forums/showthread.php?19253-Custom-Pointers-Coding-Toolkit-Over-Several-Posts).
At the time of creation of this thread (Feb 29, 2016) the solution present here is only an "Initial Solution" in that, while the method (algorithm) and resulting function(s) will determine if LOS exists between two Tokens on an Image, it does so ONLY for the most primitive case: that of an Attacker and a Target, but without the possibility of any walls or other objects that the Target might "hide behind" - see the Further Remarks section.
Finally, all quotes have been edited for clarity.
Background
Back in August 2013 I developed a Custom Pointer Toolkit (available here (https://www.fantasygrounds.com/forums/showthread.php?19253-Custom-Pointers-Coding-Toolkit-Over-Several-Posts)) which simplified the creation of non-standard Pointers for use within our games. A Pointer is the Line, Circle, Square and Cone shapes that we draw on Images to indicate various things. At the time Zeus asked the following:
just to clarify something. If we know the start/stop point of a pointer as well as its area coverage, it should be possible to track the image area covered by a pointer (mapped to x,y points in an image control). If this is the case then I believe this would be all that would be necessary to initiate a basic mechanism for determining Line of Sight to any targeted token (also on the same image).
I am thinking it maybe possible to attach an invisible 25-45 degree wide cone to all tokens, facing out from the current facing direction of the token. As the token rotates, so too does the LoS cone. Now to determine LoS we simply have to check to see if the x,y position of the target token falls within the LoS cone area, if it does we have LoS, if not we don't have LoS etc. etc.
To which I replied:
You wouldn't need to actually draw the "Invisible Cone" (although that's not a bad way to think about it) - you simply need to check if the Target coordinates were within an area defined by the coordinates defining the (LOS) Cone.
The functions used to draw a Cone in the Toolkit take as arguments the Starting Coordinates of the Pointer, the Ending Coordinates of the Pointer and the Angle-Of-Arc of the Cone (the Field-Of-Vision, or FOV). This is convenient, because with these three things, plus the Coordinates of the Target, it is relatively simple to solve our problem - let me explain.
The Target lies in our Line-Of-Sight (ie within the "Invisible LOS-Cone") if (Conditions):
The Target is between the two "arms" or straight-edges of the LOS Cone, and
The distance from the Starting Point (the Attacker) to the Target is less than or equal to the length of the LOS-Cone.
Thus (Remarks):
The LOS-Cone (the Pointer) is a symmetrical cone along its major axis. Let this major axis be known as the LOS-Line.
The angle that the LOS-Line lies relative to an arbitrary Control-Line is given by the math.atan2() function.
The angle that the line from the Starting Point to the Target (hereafter known as the Target-Line) lies relative to the arbitrary Control-Line is also given by the math.atan2() function.
Therefore the angle that the Target-Line and the LOS-Line make is simply the subtraction of the two math.atan2() results (from Remarks 1 and 2).
If the absolute value (math.abs()) of the result from Remark 3 is less than or equal to half of the FOV then we have fulfilled Requirement 1 (half the FOV because the LOS-Cone lies symmetrically on either side of the LOS-Line).
If the length of the Target-Line is less than or equal to the length of the LOS-Line than we have fulfilled Requirement 2.
If both Requirement 1 and Requirement 2 are fulfilled (ie TRUE) then the Target is within Line-Of-Sight.
I then gave a code sample (the fpLOSTrue function) and a few usage remarks.
At the time of this discussion there was some brief excitement that we were well on the way to achieving (basic) LOS, but this was quickly dampened when I posted:
Not quite, no.
The Pointer Toolkit will allow us to draw a Cone Pointer based on its Starting Point and Ending Point, provided we supply the relevant function with a "hard wired" Angle-Of-Arc, which will then be drawn by FG for us.
The fpLOSTrue function will allow us to determine if a Target Point lies within the area defined by a Cone with a Starting Point, Ending Point and a FOV (Angle-Of-Arc).
The Starting Points, Ending Points and Angle-Of-Arcs supplied to both Function and Toolkit COULD be the same, but there is no intrinsic relationship between the Toolkit and the fpLOSTrue function.
The hard part is that the Starting Point, Ending Point, and Target Point need to be exposed to us by the FG Code (ie the FG Coders) so that we can use them in both the Function and/or the Toolkit - as far as the Toolkit is concerned, the Starting Point and Ending Point are exposed via the inbuilt onBuildCustomPointer function. However, we would need to have these two Points and the Target Point exposed to us in some other function for us to be able to use them in the fpLOSTrue function, and the to best of my knowledge that exposure function does not exist.
Until it does we cannot do automatic targeting (at least not via this method).
Continued in Part 2.
Introduction
This thread has been created for the expressed purpose of discussing and developing a Line-Of-Sight (LOS) system for use within our games. It has come about from a discussion in August 2013 around the creation of Custom Pointers and some further thoughts and correspondence since then. The original discussion can be found in Posts #16-19 of this thread (https://www.fantasygrounds.com/forums/showthread.php?19253-Custom-Pointers-Coding-Toolkit-Over-Several-Posts).
At the time of creation of this thread (Feb 29, 2016) the solution present here is only an "Initial Solution" in that, while the method (algorithm) and resulting function(s) will determine if LOS exists between two Tokens on an Image, it does so ONLY for the most primitive case: that of an Attacker and a Target, but without the possibility of any walls or other objects that the Target might "hide behind" - see the Further Remarks section.
Finally, all quotes have been edited for clarity.
Background
Back in August 2013 I developed a Custom Pointer Toolkit (available here (https://www.fantasygrounds.com/forums/showthread.php?19253-Custom-Pointers-Coding-Toolkit-Over-Several-Posts)) which simplified the creation of non-standard Pointers for use within our games. A Pointer is the Line, Circle, Square and Cone shapes that we draw on Images to indicate various things. At the time Zeus asked the following:
just to clarify something. If we know the start/stop point of a pointer as well as its area coverage, it should be possible to track the image area covered by a pointer (mapped to x,y points in an image control). If this is the case then I believe this would be all that would be necessary to initiate a basic mechanism for determining Line of Sight to any targeted token (also on the same image).
I am thinking it maybe possible to attach an invisible 25-45 degree wide cone to all tokens, facing out from the current facing direction of the token. As the token rotates, so too does the LoS cone. Now to determine LoS we simply have to check to see if the x,y position of the target token falls within the LoS cone area, if it does we have LoS, if not we don't have LoS etc. etc.
To which I replied:
You wouldn't need to actually draw the "Invisible Cone" (although that's not a bad way to think about it) - you simply need to check if the Target coordinates were within an area defined by the coordinates defining the (LOS) Cone.
The functions used to draw a Cone in the Toolkit take as arguments the Starting Coordinates of the Pointer, the Ending Coordinates of the Pointer and the Angle-Of-Arc of the Cone (the Field-Of-Vision, or FOV). This is convenient, because with these three things, plus the Coordinates of the Target, it is relatively simple to solve our problem - let me explain.
The Target lies in our Line-Of-Sight (ie within the "Invisible LOS-Cone") if (Conditions):
The Target is between the two "arms" or straight-edges of the LOS Cone, and
The distance from the Starting Point (the Attacker) to the Target is less than or equal to the length of the LOS-Cone.
Thus (Remarks):
The LOS-Cone (the Pointer) is a symmetrical cone along its major axis. Let this major axis be known as the LOS-Line.
The angle that the LOS-Line lies relative to an arbitrary Control-Line is given by the math.atan2() function.
The angle that the line from the Starting Point to the Target (hereafter known as the Target-Line) lies relative to the arbitrary Control-Line is also given by the math.atan2() function.
Therefore the angle that the Target-Line and the LOS-Line make is simply the subtraction of the two math.atan2() results (from Remarks 1 and 2).
If the absolute value (math.abs()) of the result from Remark 3 is less than or equal to half of the FOV then we have fulfilled Requirement 1 (half the FOV because the LOS-Cone lies symmetrically on either side of the LOS-Line).
If the length of the Target-Line is less than or equal to the length of the LOS-Line than we have fulfilled Requirement 2.
If both Requirement 1 and Requirement 2 are fulfilled (ie TRUE) then the Target is within Line-Of-Sight.
I then gave a code sample (the fpLOSTrue function) and a few usage remarks.
At the time of this discussion there was some brief excitement that we were well on the way to achieving (basic) LOS, but this was quickly dampened when I posted:
Not quite, no.
The Pointer Toolkit will allow us to draw a Cone Pointer based on its Starting Point and Ending Point, provided we supply the relevant function with a "hard wired" Angle-Of-Arc, which will then be drawn by FG for us.
The fpLOSTrue function will allow us to determine if a Target Point lies within the area defined by a Cone with a Starting Point, Ending Point and a FOV (Angle-Of-Arc).
The Starting Points, Ending Points and Angle-Of-Arcs supplied to both Function and Toolkit COULD be the same, but there is no intrinsic relationship between the Toolkit and the fpLOSTrue function.
The hard part is that the Starting Point, Ending Point, and Target Point need to be exposed to us by the FG Code (ie the FG Coders) so that we can use them in both the Function and/or the Toolkit - as far as the Toolkit is concerned, the Starting Point and Ending Point are exposed via the inbuilt onBuildCustomPointer function. However, we would need to have these two Points and the Target Point exposed to us in some other function for us to be able to use them in the fpLOSTrue function, and the to best of my knowledge that exposure function does not exist.
Until it does we cannot do automatic targeting (at least not via this method).
Continued in Part 2.