public class Vector2 extends java.lang.Object implements java.io.Serializable, Vector<Vector2>
Modifier and Type | Field and Description |
---|---|
float |
x
the x-component of this vector
|
static Vector2 |
X |
float |
y
the y-component of this vector
|
static Vector2 |
Y |
static Vector2 |
Zero |
Constructor and Description |
---|
Vector2()
Constructs a new vector at (0,0)
|
Vector2(float x,
float y)
Constructs a vector with the given components
|
Vector2(Vector2 v)
Constructs a vector from the given vector
|
Modifier and Type | Method and Description |
---|---|
Vector2 |
add(float x,
float y)
Adds the given components to this vector
|
Vector2 |
add(Vector2 v)
Adds the given vector to this vector
|
float |
angle() |
Vector2 |
clamp(float min,
float max)
Clamps this vector's length to given value
|
Vector2 |
cpy() |
float |
crs(float x,
float y)
Calculates the 2D cross product between this and the given vector.
|
float |
crs(Vector2 v)
Calculates the 2D cross product between this and the given vector.
|
Vector2 |
div(float value) |
Vector2 |
div(float vx,
float vy) |
Vector2 |
div(Vector2 other) |
float |
dot(Vector2 v) |
float |
dst(float x,
float y) |
float |
dst(Vector2 v) |
float |
dst2(float x,
float y) |
float |
dst2(Vector2 v)
This is much faster to calculate than
Vector.dst(Vector)
It avoids a calculating square root, so it is mostly useful for comparisons |
boolean |
epsilonEquals(float x,
float y,
float epsilon)
Compares this vector with the other vector, using the supplied epsilon for fuzzy equality testing.
|
boolean |
epsilonEquals(Vector2 obj,
float epsilon)
Compares this vector with the other vector, using the supplied epsilon for fuzzy equality testing.
|
boolean |
equals(java.lang.Object obj) |
int |
hashCode() |
float |
len() |
float |
len2() |
Vector2 |
lerp(Vector2 target,
float alpha)
Linearly interpolates between this vector and the target vector by alpha which is in the range [0,1].
|
Vector2 |
limit(float limit)
Limits this vector's length to given value
|
Vector2 |
mul(float scalar)
Deprecated.
Use
scl(float) instead. |
Vector2 |
mul(float x,
float y)
Deprecated.
Use
scl(float, float) instead. |
Vector2 |
mul(Matrix3 mat)
Left-multiplies this vector by the given matrix
|
Vector2 |
mul(Vector2 v)
Deprecated.
Use
scl(Vector2) instead. |
Vector2 |
nor()
Normalizes this vector.
|
Vector2 |
rotate(float degrees)
Rotates the Vector2 by the given angle, counter-clockwise assuming the y-axis points up.
|
Vector2 |
scl(float scalar)
Multiplies this vector by a scalar
|
Vector2 |
scl(float x,
float y)
Multiplies this vector by a scalar
|
Vector2 |
scl(Vector2 v)
Multiplies this vector by a vector
|
Vector2 |
set(float x,
float y)
Sets the components of this vector
|
Vector2 |
set(Vector2 v)
Sets this vector from the given vector
|
Vector2 |
setAngle(float degrees)
Sets the angle of the vector in degrees relative to the x-axis, towards the positive y-axis (typically counter-clockwise).
|
Vector2 |
sub(float x,
float y)
Substracts the other vector from this vector.
|
Vector2 |
sub(Vector2 v)
Subtracts the given vector from this vector.
|
java.lang.String |
toString() |
public static final Vector2 X
public static final Vector2 Y
public static final Vector2 Zero
public float x
public float y
public Vector2()
public Vector2(float x, float y)
x
- The x-componenty
- The y-componentpublic Vector2(Vector2 v)
v
- The vectorpublic Vector2 cpy()
public float len2()
public Vector2 set(float x, float y)
x
- The x-componenty
- The y-componentpublic Vector2 nor()
public Vector2 add(float x, float y)
x
- The x-componenty
- The y-componentpublic float dot(Vector2 v)
public Vector2 scl(float scalar)
public Vector2 mul(float scalar)
scl(float)
instead.public Vector2 scl(float x, float y)
public Vector2 mul(float x, float y)
scl(float, float)
instead.public Vector2 mul(Vector2 v)
scl(Vector2)
instead.public Vector2 div(float value)
public Vector2 div(float vx, float vy)
public float dst(Vector2 v)
public float dst(float x, float y)
x
- The x-component of the other vectory
- The y-component of the other vectorpublic float dst2(Vector2 v)
Vector
Vector.dst(Vector)
It avoids a calculating square root, so it is mostly useful for comparisonspublic float dst2(float x, float y)
x
- The x-component of the other vectory
- The y-component of the other vectorpublic Vector2 limit(float limit)
public Vector2 clamp(float min, float max)
public java.lang.String toString()
toString
in class java.lang.Object
public Vector2 sub(float x, float y)
x
- The x-component of the other vectory
- The y-component of the other vectorpublic Vector2 mul(Matrix3 mat)
mat
- the matrixpublic float crs(Vector2 v)
v
- the other vectorpublic float crs(float x, float y)
x
- the x-coordinate of the other vectory
- the y-coordinate of the other vectorpublic float angle()
public Vector2 setAngle(float degrees)
degrees
- The angle to set.public Vector2 rotate(float degrees)
degrees
- the angle in degreespublic Vector2 lerp(Vector2 target, float alpha)
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public boolean epsilonEquals(Vector2 obj, float epsilon)
obj
- epsilon
- public boolean epsilonEquals(float x, float y, float epsilon)
x
- y
- epsilon
-