com.threerings.math
Class Vector2f

java.lang.Object
  extended by com.threerings.math.Vector2f
All Implemented Interfaces:
Encodable, Exportable, com.threerings.io.Streamable

public final class Vector2f
extends Object
implements Encodable, com.threerings.io.Streamable

A two element vector.


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.threerings.io.Streamable
com.threerings.io.Streamable.Closure
 
Field Summary
static Vector2f MAX_VALUE
          A vector containing the maximum floating point value for all components.
static Vector2f MIN_VALUE
          A vector containing the minimum floating point value for all components (note: the components are -Float.MAX_VALUE, not Float.MIN_VALUE).
static Vector2f UNIT_X
          A unit vector in the X+ direction.
static Vector2f UNIT_Y
          A unit vector in the Y+ direction.
 float x
          The components of the vector.
 float y
          The components of the vector.
static Vector2f ZERO
          The zero vector.
 
Constructor Summary
Vector2f()
          Creates a zero vector.
Vector2f(float[] values)
          Creates a vector from an array of values.
Vector2f(float x, float y)
          Creates a vector from two components.
Vector2f(Vector2f other)
          Copy constructor.
 
Method Summary
 Vector2f add(float x, float y)
          Adds a vector to this one.
 Vector2f add(float x, float y, Vector2f result)
          Adds a vector to this one and stores the result in the object provided.
 Vector2f add(Vector2f other)
          Adds a vector to this one.
 Vector2f add(Vector2f other, Vector2f result)
          Adds a vector to this one, storing the result in the object provided.
 Vector2f addLocal(float x, float y)
          Adds a vector in-place to this one.
 Vector2f addLocal(Vector2f other)
          Adds a vector in-place to this one.
 Vector2f addScaled(Vector2f other, float v)
          Adds a scaled vector to this one.
 Vector2f addScaled(Vector2f other, float v, Vector2f result)
          Adds a scaled vector to this one and stores the result in the supplied vector.
 Vector2f addScaledLocal(Vector2f other, float v)
          Adds a scaled vector in-place to this one.
 float angle(Vector2f other)
          Returns the angle between this vector and the specified other vector.
 void decodeFromStream(DataInputStream in)
          Initializes this object with data read from the specified stream.
 void decodeFromString(String string)
          Initializes this object with the contents of the specified string.
 float direction(Vector2f other)
          Returns the direction of a vector pointing from this point to the specified other point.
 float distance(Vector2f other)
          Returns the distance from this vector to the specified other vector.
 float distanceSquared(Vector2f other)
          Returns the squared distance from this vector to the specified other.
 float dot(Vector2f other)
          Computes and returns the dot product of this and the specified other vector.
 void encodeToStream(DataOutputStream out)
          Encodes this object to the specified stream.
 String encodeToString()
          Returns a string representation of this object.
 boolean equals(Object other)
           
 void get(float[] values)
          Populates the supplied array with the contents of this vector.
 FloatBuffer get(FloatBuffer buf)
          Populates the supplied buffer with the contents of this vector.
 float get(int idx)
          Returns the element at the idx'th position of the vector.
 int hashCode()
           
 float length()
          Returns the length of this vector.
 float lengthSquared()
          Returns the squared length of this vector.
 Vector2f lerp(Vector2f other, float t)
          Linearly interpolates between this and the specified other vector by the supplied amount.
 Vector2f lerp(Vector2f other, float t, Vector2f result)
          Linearly interpolates between this and the supplied other vector by the supplied amount, storing the result in the supplied object.
 Vector2f lerpLocal(Vector2f other, float t)
          Linearly interpolates between this and the specified other vector in-place by the supplied amount.
 Vector2f mult(float v)
          Multiplies this vector by a scalar.
 Vector2f mult(float v, Vector2f result)
          Multiplies this vector by a scalar and places the result in the supplied object.
 Vector2f mult(Vector2f other)
          Multiplies this vector by another.
 Vector2f mult(Vector2f other, Vector2f result)
          Multiplies this vector by another, storing the result in the object provided.
 Vector2f multLocal(float v)
          Multiplies this vector in-place by a scalar.
 Vector2f multLocal(Vector2f other)
          Multiplies this vector in-place by another.
 Vector2f negate()
          Negates this vector.
 Vector2f negate(Vector2f result)
          Negates this vector, storing the result in the supplied object.
 Vector2f negateLocal()
          Negates this vector in-place.
 Vector2f normalize()
          Normalizes this vector.
 Vector2f normalize(Vector2f result)
          Normalizes this vector, storing the result in the object supplied.
 Vector2f normalizeLocal()
          Normalizes this vector in-place.
 Vector2f rotate(float angle)
          Rotates this vector by the specified angle.
 Vector2f rotate(float angle, Vector2f result)
          Rotates this vector by the specified angle, storing the result in the vector provided.
 Vector2f rotateAndAdd(float angle, Vector2f add, Vector2f result)
          Rotates this vector by the specified angle and adds another vector to it, placing the result in the object provided.
 Vector2f rotateLocal(float angle)
          Rotates this vector in-place by the specified angle.
 Vector2f rotateScaleAndAdd(float angle, float scale, Vector2f add, Vector2f result)
          Rotates this vector by the specified angle, applies a uniform scale, and adds another vector to it, placing the result in the object provided.
 Vector2f set(float[] values)
          Copies the elements of an array.
 Vector2f set(float x, float y)
          Sets all of the elements of the vector.
 Vector2f set(Vector2f other)
          Copies the elements of another vector.
 Vector2f subtract(Vector2f other)
          Subtracts a vector from this one.
 Vector2f subtract(Vector2f other, Vector2f result)
          Subtracts a vector from this one and places the result in the supplied object.
 Vector2f subtractLocal(Vector2f other)
          Subtracts a vector in-place from this one.
 String toString()
           
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

UNIT_X

public static final Vector2f UNIT_X
A unit vector in the X+ direction.


UNIT_Y

public static final Vector2f UNIT_Y
A unit vector in the Y+ direction.


ZERO

public static final Vector2f ZERO
The zero vector.


MIN_VALUE

public static final Vector2f MIN_VALUE
A vector containing the minimum floating point value for all components (note: the components are -Float.MAX_VALUE, not Float.MIN_VALUE).


MAX_VALUE

public static final Vector2f MAX_VALUE
A vector containing the maximum floating point value for all components.


x

public float x
The components of the vector.


y

public float y
The components of the vector.

Constructor Detail

Vector2f

public Vector2f(float x,
                float y)
Creates a vector from two components.


Vector2f

public Vector2f(float[] values)
Creates a vector from an array of values.


Vector2f

public Vector2f(Vector2f other)
Copy constructor.


Vector2f

public Vector2f()
Creates a zero vector.

Method Detail

dot

public float dot(Vector2f other)
Computes and returns the dot product of this and the specified other vector.


negateLocal

public Vector2f negateLocal()
Negates this vector in-place.

Returns:
a reference to this vector, for chaining.

negate

public Vector2f negate()
Negates this vector.

Returns:
a new vector containing the result.

negate

public Vector2f negate(Vector2f result)
Negates this vector, storing the result in the supplied object.

Returns:
a reference to the result, for chaining.

normalizeLocal

public Vector2f normalizeLocal()
Normalizes this vector in-place.

Returns:
a reference to this vector, for chaining.

normalize

public Vector2f normalize()
Normalizes this vector.

Returns:
a new vector containing the result.

normalize

public Vector2f normalize(Vector2f result)
Normalizes this vector, storing the result in the object supplied.

Returns:
a reference to the result, for chaining.

angle

public float angle(Vector2f other)
Returns the angle between this vector and the specified other vector.


direction

public float direction(Vector2f other)
Returns the direction of a vector pointing from this point to the specified other point.


length

public float length()
Returns the length of this vector.


lengthSquared

public float lengthSquared()
Returns the squared length of this vector.


distance

public float distance(Vector2f other)
Returns the distance from this vector to the specified other vector.


distanceSquared

public float distanceSquared(Vector2f other)
Returns the squared distance from this vector to the specified other.


multLocal

public Vector2f multLocal(float v)
Multiplies this vector in-place by a scalar.

Returns:
a reference to this vector, for chaining.

mult

public Vector2f mult(float v)
Multiplies this vector by a scalar.

Returns:
a new vector containing the result.

mult

public Vector2f mult(float v,
                     Vector2f result)
Multiplies this vector by a scalar and places the result in the supplied object.

Returns:
a reference to the result, for chaining.

multLocal

public Vector2f multLocal(Vector2f other)
Multiplies this vector in-place by another.

Returns:
a reference to this vector, for chaining.

mult

public Vector2f mult(Vector2f other)
Multiplies this vector by another.

Returns:
a new vector containing the result.

mult

public Vector2f mult(Vector2f other,
                     Vector2f result)
Multiplies this vector by another, storing the result in the object provided.

Returns:
a reference to the result vector, for chaining.

addLocal

public Vector2f addLocal(Vector2f other)
Adds a vector in-place to this one.

Returns:
a reference to this vector, for chaining.

add

public Vector2f add(Vector2f other)
Adds a vector to this one.

Returns:
a new vector containing the result.

add

public Vector2f add(Vector2f other,
                    Vector2f result)
Adds a vector to this one, storing the result in the object provided.

Returns:
a reference to the result, for chaining.

subtractLocal

public Vector2f subtractLocal(Vector2f other)
Subtracts a vector in-place from this one.

Returns:
a reference to this vector, for chaining.

subtract

public Vector2f subtract(Vector2f other)
Subtracts a vector from this one.

Returns:
a new vector containing the result.

subtract

public Vector2f subtract(Vector2f other,
                         Vector2f result)
Subtracts a vector from this one and places the result in the supplied object.

Returns:
a reference to the result, for chaining.

addLocal

public Vector2f addLocal(float x,
                         float y)
Adds a vector in-place to this one.

Returns:
a reference to this vector, for chaining.

add

public Vector2f add(float x,
                    float y)
Adds a vector to this one.

Returns:
a new vector containing the result.

add

public Vector2f add(float x,
                    float y,
                    Vector2f result)
Adds a vector to this one and stores the result in the object provided.

Returns:
a reference to the result, for chaining.

addScaledLocal

public Vector2f addScaledLocal(Vector2f other,
                               float v)
Adds a scaled vector in-place to this one.

Returns:
a reference to this vector, for chaining.

addScaled

public Vector2f addScaled(Vector2f other,
                          float v)
Adds a scaled vector to this one.

Returns:
a new vector containing the result.

addScaled

public Vector2f addScaled(Vector2f other,
                          float v,
                          Vector2f result)
Adds a scaled vector to this one and stores the result in the supplied vector.

Returns:
a reference to the result, for chaining.

rotateLocal

public Vector2f rotateLocal(float angle)
Rotates this vector in-place by the specified angle.

Returns:
a reference to this vector, for chaining.

rotate

public Vector2f rotate(float angle)
Rotates this vector by the specified angle.

Returns:
a new vector containing the result.

rotate

public Vector2f rotate(float angle,
                       Vector2f result)
Rotates this vector by the specified angle, storing the result in the vector provided.

Returns:
a reference to the result vector, for chaining.

rotateAndAdd

public Vector2f rotateAndAdd(float angle,
                             Vector2f add,
                             Vector2f result)
Rotates this vector by the specified angle and adds another vector to it, placing the result in the object provided.

Returns:
a reference to the result, for chaining.

rotateScaleAndAdd

public Vector2f rotateScaleAndAdd(float angle,
                                  float scale,
                                  Vector2f add,
                                  Vector2f result)
Rotates this vector by the specified angle, applies a uniform scale, and adds another vector to it, placing the result in the object provided.

Returns:
a reference to the result, for chaining.

lerpLocal

public Vector2f lerpLocal(Vector2f other,
                          float t)
Linearly interpolates between this and the specified other vector in-place by the supplied amount.

Returns:
a reference to this vector, for chaining.

lerp

public Vector2f lerp(Vector2f other,
                     float t)
Linearly interpolates between this and the specified other vector by the supplied amount.

Returns:
a new vector containing the result.

lerp

public Vector2f lerp(Vector2f other,
                     float t,
                     Vector2f result)
Linearly interpolates between this and the supplied other vector by the supplied amount, storing the result in the supplied object.

Returns:
a reference to the result, for chaining.

set

public Vector2f set(Vector2f other)
Copies the elements of another vector.

Returns:
a reference to this vector, for chaining.

set

public Vector2f set(float[] values)
Copies the elements of an array.

Returns:
a reference to this vector, for chaining.

set

public Vector2f set(float x,
                    float y)
Sets all of the elements of the vector.

Returns:
a reference to this vector, for chaining.

get

public float get(int idx)
Returns the element at the idx'th position of the vector.


get

public void get(float[] values)
Populates the supplied array with the contents of this vector.


get

public FloatBuffer get(FloatBuffer buf)
Populates the supplied buffer with the contents of this vector.

Returns:
a reference to the buffer, for chaining.

encodeToString

public String encodeToString()
Description copied from interface: Encodable
Returns a string representation of this object.

Specified by:
encodeToString in interface Encodable

decodeFromString

public void decodeFromString(String string)
                      throws Exception
Description copied from interface: Encodable
Initializes this object with the contents of the specified string.

Specified by:
decodeFromString in interface Encodable
Throws:
Exception

encodeToStream

public void encodeToStream(DataOutputStream out)
                    throws IOException
Description copied from interface: Encodable
Encodes this object to the specified stream.

Specified by:
encodeToStream in interface Encodable
Throws:
IOException

decodeFromStream

public void decodeFromStream(DataInputStream in)
                      throws IOException
Description copied from interface: Encodable
Initializes this object with data read from the specified stream.

Specified by:
decodeFromStream in interface Encodable
Throws:
IOException

toString

public String toString()
Overrides:
toString in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object other)
Overrides:
equals in class Object


Copyright © 2011. All Rights Reserved.