Skip to content

Instantly share code, notes, and snippets.

@kahrl
Created August 14, 2013 20:56
Show Gist options
  • Save kahrl/6235515 to your computer and use it in GitHub Desktop.
Save kahrl/6235515 to your computer and use it in GitHub Desktop.
diff --git a/src/content_mapblock.cpp b/src/content_mapblock.cpp
index d2509ad..bd03b3b 100644
--- a/src/content_mapblock.cpp
+++ b/src/content_mapblock.cpp
@@ -653,47 +653,29 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
// -Z towards +Z, thus the direction is +Z.
// Rotate texture to make animation go in flow direction
// Positive if liquid moves towards +Z
- int dz = (corner_levels[side_corners[3][0]] +
+ f32 dz = (corner_levels[side_corners[3][0]] +
corner_levels[side_corners[3][1]]) -
(corner_levels[side_corners[2][0]] +
corner_levels[side_corners[2][1]]);
// Positive if liquid moves towards +X
- int dx = (corner_levels[side_corners[1][0]] +
+ f32 dx = (corner_levels[side_corners[1][0]] +
corner_levels[side_corners[1][1]]) -
(corner_levels[side_corners[0][0]] +
corner_levels[side_corners[0][1]]);
- // -X
- if(-dx >= abs(dz))
- {
- v2f t = vertices[0].TCoords;
- vertices[0].TCoords = vertices[1].TCoords;
- vertices[1].TCoords = vertices[2].TCoords;
- vertices[2].TCoords = vertices[3].TCoords;
- vertices[3].TCoords = t;
- }
- // +X
- if(dx >= abs(dz))
- {
- v2f t = vertices[0].TCoords;
- vertices[0].TCoords = vertices[3].TCoords;
- vertices[3].TCoords = vertices[2].TCoords;
- vertices[2].TCoords = vertices[1].TCoords;
- vertices[1].TCoords = t;
- }
- // -Z
- if(-dz >= abs(dx))
- {
- v2f t = vertices[0].TCoords;
- vertices[0].TCoords = vertices[3].TCoords;
- vertices[3].TCoords = vertices[2].TCoords;
- vertices[2].TCoords = vertices[1].TCoords;
- vertices[1].TCoords = t;
- t = vertices[0].TCoords;
- vertices[0].TCoords = vertices[3].TCoords;
- vertices[3].TCoords = vertices[2].TCoords;
- vertices[2].TCoords = vertices[1].TCoords;
- vertices[1].TCoords = t;
- }
+ f32 tcoord_angle = atan2(dz, dx) * core::RADTODEG;
+ v2f tcoord_center(0.5, 0.5);
+ vertices[0].TCoords.rotateBy(
+ tcoord_angle, tcoord_center);
+ vertices[1].TCoords.rotateBy(
+ tcoord_angle, tcoord_center);
+ vertices[2].TCoords.rotateBy(
+ tcoord_angle, tcoord_center);
+ vertices[3].TCoords.rotateBy(
+ tcoord_angle, tcoord_center);
+
+ v2f t = vertices[0].TCoords;
+ vertices[0].TCoords = vertices[2].TCoords;
+ vertices[2].TCoords = t;
u16 indices[] = {0,1,2,2,3,0};
// Add to mesh collector
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment