ASYLUM: Added support for polygon testing inside bounding boxes.

git-svn-id: http://asylumengine.googlecode.com/svn/trunk@228 0bfb4aae-4ea4-11de-8d8d-752d95cf3e3c
This commit is contained in:
Joseph Davies 2009-07-07 01:07:01 +00:00 committed by Eugene Sandulenko
parent 19d9e775b9
commit 7795ce38d8
No known key found for this signature in database
GPG key ID: 014D387312D34F08
2 changed files with 36 additions and 5 deletions

View file

@ -59,7 +59,7 @@ Scene::Scene(Screen *screen, Sound *sound, uint8 sceneIdx): _screen(screen), _so
_leftClick = false;
_rightButton = false;
_isActive = false;
g_debugPolygons = 0;
g_debugPolygons = 1;
}
Scene::~Scene() {
@ -300,9 +300,11 @@ void Scene::update() {
for (uint32 p = 0; p < _sceneResource->getGamePolygons()->numEntries; p++) {
PolyDefinitions poly = _sceneResource->getGamePolygons()->polygons[p];
if (poly.boundingRect.contains(_mouseX + _startX, _mouseY + _startY)) {
curHotspot = (int32)p;
updateCursor();
break;
if (pointInPoly(&poly, _mouseX + _startX, _mouseY + _startY)) {
curHotspot = (int32)p;
updateCursor();
break;
}
}
}
@ -408,6 +410,33 @@ void Scene::updateBarrier(Screen *screen, ResourcePack *res, uint8 barrierIndex)
delete gra;
}
bool Scene::pointInPoly(PolyDefinitions *poly, int x, int y) {
// Copied from backends/vkeybd/polygon.cpp
int yflag0;
int yflag1;
bool inside_flag = false;
unsigned int pt;
Common::Point *vtx0 = &poly->points[poly->numPoints - 1];
Common::Point *vtx1 = &poly->points[0];
yflag0 = (vtx0->y >= y);
for (pt = 0; pt < poly->numPoints; pt++, vtx1++) {
yflag1 = (vtx1->y >= y);
if (yflag0 != yflag1) {
if (((vtx1->y - y) * (vtx0->x - vtx1->x) >=
(vtx1->x - x) * (vtx0->y - vtx1->y)) == yflag1) {
inside_flag = !inside_flag;
}
}
yflag0 = yflag1;
vtx0 = vtx1;
}
return inside_flag;
}
// POLYGONS DEBUG
void Scene::ShowPolygons() {
for (uint32 p = 0; p < _sceneResource->getGamePolygons()->numEntries; p++) {

View file

@ -40,8 +40,9 @@ class Screen;
class Sound;
class SceneResource;
class Text;
class ActionDefinitions;
class Interpreter;
class ActionDefinitions;
class PolyDefinitions;
class Scene {
public:
@ -99,6 +100,7 @@ private:
void updateBarrier(Screen *screen, ResourcePack *res, uint8 actorIndex);
void ShowPolygons();
bool pointInPoly(PolyDefinitions *poly, int x, int y);
friend class Interpreter;
}; // end of class Scene