Class Vector2

java.lang.Object
zombie.iso.Vector2
All Implemented Interfaces:
Cloneable

public final class Vector2 extends Object implements Cloneable
  • Field Details

    • x

      public float x
      The horizontal part of this vector
    • y

      public float y
      The vertical part of this vector
  • Constructor Details

    • Vector2

      public Vector2()
      Create a new vector with zero length
    • Vector2

      public Vector2(Vector2 other)
      Create a new vector which is identical to another vector
      Parameters:
      other - The Vector2 to copy
    • Vector2

      public Vector2(float _x, float _y)
      Create a new vector with specified horizontal and vertical parts
      Parameters:
      _x - The horizontal part
      _y - The vertical part
  • Method Details

    • fromLengthDirection

      public static Vector2 fromLengthDirection(float length, float direction)
      Create a new vector with a specified length and direction
      Parameters:
      length - The length of the new vector
      direction - The direction of the new vector, in radians
    • dot

      public static float dot(float _x, float _y, float tx, float ty)
    • addScaled

      public static Vector2 addScaled(Vector2 a, Vector2 b, float scale, Vector2 result)
      Result = a + b * scale
      Returns:
      The supplied result vector.
    • rotate

      public void rotate(float rad)
    • add

      public Vector2 add(Vector2 other)
      Add another vector to this one and return this
      Parameters:
      other - The other Vector2 to add to this one
      Returns:
      this
    • aimAt

      public Vector2 aimAt(Vector2 other)
      Set the direction of this vector to point to another vector, maintaining the length
      Parameters:
      other - The Vector2 to point this one at.
    • angleTo

      public float angleTo(Vector2 other)
      Calculate the angle between this point and another
      Parameters:
      other - The second point as vector
      Returns:
      The angle between them, in radians
    • angleBetween

      public float angleBetween(Vector2 other)
      Calculate angle between this and other vectors
      Parameters:
      other - The other vector
      Returns:
      The angle in radians in the range [0,PI]
    • clone

      public Vector2 clone()
      Clone this vector
      Overrides:
      clone in class Object
    • distanceTo

      public float distanceTo(Vector2 other)
      Calculate the distance between this point and another
      Parameters:
      other - The second point as vector
      Returns:
      The distance between them
    • dot

      public float dot(Vector2 other)
    • equals

      public boolean equals(Object other)
      See if this vector is equal to another
      Overrides:
      equals in class Object
      Parameters:
      other - A Vector2 to compare this one to
      Returns:
      true if other is a Vector2 equal to this one
    • getDirection

      public float getDirection()
    • getDirection

      public static float getDirection(float _x, float _y)
    • getDirectionNeg

      @Deprecated public float getDirectionNeg()
      Deprecated.
      get the direction in which this vector is pointing
      Returns:
      The direction in which this vector is pointing in radians
    • setDirection

      public Vector2 setDirection(float direction)
      Set the direction of this vector, maintaining the length
      Parameters:
      direction - The new direction of this vector, in radians
    • getLength

      public float getLength()
      get the length of this vector
      Returns:
      The length of this vector
    • getLengthSquared

      public float getLengthSquared()
      get the squared length of this vector
      Returns:
      The squared length of this vector
    • setLength

      public Vector2 setLength(float length)
      Set the length of this vector, maintaining the direction
      Parameters:
      length - The length of this vector
    • normalize

      public float normalize()
    • set

      public Vector2 set(Vector2 other)
      Make this vector identical to another vector
      Parameters:
      other - The Vector2 to copy
    • set

      public Vector2 set(float _x, float _y)
      Set the horizontal and vertical parts of this vector
      Parameters:
      _x - The horizontal part
      _y - The vertical part
    • setLengthAndDirection

      public Vector2 setLengthAndDirection(float direction, float length)
      Set the length and direction of this vector
      Parameters:
      direction - The direction of this vector, in radians
      length - The length of this vector
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getX

      public float getX()
      Returns:
      the x
    • setX

      public void setX(float _x)
    • getY

      public float getY()
      Returns:
      the y
    • setY

      public void setY(float _y)
    • floorX

      public int floorX()
    • floorY

      public int floorY()
    • tangent

      public void tangent()
    • scale

      public void scale(float scale)
    • scale

      public static Vector2 scale(Vector2 val, float scale)
    • moveTowards

      public static Vector2 moveTowards(Vector2 vector20, Vector2 vector21, float float3)