summaryrefslogtreecommitdiff
path: root/src/tileanimation.cpp
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2017-01-14 16:48:49 +0100
committersfan5 <sfan5@live.de>2017-01-18 23:21:01 +0100
commit7279f0b37335396c85f6bdd7dc67ff56e53df0f9 (patch)
treebe0ee716cf8bc6e5379415a663db91b8a358c8ab /src/tileanimation.cpp
parentc5967f75f0a9827d1b65b384edd6ba07c73ffd2f (diff)
downloadminetest-7279f0b37335396c85f6bdd7dc67ff56e53df0f9.tar.gz
minetest-7279f0b37335396c85f6bdd7dc67ff56e53df0f9.tar.bz2
minetest-7279f0b37335396c85f6bdd7dc67ff56e53df0f9.zip
Add particle animation, glow
This is implemented by reusing and extending the TileAnimation code for the methods used by particles.
Diffstat (limited to 'src/tileanimation.cpp')
-rw-r--r--src/tileanimation.cpp32
1 files changed, 27 insertions, 5 deletions
diff --git a/src/tileanimation.cpp b/src/tileanimation.cpp
index a23eecc2e..67d27d396 100644
--- a/src/tileanimation.cpp
+++ b/src/tileanimation.cpp
@@ -69,7 +69,8 @@ void TileAnimationParams::deSerialize(std::istream &is, u16 protocol_version)
}
}
-void TileAnimationParams::determineParams(v2u32 texture_size, int *frame_count, int *frame_length_ms) const
+void TileAnimationParams::determineParams(v2u32 texture_size, int *frame_count,
+ int *frame_length_ms, v2u32 *frame_size) const
{
if (type == TAT_VERTICAL_FRAMES) {
int frame_height = (float)texture_size.X /
@@ -80,15 +81,17 @@ void TileAnimationParams::determineParams(v2u32 texture_size, int *frame_count,
*frame_count = _frame_count;
if (frame_length_ms)
*frame_length_ms = 1000.0 * vertical_frames.length / _frame_count;
+ if (frame_size)
+ *frame_size = v2u32(texture_size.X, frame_height);
} else if (type == TAT_SHEET_2D) {
if (frame_count)
*frame_count = sheet_2d.frames_w * sheet_2d.frames_h;
if (frame_length_ms)
*frame_length_ms = 1000 * sheet_2d.frame_length;
- } else { // TAT_NONE
- *frame_count = 1;
- *frame_length_ms = 1000;
+ if (frame_size)
+ *frame_size = v2u32(texture_size.X / sheet_2d.frames_w, texture_size.Y / sheet_2d.frames_h);
}
+ // caller should check for TAT_NONE
}
void TileAnimationParams::getTextureModifer(std::ostream &os, v2u32 texture_size, int frame) const
@@ -97,7 +100,7 @@ void TileAnimationParams::getTextureModifer(std::ostream &os, v2u32 texture_size
return;
if (type == TAT_VERTICAL_FRAMES) {
int frame_count;
- determineParams(texture_size, &frame_count, NULL);
+ determineParams(texture_size, &frame_count, NULL, NULL);
os << "^[verticalframe:" << frame_count << ":" << frame;
} else if (type == TAT_SHEET_2D) {
int q, r;
@@ -107,3 +110,22 @@ void TileAnimationParams::getTextureModifer(std::ostream &os, v2u32 texture_size
<< ":" << r << "," << q;
}
}
+
+v2f TileAnimationParams::getTextureCoords(v2u32 texture_size, int frame) const
+{
+ v2u32 ret(0, 0);
+ if (type == TAT_VERTICAL_FRAMES) {
+ int frame_height = (float)texture_size.X /
+ (float)vertical_frames.aspect_w *
+ (float)vertical_frames.aspect_h;
+ ret = v2u32(0, frame_height * frame);
+ } else if (type == TAT_SHEET_2D) {
+ v2u32 frame_size;
+ determineParams(texture_size, NULL, NULL, &frame_size);
+ int q, r;
+ q = frame / sheet_2d.frames_w;
+ r = frame % sheet_2d.frames_w;
+ ret = v2u32(r * frame_size.X, q * frame_size.Y);
+ }
+ return v2f(ret.X / (float) texture_size.X, ret.Y / (float) texture_size.Y);
+}