Package net.risingworld.api.utils
Class Vector4f
java.lang.Object
net.risingworld.api.utils.Vector4f
- All Implemented Interfaces:
Serializable
A Vector which holds four float values: X, Y, Z and W
It can be used to represent a four dimensional value.
It can be used to represent a four dimensional value.
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final Vector4f
A vector with values 1, 1, 1, 1static final Vector4f
A unit vector along the W axisstatic final Vector4f
A unit vector along the X axisstatic final Vector4f
A unit vector along the Y axisstatic final Vector4f
A unit vector along the Z axisfloat
The W value of this vectorfloat
The X value of this vectorfloat
The Y value of this vectorfloat
The Z value of this vectorstatic final Vector4f
A vector with values 0, 0, 0, 0 -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionadd
(float addX, float addY, float addZ, float addW) Creates a new vector with the same values of this vector and adds the provided values.Creates a new vector with the same values of this vector and adds the values of the provided vector.addLocal
(float addX, float addY, float addZ, float addW) Adds the provided values to the values of this vector.Adds the values of the provided vector to the values of this vector.float
angleBetween
(Vector4f other) Gets the angle between this vector and another vector.
Please note: Both vectors need to be unit vectors (normalized).copy()
Creates a copy of this Vector.float
distance
(float x, float y, float z, float w) Gets the distance between this vector and the provided coordinates.float
Gets the distance between this vector and another vector.float
distanceSquared
(float x, float y, float z, float w) Gets the squared distance between this vector and the provided coordinates.float
distanceSquared
(Vector4f other) Gets the squared distance between this vector and another Vector4f.Creates a new vector with the same values of this vector and divides the values of the provided vector.divideLocal
(float scalar) divideLocal
(Vector4f other) float
dot
(float x, float y, float z, float w) Gets the dot product of this vector with the provided coordinates.float
Gets the dot product of this vector with the provided vector.boolean
equals
(float x, float y, float z, float w) boolean
Gets whether or not this vector is equal to another object.float
getW()
Returns the w value of this vector.float
getX()
Returns the x value of this vector.float
getY()
Returns the y value of this vector.float
getZ()
Returns the z value of this vector.int
hashCode()
Gets a unique* hash code for this vector, based on its values.interpolateLocal
(Vector4f finalVector, float mu) Interpolates this vector to the provided final vector, e.g if this vector is (0, 5, 10, 0), and the final vector is (-10, 0, 10, 0), the result (by using a mu-value of 0.5f) would be (-5, 2.5f, 10, 0)boolean
Checks if this vector is a unit vector.float
length()
Gets the length of this vector.float
Gets the squared length of this vector.mult
(float scalar) Creates a new vector with the same values of this vector and multiplies them with the provided scalar.mult
(float multX, float multY, float multZ, float multW) Creates a new vector with the same values of this vector and multiplies the provided values.Creates a new vector with the same values of this vector and multiplies the values of the provided vector.multLocal
(float scalar) Multiplies the values of this vector with the provided scalar.multLocal
(float multX, float multY, float multZ, float multW) Multiplies the values of this vector with the provided values.Multiplies the values of this vector with the values of the provided vector.negate()
Creates a new vector which contains negated values of this vector.Negates all values of this vector.Normalizes this vector (i.e turn it into a unit vector).set
(float x, float y, float z, float w) Sets the x, y, z and w values of this vector to the provided values.Sets the x, y, z and w values of this vector to the values of the provided vector.setW
(float w) Sets the w value of this vector.setX
(float x) Sets the x value of this vector.setY
(float y) Sets the y value of this vector.setZ
(float z) Sets the z value of this vector.subtract
(float subtractX, float subtractY, float subtractZ, float subtractW) Creates a new vector with the same values of this vector and subtracts the provided values.Creates a new vector with the same values of this vector and subtracts the values of the provided vector.subtractLocal
(float subtractX, float subtractY, float subtractZ, float subtractW) Subtracts the provided values from the values of this vector.subtractLocal
(Vector4f other) Subtracts the values of the provided vector from the values of this vector.toString()
Gets a String representation of this vector, for example(1.0, 4.2, 0.0, -10.0)
zero()
Sets all values to 0 (same setset(0, 0, 0, 0);
).
-
Field Details
-
ZERO
A vector with values 0, 0, 0, 0 -
ONE
A vector with values 1, 1, 1, 1 -
UNIT_X
A unit vector along the X axis -
UNIT_Y
A unit vector along the Y axis -
UNIT_Z
A unit vector along the Z axis -
UNIT_W
A unit vector along the W axis -
x
public float xThe X value of this vector -
y
public float yThe Y value of this vector -
z
public float zThe Z value of this vector -
w
public float wThe W value of this vector
-
-
Constructor Details
-
Vector4f
public Vector4f()Creates a new Vector4f with default values 0, 0, 0, 0. -
Vector4f
public Vector4f(float x, float y, float z, float w) Creates a new Vector4f with the provided values.- Parameters:
x
- the x value of the vector.y
- the y value of the vector.z
- the z value of the vector.w
- the w value of the vector.
-
Vector4f
Creates a new Vector4f and copies the X, Y, Z and W values from the provided vector.- Parameters:
copy
- the Vector4f to copy.
-
-
Method Details
-
copy
Creates a copy of this Vector.- Returns:
- a new instance with the same values of this Vector.
-
set
Sets the x, y, z and w values of this vector to the values of the provided vector.- Parameters:
vector
- the Vector4f to copy.- Returns:
- this vector.
-
set
Sets the x, y, z and w values of this vector to the provided values.- Parameters:
x
- the x value.y
- the y value.z
- the z value.w
- the w value.- Returns:
- this vector.
-
setX
Sets the x value of this vector.- Parameters:
x
- the new x value.- Returns:
- this vector.
-
setY
Sets the y value of this vector.- Parameters:
y
- the new y value.- Returns:
- this vector.
-
setZ
Sets the z value of this vector.- Parameters:
z
- the new z value.- Returns:
- this vector.
-
setW
Sets the w value of this vector.- Parameters:
w
- the new w value.- Returns:
- this vector.
-
getX
public float getX()Returns the x value of this vector.- Returns:
- the current x value.
-
getY
public float getY()Returns the y value of this vector.- Returns:
- the current y value.
-
getZ
public float getZ()Returns the z value of this vector.- Returns:
- the current z value.
-
getW
public float getW()Returns the w value of this vector.- Returns:
- the current w value.
-
dot
Gets the dot product of this vector with the provided vector.- Parameters:
other
- the vector to calculate the dot product with.- Returns:
- the resulting dot product.
-
dot
public float dot(float x, float y, float z, float w) Gets the dot product of this vector with the provided coordinates.- Parameters:
x
- the x coordinate.y
- the y coordinate.z
- the z coordinate.w
- the w coordinate.- Returns:
- the resulting dot product.
-
length
public float length()Gets the length of this vector.- Returns:
- the length of this vector.
- See Also:
-
lengthSquared
public float lengthSquared()Gets the squared length of this vector. Use this function to avoid calculating the squareroot.- Returns:
- the squared length of this vector.
- See Also:
-
distance
Gets the distance between this vector and another vector.- Parameters:
other
- the other vector.- Returns:
- the distance between this vector and another vector.
- See Also:
-
distance
public float distance(float x, float y, float z, float w) Gets the distance between this vector and the provided coordinates.- Parameters:
x
- the other x coordinate.y
- the other y coordinate.z
- the other z coordinate.w
- the other w coordinate.- Returns:
- the distance between this vector and the provided coordinates.
- See Also:
-
distanceSquared
Gets the squared distance between this vector and another Vector4f. Use this function to avoid calculating the squareroot.- Parameters:
other
- the other Vector4f.- Returns:
- the squared distance between this vector and the provided Vector4f.
-
distanceSquared
public float distanceSquared(float x, float y, float z, float w) Gets the squared distance between this vector and the provided coordinates. Use this function to avoid calculating the squareroot.- Parameters:
x
- the other x coordinate.y
- the other y coordinate.z
- the other z coordinate.w
- the other w coordinate.- Returns:
- the squared distance between this vector and the provided coordinates.
-
add
Creates a new vector with the same values of this vector and adds the values of the provided vector. Same asnew Vector4f(this).addLocal(other);
- Parameters:
other
- the vector to add.- Returns:
- the newly created vector.
-
add
Creates a new vector with the same values of this vector and adds the provided values. Same asnew Vector4f(this).addLocal(x, y, z, w);
- Parameters:
addX
- the x value to add.addY
- the y value to add.addZ
- the z value to add.addW
- the w value to add.- Returns:
- the newly created vector.
-
addLocal
Adds the values of the provided vector to the values of this vector.- Parameters:
other
- the vector to add.- Returns:
- this vector.
-
addLocal
Adds the provided values to the values of this vector.- Parameters:
addX
- the x value to add.addY
- the y value to add.addZ
- the z value to add.addW
- the w value to add.- Returns:
- this vector.
-
subtract
Creates a new vector with the same values of this vector and subtracts the values of the provided vector. Same asnew Vector4f(this).subtractLocal(other);
- Parameters:
other
- the vector to subtract.- Returns:
- the newly created vector.
-
subtract
Creates a new vector with the same values of this vector and subtracts the provided values. Same asnew Vector4f(this).subtractLocal(x, y, z, w);
- Parameters:
subtractX
- the x value to subtract.subtractY
- the y value to subtract.subtractZ
- the z value to subtract.subtractW
- the w value to subtract.- Returns:
- the newly created vector.
-
subtractLocal
Subtracts the values of the provided vector from the values of this vector.- Parameters:
other
- the vector to subtract.- Returns:
- this vector.
-
subtractLocal
Subtracts the provided values from the values of this vector.- Parameters:
subtractX
- the x value to subtract.subtractY
- the y value to subtract.subtractZ
- the z value to subtract.subtractW
- the w value to subtract.- Returns:
- this vector.
-
mult
Creates a new vector with the same values of this vector and multiplies them with the provided scalar.- Parameters:
scalar
- the value to multiply the vector by.- Returns:
- the newly created vector.
-
mult
Creates a new vector with the same values of this vector and multiplies the values of the provided vector. Same asnew Vector4f(this).multLocal(other);
- Parameters:
other
- the vector to multiply.- Returns:
- the newly created vector.
-
mult
Creates a new vector with the same values of this vector and multiplies the provided values. Same asnew Vector4f(this).multLocal(x, y, z, w);
- Parameters:
multX
- the x value to multiply.multY
- the y value to multiply.multZ
- the z value to multiply.multW
- the w value to multiply.- Returns:
- the newly created vector.
-
multLocal
Multiplies the values of this vector with the provided scalar.- Parameters:
scalar
- the value to multiply this vector by.- Returns:
- this vector.
-
multLocal
Multiplies the values of this vector with the values of the provided vector.- Parameters:
other
- the vector to multiply.- Returns:
- this vector.
-
multLocal
Multiplies the values of this vector with the provided values.- Parameters:
multX
- the x value to multiply the x coordinate of this vector by.multY
- the y value to multiply the y coordinate of this vector by.multZ
- the z value to multiply the z coordinate of this vector by.multW
- the w value to multiply the w coordinate of this vector by.- Returns:
- this vector.
-
divide
Creates a new vector with the same values of this vector and divides the values of the provided vector. Same asnew Vector4f(this).divideLocal(other);
- Parameters:
other
- the vector to divide.- Returns:
- the newly created vector.
-
divideLocal
-
divideLocal
-
negate
Creates a new vector which contains negated values of this vector.- Returns:
- the newly created vector.
-
negateLocal
Negates all values of this vector.- Returns:
- this vector.
-
normalizeLocal
Normalizes this vector (i.e turn it into a unit vector).- Returns:
- this vector (normalized).
-
angleBetween
Gets the angle between this vector and another vector.
Please note: Both vectors need to be unit vectors (normalized).- Parameters:
other
- the other vector (unit vector).- Returns:
- the angle in degrees.
-
zero
Sets all values to 0 (same setset(0, 0, 0, 0);
).- Returns:
- this vector.
-
isUnitVector
public boolean isUnitVector()Checks if this vector is a unit vector.- Returns:
- true if this is a unit vector, false if not.
-
interpolateLocal
Interpolates this vector to the provided final vector, e.g if this vector is (0, 5, 10, 0), and the final vector is (-10, 0, 10, 0), the result (by using a mu-value of 0.5f) would be (-5, 2.5f, 10, 0)- Parameters:
finalVector
- the final vector to interpolate towards.mu
- the mu value between 0.0 and 1.0 (i.e the percentage change from this vector to towards the final vector).- Returns:
- this vector containing the interpolated values.
-
equals
Gets whether or not this vector is equal to another object. This function returns true, if the other object is aVector4f
and if it has exactly the same x, y, z and w values. -
equals
public boolean equals(float x, float y, float z, float w) -
hashCode
public int hashCode()Gets a unique* hash code for this vector, based on its values. If two vectors have the same x, y, z and w values, they will return the same hash code.
* Please keep in mind that the uniqueness is not fully reliable. There is always a small chance that collisions occur (i.e two completely different vectors return the same hash code). But usually the reliability is sufficient. -
toString
Gets a String representation of this vector, for example(1.0, 4.2, 0.0, -10.0)
-