Skip to content

Commit

Permalink
Optimize trigonometry out of MapblockMeshGenerator::drawLiquidTop
Browse files Browse the repository at this point in the history
  • Loading branch information
numberZero committed Jun 17, 2023
1 parent 288c3d5 commit 3b05fc4
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/client/content_mapblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -774,15 +774,24 @@ void MapblockMeshGenerator::drawLiquidTop()
// Positive if liquid moves towards +X
f32 dx = (corner_levels[0][0] + corner_levels[1][0]) -
(corner_levels[0][1] + corner_levels[1][1]);
f32 tcoord_angle = atan2(dz, dx) * core::RADTODEG;
v2f tcoord_center(0.5, 0.5);
v2f tcoord_translate(blockpos_nodes.Z + p.Z, blockpos_nodes.X + p.X);
tcoord_translate.rotateBy(tcoord_angle);
v2f dir = v2f(dx, dz).normalize();
if (dir == v2f{0.0f, 0.0f}) // if corners are symmetrical
dir = v2f{1.0f, 0.0f};
tcoord_translate.set(
dir.X * tcoord_translate.X - dir.Y * tcoord_translate.Y,
dir.Y * tcoord_translate.X + dir.X * tcoord_translate.Y);

tcoord_translate.X -= floor(tcoord_translate.X);
tcoord_translate.Y -= floor(tcoord_translate.Y);

for (video::S3DVertex &vertex : vertices) {
vertex.TCoords.rotateBy(tcoord_angle, tcoord_center);
vertex.TCoords -= tcoord_center;
vertex.TCoords.set(
dir.X * vertex.TCoords.X - dir.Y * vertex.TCoords.Y,
dir.Y * vertex.TCoords.X + dir.X * vertex.TCoords.Y);
vertex.TCoords += tcoord_center;
vertex.TCoords += tcoord_translate;
}

Expand Down

0 comments on commit 3b05fc4

Please sign in to comment.