added tweening functions for int, double, vec2i, vec2f

This commit is contained in:
DaniTheSkunk 2022-10-11 20:45:52 +00:00
parent 74b2c36243
commit 66c05256e6
3 changed files with 23 additions and 0 deletions

View File

@ -11,4 +11,12 @@ public class Util {
} }
return new String(chars, 0, len); 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);
}
} }

View File

@ -27,6 +27,13 @@ public final class Vec2f {
return new Vec2f(a.x / b, a.y / b); 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 //getters and setters
public double getX() { public double getX() {
return x; return x;

View File

@ -40,6 +40,7 @@ public final class Vec2i {
return new Vec2i(a.x * b.x, a.y * b.y); return new Vec2i(a.x * b.x, a.y * b.y);
} }
public static Vec2i div(Vec2i a, int b) { public static Vec2i div(Vec2i a, int b) {
return new Vec2i(a.x / b, a.y / 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); 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() { public int getX() {
return x; return x;
} }