Package org.lazywizard.lazylib
Class VectorUtils
Object
VectorUtils
Contains methods for manipulating
Vector2fs.- Since:
- 1.7
- Author:
- LazyWizard
-
Method Summary
Modifier and TypeMethodDescriptionstatic Vector2fclampLength(Vector2f toClamp, float maxLength) Reduces a vector's length if it is higher than the passed in argument.static Vector2fclampLength(Vector2f toClamp, float minLength, float maxLength) Ensures a vector's length is within the given parameters and stores the result in a destination vector.static Vector2fclampLength(Vector2f toClamp, float minLength, float maxLength, Vector2f dest) Ensures a vector's length is within the given parameters and stores the result in a destination vector.static Vector2fclampLength(Vector2f toClamp, float maxLength, Vector2f dest) Reduces a vector's length if it is higher than the passed in argument and stores the result in a destination vector.static floatReturns the angle between twoVector2fs in degrees.static floatgetAngleStrict(Vector2f from, Vector2f to) Returns the angle between twoVector2fs in degrees.static floatgetCrossProduct(Vector2f vector1, Vector2f vector2) Returns the cross product of twoVector2fs.static Vector2fgetDirectionalVector(Vector2f source, Vector2f destination) static floatReturns the facing (angle) of aVector2fin degrees.static floatgetFacingStrict(Vector2f vector) Returns the facing (angle) of aVector2fin degrees.static booleanisZeroVector(Vector2f vector) Tests whether a vector is a zero vector (coordinates of {0, 0}).static Vector2fScales a vector to the requested length.static Vector2fScales a vector to the requested length and stores the result in a destination vector.static Vector2fRotates aVector2fby a specified amount.static Vector2fRotates aVector2fby a specified amount and stores the result in a destination vector.rotateAroundPivot(List<Vector2f> toRotate, Vector2f pivotPoint, float angle) static Vector2frotateAroundPivot(Vector2f toRotate, Vector2f pivotPoint, float angle) Rotates aVector2fby a specified amount around a pivot point.static Vector2frotateAroundPivot(Vector2f toRotate, Vector2f pivotPoint, float angle, Vector2f dest) Rotates aVector2fby a specified amount around a pivot point and stores the result in a destination vector.static float[]toFloatArray(List<Vector2f> vectors) toVectorList(float[] coordinates)
-
Method Details
-
getFacing
Returns the facing (angle) of aVector2fin degrees. Accurate to within ~0.29 degrees. If you need more accuracy, usegetFacingStrict(Vector2f).- Parameters:
vector- The vector to get the facing of.- Returns:
- The facing (angle) of
vectorin degrees, or 0 if the vector has no length. - Since:
- 1.7
- See Also:
-
getFacingStrict
Returns the facing (angle) of aVector2fin degrees. This method uses the slower but more accurate behavior of pre-2.3getFacing(Vector2f).- Parameters:
vector- The vector to get the facing of.- Returns:
- The facing (angle) of
vectorin degrees, or 0 if the vector has no length. - Since:
- 2.3
-
getAngle
Returns the angle between twoVector2fs in degrees. Accurate to within ~0.29 degrees. If you need more accuracy, usegetAngleStrict(Vector2f, Vector2f). -
getAngleStrict
Returns the angle between twoVector2fs in degrees. This method uses the slower but more accurate behavior of pre-2.3getAngle(Vector2f, Vector2f). -
getDirectionalVector
- Parameters:
source- The origin of the vector.destination- The location to point at.- Returns:
- A normalized
Vector2fpointing atdestination. - Since:
- 1.8
-
getCrossProduct
Returns the cross product of twoVector2fs. -
isZeroVector
Tests whether a vector is a zero vector (coordinates of {0, 0}).- Parameters:
vector- The vector to test.- Returns:
trueif both ofvector's coordinates are 0,falseotherwise.- Since:
- 2.3
-
resize
Scales a vector to the requested length and stores the result in a destination vector. Note: if the vector's length is 0, no scaling will be performed.- Parameters:
vector- The vector to be resized. Will not be modified; instead the result will be placed indest.length- The new total length of the destination vector.dest- The destinationVector2f. Can bevector.- Returns:
dest, scaled based onvector, returned for easier chaining of methods.- Since:
- 2.3
-
resize
Scales a vector to the requested length. Note: if the vector's length is 0, no scaling will be performed.- Parameters:
vector- The vector to be modified.length- The new total length ofvector.- Returns:
- The modified
vector, returned for easier chaining of methods. - Since:
- 2.3
- See Also:
-
clampLength
Reduces a vector's length if it is higher than the passed in argument and stores the result in a destination vector.- Parameters:
toClamp- The vector whose length should be clamped. Will not be modified; instead the result will be placed indest.maxLength- The maximum length of the destination vector. If its current length is higher, it will be reduced to this amount.dest- The destinationVector2f. Can betoClamp.- Returns:
dest, clamped based ontoClamp, returned for easier chaining of methods.- Since:
- 2.3
-
clampLength
Reduces a vector's length if it is higher than the passed in argument.- Parameters:
toClamp- The vector whose length should be clamped.maxLength- The maximum length oftoClamp. If its current length is higher, it will be reduced to this amount.- Returns:
- The modified
toClamp, returned for easier chaining of methods. - Since:
- 2.3
- See Also:
-
clampLength
public static Vector2f clampLength(Vector2f toClamp, float minLength, float maxLength, Vector2f dest) Ensures a vector's length is within the given parameters and stores the result in a destination vector.- Parameters:
toClamp- The vector whose length should be clamped. Will not be modified; instead the result will be placed indest.minLength- The minimum length of the destination vector. If its current length is lower, it will be increased to this amount.maxLength- The maximum length of the destination vector. If its current length is higher, it will be reduced to this amount.dest- The destinationVector2f. Can betoClamp.- Returns:
dest, clamped based ontoClamp, returned for easier chaining of methods.- Since:
- 2.3
-
clampLength
Ensures a vector's length is within the given parameters and stores the result in a destination vector.- Parameters:
toClamp- The vector whose length should be clamped. Will not be modified; instead the result will be placed indest.minLength- The minimum length oftoClamp. If its current length is lower, it will be increased to this amount.maxLength- The maximum length oftoClamp. If its current length is higher, it will be reduced to this amount.- Returns:
- The modified
toClamp, returned for easier chaining of methods. - Since:
- 2.3
- See Also:
-
rotate
Rotates aVector2fby a specified amount and stores the result in a destination vector.- Parameters:
toRotate- TheVector2fto rotate. Will not be modified; instead the result will be placed indest.angle- How much to rotate the destination vector, in degrees.dest- The destinationVector2f. Can betoRotate.- Returns:
dest, rotated based ontoRotate, returned for easier chaining of methods.- Since:
- 1.7
-
rotate
Rotates aVector2fby a specified amount.- Parameters:
toRotate- TheVector2fto rotate.angle- How much to rotatetoRotate, in degrees.- Returns:
- The modified
toRotate, returned for easier chaining of methods. - Since:
- 2.3
- See Also:
-
rotate
-
rotateAroundPivot
public static Vector2f rotateAroundPivot(Vector2f toRotate, Vector2f pivotPoint, float angle, Vector2f dest) Rotates aVector2fby a specified amount around a pivot point and stores the result in a destination vector.- Parameters:
toRotate- TheVector2fto rotate. Will not be modified; instead the result will be placed indest.pivotPoint- The central point to pivot around.angle- How much to rotate the destination vector, in degrees.dest- The destinationVector2f. Can betoRotate.- Returns:
dest, rotated based ontoRotatearoundpivotPoint, returned for easier chaining of methods.- Since:
- 1.7
-
rotateAroundPivot
Rotates aVector2fby a specified amount around a pivot point.- Parameters:
toRotate- TheVector2fto rotate.pivotPoint- The central point to pivot around.angle- How much to rotatetoRotate, in degrees.- Returns:
- The modified
toRotate, returned for easier chaining of methods. - Since:
- 2.3
- See Also:
-
rotateAroundPivot
public static List<Vector2f> rotateAroundPivot(List<Vector2f> toRotate, Vector2f pivotPoint, float angle) -
toVectorList
- Parameters:
coordinates- An array of floats representing a list of x and y coordinates. The length ofcoordinatesmust be even or this method will throw aRuntimeException!.- Returns:
- A
ListofVector2fs that contains all coordinates passed in. - Since:
- 3.0
-
toFloatArray
-