Package rosequartz.math
Class Vec<T extends Vec<T>>
java.lang.Object
rosequartz.math.Vec<T>
- Type Parameters:
T- subclass
Implements various methods for every vector, like scaling or calculating length.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabs()Sets every value of this vector to its absolute value.add(float... vec)Adds the given vector to this vector component-wise and stores the result in this.Adds the given vector to this vector component-wise and stores the result in this.Adds the given vector to this vector component-wise and stores the result in dest.addN(float... vec)Adds the given vector to this vector component-wise and stores the result in a new vector, returning it.Adds the given vector to this vector component-wise and stores the result in a new vector, returning it.floatCalculates the angle between this and the given vector in radians.intReturns the amount of components the vector has.floatCalculates the distance between this and the given vector and stores the result in this.div(float... vec)Divides this vector by the given vector component-wise and stores the result in this.Divides this vector by the given vector component-wise and stores the result in this.Divides this vector by the given vector component-wise and stores the result in dest.divN(float... vec)Divides this vector by the given vector component-wise and stores the result in this.Divides this vector by the given vector component-wise and stores the result in this.floatCalculates the dot product of this and the given vector.booleanfloatget(int index)Returns the value at the given index.protected abstract float[]Returns an array containing all components in the order they appear in the vector.protected abstract TCreates a new vector (values don't matter) of this type.floatlength()Returns the length of the vector.Sets the values of this vector to the component-wise maximum of this and the given vector.Sets the values of this vector to the component-wise minimum of this and the given vector.mul(float... vec)Multiplies the given vector with this vector component-wise and stores the result in this.Multiplies the given vector with this vector component-wise and stores the result in this.Multiplies the given vector with this vector component-wise and stores the result in dest.mulN(float... vec)Multiplies the given vector with this vector component-wise and stores the result in a new vector, returning it.Multiplies the given vector with this vector component-wise and stores the result in a new vector, returning it.negate()Negates the vector (scales it by -1).Normalizes the vector.scale(float factor)Scales the vector by the given factor and stores the result in this.protected abstract voidsetComponents(float[] values)Sets the components of the vector.sub(float... vec)Subtracts this vector by the given vector component-wise and stores the result in this.Subtracts this vector by the given vector component-wise and stores the result in this.Subtracts this vector by the given vector component-wise and stores the result in dest.subN(float... vec)Subtracts this vector by the given vector component-wise and stores the result in a new vector, returning it.Subtracts this vector by the given vector component-wise and stores the result in a new vector, returning it.toString()
-
Constructor Details
-
Vec
public Vec()
-
-
Method Details
-
getComponents
protected abstract float[] getComponents()Returns an array containing all components in the order they appear in the vector.- Returns:
- array containing all vector components
-
setComponents
protected abstract void setComponents(float[] values)Sets the components of the vector.- Parameters:
values- an array containing the values for all components.
-
getNewVector
Creates a new vector (values don't matter) of this type.- Returns:
- new vector of this type
-
length
public float length()Returns the length of the vector. For the amount of components, look at 'components'.- Returns:
- vector length
- See Also:
components()
-
get
public float get(int index)Returns the value at the given index.- Parameters:
index- index of component- Returns:
- value
-
components
public int components()Returns the amount of components the vector has. A Vector3 has 3 components, a Vector4 has 4 components and so on.- Returns:
- component count
-
scale
Scales the vector by the given factor and stores the result in this.- Parameters:
factor- factor to scale vector with- Returns:
- this
-
normalize
Normalizes the vector.- Returns:
- this
-
add
Adds the given vector to this vector component-wise and stores the result in this.- Parameters:
vec- vector to add to this one- Returns:
- this
-
add
Adds the given vector to this vector component-wise and stores the result in this.- Parameters:
vec- vector to add to this one- Returns:
- this
-
add
Adds the given vector to this vector component-wise and stores the result in dest.- Parameters:
vec- vector to add to this onedest- vector to store result in- Returns:
- this
-
addN
Adds the given vector to this vector component-wise and stores the result in a new vector, returning it.- Parameters:
vec- vector to add to this one- Returns:
- new vector holding result
-
addN
Adds the given vector to this vector component-wise and stores the result in a new vector, returning it.- Parameters:
vec- vector to add to this one- Returns:
- new vector holding result
-
sub
Subtracts this vector by the given vector component-wise and stores the result in this.- Parameters:
vec- vector to subtract this one by- Returns:
- this
-
sub
Subtracts this vector by the given vector component-wise and stores the result in this.- Parameters:
vec- vector to subtract this one by- Returns:
- this
-
sub
Subtracts this vector by the given vector component-wise and stores the result in dest.- Parameters:
vec- vector to subtract this one bydest- vector to store result in- Returns:
- this
-
subN
Subtracts this vector by the given vector component-wise and stores the result in a new vector, returning it.- Parameters:
vec- vector to subtract this one by- Returns:
- this
-
subN
Subtracts this vector by the given vector component-wise and stores the result in a new vector, returning it.- Parameters:
vec- vector to subtract this one by- Returns:
- this
-
mul
Multiplies the given vector with this vector component-wise and stores the result in this.- Parameters:
vec- vector to multiply with this one- Returns:
- this
-
mul
Multiplies the given vector with this vector component-wise and stores the result in this.- Parameters:
vec- vector to multiply with this one- Returns:
- this
-
mul
Multiplies the given vector with this vector component-wise and stores the result in dest.- Parameters:
vec- vector to multiply with this onedest- vector to store result in- Returns:
- this
-
mulN
Multiplies the given vector with this vector component-wise and stores the result in a new vector, returning it.- Parameters:
vec- vector to multiply with this one- Returns:
- this
-
mulN
Multiplies the given vector with this vector component-wise and stores the result in a new vector, returning it.- Parameters:
vec- vector to multiply with this one- Returns:
- this
-
div
Divides this vector by the given vector component-wise and stores the result in this.- Parameters:
vec- vector to divide this one by- Returns:
- this
-
div
Divides this vector by the given vector component-wise and stores the result in this.- Parameters:
vec- vector to divide this one by- Returns:
- this
-
div
Divides this vector by the given vector component-wise and stores the result in dest.- Parameters:
vec- vector to divide this one bydest- vector to store result in- Returns:
- this
-
divN
Divides this vector by the given vector component-wise and stores the result in this.- Parameters:
vec- vector to divide this one by- Returns:
- this
-
divN
Divides this vector by the given vector component-wise and stores the result in this.- Parameters:
vec- vector to divide this one by- Returns:
- this
-
distance
Calculates the distance between this and the given vector and stores the result in this.- Parameters:
vec- other vector- Returns:
- distance between this and the other vector
-
dot
Calculates the dot product of this and the given vector.- Parameters:
vec- other vector- Returns:
- dot product
-
angle
Calculates the angle between this and the given vector in radians.- Parameters:
vec- other vector- Returns:
- angle between this and the given vector in radians
-
negate
Negates the vector (scales it by -1).- Returns:
- this
-
min
Sets the values of this vector to the component-wise minimum of this and the given vector.- Parameters:
vec- other vector- Returns:
- this
-
max
Sets the values of this vector to the component-wise maximum of this and the given vector.- Parameters:
vec- other vector- Returns:
- this
-
abs
Sets every value of this vector to its absolute value.- Returns:
- this
-
equals
-
toString
-