Class Vector2f

All Implemented Interfaces:
Cloneable<Vector2f>, Printable

public class Vector2f extends VectorFloat<Vector2f>
2-dimensional vector with floating point precision. GLSL equivalent to vec2.
  • Field Details

    • x

      public float x
    • y

      public float y
    • temp

      public static final Vector2f temp
      Reusable temporary vector, to avoid repeatedly creating new instances in performance-critical contexts.
  • Constructor Details

    • Vector2f

      public Vector2f()
      Creates a default 2-dimensional vector with all values set to 0f.
    • Vector2f

      public Vector2f(float x, float y)
      Creates a 2-dimensional vector with given values.
  • Method Details

    • add

      public Vector2f add(float x, float y)
    • add

      public Vector2f add(Vector2f vector2f)
      Description copied from class: Vector
      Adds another vector to this vector.
      Specified by:
      add in class Vector<Vector2f>
      Returns:
      Self
    • scale

      public Vector2f scale(float scalar)
      Description copied from class: Vector
      Scales this vector by a scalar.
      Specified by:
      scale in class Vector<Vector2f>
      Returns:
      Self
    • lengthSquared

      public float lengthSquared()
      Description copied from class: VectorFloat
      Calculates the squared length of this vector.
      Specified by:
      lengthSquared in class VectorFloat<Vector2f>
    • dot

      public float dot(Vector2f vector2f)
      Description copied from class: VectorFloat
      Calculates the dot product of this vector with another vector.
      Specified by:
      dot in class VectorFloat<Vector2f>
      Returns:
      Dot product of this vector multiplied by another vector
    • toBuffer

      public void toBuffer(FloatBuffer buffer)
      Description copied from class: VectorFloat
      Stores the vector in a given buffer.
      Specified by:
      toBuffer in class VectorFloat<Vector2f>
      Parameters:
      buffer - The buffer to store the vector data in
    • equals

      public boolean equals(Vector2f vector)
      Description copied from interface: Cloneable
      Checks if the given object is equal to this object.
      Specified by:
      equals in interface Cloneable<Vector2f>
      Specified by:
      equals in class Vector<Vector2f>
      Parameters:
      vector - Other object
      Returns:
      true if both objects are equal.
    • clone

      public Vector2f clone()
      Description copied from interface: Cloneable
      Returns a new object that is equal to this object.
      Specified by:
      clone in interface Cloneable<Vector2f>
      Specified by:
      clone in class Vector<Vector2f>
      Returns:
      Clone of this object
    • toString

      public String toString()
      Converts this vector to a string representation in the format "(x,y)".
      Specified by:
      toString in interface Printable
      Specified by:
      toString in class Vector<Vector2f>
      Returns:
      String representation of this object.
    • parse

      public static Vector2f parse(String input) throws InvalidStringException
      Throws:
      InvalidStringException
    • up

      public static Vector2f up()
      Creates a new vector (0, 1)
    • down

      public static Vector2f down()
      Creates a new vector (0, -1)
    • left

      public static Vector2f left()
      Creates a new vector (-1, 0)
    • right

      public static Vector2f right()
      Creates a new vector (1, 0)
    • getTemp

      public static Vector2f getTemp(float x, float y)
      Returns a temporary vector with given values. Note that this temporary vector is a global instance, so avoid concurrent usage.