libgdx API

com.badlogic.gdx.math
Class Vector3

java.lang.Object
  extended by com.badlogic.gdx.math.Vector3
All Implemented Interfaces:
java.io.Serializable

public class Vector3
extends java.lang.Object
implements java.io.Serializable

Encapsulates a 3D vector. Allows chaining operations by returning a reference to itself in all modification methods.

Author:
badlogicgames@gmail.com
See Also:
Serialized Form

Field Summary
static Vector3 tmp
          Static temporary vector.
static Vector3 tmp2
          Static temporary vector.
static Vector3 tmp3
          Static temporary vector.
 float x
          the x-component of this vector
static Vector3 X
           
 float y
          the x-component of this vector
static Vector3 Y
           
 float z
          the x-component of this vector
static Vector3 Z
           
static Vector3 Zero
           
 
Constructor Summary
Vector3()
          Constructs a vector at (0,0,0)
Vector3(float[] values)
          Creates a vector from the given array.
Vector3(float x, float y, float z)
          Creates a vector with the given components
Vector3(Vector3 vector)
          Creates a vector from the given vector
 
Method Summary
 Vector3 add(float values)
          Adds the given value to all three components of the vector.
 Vector3 add(float x, float y, float z)
          Adds the given vector to this component
 Vector3 add(Vector3 vector)
          Adds the given vector to this vector
 Vector3 cpy()
           
 Vector3 crs(float x, float y, float z)
          Sets this vector to the cross product between it and the other vector.
 Vector3 crs(Vector3 vector)
          Sets this vector to the cross product between it and the other vector.
 Vector3 div(float value)
          Divides all components of this vector by the given value
 Vector3 div(float vx, float vy, float vz)
           
 Vector3 div(Vector3 other)
           
 float dot(float x, float y, float z)
          Returns the dot product between this and the given vector.
 float dot(Vector3 vector)
           
 float dst(float x, float y, float z)
           
 float dst(Vector3 vector)
           
 float dst2(float x, float y, float z)
          Returns the squared distance between this point and the given point
 float dst2(Vector3 point)
          Returns the squared distance between this point and the given point
 boolean epsilonEquals(float x, float y, float z, float epsilon)
          Compares this vector with the other vector, using the supplied epsilon for fuzzy equality testing.
 boolean epsilonEquals(Vector3 obj, float epsilon)
          Compares this vector with the other vector, using the supplied epsilon for fuzzy equality testing.
 boolean equals(java.lang.Object obj)
          
 int hashCode()
          
 boolean idt(Vector3 vector)
           
 boolean isUnit()
           
 boolean isZero()
           
 float len()
           
 float len2()
           
 Vector3 lerp(Vector3 target, float alpha)
          Linearly interpolates between this vector and the target vector by alpha which is in the range [0,1].
 Vector3 mul(float value)
          Multiplies all components of this vector by the given value
 Vector3 mul(float vx, float vy, float vz)
          Multiplies all components of this vector by the given values
 Vector3 mul(Matrix4 matrix)
          Multiplies the vector by the given matrix.
 Vector3 mul(Vector3 other)
          Multiplies all components of this vector by the given vector3's values
 Vector3 nor()
          Normalizes this vector to unit length
 Vector3 prj(Matrix4 matrix)
          Multiplies this vector by the given matrix dividing by w.
 Vector3 rot(Matrix4 matrix)
          Multiplies this vector by the first three columns of the matrix, essentially only applying rotation and scaling.
 Vector3 rotate(float angle, float axisX, float axisY, float axisZ)
          Rotates this vector by the given angle around the given axis.
 Vector3 rotate(Vector3 axis, float angle)
          Rotates this vector by the given angle around the given axis.
 Vector3 scale(float scalarX, float scalarY, float scalarZ)
          Scales the vector components by the given scalars.
 Vector3 set(float[] values)
          Sets the components from the array.
 Vector3 set(float x, float y, float z)
          Sets the vector to the given components
 Vector3 set(Vector3 vector)
          Sets the components of the given vector
 Vector3 slerp(Vector3 target, float alpha)
          Spherically interpolates between this vector and the target vector by alpha which is in the range [0,1].
 Vector3 sub(float value)
          Subtracts the given value from all components of this vector
 Vector3 sub(float x, float y, float z)
          Subtracts the other vector from this vector.
 Vector3 sub(Vector3 a_vec)
          Subtracts the given vector from this vector
 Vector3 tmp()
          NEVER EVER SAVE THIS REFERENCE! Do not use this unless you are aware of the side-effects, e.g.
 Vector3 tmp2()
          NEVER EVER SAVE THIS REFERENCE! Do not use this unless you are aware of the side-effects, e.g.
 java.lang.String toString()
          
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

x

public float x
the x-component of this vector


y

public float y
the x-component of this vector


z

public float z
the x-component of this vector


tmp

public static final Vector3 tmp
Static temporary vector. Use with care! Use only when sure other code will not also use this.

See Also:
tmp()

tmp2

public static final Vector3 tmp2
Static temporary vector. Use with care! Use only when sure other code will not also use this.

See Also:
tmp()

tmp3

public static final Vector3 tmp3
Static temporary vector. Use with care! Use only when sure other code will not also use this.

See Also:
tmp()

X

public static final Vector3 X

Y

public static final Vector3 Y

Z

public static final Vector3 Z

Zero

public static final Vector3 Zero
Constructor Detail

Vector3

public Vector3()
Constructs a vector at (0,0,0)


Vector3

public Vector3(float x,
               float y,
               float z)
Creates a vector with the given components

Parameters:
x - The x-component
y - The y-component
z - The z-component

Vector3

public Vector3(Vector3 vector)
Creates a vector from the given vector

Parameters:
vector - The vector

Vector3

public Vector3(float[] values)
Creates a vector from the given array. The array must have at least 3 elements.

Parameters:
values - The array
Method Detail

set

public Vector3 set(float x,
                   float y,
                   float z)
Sets the vector to the given components

Parameters:
x - The x-component
y - The y-component
z - The z-component
Returns:
this vector for chaining

set

public Vector3 set(Vector3 vector)
Sets the components of the given vector

Parameters:
vector - The vector
Returns:
This vector for chaining

set

public Vector3 set(float[] values)
Sets the components from the array. The array must have at least 3 elements

Parameters:
values - The array
Returns:
this vector for chaining

cpy

public Vector3 cpy()
Returns:
a copy of this vector

tmp

public Vector3 tmp()
NEVER EVER SAVE THIS REFERENCE! Do not use this unless you are aware of the side-effects, e.g. other methods might call this as well.

Returns:
a temporary copy of this vector

tmp2

public Vector3 tmp2()
NEVER EVER SAVE THIS REFERENCE! Do not use this unless you are aware of the side-effects, e.g. other methods might call this as well.

Returns:
a temporary copy of this vector

add

public Vector3 add(Vector3 vector)
Adds the given vector to this vector

Parameters:
vector - The other vector
Returns:
This vector for chaining

add

public Vector3 add(float x,
                   float y,
                   float z)
Adds the given vector to this component

Parameters:
x - The x-component of the other vector
y - The y-component of the other vector
z - The z-component of the other vector
Returns:
This vector for chaining.

add

public Vector3 add(float values)
Adds the given value to all three components of the vector.

Parameters:
values - The value
Returns:
This vector for chaining

sub

public Vector3 sub(Vector3 a_vec)
Subtracts the given vector from this vector

Parameters:
a_vec - The other vector
Returns:
This vector for chaining

sub

public Vector3 sub(float x,
                   float y,
                   float z)
Subtracts the other vector from this vector.

Parameters:
x - The x-component of the other vector
y - The y-component of the other vector
z - The z-component of the other vector
Returns:
This vector for chaining

sub

public Vector3 sub(float value)
Subtracts the given value from all components of this vector

Parameters:
value - The value
Returns:
This vector for chaining

mul

public Vector3 mul(float value)
Multiplies all components of this vector by the given value

Parameters:
value - The value
Returns:
This vector for chaining

mul

public Vector3 mul(Vector3 other)
Multiplies all components of this vector by the given vector3's values

Parameters:
other - The vector3 to multiply by
Returns:
This vector for chaining

mul

public Vector3 mul(float vx,
                   float vy,
                   float vz)
Multiplies all components of this vector by the given values

Parameters:
vx - X value
vy - Y value
vz - Z value
Returns:
This vector for chaining

div

public Vector3 div(float value)
Divides all components of this vector by the given value

Parameters:
value - The value
Returns:
This vector for chaining

div

public Vector3 div(float vx,
                   float vy,
                   float vz)

div

public Vector3 div(Vector3 other)

len

public float len()
Returns:
The euclidian length

len2

public float len2()
Returns:
The squared euclidian length

idt

public boolean idt(Vector3 vector)
Parameters:
vector - The other vector
Returns:
Wether this and the other vector are equal

dst

public float dst(Vector3 vector)
Parameters:
vector - The other vector
Returns:
The euclidian distance between this and the other vector

nor

public Vector3 nor()
Normalizes this vector to unit length

Returns:
This vector for chaining

dot

public float dot(Vector3 vector)
Parameters:
vector - The other vector
Returns:
The dot product between this and the other vector

crs

public Vector3 crs(Vector3 vector)
Sets this vector to the cross product between it and the other vector.

Parameters:
vector - The other vector
Returns:
This vector for chaining

crs

public Vector3 crs(float x,
                   float y,
                   float z)
Sets this vector to the cross product between it and the other vector.

Parameters:
x - The x-component of the other vector
y - The y-component of the other vector
z - The z-component of the other vector
Returns:
This vector for chaining

mul

public Vector3 mul(Matrix4 matrix)
Multiplies the vector by the given matrix.

Parameters:
matrix - The matrix
Returns:
This vector for chaining

prj

public Vector3 prj(Matrix4 matrix)
Multiplies this vector by the given matrix dividing by w. This is mostly used to project/unproject vectors via a perspective projection matrix.

Parameters:
matrix - The matrix.
Returns:
This vector for chaining

rot

public Vector3 rot(Matrix4 matrix)
Multiplies this vector by the first three columns of the matrix, essentially only applying rotation and scaling.

Parameters:
matrix - The matrix
Returns:
This vector for chaining

rotate

public Vector3 rotate(float angle,
                      float axisX,
                      float axisY,
                      float axisZ)
Rotates this vector by the given angle around the given axis.

Parameters:
axisX - the x-component of the axis
axisY - the y-component of the axis
axisZ - the z-component of the axis
Returns:
This vector for chaining

rotate

public Vector3 rotate(Vector3 axis,
                      float angle)
Rotates this vector by the given angle around the given axis.

Parameters:
axis -
angle - the angle
Returns:
This vector for chaining

isUnit

public boolean isUnit()
Returns:
Whether this vector is a unit length vector

isZero

public boolean isZero()
Returns:
Whether this vector is a zero vector

lerp

public Vector3 lerp(Vector3 target,
                    float alpha)
Linearly interpolates between this vector and the target vector by alpha which is in the range [0,1]. The result is stored in this vector.

Parameters:
target - The target vector
alpha - The interpolation coefficient
Returns:
This vector for chaining.

slerp

public Vector3 slerp(Vector3 target,
                     float alpha)
Spherically interpolates between this vector and the target vector by alpha which is in the range [0,1]. The result is stored in this vector.

Parameters:
target - The target vector
alpha - The interpolation coefficient
Returns:
This vector for chaining.

toString

public java.lang.String toString()

Overrides:
toString in class java.lang.Object

dot

public float dot(float x,
                 float y,
                 float z)
Returns the dot product between this and the given vector.

Parameters:
x - The x-component of the other vector
y - The y-component of the other vector
z - The z-component of the other vector
Returns:
The dot product

dst2

public float dst2(Vector3 point)
Returns the squared distance between this point and the given point

Parameters:
point - The other point
Returns:
The squared distance

dst2

public float dst2(float x,
                  float y,
                  float z)
Returns the squared distance between this point and the given point

Parameters:
x - The x-component of the other point
y - The y-component of the other point
z - The z-component of the other point
Returns:
The squared distance

dst

public float dst(float x,
                 float y,
                 float z)

hashCode

public int hashCode()

Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)

Overrides:
equals in class java.lang.Object

epsilonEquals

public boolean epsilonEquals(Vector3 obj,
                             float epsilon)
Compares this vector with the other vector, using the supplied epsilon for fuzzy equality testing.

Parameters:
obj -
epsilon -
Returns:
whether the vectors are the same.

epsilonEquals

public boolean epsilonEquals(float x,
                             float y,
                             float z,
                             float epsilon)
Compares this vector with the other vector, using the supplied epsilon for fuzzy equality testing.

Returns:
whether the vectors are the same.

scale

public Vector3 scale(float scalarX,
                     float scalarY,
                     float scalarZ)
Scales the vector components by the given scalars.

Parameters:
scalarX -
scalarY -
scalarZ -

libgdx API

Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com)