added tweening functions for int, double, vec2i, vec2f
This commit is contained in:
parent
74b2c36243
commit
66c05256e6
|
@ -11,4 +11,12 @@ public class Util {
|
|||
}
|
||||
return new String(chars, 0, len);
|
||||
}
|
||||
|
||||
public static double tweenDouble(double a, double b, double amount) {
|
||||
return (b - a) * amount + a;
|
||||
}
|
||||
|
||||
public static int tweenInt(int a, int b, double amount) {
|
||||
return (int) ((b - a) * amount + a);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,13 @@ public final class Vec2f {
|
|||
return new Vec2f(a.x / b, a.y / b);
|
||||
}
|
||||
|
||||
public static Vec2f tween(Vec2f a, Vec2f b, double amount) {
|
||||
return new Vec2f(
|
||||
Util.tweenDouble(a.x, b.x, amount),
|
||||
Util.tweenDouble(a.y, b.y, amount)
|
||||
);
|
||||
}
|
||||
|
||||
//getters and setters
|
||||
public double getX() {
|
||||
return x;
|
||||
|
|
|
@ -40,6 +40,7 @@ public final class Vec2i {
|
|||
return new Vec2i(a.x * b.x, a.y * b.y);
|
||||
}
|
||||
|
||||
|
||||
public static Vec2i div(Vec2i a, int b) {
|
||||
return new Vec2i(a.x / b, a.y / b);
|
||||
}
|
||||
|
@ -64,6 +65,13 @@ public final class Vec2i {
|
|||
return new Vec2f(a.x / (double) b.x, a.y / (double) b.y);
|
||||
}
|
||||
|
||||
public static Vec2i tween(Vec2i a, Vec2i b, double amount) {
|
||||
return new Vec2i(Util.tweenInt(a.x, b.x, amount),
|
||||
Util.tweenInt(a.y, b.y, amount)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue