From 66c05256e6b74762117376e915046de03fcde4cd Mon Sep 17 00:00:00 2001 From: DaniTheSkunk Date: Tue, 11 Oct 2022 20:45:52 +0000 Subject: [PATCH] added tweening functions for int, double, vec2i, vec2f --- com/danitheskunk/skunkworks/Util.java | 8 ++++++++ com/danitheskunk/skunkworks/Vec2f.java | 7 +++++++ com/danitheskunk/skunkworks/Vec2i.java | 8 ++++++++ 3 files changed, 23 insertions(+) diff --git a/com/danitheskunk/skunkworks/Util.java b/com/danitheskunk/skunkworks/Util.java index d621cdb..46c27a9 100644 --- a/com/danitheskunk/skunkworks/Util.java +++ b/com/danitheskunk/skunkworks/Util.java @@ -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); + } } diff --git a/com/danitheskunk/skunkworks/Vec2f.java b/com/danitheskunk/skunkworks/Vec2f.java index 5d8b99c..4337ae4 100644 --- a/com/danitheskunk/skunkworks/Vec2f.java +++ b/com/danitheskunk/skunkworks/Vec2f.java @@ -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; diff --git a/com/danitheskunk/skunkworks/Vec2i.java b/com/danitheskunk/skunkworks/Vec2i.java index f9dbd13..293a3dc 100644 --- a/com/danitheskunk/skunkworks/Vec2i.java +++ b/com/danitheskunk/skunkworks/Vec2i.java @@ -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; }