mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
Merge pull request #94 from FlightControl-Master/Bugfix-Polygon-zone-test
Fixed the raycasting of ZONE_POLYGON_BASE
This commit is contained in:
commit
e842c7a042
@ -490,33 +490,34 @@ end
|
|||||||
|
|
||||||
|
|
||||||
--- Returns if a location is within the zone.
|
--- Returns if a location is within the zone.
|
||||||
|
-- Source learned and taken from: https://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
|
||||||
-- @param #ZONE_POLYGON_BASE self
|
-- @param #ZONE_POLYGON_BASE self
|
||||||
-- @param DCSTypes#Vec2 PointVec2 The location to test.
|
-- @param DCSTypes#Vec2 PointVec2 The location to test.
|
||||||
-- @return #boolean true if the location is within the zone.
|
-- @return #boolean true if the location is within the zone.
|
||||||
function ZONE_POLYGON_BASE:IsPointVec2InZone( PointVec2 )
|
function ZONE_POLYGON_BASE:IsPointVec2InZone( PointVec2 )
|
||||||
self:F2( PointVec2 )
|
self:F2( PointVec2 )
|
||||||
|
|
||||||
local i
|
local Next
|
||||||
local j
|
local Prev
|
||||||
local c = false
|
local InPolygon = false
|
||||||
|
|
||||||
i = 1
|
Next = 1
|
||||||
j = #self.Polygon
|
Prev = #self.Polygon
|
||||||
|
|
||||||
while i < #self.Polygon do
|
while Next <= #self.Polygon do
|
||||||
j = i
|
self:T( { Next, Prev, self.Polygon[Next], self.Polygon[Prev] } )
|
||||||
i = i + 1
|
if ( ( ( self.Polygon[Next].y > PointVec2.y ) ~= ( self.Polygon[Prev].y > PointVec2.y ) ) and
|
||||||
self:T( { i, j, self.Polygon[i], self.Polygon[j] } )
|
( PointVec2.x < ( self.Polygon[Prev].x - self.Polygon[Next].x ) * ( PointVec2.y - self.Polygon[Next].y ) / ( self.Polygon[Prev].y - self.Polygon[Next].y ) + self.Polygon[Next].x )
|
||||||
if ( ( ( self.Polygon[i].y > PointVec2.y ) ~= ( self.Polygon[j].y > PointVec2.y ) ) and
|
|
||||||
( PointVec2.x < ( self.Polygon[j].x - self.Polygon[i].x ) * ( PointVec2.y - self.Polygon[i].y ) / ( self.Polygon[j].y - self.Polygon[i].y ) + self.Polygon[i].x )
|
|
||||||
) then
|
) then
|
||||||
c = not c
|
InPolygon = not InPolygon
|
||||||
end
|
end
|
||||||
self:T2( { "c = ", c } )
|
self:T2( { InPolygon = InPolygon } )
|
||||||
|
Prev = Next
|
||||||
|
Next = Next + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
self:T( { "c = ", c } )
|
self:T( { InPolygon = InPolygon } )
|
||||||
return c
|
return InPolygon
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Define a random @{DCSTypes#Vec2} within the zone.
|
--- Define a random @{DCSTypes#Vec2} within the zone.
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
env.info( '*** MOOSE STATIC INCLUDE START *** ' )
|
env.info( '*** MOOSE STATIC INCLUDE START *** ' )
|
||||||
env.info( 'Moose Generation Timestamp: 20160625_1329' )
|
env.info( 'Moose Generation Timestamp: 20160626_0720' )
|
||||||
local base = _G
|
local base = _G
|
||||||
|
|
||||||
Include = {}
|
Include = {}
|
||||||
@ -8957,33 +8957,34 @@ end
|
|||||||
|
|
||||||
|
|
||||||
--- Returns if a location is within the zone.
|
--- Returns if a location is within the zone.
|
||||||
|
-- Source learned and taken from: https://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
|
||||||
-- @param #ZONE_POLYGON_BASE self
|
-- @param #ZONE_POLYGON_BASE self
|
||||||
-- @param DCSTypes#Vec2 PointVec2 The location to test.
|
-- @param DCSTypes#Vec2 PointVec2 The location to test.
|
||||||
-- @return #boolean true if the location is within the zone.
|
-- @return #boolean true if the location is within the zone.
|
||||||
function ZONE_POLYGON_BASE:IsPointVec2InZone( PointVec2 )
|
function ZONE_POLYGON_BASE:IsPointVec2InZone( PointVec2 )
|
||||||
self:F2( PointVec2 )
|
self:F2( PointVec2 )
|
||||||
|
|
||||||
local i
|
local Next
|
||||||
local j
|
local Prev
|
||||||
local c = false
|
local InPolygon = false
|
||||||
|
|
||||||
i = 1
|
Next = 1
|
||||||
j = #self.Polygon
|
Prev = #self.Polygon
|
||||||
|
|
||||||
while i < #self.Polygon do
|
while Next <= #self.Polygon do
|
||||||
j = i
|
self:T( { Next, Prev, self.Polygon[Next], self.Polygon[Prev] } )
|
||||||
i = i + 1
|
if ( ( ( self.Polygon[Next].y > PointVec2.y ) ~= ( self.Polygon[Prev].y > PointVec2.y ) ) and
|
||||||
self:T( { i, j, self.Polygon[i], self.Polygon[j] } )
|
( PointVec2.x < ( self.Polygon[Prev].x - self.Polygon[Next].x ) * ( PointVec2.y - self.Polygon[Next].y ) / ( self.Polygon[Prev].y - self.Polygon[Next].y ) + self.Polygon[Next].x )
|
||||||
if ( ( ( self.Polygon[i].y > PointVec2.y ) ~= ( self.Polygon[j].y > PointVec2.y ) ) and
|
|
||||||
( PointVec2.x < ( self.Polygon[j].x - self.Polygon[i].x ) * ( PointVec2.y - self.Polygon[i].y ) / ( self.Polygon[j].y - self.Polygon[i].y ) + self.Polygon[i].x )
|
|
||||||
) then
|
) then
|
||||||
c = not c
|
InPolygon = not InPolygon
|
||||||
end
|
end
|
||||||
self:T2( { "c = ", c } )
|
self:T2( { InPolygon = InPolygon } )
|
||||||
|
Prev = Next
|
||||||
|
Next = Next + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
self:T( { "c = ", c } )
|
self:T( { InPolygon = InPolygon } )
|
||||||
return c
|
return InPolygon
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Define a random @{DCSTypes#Vec2} within the zone.
|
--- Define a random @{DCSTypes#Vec2} within the zone.
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
env.info( '*** MOOSE STATIC INCLUDE START *** ' )
|
env.info( '*** MOOSE STATIC INCLUDE START *** ' )
|
||||||
env.info( 'Moose Generation Timestamp: 20160625_1329' )
|
env.info( 'Moose Generation Timestamp: 20160626_0720' )
|
||||||
local base = _G
|
local base = _G
|
||||||
|
|
||||||
Include = {}
|
Include = {}
|
||||||
@ -8957,33 +8957,34 @@ end
|
|||||||
|
|
||||||
|
|
||||||
--- Returns if a location is within the zone.
|
--- Returns if a location is within the zone.
|
||||||
|
-- Source learned and taken from: https://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
|
||||||
-- @param #ZONE_POLYGON_BASE self
|
-- @param #ZONE_POLYGON_BASE self
|
||||||
-- @param DCSTypes#Vec2 PointVec2 The location to test.
|
-- @param DCSTypes#Vec2 PointVec2 The location to test.
|
||||||
-- @return #boolean true if the location is within the zone.
|
-- @return #boolean true if the location is within the zone.
|
||||||
function ZONE_POLYGON_BASE:IsPointVec2InZone( PointVec2 )
|
function ZONE_POLYGON_BASE:IsPointVec2InZone( PointVec2 )
|
||||||
self:F2( PointVec2 )
|
self:F2( PointVec2 )
|
||||||
|
|
||||||
local i
|
local Next
|
||||||
local j
|
local Prev
|
||||||
local c = false
|
local InPolygon = false
|
||||||
|
|
||||||
i = 1
|
Next = 1
|
||||||
j = #self.Polygon
|
Prev = #self.Polygon
|
||||||
|
|
||||||
while i < #self.Polygon do
|
while Next <= #self.Polygon do
|
||||||
j = i
|
self:T( { Next, Prev, self.Polygon[Next], self.Polygon[Prev] } )
|
||||||
i = i + 1
|
if ( ( ( self.Polygon[Next].y > PointVec2.y ) ~= ( self.Polygon[Prev].y > PointVec2.y ) ) and
|
||||||
self:T( { i, j, self.Polygon[i], self.Polygon[j] } )
|
( PointVec2.x < ( self.Polygon[Prev].x - self.Polygon[Next].x ) * ( PointVec2.y - self.Polygon[Next].y ) / ( self.Polygon[Prev].y - self.Polygon[Next].y ) + self.Polygon[Next].x )
|
||||||
if ( ( ( self.Polygon[i].y > PointVec2.y ) ~= ( self.Polygon[j].y > PointVec2.y ) ) and
|
|
||||||
( PointVec2.x < ( self.Polygon[j].x - self.Polygon[i].x ) * ( PointVec2.y - self.Polygon[i].y ) / ( self.Polygon[j].y - self.Polygon[i].y ) + self.Polygon[i].x )
|
|
||||||
) then
|
) then
|
||||||
c = not c
|
InPolygon = not InPolygon
|
||||||
end
|
end
|
||||||
self:T2( { "c = ", c } )
|
self:T2( { InPolygon = InPolygon } )
|
||||||
|
Prev = Next
|
||||||
|
Next = Next + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
self:T( { "c = ", c } )
|
self:T( { InPolygon = InPolygon } )
|
||||||
return c
|
return InPolygon
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Define a random @{DCSTypes#Vec2} within the zone.
|
--- Define a random @{DCSTypes#Vec2} within the zone.
|
||||||
|
|||||||
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user