[Scummvm-cvs-logs] CVS: residual actor.cpp,1.24,1.25 actor.h,1.11,1.12 lua.cpp,1.53,1.54 scene.cpp,1.23,1.24 scene.h,1.15,1.16 walkplane.cpp,1.7,1.8 walkplane.h,1.5,1.6

Daniel Schepler dschepler at users.sourceforge.net
Thu Mar 25 01:45:00 CET 2004


Update of /cvsroot/scummvm/residual
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17650

Modified Files:
	actor.cpp actor.h lua.cpp scene.cpp scene.h walkplane.cpp 
	walkplane.h 
Log Message:
Preliminary improvement of walk plane code.  With this, you should be
able to play the game up through getting the work order signed.  More
walk plane improvements to come...

Factor out code to search for a sector containing a point.


Index: actor.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/actor.cpp,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- actor.cpp	24 Mar 2004 01:36:05 -0000	1.24
+++ actor.cpp	25 Mar 2004 09:33:17 -0000	1.25
@@ -69,36 +69,25 @@
 	}
 }
 
-bool Actor::validBoxVector(Vector3d forwardVec, float dist) {
-	// TODO: Verify if any other sector flags allow walking
-	// Possibly use a box-aware TraceLine function instead of just checking
-	// dest point
-	Vector3d tempVec = pos_ + (forwardVec * dist);
-	int numSectors = Engine::instance()->currScene()->getSectorCount();
-
-	if (constrain_ == false)
-		return true;
-
-	for (int i = 0; i < numSectors; i++) {
-		Sector *sector = Engine::instance()->currScene()->getSectorBase(i);
-		if ((sector->type() & 0x1000) && sector->visible()) {
-			if (sector->isPointInSector(tempVec))
-				return true;
-		}
-	}
-	return false;
-}
-
 void Actor::walkForward() {
 	float dist = Engine::instance()->perSecond(walkRate_);
 	float yaw_rad = yaw_ * (M_PI / 180), pitch_rad = pitch_ * (M_PI / 180);
 	Vector3d forwardVec(-std::sin(yaw_rad) * std::cos(pitch_rad),
 		std::cos(yaw_rad) * std::cos(pitch_rad),
 		std::sin(pitch_rad));
-	if (validBoxVector(forwardVec, dist)) {
-		pos_ += forwardVec * dist;
+	Vector3d destPos = pos_ + forwardVec * dist;
+
+	if (! constrain_) {
+		pos_ = destPos;
 		lastWalkTime_ = Engine::instance()->frameStart();
 	}
+	else {
+		Sector *sector = Engine::instance()->currScene()->findPointSector(destPos, 0x1000);
+		if (sector != NULL) {
+			pos_ = sector->projectToPlane(destPos);
+			lastWalkTime_ = Engine::instance()->frameStart();
+		}
+	}
 }
 
 void Actor::setRestChore(int chore, Costume *cost) {

Index: actor.h
===================================================================
RCS file: /cvsroot/scummvm/residual/actor.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- actor.h	24 Mar 2004 01:36:05 -0000	1.11
+++ actor.h	25 Mar 2004 09:33:17 -0000	1.12
@@ -59,8 +59,6 @@
 	float angleTo(const Actor &a) const;
 	float yawTo(Vector3d p) const;
 
-	bool validBoxVector(Vector3d forwardVec, float dist);
-
 	bool inSet(const char *name) const {
 		return setName_ == name;
 	}

Index: lua.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/lua.cpp,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -d -r1.53 -r1.54
--- lua.cpp	24 Mar 2004 13:02:14 -0000	1.53
+++ lua.cpp	25 Mar 2004 09:33:17 -0000	1.54
@@ -693,20 +693,17 @@
 		error("Invalid sector type %d\n", sectorType);
 }
 
-	int numSectors = Engine::instance()->currScene()->getSectorCount();
-	for (int i = 0; i < numSectors; i++) {
-		Sector *sector = Engine::instance()->currScene()->getSectorBase(i);
-		if (sector->visible() && (sector->type() & sectorFlag)) {
-			if (sector->isPointInSector(act->pos())) {
-				lua_pushnumber(sector->id());
-				lua_pushstring(const_cast<char *>(sector->name()));
-				lua_pushnumber(sector->type());
-				return;
-			}
-		}
+	Sector *result = Engine::instance()->currScene()->findPointSector(act->pos(), sectorFlag);
+	if (result != NULL) {
+		lua_pushnumber(result->id());
+		lua_pushstring(const_cast<char *>(result->name()));
+		lua_pushnumber(result->type());
+	}
+	else {
+		lua_pushnil();
+		lua_pushnil();
+		lua_pushnil();
 	}
-
-	lua_pushnil();
 }
 
 static void IsActorInSector(void) {

Index: scene.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/scene.cpp,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- scene.cpp	24 Mar 2004 12:20:46 -0000	1.23
+++ scene.cpp	25 Mar 2004 09:33:17 -0000	1.24
@@ -171,6 +171,16 @@
 	}
 }
 
+Sector *Scene::findPointSector(Vector3d p, int flags) {
+	for (int i = 0; i < numSectors_; i++) {
+		Sector *sector = sectors_ + i;
+		if ((sector->type() & flags) && sector->visible() &&
+		    sector->isPointInSector(p))
+			return sector;
+	}
+	return NULL;
+}
+
 ObjectState *Scene::findState(const char *filename) {
 	for (StateList::iterator i = states_.begin(); i != states_.end();
 	     i++) {

Index: scene.h
===================================================================
RCS file: /cvsroot/scummvm/residual/scene.h,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- scene.h	23 Mar 2004 10:38:02 -0000	1.15
+++ scene.h	25 Mar 2004 09:33:17 -0000	1.16
@@ -66,6 +66,7 @@
 		else
 			return NULL;
 	}
+	Sector *findPointSector(Vector3d p, int flags);
 
 	void addObjectState(ObjectState *s) {
 		states_.push_back(s);

Index: walkplane.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/walkplane.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- walkplane.cpp	25 Feb 2004 08:21:31 -0000	1.7
+++ walkplane.cpp	25 Mar 2004 09:33:17 -0000	1.8
@@ -79,6 +79,12 @@
 
 	// Repeat the last vertex for convenience
 	vertices_[numVertices_] = vertices_[0];
+
+	normal_ = cross(vertices_[1] - vertices_[0],
+			vertices_[numVertices_ - 1] - vertices_[0]);
+	float length = normal_.magnitude();
+	if (length > 0)
+		normal_ /= length;
 }
 
 void Sector::setVisible(bool visible) {
@@ -103,3 +109,13 @@
 	}
 	return true;
 }
+
+Vector3d Sector::projectToPlane(Vector3d point) const {
+	if (normal_.z() == 0)
+		error("Trying to walk along vertical plane\n");
+
+	// Formula: return p - (n . (p - v_0))/(n . k) k
+	Vector3d result = point;
+	result.z() -= dot(normal_, point - vertices_[0]) / normal_.z();
+	return result;
+}

Index: walkplane.h
===================================================================
RCS file: /cvsroot/scummvm/residual/walkplane.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- walkplane.h	25 Feb 2004 08:21:31 -0000	1.5
+++ walkplane.h	25 Mar 2004 09:33:17 -0000	1.6
@@ -39,6 +39,8 @@
 	bool visible() const { return visible_; }
 	bool isPointInSector(Vector3d point) const;
 
+	Vector3d projectToPlane(Vector3d point) const;
+
 private:
 	int numVertices_, id_;
 
@@ -47,5 +49,7 @@
 	bool visible_;
 	Vector3d *vertices_;
 	float height_;
+
+	Vector3d normal_;
 };
 #endif





More information about the Scummvm-git-logs mailing list