com.threerings.math
Class Vector3f

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

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

A three element vector.


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.threerings.io.Streamable
com.threerings.io.Streamable.Closure
 
Field Summary
static Vector3f MAX_VALUE
          A vector containing the maximum floating point value for all components.
static Vector3f 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 Vector3f NORMAL_XYZ
          A normalized version of UNIT_XYZ.
static Vector3f UNIT_X
          A unit vector in the X+ direction.
static Vector3f UNIT_XYZ
          A vector containing unity for all components.
static Vector3f UNIT_Y
          A unit vector in the Y+ direction.
static Vector3f UNIT_Z
          A unit vector in the Z+ direction.
 float x
          The components of the vector.
 float y
          The components of the vector.
 float z
          The components of the vector.
static Vector3f ZERO
          The zero vector.
 
Constructor Summary
Vector3f()
          Creates a zero vector.
Vector3f(float[] values)
          Creates a vector from an array of values.
Vector3f(float x, float y, float z)
          Creates a vector from three components.
Vector3f(Vector3f other)
          Copy constructor.
 
Method Summary
 Vector3f add(float x, float y, float z)
          Adds a vector to this one.
 Vector3f add(float x, float y, float z, Vector3f result)
          Adds a vector to this one and stores the result in the object provided.
 Vector3f add(Vector3f other)
          Adds a vector to this one.
 Vector3f add(Vector3f other, Vector3f result)
          Adds a vector to this one, storing the result in the object provided.
 Vector3f addLocal(float x, float y, float z)
          Adds a vector in-place to this one.
 Vector3f addLocal(Vector3f other)
          Adds a vector in-place to this one.
 Vector3f addScaled(Vector3f other, float v)
          Adds a scaled vector to this one.
 Vector3f addScaled(Vector3f other, float v, Vector3f result)
          Adds a scaled vector to this one and stores the result in the supplied vector.
 Vector3f addScaledLocal(Vector3f other, float v)
          Adds a scaled vector in-place to this one.
 float angle(Vector3f other)
          Returns the angle between this vector and the specified other vector.
 Vector3f cross(Vector3f other)
          Computes the cross product of this and the specified other vector.
 Vector3f cross(Vector3f other, Vector3f result)
          Computes the cross product of this and the specified other vector, placing the result in the object supplied.
 Vector3f crossLocal(Vector3f other)
          Computes the cross product of this and the specified other vector, storing the result in this 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 distance(Vector3f other)
          Returns the distance from this vector to the specified other vector.
 float distanceSquared(Vector3f other)
          Returns the squared distance from this vector to the specified other.
 float dot(Vector3f 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.
 Vector3f lerp(Vector3f other, float t)
          Linearly interpolates between this and the specified other vector by the supplied amount.
 Vector3f lerp(Vector3f other, float t, Vector3f result)
          Linearly interpolates between this and the supplied other vector by the supplied amount, storing the result in the supplied object.
 Vector3f lerpLocal(Vector3f other, float t)
          Linearly interpolates between this and the specified other vector in-place by the supplied amount.
 float manhattanDistance(Vector3f other)
          Returns the Manhattan distance between this vector and the specified other.
 Vector3f mult(float v)
          Multiplies this vector by a scalar.
 Vector3f mult(float v, Vector3f result)
          Multiplies this vector by a scalar and places the result in the supplied object.
 Vector3f mult(Vector3f other)
          Multiplies this vector by another.
 Vector3f mult(Vector3f other, Vector3f result)
          Multiplies this vector by another, storing the result in the object provided.
 Vector3f multLocal(float v)
          Multiplies this vector in-place by a scalar.
 Vector3f multLocal(Vector3f other)
          Multiplies this vector in-place by another.
 Vector3f negate()
          Negates this vector.
 Vector3f negate(Vector3f result)
          Negates this vector, storing the result in the supplied object.
 Vector3f negateLocal()
          Negates this vector in-place.
 Vector3f normalize()
          Normalizes this vector.
 Vector3f normalize(Vector3f result)
          Normalizes this vector, storing the result in the object supplied.
 Vector3f normalizeLocal()
          Normalizes this vector in-place.
 Vector3f set(float[] values)
          Copies the elements of an array.
 Vector3f set(float x, float y, float z)
          Sets all of the elements of the vector.
 Vector3f set(Vector3f other)
          Copies the elements of another vector.
 Vector3f subtract(Vector3f other)
          Subtracts a vector from this one.
 Vector3f subtract(Vector3f other, Vector3f result)
          Subtracts a vector from this one and places the result in the supplied object.
 Vector3f subtractLocal(Vector3f other)
          Subtracts a vector in-place from this one.
 String toString()
           
 float triple(Vector3f b, Vector3f c)
          Computes the triple product of this and the specified other vectors, which is equal to this.dot(b.cross(c)).
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

UNIT_X

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


UNIT_Y

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


UNIT_Z

public static final Vector3f UNIT_Z
A unit vector in the Z+ direction.


UNIT_XYZ

public static final Vector3f UNIT_XYZ
A vector containing unity for all components.


NORMAL_XYZ

public static final Vector3f NORMAL_XYZ
A normalized version of UNIT_XYZ.


ZERO

public static final Vector3f ZERO
The zero vector.


MIN_VALUE

public static final Vector3f 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 Vector3f 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.


z

public float z
The components of the vector.

Constructor Detail

Vector3f

public Vector3f(float x,
                float y,
                float z)
Creates a vector from three components.


Vector3f

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


Vector3f

public Vector3f(Vector3f other)
Copy constructor.


Vector3f

public Vector3f()
Creates a zero vector.

Method Detail

dot

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


crossLocal

public Vector3f crossLocal(Vector3f other)
Computes the cross product of this and the specified other vector, storing the result in this vector.

Returns:
a reference to this vector, for chaining.

cross

public Vector3f cross(Vector3f other)
Computes the cross product of this and the specified other vector.

Returns:
a new vector containing the result.

cross

public Vector3f cross(Vector3f other,
                      Vector3f result)
Computes the cross product of this and the specified other vector, placing the result in the object supplied.

Returns:
a reference to the result, for chaining.

triple

public float triple(Vector3f b,
                    Vector3f c)
Computes the triple product of this and the specified other vectors, which is equal to this.dot(b.cross(c)).


negateLocal

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

Returns:
a reference to this vector, for chaining.

negate

public Vector3f negate()
Negates this vector.

Returns:
a new vector containing the result.

negate

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

Returns:
a reference to the result, for chaining.

normalizeLocal

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

Returns:
a reference to this vector, for chaining.

normalize

public Vector3f normalize()
Normalizes this vector.

Returns:
a new vector containing the result.

normalize

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

Returns:
a reference to the result, for chaining.

angle

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


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(Vector3f other)
Returns the distance from this vector to the specified other vector.


distanceSquared

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


manhattanDistance

public float manhattanDistance(Vector3f other)
Returns the Manhattan distance between this vector and the specified other.


multLocal

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

Returns:
a reference to this vector, for chaining.

mult

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

Returns:
a new vector containing the result.

mult

public Vector3f mult(float v,
                     Vector3f 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 Vector3f multLocal(Vector3f other)
Multiplies this vector in-place by another.

Returns:
a reference to this vector, for chaining.

mult

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

Returns:
a new vector containing the result.

mult

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

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

addLocal

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

Returns:
a reference to this vector, for chaining.

add

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

Returns:
a new vector containing the result.

add

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

Returns:
a reference to the result, for chaining.

subtractLocal

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

Returns:
a reference to this vector, for chaining.

subtract

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

Returns:
a new vector containing the result.

subtract

public Vector3f subtract(Vector3f other,
                         Vector3f 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 Vector3f addLocal(float x,
                         float y,
                         float z)
Adds a vector in-place to this one.

Returns:
a reference to this vector, for chaining.

add

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

Returns:
a new vector containing the result.

add

public Vector3f add(float x,
                    float y,
                    float z,
                    Vector3f 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 Vector3f addScaledLocal(Vector3f other,
                               float v)
Adds a scaled vector in-place to this one.

Returns:
a reference to this vector, for chaining.

addScaled

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

Returns:
a new vector containing the result.

addScaled

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

Returns:
a reference to the result, for chaining.

lerpLocal

public Vector3f lerpLocal(Vector3f 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 Vector3f lerp(Vector3f 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 Vector3f lerp(Vector3f other,
                     float t,
                     Vector3f 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 Vector3f set(Vector3f other)
Copies the elements of another vector.

Returns:
a reference to this vector, for chaining.

set

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

Returns:
a reference to this vector, for chaining.

set

public Vector3f set(float x,
                    float y,
                    float z)
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.