-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
1,052 additions
and
38 deletions.
There are no files selected for viewing
Submodule guilib
updated
5 files
21 changes: 21 additions & 0 deletions
21
src/main/java/com/troblecodings/signals/animation/AnimationMode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.troblecodings.signals.animation; | ||
|
||
import java.util.Arrays; | ||
|
||
public enum AnimationMode { | ||
|
||
ROTATION("ROTATION"), TRANSLATION("TRANSLATION"); | ||
|
||
private String mode; | ||
|
||
private AnimationMode(final String mode) { | ||
this.mode = mode; | ||
} | ||
|
||
public static AnimationMode of(final String mode) { | ||
return Arrays.stream(values()) | ||
.filter(animationMode -> animationMode.mode.equalsIgnoreCase(mode)).findFirst() | ||
.orElse(null); | ||
} | ||
|
||
} |
84 changes: 84 additions & 0 deletions
84
src/main/java/com/troblecodings/signals/animation/AnimationRotionCalc.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package com.troblecodings.signals.animation; | ||
|
||
import java.util.Objects; | ||
|
||
import javax.vecmath.Vector3f; | ||
|
||
import org.lwjgl.util.vector.Quaternion; | ||
|
||
public class AnimationRotionCalc { | ||
|
||
private float step; | ||
private final RotationAxis axis; | ||
private float progress; | ||
private float max; | ||
|
||
public AnimationRotionCalc(final Vector3f startPosition, final Vector3f finalPosition, | ||
final float animationSpeed, final RotationAxis axis) { | ||
this.step = 0.005f * animationSpeed; | ||
this.axis = axis; | ||
calculateWayAndValues(startPosition, finalPosition); | ||
} | ||
|
||
private void calculateWayAndValues(final Vector3f start, final Vector3f end) { | ||
switch (axis) { | ||
case X: { | ||
progress = start.getX(); | ||
max = end.getX(); | ||
break; | ||
} | ||
case Y: { | ||
progress = start.getY(); | ||
max = end.getY(); | ||
break; | ||
} | ||
case Z: { | ||
progress = start.getZ(); | ||
max = end.getZ(); | ||
break; | ||
} | ||
} | ||
if (max < progress) { | ||
this.step = -step; | ||
} | ||
} | ||
|
||
public void updateAnimation() { | ||
progress += step; | ||
} | ||
|
||
public boolean isAnimationFinished() { | ||
if (step > 0) { | ||
if (progress < max) | ||
return false; | ||
} else { | ||
if (max < progress) | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
public Quaternion getQuaternion() { | ||
return axis.getForAxis(progress); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(axis, max, progress, step); | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object obj) { | ||
if (this == obj) | ||
return true; | ||
if (obj == null) | ||
return false; | ||
if (getClass() != obj.getClass()) | ||
return false; | ||
final AnimationRotionCalc other = (AnimationRotionCalc) obj; | ||
return axis == other.axis && Float.floatToIntBits(max) == Float.floatToIntBits(other.max) | ||
&& Float.floatToIntBits(progress) == Float.floatToIntBits(other.progress) | ||
&& Float.floatToIntBits(step) == Float.floatToIntBits(other.step); | ||
} | ||
|
||
} |
110 changes: 110 additions & 0 deletions
110
src/main/java/com/troblecodings/signals/animation/AnimationTranslationCalc.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package com.troblecodings.signals.animation; | ||
|
||
import java.util.Objects; | ||
|
||
import com.troblecodings.core.VectorWrapper; | ||
|
||
public class AnimationTranslationCalc { | ||
|
||
private float stepX; | ||
private float stepY; | ||
private float stepZ; | ||
private float progressX; | ||
private float progressY; | ||
private float progressZ; | ||
private float maxX; | ||
private float maxY; | ||
private float maxZ; | ||
|
||
private boolean finishedX = false; | ||
private boolean finishedY = false; | ||
private boolean finishedZ = false; | ||
|
||
public AnimationTranslationCalc(final VectorWrapper startPosition, | ||
final VectorWrapper finalPosition, final float animationSpeed) { | ||
this.stepX = 0.005f * animationSpeed; | ||
this.stepY = 0.005f * animationSpeed; | ||
this.stepZ = 0.005f * animationSpeed; | ||
calculateWayAndValues(startPosition, finalPosition); | ||
} | ||
|
||
private void calculateWayAndValues(final VectorWrapper start, final VectorWrapper end) { | ||
this.progressX = start.getX(); | ||
this.progressY = start.getY(); | ||
this.progressZ = start.getZ(); | ||
|
||
this.maxX = end.getX(); | ||
this.maxY = end.getY(); | ||
this.maxZ = end.getZ(); | ||
|
||
if (maxX < progressX) { | ||
this.stepX = -stepX; | ||
} | ||
if (maxY < progressY) { | ||
this.stepY = -stepY; | ||
} | ||
if (maxZ < progressZ) { | ||
this.stepZ = -stepZ; | ||
} | ||
} | ||
|
||
public void updateAnimation() { | ||
if (!finishedX) { | ||
progressX += stepX; | ||
this.finishedX = isAnimationOnAxisIsFinished(stepX, progressX, maxX); | ||
} | ||
if (!finishedY) { | ||
progressY += stepY; | ||
this.finishedY = isAnimationOnAxisIsFinished(stepY, progressY, maxY); | ||
} | ||
if (!finishedZ) { | ||
progressZ += stepZ; | ||
this.finishedZ = isAnimationOnAxisIsFinished(stepZ, progressZ, maxZ); | ||
} | ||
} | ||
|
||
public boolean isAnimationFinished() { | ||
return finishedX && finishedY && finishedZ; | ||
} | ||
|
||
private static boolean isAnimationOnAxisIsFinished(final float step, final float progress, | ||
final float max) { | ||
if (step > 0) { | ||
if (progress < max) { | ||
return false; | ||
} | ||
} else { | ||
if (max < progress) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
public VectorWrapper getTranslation() { | ||
return new VectorWrapper(progressX, progressY, progressZ); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(maxX, maxY, maxZ, progressX, progressY, progressZ); | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object obj) { | ||
if (this == obj) | ||
return true; | ||
if (obj == null) | ||
return false; | ||
if (getClass() != obj.getClass()) | ||
return false; | ||
final AnimationTranslationCalc other = (AnimationTranslationCalc) obj; | ||
return Float.floatToIntBits(maxX) == Float.floatToIntBits(other.maxX) | ||
&& Float.floatToIntBits(maxY) == Float.floatToIntBits(other.maxY) | ||
&& Float.floatToIntBits(maxZ) == Float.floatToIntBits(other.maxZ) | ||
&& Float.floatToIntBits(progressX) == Float.floatToIntBits(other.progressX) | ||
&& Float.floatToIntBits(progressY) == Float.floatToIntBits(other.progressY) | ||
&& Float.floatToIntBits(progressZ) == Float.floatToIntBits(other.progressZ); | ||
} | ||
|
||
} |
104 changes: 104 additions & 0 deletions
104
src/main/java/com/troblecodings/signals/animation/ModelTranslation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package com.troblecodings.signals.animation; | ||
|
||
import java.util.Objects; | ||
|
||
import org.lwjgl.util.vector.Quaternion; | ||
|
||
import com.troblecodings.core.VectorWrapper; | ||
|
||
import net.minecraft.client.renderer.GlStateManager; | ||
|
||
public class ModelTranslation { | ||
|
||
private VectorWrapper pivotTranslation = VectorWrapper.ZERO; | ||
private Quaternion quaternion = null; | ||
private SignalAnimation animation; | ||
private VectorWrapper modelTranslation = VectorWrapper.ZERO; | ||
private VectorWrapper translation = VectorWrapper.ZERO; | ||
private boolean renderModel = false; | ||
|
||
public ModelTranslation(final VectorWrapper firstTranslation, final Quaternion quaternion) { | ||
this.pivotTranslation = firstTranslation; | ||
this.quaternion = quaternion; | ||
} | ||
|
||
public ModelTranslation(final VectorWrapper translation) { | ||
this.translation = translation; | ||
} | ||
|
||
public void translate() { | ||
GlStateManager.translate(modelTranslation.getX() - 0.5f, modelTranslation.getY() - 0.5f, | ||
modelTranslation.getZ() - 0.5f); | ||
|
||
if (quaternion != null) { | ||
GlStateManager.rotate(quaternion); | ||
} | ||
if (!translation.equals(VectorWrapper.ZERO)) { | ||
GlStateManager.translate(translation.getX(), translation.getY(), translation.getZ()); | ||
} | ||
GlStateManager.translate(pivotTranslation.getX(), pivotTranslation.getY(), | ||
pivotTranslation.getZ()); | ||
} | ||
|
||
public Quaternion getQuaternion() { | ||
return quaternion; | ||
} | ||
|
||
public VectorWrapper getTranslation() { | ||
return translation; | ||
} | ||
|
||
public boolean shouldRenderModel() { | ||
return renderModel; | ||
} | ||
|
||
public ModelTranslation setRenderModel(final boolean renderModel) { | ||
this.renderModel = renderModel; | ||
return this; | ||
} | ||
|
||
public void setUpNewTranslation(final ModelTranslation other) { | ||
this.pivotTranslation = other.pivotTranslation; | ||
this.quaternion = other.quaternion; | ||
this.translation = other.translation; | ||
} | ||
|
||
public void setModelTranslation(final VectorWrapper translation) { | ||
this.modelTranslation = translation; | ||
} | ||
|
||
public void assignAnimation(final SignalAnimation animation) { | ||
this.animation = animation; | ||
} | ||
|
||
public void removeAnimation() { | ||
this.animation = null; | ||
} | ||
|
||
public boolean isAnimationAssigned() { | ||
return animation != null; | ||
} | ||
|
||
public SignalAnimation getAssigendAnimation() { | ||
return animation; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(pivotTranslation, quaternion, renderModel); | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object obj) { | ||
if (this == obj) | ||
return true; | ||
if (obj == null) | ||
return false; | ||
if (getClass() != obj.getClass()) | ||
return false; | ||
final ModelTranslation other = (ModelTranslation) obj; | ||
return Objects.equals(pivotTranslation, other.pivotTranslation) | ||
&& Objects.equals(quaternion, other.quaternion) && renderModel == other.renderModel; | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/com/troblecodings/signals/animation/RotationAxis.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.troblecodings.signals.animation; | ||
|
||
import java.util.Arrays; | ||
|
||
import org.lwjgl.util.vector.Quaternion; | ||
|
||
import com.troblecodings.core.QuaternionWrapper; | ||
import com.troblecodings.signals.OpenSignalsMain; | ||
|
||
public enum RotationAxis { | ||
|
||
X("X"), Y("Y"), Z("Z"); | ||
|
||
private final String axis; | ||
|
||
private RotationAxis(final String axis) { | ||
this.axis = axis; | ||
} | ||
|
||
public static RotationAxis of(final String axis) { | ||
return Arrays.stream(values()) | ||
.filter(rotationAxis -> rotationAxis.axis.equalsIgnoreCase(axis)).findFirst() | ||
.orElseGet(() -> { | ||
OpenSignalsMain.exitMinecraftWithMessage("[" + axis | ||
+ "] is not a valid axis for a RotationAnimation! Valid are: " | ||
+ values()); | ||
return null; | ||
}); | ||
} | ||
|
||
public Quaternion getForAxis(final float value) { | ||
switch (this) { | ||
case X: | ||
return QuaternionWrapper.fromXYZ(value, 0, 0); | ||
case Y: | ||
return QuaternionWrapper.fromXYZ(0, value, 0); | ||
case Z: | ||
return QuaternionWrapper.fromXYZ(0, 0, value); | ||
default: | ||
return QuaternionWrapper.fromXYZ(0, 0, 0); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.