[Scummvm-git-logs] scummvm master -> dc7e5c22fd77e1e88474617122493aa0657ca7f2
aquadran
noreply at scummvm.org
Wed Nov 4 19:15:11 UTC 2026
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://api.github.com/repos/scummvm/scummvm .
Summary:
dc7e5c22fd GRIM: Fix collision handling for box models
Commit: dc7e5c22fd77e1e88474617122493aa0657ca7f2
https://github.com/scummvm/scummvm/commit/dc7e5c22fd77e1e88474617122493aa0657ca7f2
Author: Joel Teichroeb (joel at teichroeb.net)
Date: 2026-11-04T20:15:07+01:00
Commit Message:
GRIM: Fix collision handling for box models
In the binary model format, one of the parameters we were skipping was
the models center and bounding box information. Since we always have
that now we can skip manually trying to calculate it from the mesh.
Tested in sets that previously worked:
bv
bd
lb
si
Sets that now have correct collision:
nq
Assisted-by: Claude:claude-sonnet-5-5
Changed paths:
engines/grim/actor.cpp
engines/grim/actor.h
engines/grim/model.cpp
engines/grim/model.h
diff --git a/engines/grim/actor.cpp b/engines/grim/actor.cpp
index 3ef565dcc7c..81be0543ed0 100644
--- a/engines/grim/actor.cpp
+++ b/engines/grim/actor.cpp
@@ -2043,7 +2043,7 @@ Math::Vector3d Actor::getTangentPos(const Math::Vector3d &pos, const Math::Vecto
}
Math::Vector3d p;
float size;
- if (!getSphereInfo(false, size, p))
+ if (!getSphereInfo(size, p))
return dest;
Math::Vector2d p1(pos.x(), pos.y());
Math::Vector2d p2(dest.x(), dest.y());
@@ -2117,7 +2117,7 @@ void Actor::getBBoxInfo(Math::Vector3d &bboxPos, Math::Vector3d &bboxSize) const
}
}
-bool Actor::getSphereInfo(bool adjustZ, float &size, Math::Vector3d &p) const {
+bool Actor::getSphereInfo(float &size, Math::Vector3d &p) const {
if (g_grim->getGameType() == GType_MONKEY4) {
EMICostume *costume = static_cast<EMICostume *>(getCurrentCostume());
if (!costume) {
@@ -2133,11 +2133,7 @@ bool Actor::getSphereInfo(bool adjustZ, float &size, Math::Vector3d &p) const {
Model *model = getCurrentCostume()->getModel();
assert(model);
- p = _pos + model->_insertOffset;
- // center the sphere on the model center.
- if (adjustZ) {
- p.z() += model->_bboxSize.z() / 2.f;
- }
+ p = _pos + model->_insertOffset + model->_center;
size = model->_radius * _collisionScale;
}
return true;
@@ -2154,11 +2150,7 @@ bool Actor::handleCollisionWith(Actor *actor, CollisionMode mode, Math::Vector3d
Math::Vector3d p1, p2;
float size1, size2;
- // you may ask: why center the sphere of the first actor only (by setting adjustZ to true)?
- // because it seems the original does so.
- // if you change this code test this places: the rocks in lb and bv (both when booting directly in the
- // set and when coming in from another one) and the poles in xb.
- if (!this->getSphereInfo(true, size1, p1) || !actor->getSphereInfo(false, size2, p2)) {
+ if (!this->getSphereInfo(size1, p1) || !actor->getSphereInfo(size2, p2)) {
return false;
}
diff --git a/engines/grim/actor.h b/engines/grim/actor.h
index 37c93795c88..2da8f5cdf69 100644
--- a/engines/grim/actor.h
+++ b/engines/grim/actor.h
@@ -593,7 +593,7 @@ private:
Math::Vector3d getSimplePuckVector() const;
void calculateOrientation(const Math::Vector3d &pos, Math::Angle *pitch, Math::Angle *yaw, Math::Angle *roll);
- bool getSphereInfo(bool adjustZ, float &size, Math::Vector3d &pos) const;
+ bool getSphereInfo(float &size, Math::Vector3d &pos) const;
EMIModel *findModelWithMesh(const Common::String &mesh);
Common::String _name;
diff --git a/engines/grim/model.cpp b/engines/grim/model.cpp
index 6b23607d260..a9de7bcb1dc 100644
--- a/engines/grim/model.cpp
+++ b/engines/grim/model.cpp
@@ -47,41 +47,6 @@ Model::Model(const Common::String &filename, Common::SeekableReadStream *data, C
TextSplitter ts(_fname, data);
loadText(&ts);
}
-
- Math::Vector3d max;
-
- _rootHierNode->update();
- bool first = true;
- for (int i = 0; i < _numHierNodes; ++i) {
- ModelNode &node = _rootHierNode[i];
- if (node._mesh) {
- g_driver->createMesh(node._mesh);
- Mesh &mesh = *node._mesh;
- Math::Vector3d p = mesh._matrix.getPosition();
- float x = p.x();
- float y = p.y();
- float z = p.z();
- for (int k = 0; k < mesh._numVertices * 3; k += 3) {
- if (first || mesh._vertices[k] + x < _bboxPos.x())
- _bboxPos.x() = mesh._vertices[k] + x;
- if (first || mesh._vertices[k + 1] + y < _bboxPos.y())
- _bboxPos.y() = mesh._vertices[k + 1] + y;
- if (first || mesh._vertices[k + 2] + z < _bboxPos.z())
- _bboxPos.z() = mesh._vertices[k + 2] + z;
-
- if (first || mesh._vertices[k] + x > max.x())
- max.x() = mesh._vertices[k] + x;
- if (first || mesh._vertices[k + 1] + y > max.y())
- max.y() = mesh._vertices[k + 1] + y;
- if (first || mesh._vertices[k + 2] + z > max.z())
- max.z() = mesh._vertices[k + 2] + z;
-
- first = false;
- }
- }
- }
-
- _bboxSize = max - _bboxPos;
}
Model::~Model() {
@@ -122,7 +87,11 @@ void Model::loadBinary(Common::SeekableReadStream *data) {
_rootHierNode[i].loadBinary(data, _rootHierNode, &_geosets[0]);
}
_radius = data->readFloatLE();
- data->seek(36, SEEK_CUR);
+ _bboxPos.readFromStream(data);
+ Math::Vector3d bboxMax;
+ bboxMax.readFromStream(data);
+ _bboxSize = bboxMax - _bboxPos;
+ _center.readFromStream(data);
_insertOffset.readFromStream(data);
}
@@ -204,6 +173,42 @@ void Model::loadText(TextSplitter *ts) {
if (!ts->isEof())
Debug::warning(Debug::Models, "Unexpected junk at end of model text");
+
+ Math::Vector3d max;
+
+ _rootHierNode->update();
+ bool first = true;
+ for (int i = 0; i < _numHierNodes; ++i) {
+ ModelNode &node = _rootHierNode[i];
+ if (node._mesh) {
+ g_driver->createMesh(node._mesh);
+ Mesh &mesh = *node._mesh;
+ Math::Vector3d p = mesh._matrix.getPosition();
+ float x = p.x();
+ float y = p.y();
+ float z = p.z();
+ for (int k = 0; k < mesh._numVertices * 3; k += 3) {
+ if (first || mesh._vertices[k] + x < _bboxPos.x())
+ _bboxPos.x() = mesh._vertices[k] + x;
+ if (first || mesh._vertices[k + 1] + y < _bboxPos.y())
+ _bboxPos.y() = mesh._vertices[k + 1] + y;
+ if (first || mesh._vertices[k + 2] + z < _bboxPos.z())
+ _bboxPos.z() = mesh._vertices[k + 2] + z;
+
+ if (first || mesh._vertices[k] + x > max.x())
+ max.x() = mesh._vertices[k] + x;
+ if (first || mesh._vertices[k + 1] + y > max.y())
+ max.y() = mesh._vertices[k + 1] + y;
+ if (first || mesh._vertices[k + 2] + z > max.z())
+ max.z() = mesh._vertices[k + 2] + z;
+
+ first = false;
+ }
+ }
+ }
+
+ _bboxSize = max - _bboxPos;
+ _center = _bboxPos + _bboxSize / 2.f;
}
void Model::draw() const {
diff --git a/engines/grim/model.h b/engines/grim/model.h
index 289ececf900..1f8936c6d70 100644
--- a/engines/grim/model.h
+++ b/engines/grim/model.h
@@ -87,6 +87,7 @@ public:
ModelNode *_rootHierNode;
Math::Vector3d _bboxPos;
Math::Vector3d _bboxSize;
+ Math::Vector3d _center;
};
class MeshFace {
More information about the Scummvm-git-logs
mailing list