From 513eff7cb579ceba18c3b680924ba0b71adb9872 Mon Sep 17 00:00:00 2001 From: gered Date: Sat, 14 Sep 2013 22:20:43 -0400 Subject: [PATCH] add helper to specifically set a vector's length along it's direction --- src/com/blarg/gdx/math/MathHelpers.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/com/blarg/gdx/math/MathHelpers.java b/src/com/blarg/gdx/math/MathHelpers.java index b22cf44..02fa922 100644 --- a/src/com/blarg/gdx/math/MathHelpers.java +++ b/src/com/blarg/gdx/math/MathHelpers.java @@ -206,6 +206,13 @@ public final class MathHelpers { result.z = desiredSize.z / originalSize.z; } + public static void setLengthOf(Vector3 v, float length) { + float scaleFactor = length / v.len(); + v.x = v.x * scaleFactor; + v.y = v.y * scaleFactor; + v.z = v.z * scaleFactor; + } + /** * Basically the same as {@link com.badlogic.gdx.math.Intersector#getLowestPositiveRoot} except for the addition * of a parameter maxR which limits the maximum root value we accept. Anything over this will also result