diff options
author | olamedia <[email protected]> | 2012-12-23 11:30:36 +0600 |
---|---|---|
committer | olamedia <[email protected]> | 2012-12-23 11:30:36 +0600 |
commit | f58bdfcb66353bb77213cab580bc49ef890417ad (patch) | |
tree | 2983a05d564891e92c115a679f9bfbf55465c755 /src/ru/olamedia/olacraft/modelAnimator/Randomizer.java | |
parent | 5320fd1dad5b77fa227e83fbbe0a958f2c5fc283 (diff) |
0.1.7
Diffstat (limited to 'src/ru/olamedia/olacraft/modelAnimator/Randomizer.java')
-rw-r--r-- | src/ru/olamedia/olacraft/modelAnimator/Randomizer.java | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/src/ru/olamedia/olacraft/modelAnimator/Randomizer.java b/src/ru/olamedia/olacraft/modelAnimator/Randomizer.java new file mode 100644 index 0000000..1e66c87 --- /dev/null +++ b/src/ru/olamedia/olacraft/modelAnimator/Randomizer.java @@ -0,0 +1,92 @@ +package ru.olamedia.olacraft.modelAnimator; + +import java.util.Random; + +public class Randomizer { + + public Randomizer(float minTimeout, float maxTimeout) { + super(); + this.minTimeout = minTimeout; + this.maxTimeout = maxTimeout; + } + + private float minTimeout = 1f; + private float maxTimeout = 1f; + private long seed; + private long prevSeed = 0; + private float seedTimeout = 0; + private float seedTime = 0; + private float delta; + private boolean isPaused = false; + private boolean isForcePaused = false; + + /** + * @return the isPaused + */ + public boolean isPaused() { + return isPaused; + } + + /** + * @param isPaused + * the isPaused to set + */ + public void setPaused(boolean isPaused) { + this.isForcePaused = isPaused; + } + + private Random rand = new Random(); + private Random prev = new Random(); + + public void tick(float delta) { + if (!isForcePaused) { + seedTimeout -= delta; + } + if (seedTimeout <= 0) { + if (!isPaused) { + prevSeed = seed; + } + Random srand = new Random(); + seed = srand.nextLong(); + seedTime = seedTimeout = minTimeout + srand.nextFloat() * (maxTimeout - minTimeout); + } + prev.setSeed(prevSeed); + rand.setSeed(seed); + prev.nextBoolean(); + isPaused = rand.nextBoolean(); + if (isPaused) { + this.delta = 0; + } else { + this.delta = (seedTime - seedTimeout) / seedTime; + } + } + + public float getMinTimeout() { + return minTimeout; + } + + public void setMinTimeout(float minTimeout) { + this.minTimeout = minTimeout; + } + + public float getMaxTimeout() { + return maxTimeout; + } + + public void setMaxTimeout(float maxTimeout) { + this.maxTimeout = maxTimeout; + } + + public void randomize(Skeleton skel) { + skel.randomize(rand, prev, delta); + } + + public void randomize(Leg leg) { + leg.randomize(rand, prev, delta); + } + + public void randomize(ISkeletonNode b) { + b.randomize(rand, prev, delta); + } + +} |