Class Vector2
java.lang.Object
zombie.iso.Vector2
- All Implemented Interfaces:
Cloneable
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdd another vector to this one and return thisstatic Vector2Result = a + b * scaleSet the direction of this vector to point to another vector, maintaining the lengthfloatangleBetween(Vector2 other) Calculate angle between this and other vectorsfloatCalculate the angle between this point and anotherclone()Clone this vectorfloatdistanceTo(Vector2 other) Calculate the distance between this point and anotherfloatdot(float otherX, float otherY) static floatdot(float x, float y, float tx, float ty) floatbooleanSee if this vector is equal to anotherintfloorX()intfloorY()static Vector2fromLengthDirection(float length, float direction) Create a new vector with a specified length and directionfloatstatic floatgetDirection(float x, float y) floatDeprecated.floatget the length of this vectorfloatget the squared length of this vectorfloatgetX()floatgetY()static Vector2moveTowards(Vector2 currentVector, Vector2 targetVector, float maxDistanceDelta) floatvoidrotate(float radians) voidscale(float scale) static Vector2set(float x, float y) Set the horizontal and vertical parts of this vectorMake this vector identical to another vectorsetDirection(float directionRadians) Set the direction of this vector, maintaining the lengthsetLength(float length) Set the length of this vector, maintaining the directionsetLengthAndDirection(float direction, float length) Set the length and direction of this vectorvoidsetX(float x) voidsetY(float y) voidtangent()toString()
-
Field Details
-
x
public float xThe horizontal part of this vector -
y
public float yThe vertical part of this vector
-
-
Constructor Details
-
Vector2
public Vector2()Create a new vector with zero length -
Vector2
Create a new vector which is identical to another vector- Parameters:
this- The Vector2 to copy
-
Vector2
public Vector2(float x, float y) Create a new vector with specified horizontal and vertical parts- Parameters:
x- The vertical partthis- The horizontal part
-
-
Method Details
-
fromLengthDirection
Create a new vector with a specified length and direction- Parameters:
length- The length of the new vectordirection- The direction of the new vector, in radians
-
dot
public static float dot(float x, float y, float tx, float ty) -
addScaled
-
rotate
public void rotate(float radians) -
add
-
aimAt
-
angleTo
Calculate the angle between this point and another- Parameters:
other- The second point as vector- Returns:
- The angle between them, in radians
-
angleBetween
Calculate angle between this and other vectors- Parameters:
other- The other vector- Returns:
- The angle in radians in the range [0,PI]
-
clone
Clone this vector -
distanceTo
Calculate the distance between this point and another- Parameters:
other- The second point as vector- Returns:
- The distance between them
-
dot
-
dot
public float dot(float otherX, float otherY) -
equals
-
getDirection
public float getDirection() -
getDirection
public static float getDirection(float x, float y) -
getDirectionNeg
Deprecated.get the direction in which this vector is pointing Note: if the length of this vector is 0, then the direction will also be 0- Returns:
- The direction in which this vector is pointing in radians
-
setDirection
Set the direction of this vector, maintaining the length- Parameters:
directionRadians- 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
Set the length of this vector, maintaining the direction- Parameters:
length- The length of this vector
-
normalize
public float normalize() -
set
-
set
Set the horizontal and vertical parts of this vector- Parameters:
x- The horizontal party- The vertical part
-
setLengthAndDirection
Set the length and direction of this vector- Parameters:
direction- The direction of this vector, in radianslength- The length of this vector
-
toString
-
getX
public float getX()- Returns:
- the x
-
setX
public void setX(float x) - Parameters:
x- the x to set
-
getY
public float getY()- Returns:
- the y
-
setY
public void setY(float y) - Parameters:
y- the y to set
-
floorX
public int floorX() -
floorY
public int floorY() -
tangent
public void tangent() -
scale
public void scale(float scale) -
scale
-
moveTowards
-