Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of waveset bounding boxes. #287

Merged
merged 2 commits into from
Jun 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 31 additions & 7 deletions core/PRP/Geometry/plDrawableSpans.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,14 +531,38 @@ void plDrawableSpans::calcBounds()
hsBounds3Ext world;

world.setFlags(hsBounds3Ext::kAxisAligned);
auto localPoints = std::make_unique<hsVector3[]>(verts.size());
auto worldPoints = std::make_unique<hsVector3[]>(verts.size());
for (size_t j = 0; j < verts.size(); j++) {
localPoints[j] = verts[j].fPos;
worldPoints[j] = fIcicles[i]->getLocalToWorld().multPoint(verts[j].fPos);
if (fIcicles[i]->getProps() & plSpan::kWaterHeight) {
constexpr float kMaxWaveHeight = 5.f;

auto localPoints = std::make_unique<hsVector3[]>(verts.size());
for (size_t j = 0; j < verts.size(); j++)
localPoints[j] = verts[j].fPos;
loc.setFromPoints(verts.size(), localPoints.get());

// Water is flattened at runtime to the water height Z
// coordinate. The bounding box needs to be bloated out
// a bit, though, to account for the maximum possible geometry
// waves.
hsVector3 reboundPts[]{ loc.getMins(), loc.getMaxs() };
for (hsVector3& pt : reboundPts)
pt = fIcicles[i]->getLocalToWorld().multPoint(pt);
reboundPts[0].Z = fIcicles[i]->getWaterHeight() - kMaxWaveHeight;
reboundPts[1].Z = fIcicles[i]->getWaterHeight() + kMaxWaveHeight;

world.setFromPoints(2, reboundPts);
for (hsVector3& pt : reboundPts)
pt = fIcicles[i]->getWorldToLocal().multPoint(pt);
loc.setFromPoints(2, reboundPts);
} else {
auto localPoints = std::make_unique<hsVector3[]>(verts.size());
auto worldPoints = std::make_unique<hsVector3[]>(verts.size());
for (size_t j = 0; j < verts.size(); j++) {
localPoints[j] = verts[j].fPos;
worldPoints[j] = fIcicles[i]->getLocalToWorld().multPoint(verts[j].fPos);
}
loc.setFromPoints(verts.size(), localPoints.get());
world.setFromPoints(verts.size(), worldPoints.get());
}
loc.setFromPoints(verts.size(), localPoints.get());
world.setFromPoints(verts.size(), worldPoints.get());
loc.unalign();

fIcicles[i]->setLocalBounds(loc);
Expand Down
Loading