diff options
author | Filippos Karapetis | 2019-12-27 01:33:02 +0200 |
---|---|---|
committer | Filippos Karapetis | 2019-12-27 01:33:28 +0200 |
commit | f7a5c21d4de443f861544db17b18c958cea2811f (patch) | |
tree | fab74f9d0e1008b626f466d5b17c1fbf9fc32b32 /engines/startrek/room.cpp | |
parent | 26fcce1e4174d528829d42196a27667c0996108d (diff) | |
download | scummvm-rg350-f7a5c21d4de443f861544db17b18c958cea2811f.tar.gz scummvm-rg350-f7a5c21d4de443f861544db17b18c958cea2811f.tar.bz2 scummvm-rg350-f7a5c21d4de443f861544db17b18c958cea2811f.zip |
STARTREK: Move isPointInPolygon() inside the Room class
This accesses the room data, so it's better to move it inside the Room
class, to reduce direct visibility of the room vertex data
Diffstat (limited to 'engines/startrek/room.cpp')
-rw-r--r-- | engines/startrek/room.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/engines/startrek/room.cpp b/engines/startrek/room.cpp index 9fc0431e81..f3b853acde 100644 --- a/engines/startrek/room.cpp +++ b/engines/startrek/room.cpp @@ -756,4 +756,26 @@ void Room::mccoyScan(int direction, TextRef text, bool changeDirection, bool fro showText(TX_SPEAKER_MCCOY, text, fromRDF); } +bool Room::isPointInPolygon(int16 offset, int16 x, int16 y) { + int16 *data = (int16 *)(_rdfData + offset); + int16 numVertices = data[1]; + int16 *vertData = &data[2]; + + for (int i = 0; i < numVertices; i++) { + Common::Point p1(vertData[0], vertData[1]); + Common::Point p2; + if (i == numVertices - 1) // Loop to 1st vertex + p2 = Common::Point(data[2], data[3]); + else + p2 = Common::Point(vertData[2], vertData[3]); + + if ((p2.x - p1.x) * (y - p1.y) - (p2.y - p1.y) * (x - p1.x) < 0) + return false; + + vertData += 2; + } + + return true; +} + } // End of namespace StarTrek |