[Scummvm-cvs-logs] CVS: residual lua.cpp,1.9,1.10 walkplane.cpp,1.1,1.2 walkplane.h,1.1,1.2
Daniel Schepler
dschepler at users.sourceforge.net
Tue Aug 19 18:21:06 CEST 2003
Update of /cvsroot/scummvm/residual
In directory sc8-pr-cvs1:/tmp/cvs-serv21776
Modified Files:
lua.cpp walkplane.cpp walkplane.h
Log Message:
Implemented isPointInSector and GetActorSector.
Index: lua.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/lua.cpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- lua.cpp 19 Aug 2003 23:46:16 -0000 1.9
+++ lua.cpp 20 Aug 2003 00:35:37 -0000 1.10
@@ -462,15 +462,35 @@
Actor *act = check_actor(1);
int sectorType = check_int(2);
- warning("GetActorSector(%s, %d): STUB", act->name(), sectorType);
+ int sectorFlag;
+ switch (sectorType) {
+ case 1:
+ sectorFlag = 0x1000;
+ break;
+ case 2:
+ sectorFlag = 0x2000;
+ break;
+ case 3:
+ sectorFlag = 0x8000;
+ break;
+ default:
+ error("Invalid sector type %d\n", sectorType);
+ }
- if (0) {
- lua_pushnumber(0); // id
- lua_pushstring(""); // name
- lua_pushnumber(0); // type
- } else {
- lua_pushnil();
+ int numSectors = Engine::instance()->currScene()->getSectorCount();
+ for (int i = 0; i < numSectors; i++) {
+ Sector *sector = Engine::instance()->currScene()->getSectorBase(i);
+ if (sector->type() & sectorFlag) {
+ if (sector->isPointInSector(act->pos())) {
+ lua_pushnumber(sector->id());
+ lua_pushstring(const_cast<char *>(sector->name()));
+ lua_pushnumber(sector->type());
+ return;
+ }
+ }
}
+
+ lua_pushnil();
}
static void IsActorInSector(void) {
Index: walkplane.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/walkplane.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- walkplane.cpp 19 Aug 2003 07:20:03 -0000 1.1
+++ walkplane.cpp 20 Aug 2003 00:35:37 -0000 1.2
@@ -57,12 +57,32 @@
visibility_ = buf;
ts.scanString(" height %f", 1, &height_);
ts.scanString(" numvertices %d", 1, &numVertices_);
- vertices_ = new Vector3d[numVertices_];
+ vertices_ = new Vector3d[numVertices_ + 1];
ts.scanString(" vertices: %f %f %f", 3, &vertices_[0].x(), &vertices_[0].y(),
&vertices_[0].z());
for (i=1;i<numVertices_;i++)
ts.scanString(" %f %f %f", 3, &vertices_[i].x(), &vertices_[i].y(), &vertices_[i].z());
+
+ // Repeat the last vertex for convenience
+ vertices_[numVertices_] = vertices_[0];
}
+bool Sector::isPointInSector(Vector3d point) const {
+ // The algorithm: for each edge A->B, check whether the z-component
+ // of (B-A) x (P-A) is >= 0. Then the point is at least in the
+ // cylinder above&below the polygon. (This works because the polygons'
+ // vertices are always given in counterclockwise order, and the
+ // polygons are always convex.)
+ //
+ // (I don't know whether the box height actually has to be considered;
+ // if not then this will be fine as is.)
+ for (int i = 0; i < numVertices_; i++) {
+ Vector3d edge = vertices_[i+1] - vertices_[i];
+ Vector3d delta = point - vertices_[i];
+ if (edge.x() * delta.y() < edge.y() * delta.x())
+ return false;
+ }
+ return true;
+}
Index: walkplane.h
===================================================================
RCS file: /cvsroot/scummvm/residual/walkplane.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- walkplane.h 19 Aug 2003 07:20:03 -0000 1.1
+++ walkplane.h 20 Aug 2003 00:35:37 -0000 1.2
@@ -33,11 +33,8 @@
const char *name() const { return name_.c_str(); }
const int id() const { return id_; }
- const int type() const { return 0; } // FIXME: Implement type de-masking
- bool isPointInSector(Vector3d point) const {
- // FIXME: Implement point-in-poly function
- return false;
- }
+ const int type() const { return type_; } // FIXME: Implement type de-masking
+ bool isPointInSector(Vector3d point) const;
private:
int numVertices_, id_;
More information about the Scummvm-git-logs
mailing list