[Scummvm-cvs-logs] scummvm master -> 5dabd4bf3767f209fcd25107a5d3a0f0aedadce4

sev- sev at scummvm.org
Sat Oct 5 10:53:36 CEST 2013


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
5dabd4bf37 FULLPIPE: Implement MovGraphReact::pointInRegion()


Commit: 5dabd4bf3767f209fcd25107a5d3a0f0aedadce4
    https://github.com/scummvm/scummvm/commit/5dabd4bf3767f209fcd25107a5d3a0f0aedadce4
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2013-10-05T01:53:08-07:00

Commit Message:
FULLPIPE: Implement MovGraphReact::pointInRegion()

Changed paths:
    engines/fullpipe/motion.cpp
    engines/fullpipe/motion.h



diff --git a/engines/fullpipe/motion.cpp b/engines/fullpipe/motion.cpp
index 2ff2c00..c3c5656 100644
--- a/engines/fullpipe/motion.cpp
+++ b/engines/fullpipe/motion.cpp
@@ -652,7 +652,6 @@ ReactParallel::ReactParallel() {
 	_x2 = 0;
 	_dy = 0;
 	_dx = 0;
-	_points = 0;
 	_y1 = 0;
 	_y2 = 0;
 }
@@ -688,12 +687,13 @@ void ReactParallel::createRegion() {
 	_points[1]->x = (int16)(_x2 - _dx * cs);
 	_points[1]->y = (int16)(_y2 - _dx * sn);
 
-	_points[2]->x = (int16)(_x1 + _dy * cs);
+	_points[2]->x = (int16)(_x2 + _dy * cs);
 	_points[2]->y = (int16)(_y2 + _dy * sn);
 
 	_points[3]->x = (int16)(_x1 + _dy * cs);
 	_points[3]->y = (int16)(_y1 + _dy * sn);
 
+	_pointCount = 4;
 	// GdiObject::Attach(_rgn, CreatePolygonRgn(_points, 4, 2);
 }
 
@@ -701,18 +701,8 @@ void ReactParallel::method14() {
 	warning("STUB: ReactParallel::method14()");
 }
 
-bool ReactParallel::pointInRegion(int x, int y) {
-	warning("STUB: ReactParallel::pointInRegion()");
-
-	warning("%d %d, %d %d, %d %d, %d %d", _points[0]->x, _points[0]->y, _points[1]->x, _points[1]->y, _points[2]->x, _points[2]->y, _points[3]->x, _points[3]->y);
-
-	return false;
-}
-
 ReactPolygonal::ReactPolygonal() {
 	_field_C = 0;
-	_points = 0;
-	_pointCount = 0;
 	_field_10 = 0;
 }
 
@@ -751,10 +741,45 @@ void ReactPolygonal::method14() {
 	warning("STUB: ReactPolygonal::method14()");
 }
 
-bool ReactPolygonal::pointInRegion(int x, int y) {
-	warning("STUB: ReactPolygonal::pointInRegion()");
+bool MovGraphReact::pointInRegion(int x, int y) {
+	if (_pointCount < 3) {
+		return false;
+	}
+
+	int counter = 0;
+	double xinters;
+	Common::Point p, p1, p2;
+
+	p.x = (double)x;
+	p.y = (double)y;
+
+	p1.x = (double)_points[0]->x;
+	p1.y = (double)_points[0]->y;
+
+	for (uint32 i = 1; i <= _pointCount; i++) {
+		p2.x = (double)_points[i % _pointCount]->x;
+		p2.y = (double)_points[i % _pointCount]->y;
+
+		if (p.y > MIN(p1.y, p2.y)) {
+			if (p.y <= MAX(p1.y, p2.y)) {
+				if (p.x <= MAX(p1.x, p2.x)) {
+					if (p1.y != p2.y) {
+						xinters = (p.y - p1.y) * (p2.x - p1.x) / (p2.y - p1.y) + p1.x;
+						if (p1.x == p2.x || p.x <= xinters) {
+							counter++;
+						}
+					}
+				}
+			}
+		}
+		p1 = p2;
+	}
 
-	return false;
+	if (counter % 2 == 0) {
+		return false;
+	} else {
+		return true;
+	}
 }
 
 int startWalkTo(int objId, int objKey, int x, int y, int a5) {
diff --git a/engines/fullpipe/motion.h b/engines/fullpipe/motion.h
index f94fbc0..750f1dc 100644
--- a/engines/fullpipe/motion.h
+++ b/engines/fullpipe/motion.h
@@ -63,9 +63,16 @@ public:
 
 class MovGraphReact : public CObject {
 public:
+	int _pointCount;
+	Common::Point **_points;
+
+public:
+	MovGraphReact() : _pointCount(0), _points(0) {}
+	~MovGraphReact() { free(_points); }
+
 	virtual void method14() {}
 	virtual void createRegion() {}
-	virtual bool pointInRegion(int x, int y) { return false; }
+	virtual bool pointInRegion(int x, int y);
 };
 
 class MctlCompoundArrayItem : public CObject {
@@ -160,7 +167,6 @@ class ReactParallel : public MovGraphReact {
 	int _y2;
 	int _dx;
 	int _dy;
-	Common::Point **_points;
 
   public:
 	ReactParallel();
@@ -168,15 +174,12 @@ class ReactParallel : public MovGraphReact {
 
 	virtual void method14();
 	virtual void createRegion();
-	virtual bool pointInRegion(int x, int y);
 };
 
 class ReactPolygonal : public MovGraphReact {
 	//CRgn _rgn;
 	int _field_C;
 	int _field_10;
-	int _pointCount;
-	Common::Point **_points;
 
   public:
 	ReactPolygonal();
@@ -184,7 +187,6 @@ class ReactPolygonal : public MovGraphReact {
 
 	virtual void method14();
 	virtual void createRegion();
-	virtual bool pointInRegion(int x, int y);
 };
 
 class MovGraphLink : public CObject {






More information about the Scummvm-git-logs mailing list