diff options
Diffstat (limited to 'src/ru/olamedia/olacraft/modelAnimator')
-rw-r--r-- | src/ru/olamedia/olacraft/modelAnimator/Arm.java | 27 | ||||
-rw-r--r-- | src/ru/olamedia/olacraft/modelAnimator/Bone.java | 215 | ||||
-rw-r--r-- | src/ru/olamedia/olacraft/modelAnimator/BoneSet.java | 163 | ||||
-rw-r--r-- | src/ru/olamedia/olacraft/modelAnimator/ISkeletonNode.java | 26 | ||||
-rw-r--r-- | src/ru/olamedia/olacraft/modelAnimator/Leg.java | 27 | ||||
-rw-r--r-- | src/ru/olamedia/olacraft/modelAnimator/ModelAnimator.java | 324 | ||||
-rw-r--r-- | src/ru/olamedia/olacraft/modelAnimator/Randomizer.java | 92 | ||||
-rw-r--r-- | src/ru/olamedia/olacraft/modelAnimator/Skeleton.java | 47 | ||||
-rw-r--r-- | src/ru/olamedia/olacraft/modelAnimator/package-info.java | 8 |
9 files changed, 929 insertions, 0 deletions
diff --git a/src/ru/olamedia/olacraft/modelAnimator/Arm.java b/src/ru/olamedia/olacraft/modelAnimator/Arm.java new file mode 100644 index 0000000..eeeea77 --- /dev/null +++ b/src/ru/olamedia/olacraft/modelAnimator/Arm.java @@ -0,0 +1,27 @@ +package ru.olamedia.olacraft.modelAnimator; + +public class Arm extends BoneSet { + // 左腕 - левая рука + // 左ひじ - левый локоть + // 左手首 - левое запястье + // 左袖 - левый рукав + public Bone top; + public Bone elbow; + public Bone wrist; + + public Arm() { + super(3); + top = new Bone(); + elbow = new Bone(); + wrist = new Bone(); + setChild(0, top); + setChild(1, elbow); + setChild(2, wrist); + } + + public void setNamePrefix(String prefix) { + top.setName(prefix + top.getName()); + elbow.setName(prefix + elbow.getName()); + wrist.setName(prefix + wrist.getName()); + } +} diff --git a/src/ru/olamedia/olacraft/modelAnimator/Bone.java b/src/ru/olamedia/olacraft/modelAnimator/Bone.java new file mode 100644 index 0000000..0bda33d --- /dev/null +++ b/src/ru/olamedia/olacraft/modelAnimator/Bone.java @@ -0,0 +1,215 @@ +package ru.olamedia.olacraft.modelAnimator; + +import java.util.Random; + +public class Bone implements ISkeletonNode { + private String name; + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } + + private float speed = 1f; + private float yaw; + private float pitch; + private float roll; + private float yawCorrection = 0; + private float pitchCorrection = 0; + private float rollCorrection = 0; + @SuppressWarnings("unused") + private boolean isAnglesModified = false; + private boolean isMatrixModified = false; + + @Override + public int getChildrenCount() { + return 0; + } + + @Override + public Bone getChild(int i) { + return null; + } + + private void updateAngles() { + if (isMatrixModified) { + + } + } + + /* + * private void updateMatrix() { + * if (isAnglesModified) { + * + * } + * } + */ + + public float getSpeed() { + return speed; + } + + /* + * (non-Javadoc) + * + * @see ru.olamedia.olacraft.modelAnimator.ISkeletonNode#setSpeed(float) + */ + @Override + public void setSpeed(float speed) { + this.speed = speed; + } + + /* + * (non-Javadoc) + * + * @see + * ru.olamedia.olacraft.modelAnimator.ISkeletonNode#copyOrientation(ru.olamedia + * .olacraft.modelAnimator.Bone) + */ + @Override + public void copyOrientation(ISkeletonNode node) { + final Bone b = (Bone) node; + setPitch(b.getPitch()); + setPitchCorrection(b.getPitchCorrection()); + setYaw(b.getYaw()); + setYawCorrection(b.getYawCorrection()); + setRoll(b.getRoll()); + setRollCorrection(b.getRollCorrection()); + } + + /* + * (non-Javadoc) + * + * @see + * ru.olamedia.olacraft.modelAnimator.ISkeletonNode#setDelta(ru.olamedia + * .olacraft.modelAnimator.Bone, ru.olamedia.olacraft.modelAnimator.Bone, + * float) + */ + @Override + public void setDelta(ISkeletonNode firstNode, ISkeletonNode secondNode, float delta) { + final Bone first = (Bone) firstNode; + final Bone second = (Bone) secondNode; + final float dPitch = second.getPitch() - first.getPitch(); + setPitch(first.getPitch() + dPitch * getSpeed() * delta); + final float dYaw = second.getYaw() - first.getYaw(); + setYaw(first.getYaw() + dYaw * getSpeed() * delta); + final float dRoll = second.getRoll() - first.getRoll(); + setRoll(first.getRoll() + dRoll * getSpeed() * delta); + } + + public float getYaw() { + updateAngles(); + return yaw; + } + + public float getCorrectedYaw() { + return getYawCorrection() + getYaw(); + } + + public void setYaw(float yaw) { + this.yaw = yaw; + isAnglesModified = true; + } + + public float getPitch() { + updateAngles(); + return pitch; + } + + public float getCorrectedPitch() { + return getPitchCorrection() + getPitch(); + } + + public void setPitch(float pitch) { + this.pitch = pitch; + isAnglesModified = true; + } + + public float getRoll() { + updateAngles(); + return roll; + } + + public float getCorrectedRoll() { + return getRollCorrection() + getRoll(); + } + + public void setRoll(float roll) { + this.roll = roll; + isAnglesModified = true; + } + + private final float yawRand = 5f; + private final float pitchRand = 1f; + private final float rollRand = 5f; + + /* + * (non-Javadoc) + * + * @see ru.olamedia.olacraft.modelAnimator.ISkeletonNode#reset() + */ + @Override + public void reset() { + yaw = 0; + pitch = 0; + roll = 0; + } + + private float nextFloatDelta(Random rand, Random prev, float delta) { + final float first = prev.nextFloat(); + final float second = rand.nextFloat(); + return first + (second - first) * delta; + } + + /* + * (non-Javadoc) + * + * @see + * ru.olamedia.olacraft.modelAnimator.ISkeletonNode#randomize(java.util. + * Random, java.util.Random, float) + */ + @Override + public void randomize(Random rand, Random prev, float delta) { + // delta = 1; + setYaw(yaw + (nextFloatDelta(rand, prev, delta) - 0.5f) * yawRand); + setPitch(pitch + (nextFloatDelta(rand, prev, delta) - 0.5f) * pitchRand); + setRoll(roll + (nextFloatDelta(rand, prev, delta) - 0.5f) * rollRand); + } + + public float getYawCorrection() { + return yawCorrection; + } + + public void setYawCorrection(float yawCorrection) { + this.yawCorrection = yawCorrection; + } + + public float getPitchCorrection() { + return pitchCorrection; + } + + public void setPitchCorrection(float pitchCorrection) { + this.pitchCorrection = pitchCorrection; + } + + public float getRollCorrection() { + return rollCorrection; + } + + public void setRollCorrection(float rollCorrection) { + this.rollCorrection = rollCorrection; + } + + @Override + public void setChild(int i, ISkeletonNode b) { + + } +} diff --git a/src/ru/olamedia/olacraft/modelAnimator/BoneSet.java b/src/ru/olamedia/olacraft/modelAnimator/BoneSet.java new file mode 100644 index 0000000..0e3ce2c --- /dev/null +++ b/src/ru/olamedia/olacraft/modelAnimator/BoneSet.java @@ -0,0 +1,163 @@ +package ru.olamedia.olacraft.modelAnimator; + +import java.util.Iterator; +import java.util.Random; + +public class BoneSet implements ISkeletonNode, Iterable<Bone> { + + private class BonesIterator implements Iterator<Bone> { + private BoneSet set; + private Iterator<Bone> childIterator = null; + private int current = 0; + + public BonesIterator(BoneSet boneSet) { + set = boneSet; + } + + @Override + public boolean hasNext() { + if (null == childIterator) { + return current < set.getChildrenCount(); + } else { + return childIterator.hasNext() || current < set.getChildrenCount(); + } + } + + private boolean nextIsChild; + + @Override + public Bone next() { + if (null == childIterator) { + ISkeletonNode node = set.getChild(current); + if (node instanceof Bone) { + Bone b = (Bone) node; + current++; + return b; + } else if (node instanceof BoneSet) { + childIterator = ((BoneSet) node).iterator(); + current++; + } + } + if (null != childIterator) { + nextIsChild = childIterator.hasNext(); + if (nextIsChild) { + Bone b = childIterator.next(); + return b; + } + if (!nextIsChild) { + childIterator = null; + } + } + if (current < set.getChildrenCount()) { + return next(); + } + return null; + } + + @Override + public void remove() { + + } + + } + + public BoneSet(int bonesCount) { + nodes = new ISkeletonNode[bonesCount]; + for (int i = 0; i < bonesCount; i++) { + // bones[i] = new Bone(); + } + } + + private ISkeletonNode[] nodes; + private String name; + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @param name + * the name to set + */ + public void setName(String name) { + this.name = name; + } + + @Override + public int getChildrenCount() { + return nodes.length; + } + + public ISkeletonNode getChild(int i) { + return nodes[i]; + } + + @Override + public void setSpeed(float speed) { + for (ISkeletonNode b : nodes) { + b.setSpeed(speed); + } + } + + @Override + public void copyOrientation(ISkeletonNode bs) { + for (int i = 0; i < nodes.length; i++) { + nodes[i].copyOrientation(bs.getChild(i)); + } + } + + @Override + public void setDelta(ISkeletonNode first, ISkeletonNode second, float delta) { + for (int i = 0; i < nodes.length; i++) { + nodes[i].setDelta(first.getChild(i), second.getChild(i), delta); + } + } + + @Override + public void reset() { + for (int i = 0; i < nodes.length; i++) { + nodes[i].reset(); + } + } + + @Override + public void randomize(Random rand, Random prev, float delta) { + for (int i = 0; i < nodes.length; i++) { + nodes[i].randomize(rand, prev, delta); + } + } + + @Override + public void setChild(int i, ISkeletonNode node) { + nodes[i] = node; + } + + @Override + public Iterator<Bone> iterator() { + return new BonesIterator(this); + } + + public int getBoneCount() { + int n = 0; + Iterator<Bone> it = iterator(); + while (it.hasNext()) { + it.next(); + n++; + } + return n; + } + + public Bone getBone(int i) { + int j = 0; + Iterator<Bone> it = iterator(); + Bone b = null; + while (it.hasNext() && j <= i) { + b = it.next(); + j++; + } + return b; + } +} diff --git a/src/ru/olamedia/olacraft/modelAnimator/ISkeletonNode.java b/src/ru/olamedia/olacraft/modelAnimator/ISkeletonNode.java new file mode 100644 index 0000000..2b1b28a --- /dev/null +++ b/src/ru/olamedia/olacraft/modelAnimator/ISkeletonNode.java @@ -0,0 +1,26 @@ +package ru.olamedia.olacraft.modelAnimator; + +import java.util.Random; + +public interface ISkeletonNode { + public void setName(String name); + + public String getName(); + + public ISkeletonNode getChild(int i); + + public void setChild(int i, ISkeletonNode b); + + public int getChildrenCount(); + + public abstract void setSpeed(float speed); + + public abstract void copyOrientation(ISkeletonNode b); + + public abstract void setDelta(ISkeletonNode first, ISkeletonNode second, float delta); + + public abstract void reset(); + + public abstract void randomize(Random rand, Random prev, float delta); + +}
\ No newline at end of file diff --git a/src/ru/olamedia/olacraft/modelAnimator/Leg.java b/src/ru/olamedia/olacraft/modelAnimator/Leg.java new file mode 100644 index 0000000..0f9000d --- /dev/null +++ b/src/ru/olamedia/olacraft/modelAnimator/Leg.java @@ -0,0 +1,27 @@ +package ru.olamedia.olacraft.modelAnimator; + +public class Leg extends BoneSet { + + public Bone top; + public Bone knee; + public Bone foot; + + public Leg() { + super(3); + top = new Bone(); + knee = new Bone(); + foot = new Bone(); + setChild(0, top); + setChild(1, knee); + setChild(2, foot); + top.setName("Top"); + knee.setName("Knee"); + foot.setName("Foot"); + } + + public void setNamePrefix(String prefix) { + top.setName(prefix + top.getName()); + knee.setName(prefix + knee.getName()); + foot.setName(prefix + foot.getName()); + } +} diff --git a/src/ru/olamedia/olacraft/modelAnimator/ModelAnimator.java b/src/ru/olamedia/olacraft/modelAnimator/ModelAnimator.java new file mode 100644 index 0000000..712cbd1 --- /dev/null +++ b/src/ru/olamedia/olacraft/modelAnimator/ModelAnimator.java @@ -0,0 +1,324 @@ +package ru.olamedia.olacraft.modelAnimator; + +public class ModelAnimator { + private boolean isWalking = false; + private boolean isCrawling = false; + private boolean isCrouching = false; + private boolean isJumping = false; + private boolean isFalling = false; + private boolean isStrafingLeft = false; + private boolean isStrafingRight = false; + private boolean isMovingForward = false; + private boolean isMovingBackward = false; + private float delta; + + private Skeleton currentOrientation = new Skeleton(); + public Skeleton finalOrientation = new Skeleton(); + public Skeleton deltaOrientation = new Skeleton(); + + public ModelAnimator() { + generateFrames(); + } + + public boolean isWalking() { + return isWalking; + } + + public void setWalking(boolean isWalking) { + this.isWalking = isWalking; + } + + public boolean isCrawling() { + return isCrawling; + } + + public void setCrawling(boolean isCrawling) { + this.isCrawling = isCrawling; + } + + public boolean isCrouching() { + return isCrouching; + } + + public void setCrouching(boolean isCrouching) { + this.isCrouching = isCrouching; + } + + public boolean isJumping() { + return isJumping; + } + + public void setJumping(boolean isJumping) { + this.isJumping = isJumping; + } + + public boolean isFalling() { + return isFalling; + } + + public void setFalling(boolean isFalling) { + this.isFalling = isFalling; + } + + public boolean isStrafingLeft() { + return isStrafingLeft; + } + + public void setStrafingLeft(boolean isStrafingLeft) { + this.isStrafingLeft = isStrafingLeft; + } + + public boolean isStrafingRight() { + return isStrafingRight; + } + + public void setStrafingRight(boolean isStrafingRight) { + this.isStrafingRight = isStrafingRight; + } + + public boolean isMovingForward() { + return isMovingForward; + } + + public void setMovingForward(boolean isMovingForward) { + this.isMovingForward = isMovingForward; + } + + public boolean isMovingBackward() { + return isMovingBackward; + } + + public void setMovingBackward(boolean isMovingBackward) { + this.isMovingBackward = isMovingBackward; + } + + public float getDelta() { + return delta; + } + + public void setDelta(float delta) { + this.delta = delta; + } + + // Frames + private Skeleton walkLeftLegForward = new Skeleton(); + private Skeleton walkRightLegForward = new Skeleton(); + private Skeleton standLeftLegApart = new Skeleton(); + private Skeleton standRightLegApart = new Skeleton(); + + private void generateFrames() { + // walkLeftLegForward.leftLeg.top.setYaw(-5); + walkLeftLegForward.skirtFrontLeft.setPitch(30); + walkLeftLegForward.skirtFrontLeft.setYaw(30); + walkLeftLegForward.skirtFrontRight.setPitch(-5); + walkRightLegForward.skirtFrontRight.setPitch(30); + walkRightLegForward.skirtFrontRight.setYaw(-30); + walkRightLegForward.skirtFrontLeft.setPitch(-5); + // walkLeftLegForward.skirtFrontLeft.setYaw(40); + // walkLeftLegForward.skirtFrontLeft.setRoll(40); + // walkLeftLegForward.rightLeg.top.setYaw(5); + walkLeftLegForward.leftLeg.top.setPitch(35); + walkLeftLegForward.leftLeg.knee.setPitch(-30); + walkLeftLegForward.leftLeg.foot.setPitch(25); + walkLeftLegForward.leftLeg.top.setYaw(-10); + walkLeftLegForward.leftLeg.knee.setYaw(-10); + walkLeftLegForward.rightLeg.top.setYaw(-10); + walkLeftLegForward.rightLeg.knee.setYaw(-10); + walkLeftLegForward.rightLeg.top.setPitch(-10); + walkLeftLegForward.rightLeg.knee.setPitch(-15); + walkLeftLegForward.rightLeg.foot.setPitch(8); + /*walkLeftLegForward.leftLeg.top.setPitch(59); + walkLeftLegForward.leftLeg.top.setYaw(-9); + walkLeftLegForward.leftLeg.top.setRoll(10); + walkLeftLegForward.leftLeg.knee.setPitch(-100); + walkLeftLegForward.leftLeg.knee.setYaw(-9);*/ + walkRightLegForward.leftLeg.copyOrientation(walkLeftLegForward.rightLeg); + walkRightLegForward.rightLeg.copyOrientation(walkLeftLegForward.leftLeg); + walkRightLegForward.rightLeg.top.setYaw(10); + walkRightLegForward.rightLeg.knee.setYaw(10); + walkRightLegForward.leftLeg.top.setYaw(10); + walkRightLegForward.leftLeg.knee.setYaw(10); + + walkLeftLegForward.waist.setYaw(18); + walkRightLegForward.waist.setYaw(-18); + walkLeftLegForward.shoulders.setYaw(-10); + walkLeftLegForward.shoulders.setRoll(-4); + walkRightLegForward.shoulders.setYaw(10); + walkRightLegForward.shoulders.setRoll(4); + // ARMS + walkLeftLegForward.rightArm.top.setPitch(15); + walkLeftLegForward.rightArm.top.setRoll(-7); + walkLeftLegForward.rightArm.elbow.setYaw(-90); + walkLeftLegForward.rightArm.wrist.setYaw(0); + walkLeftLegForward.rightArm.wrist.setPitch(0); + walkLeftLegForward.rightArm.wrist.setRoll(50); + walkLeftLegForward.leftArm.wrist.setRoll(30); + walkLeftLegForward.leftArm.top.setPitch(-14); + walkLeftLegForward.leftArm.top.setYaw(-2); + walkLeftLegForward.leftArm.top.setRoll(17); + // walkRightLegForward.leftArm.elbow.setRoll(90); + walkRightLegForward.leftArm.top.setPitch(15); + walkRightLegForward.leftArm.top.setRoll(7); + walkRightLegForward.leftArm.elbow.setYaw(90); + walkRightLegForward.leftArm.wrist.setYaw(0); + walkRightLegForward.leftArm.wrist.setPitch(0); + walkRightLegForward.leftArm.wrist.setRoll(-50); + walkRightLegForward.rightArm.wrist.setRoll(-30); + walkRightLegForward.rightArm.top.setPitch(-14); + walkRightLegForward.rightArm.top.setYaw(2); + walkRightLegForward.rightArm.top.setRoll(-17); + + standLeftLegApart.leftLeg.top.setRoll(-10); + standLeftLegApart.leftLeg.foot.setYaw(-10); + standRightLegApart.rightLeg.top.setRoll(10); + standRightLegApart.rightLeg.foot.setYaw(10); + } + + private boolean areLegsApart = false; + private boolean areLegsTogether = true; + private boolean isLeftLegAhead = false; + private boolean isLegReturning = false; + private float walkStepTimer = 0; + private float walkStepTime = 0.25f; + private float standTimer = 0; + private float standTime = 3f; + private boolean isStandLeftLegApart = true; + + private void standTick() { + standTimer += getDelta(); + if (standTimer >= standTime) { + // Switch legs + standTimer -= standTime; + isStandLeftLegApart = !isStandLeftLegApart; + } + } + + private void setLegsStanding() { + if (isStandLeftLegApart) { + finalOrientation.leftLeg.copyOrientation(standLeftLegApart.leftLeg); + finalOrientation.rightLeg.copyOrientation(standLeftLegApart.rightLeg); + } else { + finalOrientation.leftLeg.copyOrientation(standRightLegApart.leftLeg); + finalOrientation.rightLeg.copyOrientation(standRightLegApart.rightLeg); + } + } + + private void walkTick() { + walkStepTimer += getDelta(); + if (walkStepTimer >= walkStepTime) { + // Switch step, legs + walkStepTimer -= walkStepTime; + if (areLegsTogether) { + areLegsTogether = false; + areLegsApart = true; + isLeftLegAhead = !isLeftLegAhead; + isLegReturning = false; + } else { + areLegsTogether = true; + areLegsApart = false; + isLegReturning = true; + } + } + } + + private void setLegsWalking() { + if (isLeftLegAhead) { + finalOrientation.leftLeg.copyOrientation(walkLeftLegForward.leftLeg); + finalOrientation.rightLeg.copyOrientation(walkLeftLegForward.rightLeg); + finalOrientation.waist.copyOrientation(walkLeftLegForward.waist); + finalOrientation.shoulders.copyOrientation(walkLeftLegForward.shoulders); + finalOrientation.leftArm.copyOrientation(walkLeftLegForward.leftArm); + finalOrientation.rightArm.copyOrientation(walkLeftLegForward.rightArm); + finalOrientation.skirtFrontLeft.copyOrientation(walkLeftLegForward.skirtFrontLeft); + finalOrientation.skirtFrontRight.copyOrientation(walkLeftLegForward.skirtFrontRight); + } else { + finalOrientation.leftLeg.copyOrientation(walkRightLegForward.leftLeg); + finalOrientation.rightLeg.copyOrientation(walkRightLegForward.rightLeg); + finalOrientation.waist.copyOrientation(walkRightLegForward.waist); + finalOrientation.shoulders.copyOrientation(walkRightLegForward.shoulders); + finalOrientation.leftArm.copyOrientation(walkRightLegForward.leftArm); + finalOrientation.rightArm.copyOrientation(walkRightLegForward.rightArm); + finalOrientation.skirtFrontLeft.copyOrientation(walkRightLegForward.skirtFrontLeft); + finalOrientation.skirtFrontRight.copyOrientation(walkRightLegForward.skirtFrontRight); + } + } + + private Randomizer leftLegRandomizer = new Randomizer(0.5f, 7f); + private Randomizer rightLegRandomizer = new Randomizer(0.5f, 7f); + + private void randomize() { + rightLegRandomizer.setPaused(!leftLegRandomizer.isPaused()); + rightLegRandomizer.tick(delta); + leftLegRandomizer.tick(delta); + leftLegRandomizer.randomize(finalOrientation.leftLeg); + rightLegRandomizer.randomize(finalOrientation.rightLeg); + } + + private void fixClothOrientation() { + + } + + public void tick() { + if (!demoMode) { + finalOrientation.reset(); + } + if (!demoMode) { + // deltaOrientation.reset(); + if (isJumping()) { + // air motion + while (!areLegsApart) { + walkTick(); + setLegsWalking(); + } + } else { + // on-ground motion + if (isWalking()) { + walkTick(); + if (isCrawling()) { + + } else if (isCrouching()) { + + } else { + // standing + setLegsWalking(); + } + } else { + // make legs together, switch forward leg + while (!areLegsTogether) { + walkTick(); + standTick(); + setLegsWalking(); + setLegsStanding(); + } + } + } + randomize(); + // System.err.println("[leg] " + + // finalOrientation.leftLeg.top.getPitch()); + fixClothOrientation(); + deltaOrientation.leftArm.top.setRollCorrection(-50f); + deltaOrientation.rightArm.top.setRollCorrection(-deltaOrientation.leftArm.top.getRollCorrection()); + deltaOrientation.setSpeed(4f); + deltaOrientation.skirtFrontLeft.setSpeed(1f); + deltaOrientation.skirtFrontRight.setSpeed(1f); + if (isLeftLegAhead && !isLegReturning) { + deltaOrientation.skirtFrontLeft.setSpeed(4f); + } + if (!isLeftLegAhead && !isLegReturning) { + deltaOrientation.skirtFrontRight.setSpeed(4f); + } + }else{ + deltaOrientation.setSpeed(4f); + } + deltaOrientation.setDelta(currentOrientation, finalOrientation, getDelta()); + // deltaOrientation.copyOrientation(finalOrientation); + currentOrientation.copyOrientation(deltaOrientation); + } + + private boolean demoMode = false; + + public void setPause(boolean boneMode) { + demoMode = boneMode; + } + +} 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); + } + +} diff --git a/src/ru/olamedia/olacraft/modelAnimator/Skeleton.java b/src/ru/olamedia/olacraft/modelAnimator/Skeleton.java new file mode 100644 index 0000000..5cae422 --- /dev/null +++ b/src/ru/olamedia/olacraft/modelAnimator/Skeleton.java @@ -0,0 +1,47 @@ +package ru.olamedia.olacraft.modelAnimator; + +public class Skeleton extends BoneSet { + + public Bone neck; // 首 - шея + public Bone shoulders; // 上半身 - верхняя часть тела + public Bone waist; // 下半身 - нижняя часть корпуса + public Bone skirtFrontLeft; + public Bone skirtFrontRight; + + public Arm leftArm; + public Arm rightArm; + + public Leg leftLeg; + public Leg rightLeg; + + public Skeleton() { + super(9); + neck = new Bone(); + neck.setName("Neck"); + waist = new Bone(); + waist.setName("Waist"); + shoulders = new Bone(); + shoulders.setName("Shoulders"); + skirtFrontLeft = new Bone(); + skirtFrontLeft.setName("Skirt Front Left"); + skirtFrontRight = new Bone(); + skirtFrontRight.setName("Skirt Front Right"); + leftArm = new Arm(); + rightArm = new Arm(); + leftLeg = new Leg(); + rightLeg = new Leg(); + leftArm.setNamePrefix("Left arm "); + rightArm.setNamePrefix("Right arm "); + leftLeg.setNamePrefix("Left leg "); + rightLeg.setNamePrefix("Right leg "); + setChild(0, neck); + setChild(1, waist); + setChild(2, shoulders); + setChild(3, skirtFrontLeft); + setChild(4, skirtFrontRight); + setChild(5, leftArm); + setChild(6, rightArm); + setChild(7, leftLeg); + setChild(8, rightLeg); + } +} diff --git a/src/ru/olamedia/olacraft/modelAnimator/package-info.java b/src/ru/olamedia/olacraft/modelAnimator/package-info.java new file mode 100644 index 0000000..7bc19b6 --- /dev/null +++ b/src/ru/olamedia/olacraft/modelAnimator/package-info.java @@ -0,0 +1,8 @@ +/** + * + */ +/** + * @author olamedia + * + */ +package ru.olamedia.olacraft.modelAnimator;
\ No newline at end of file |