org.openmali.vecmath2
Class Vector4f

java.lang.Object
  extended by org.openmali.vecmath2.TupleNf<VectorNf>
      extended by org.openmali.vecmath2.VectorNf
          extended by org.openmali.vecmath2.Vector4f
All Implemented Interfaces:
java.io.Externalizable, java.io.Serializable, TupleInterface<VectorNf>, VectorInterface<VectorNf,VectorNf>

public class Vector4f
extends VectorNf
implements java.io.Externalizable, VectorInterface<VectorNf,VectorNf>

A simple 4-dimensional float-Vector implementation. Inspired by Kenji Hiranabe's Vector4f implementation

See Also:
Serialized Form

Field Summary
static Vector4f ZERO
           
 
Fields inherited from class org.openmali.vecmath2.TupleNf
isDirty, roTrick, values
 
Constructor Summary
  Vector4f()
          Creates a new Vector4f instance.
protected Vector4f(boolean readOnly)
          Creates a new Vector4f instance.
protected Vector4f(boolean readOnly, float[] values, boolean[] isDirty, boolean copy)
          Creates a new Vector4f instance.
protected Vector4f(boolean readOnly, float x, float y, float z, float w)
          Creates a new Vector4f instance.
protected Vector4f(boolean readOnly, Vector4f vec)
          Creates a new Vector4f instance.
  Vector4f(float[] values)
          Creates a new Vector4f instance.
  Vector4f(float x, float y, float z, float w)
          Creates a new Vector4f instance.
  Vector4f(Vector4f vec)
          Creates a new Vector4f instance.
 
Method Summary
 Vector4f add(float x, float y, float z, float w)
          Adds the given parameters to this tuple's values.
 Vector4f addW(float w)
          Adds v to this vector's w value.
 Vector4f addX(float v)
          Adds v to this vector's x value.
 Vector4f addY(float v)
          Adds v to this vector's y value.
 Vector4f addZ(float v)
          Adds v to this vector's z value.
 Vector4f asReadOnly()
          
 Vector4f clone()
          Creates and returns a copy of this object.
 Vector4f cross(Vector4f v1, Vector4f v2)
          Sets this vector to be the vector cross product of vectors v1 and v2.
 float distanceL1(VectorNf v2)
          Computes the L-1 (Manhattan) distance between this point and point p1.
 float distanceLinf(VectorNf v2)
          Computes the L-infinite distance between this point and point p1.
 Vector4f div(float vx, float vy, float vz, float vw)
          Divides this vector's values by vx, vy, vz.
 Vector4f divW(float v)
          Divides this vector's w value by v.
 Vector4f divX(float v)
          Divides this vector's x value by v.
 Vector4f divY(float v)
          Divides this vector's y value by v.
 Vector4f divZ(float v)
          Divides this vector's z value by v.
 boolean equals(java.lang.Object o)
          Returns true if the Object t1 is of type Vector4f and all of the data members of t1 are equal to the corresponding data members in this Vector4f.
static Vector4f fromPool()
          Allocates an Vector4f instance from the pool.
static Vector4f fromPool(float x, float y, float z, float w)
          Allocates an Vector4f instance from the pool.
static Vector4f fromPool(Vector4f tuple)
          Allocates an Vector4f instance from the pool.
 void get(Tuple3f buffer)
          Writes all values of this Tuple to the specified buffer Tuple.
 void getLinearHyperPlaneNormal(TupleNf<?> p1, TupleNf<?> p2, TupleNf<?> p3)
          returns the normal of a linear hyperplane (that is a 4D hyperplane passing through the origin) from three points. i.e.
static TupleNf<?> getLinearHyperPlaneNormal(TupleNf<?> p1, TupleNf<?> p2, TupleNf<?> p3, TupleNf<?> normal)
          returns the normal of a linear hyperplane (that is a 4D hyperplane passing through the origin) from three points. i.e.
 Vector4f getReadOnly()
          
 float getW()
           
 float getX()
           
 float getY()
           
 float getZ()
           
 float length3()
          computes the length of the (x,y,z)-component of this vector.
 float lengthSquared3()
          Computes the squared length of the (x,y,z)-component of this vector.
 Vector4f mul(float vx, float vy, float vz, float vw)
          Multiplies this vector's values with vx, vy, vz.
 Vector4f mulW(float v)
          Multiplies this vector's w value with v.
 Vector4f mulX(float v)
          Multiplies this vector's x value with v.
 Vector4f mulY(float v)
          Multiplies this vector's y value with v.
 Vector4f mulZ(float v)
          Multiplies this vector's z value with v.
static Vector4f newReadOnly()
          Creates a new Vector4f instance.
static Vector4f newReadOnly(float[] values)
          Creates a new Vector4f instance.
static Vector4f newReadOnly(float x, float y, float z, float w)
          Creates a new Vector4f instance.
static Vector4f newReadOnly(Vector4f vec)
          Creates a new Vector4f instance.
 Vector4f scale(float factorX, float factorY, float factorZ, float factorW)
          Sets the value of this vector to the scalar multiplication of vector t1.
 Vector4f set(float x, float y, float z, float w)
          Sets all values of this Tuple to the specified ones.
 Vector4f set(Tuple3f tuple)
          Sets all values of this vector to the specified ones.
 Vector4f set(Vector3f v, float w)
          Sets this vector's xyz components to the ones of the given vector and w to w.
 Vector4f setW(float w)
          Sets the value of the w-element of this vector.
 Vector4f setX(float x)
          Sets the value of the x-element of this vector.
 Vector4f setY(float y)
          Sets the value of the y-element of this vector.
 Vector4f setZ(float z)
          Sets the value of the z-element of this vector.
 Vector4f sub(float x, float y, float z, float w)
          Subtracts the given parameters from this vector's values.
 Vector4f sub(Tuple3f tuple2)
          Sets the value of this tuple to the vector difference of itself and tuple t1 (this = this - t1).
 Vector4f sub(Tuple3f tuple1, Tuple3f tuple2)
          Sets the value of this tuple to the vector difference of tuple t1 and t2 (this = t1 - t2).
 Vector4f subW(float v)
          Subtracts v from this vector's w value.
 Vector4f subX(float v)
          Subtracts v from this vector's x value.
 Vector4f subY(float v)
          Subtracts v from this vector's y value.
 Vector4f subZ(float v)
          Subtracts v from this vector's z value.
static void toPool(Vector4f o)
          Stores the given Vector4f instance in the pool.
 
Methods inherited from class org.openmali.vecmath2.VectorNf
angle, cross, dot, getNorm, getNormSquared, length, lengthSquared, LUDBackSolve, mul, mul, newReadOnly, newReadOnly, newReadOnly, normalize, normalize, SVDBackSolve
 
Methods inherited from class org.openmali.vecmath2.TupleNf
absolute, absolute, add, add, addValue, clamp, clamp, clampMax, clampMax, clampMin, clampMin, deserialize, div, divValue, epsilonEquals, equals, fill, get, get, get, getSerializationBufferSize, getSize, getValue, hashCode, interpolate, interpolate, isDirty, isReadOnly, mul, mulValue, negate, negate, readExternal, readFromBuffer, readFromBuffer, readFromBuffer, readFromBuffer, round, round, scale, scale, scaleAdd, scaleAdd, serialize, set, set, set, setClean, setValue, setZero, sub, sub, subValue, toString, writeExternal, writeToBuffer, writeToBuffer, writeToBuffer, writeToBuffer
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.io.Externalizable
readExternal, writeExternal
 
Methods inherited from interface org.openmali.vecmath2.VectorInterface
angle, cross, dot, length, lengthSquared, normalize, normalize
 
Methods inherited from interface org.openmali.vecmath2.TupleInterface
absolute, absolute, add, add, addValue, clamp, clamp, clampMax, clampMax, clampMin, clampMin, div, divValue, epsilonEquals, fill, get, get, get, getSize, getValue, interpolate, interpolate, isDirty, isReadOnly, mul, mulValue, negate, negate, round, round, scale, scale, scaleAdd, scaleAdd, set, set, set, setClean, setValue, setZero, sub, sub, subValue
 

Field Detail

ZERO

public static final Vector4f ZERO
Constructor Detail

Vector4f

protected Vector4f(boolean readOnly,
                   float x,
                   float y,
                   float z,
                   float w)
Creates a new Vector4f instance.

Parameters:
readOnly -
x - the x element to use
y - the y element to use
z - the z element to use
w - the w element to use

Vector4f

protected Vector4f(boolean readOnly,
                   float[] values,
                   boolean[] isDirty,
                   boolean copy)
Creates a new Vector4f instance.

Parameters:
readOnly -
values - the values array (must be at least size 4)
isDirty -
copy -

Vector4f

protected Vector4f(boolean readOnly,
                   Vector4f vec)
Creates a new Vector4f instance.

Parameters:
readOnly -
vec - the Vector4f to copy the values from

Vector4f

protected Vector4f(boolean readOnly)
Creates a new Vector4f instance.

Parameters:
readOnly -

Vector4f

public Vector4f(float x,
                float y,
                float z,
                float w)
Creates a new Vector4f instance.

Parameters:
x - the x element to use
y - the y element to use
z - the z element to use
w - the w element to use

Vector4f

public Vector4f(float[] values)
Creates a new Vector4f instance.

Parameters:
values - the values array (must be at least size 4)

Vector4f

public Vector4f(Vector4f vec)
Creates a new Vector4f instance.

Parameters:
vec - the Vector4f to copy the values from

Vector4f

public Vector4f()
Creates a new Vector4f instance.

Method Detail

setX

public final Vector4f setX(float x)
Sets the value of the x-element of this vector.

Parameters:
x -
Returns:
itself

setY

public final Vector4f setY(float y)
Sets the value of the y-element of this vector.

Parameters:
y -
Returns:
itself

setZ

public final Vector4f setZ(float z)
Sets the value of the z-element of this vector.

Parameters:
z -
Returns:
itself

setW

public final Vector4f setW(float w)
Sets the value of the w-element of this vector.

Parameters:
w -
Returns:
itself

getX

public final float getX()
Returns:
the value of the x-element of this tuple.

getY

public final float getY()
Returns:
the value of the y-element of this tuple.

getZ

public final float getZ()
Returns:
the value of the z-element of this tuple.

getW

public final float getW()
Returns:
the value of the w-element of this tuple.

set

public final Vector4f set(float x,
                          float y,
                          float z,
                          float w)
Sets all values of this Tuple to the specified ones.

Parameters:
x - the x element to use
y - the y element to use
z - the z element to use
w - the w element to use
Returns:
itself

set

public final Vector4f set(Vector3f v,
                          float w)
Sets this vector's xyz components to the ones of the given vector and w to w.

Parameters:
v -
w -
Returns:
itself

addX

public final Vector4f addX(float v)
Adds v to this vector's x value.

Parameters:
v -
Returns:
itself

addY

public final Vector4f addY(float v)
Adds v to this vector's y value.

Parameters:
v -
Returns:
itself

addZ

public final Vector4f addZ(float v)
Adds v to this vector's z value.

Parameters:
v -
Returns:
itself

addW

public final Vector4f addW(float w)
Adds v to this vector's w value.

Parameters:
w -
Returns:
itself

add

public final Vector4f add(float x,
                          float y,
                          float z,
                          float w)
Adds the given parameters to this tuple's values.

Parameters:
x -
y -
z -
w -
Returns:
itself

subX

public final Vector4f subX(float v)
Subtracts v from this vector's x value.

Parameters:
v -
Returns:
itself

subY

public final Vector4f subY(float v)
Subtracts v from this vector's y value.

Parameters:
v -
Returns:
itself

subZ

public final Vector4f subZ(float v)
Subtracts v from this vector's z value.

Parameters:
v -
Returns:
itself

subW

public final Vector4f subW(float v)
Subtracts v from this vector's w value.

Parameters:
v -
Returns:
itself

sub

public final Vector4f sub(float x,
                          float y,
                          float z,
                          float w)
Subtracts the given parameters from this vector's values.

Parameters:
x -
y -
z -
w -
Returns:
itself

mulX

public final Vector4f mulX(float v)
Multiplies this vector's x value with v.

Parameters:
v -
Returns:
itself

mulY

public final Vector4f mulY(float v)
Multiplies this vector's y value with v.

Parameters:
v -
Returns:
itself

mulZ

public final Vector4f mulZ(float v)
Multiplies this vector's z value with v.

Parameters:
v -
Returns:
itself

mulW

public final Vector4f mulW(float v)
Multiplies this vector's w value with v.

Parameters:
v -
Returns:
itself

mul

public final Vector4f mul(float vx,
                          float vy,
                          float vz,
                          float vw)
Multiplies this vector's values with vx, vy, vz.

Parameters:
vx -
vy -
vz -
vw -
Returns:
itself

scale

public final Vector4f scale(float factorX,
                            float factorY,
                            float factorZ,
                            float factorW)
Sets the value of this vector to the scalar multiplication of vector t1.

Parameters:
factorX -
factorY -
factorZ -
factorW -
Returns:
itself

divX

public final Vector4f divX(float v)
Divides this vector's x value by v.

Parameters:
v -
Returns:
itself

divY

public final Vector4f divY(float v)
Divides this vector's y value by v.

Parameters:
v -
Returns:
itself

divZ

public final Vector4f divZ(float v)
Divides this vector's z value by v.

Parameters:
v -
Returns:
itself

divW

public final Vector4f divW(float v)
Divides this vector's w value by v.

Parameters:
v -
Returns:
itself

div

public final Vector4f div(float vx,
                          float vy,
                          float vz,
                          float vw)
Divides this vector's values by vx, vy, vz.

Parameters:
vx -
vy -
Returns:
itself

set

public final Vector4f set(Tuple3f tuple)
Sets all values of this vector to the specified ones.

Parameters:
tuple - the tuple to be copied
Returns:
itself

get

public final void get(Tuple3f buffer)
Writes all values of this Tuple to the specified buffer Tuple.

Parameters:
buffer - the buffer Tuple to write the values to

sub

public final Vector4f sub(Tuple3f tuple1,
                          Tuple3f tuple2)
Sets the value of this tuple to the vector difference of tuple t1 and t2 (this = t1 - t2).

Parameters:
tuple1 - the first tuple
tuple2 - the second tuple
Returns:
itself

sub

public final Vector4f sub(Tuple3f tuple2)
Sets the value of this tuple to the vector difference of itself and tuple t1 (this = this - t1).

Parameters:
tuple2 - the other tuple
Returns:
itself

cross

public final Vector4f cross(Vector4f v1,
                            Vector4f v2)
Sets this vector to be the vector cross product of vectors v1 and v2.

Parameters:
v1 - the first vector
v2 - the second vector
Returns:
itself

lengthSquared3

public final float lengthSquared3()
Computes the squared length of the (x,y,z)-component of this vector. If you want to have also the w-component in the computation, please use VectorNf.getNormSquared()

Returns:
the squared length of this vector, only cares about (x,y,z).
See Also:
VectorNf.getNormSquared()

length3

public final float length3()
computes the length of the (x,y,z)-component of this vector. If you want to have also the w-component in the computation, please use VectorNf.getNorm()

Returns:
the length of this vector, only cares about (x,y,z).
See Also:
VectorNf.getNorm()

distanceL1

public final float distanceL1(VectorNf v2)
Computes the L-1 (Manhattan) distance between this point and point p1. The L-1 distance is equal to abs(x1 - x2) + abs(y1 - y2) + abs(z1 - z2) + abs(w1 - w2).
wouldn't it be wiser to compute, L1 only over (x,y,z), because w is mostly only a helper variable?

Parameters:
v2 - the other point
Returns:
L-1 distance

getLinearHyperPlaneNormal

public static TupleNf<?> getLinearHyperPlaneNormal(TupleNf<?> p1,
                                                   TupleNf<?> p2,
                                                   TupleNf<?> p3,
                                                   TupleNf<?> normal)
returns the normal of a linear hyperplane (that is a 4D hyperplane passing through the origin) from three points. i.e. Ax1 + Bx2 + Cx3 + Dx4 = 0 deals with degeneracies, if the points are colinear though, and so no unique plane can be found then the method fills the passback with NaN. zero garbage. slow method, needs optimizing

Parameters:
p1 -
p2 -
p3 -
normal -

getLinearHyperPlaneNormal

public final void getLinearHyperPlaneNormal(TupleNf<?> p1,
                                            TupleNf<?> p2,
                                            TupleNf<?> p3)
returns the normal of a linear hyperplane (that is a 4D hyperplane passing through the origin) from three points. i.e. Ax1 + Bx2 + Cx3 + Dx4 = 0 deals with degeneracies, if the points are colinear though, and so no unique plane can be found then the method fills the passback with NaN. zero garbage. slow method, needs optimizing

Parameters:
p1 -
p2 -
p3 -

distanceLinf

public final float distanceLinf(VectorNf v2)
Computes the L-infinite distance between this point and point p1. The L-infinite distance is equal to MAX[abs(x1 - x2), abs(y1 - y2), abs(z1 - z2), abs(w1 - w2)].
wouldn't it be wiser to compute, Linf only over (x,y,z), because w is mostly only a helper variable?

Parameters:
v2 - the other point
Returns:
L-infinite distance

asReadOnly

public Vector4f asReadOnly()

Overrides:
asReadOnly in class VectorNf
Returns:
a new instance sharing the values array with this instance. The new instance is read-only. Changes to this instance will be reflected in the new read-only-instance.
See Also:
TupleNf.getReadOnly()

getReadOnly

public Vector4f getReadOnly()

Overrides:
getReadOnly in class VectorNf
Returns:
a single instance sharing the values array with this instance (one unique instance per 'master-instance'). The instance is read-only. Changes to this instance will be reflected in the read-only-instance.
See Also:
TupleNf.asReadOnly()

equals

public boolean equals(java.lang.Object o)
Returns true if the Object t1 is of type Vector4f and all of the data members of t1 are equal to the corresponding data members in this Vector4f.

Overrides:
equals in class TupleNf<VectorNf>
Parameters:
o - the Object with which the comparison is made
Returns:
true or false

clone

public Vector4f clone()
Creates and returns a copy of this object.

Overrides:
clone in class VectorNf
Returns:
a clone of this instance.
Throws:
java.lang.OutOfMemoryError - if there is not enough memory.
See Also:
Cloneable

newReadOnly

public static Vector4f newReadOnly(float x,
                                   float y,
                                   float z,
                                   float w)
Creates a new Vector4f instance.

Parameters:
x - the x element to use
y - the y element to use
z - the z element to use
w - the w element to use

newReadOnly

public static Vector4f newReadOnly(float[] values)
Creates a new Vector4f instance.

Parameters:
values - the values array (must be at least size 4)

newReadOnly

public static Vector4f newReadOnly(Vector4f vec)
Creates a new Vector4f instance.

Parameters:
vec - the Vector4f to copy the values from

newReadOnly

public static Vector4f newReadOnly()
Creates a new Vector4f instance.


fromPool

public static Vector4f fromPool()
Allocates an Vector4f instance from the pool.


fromPool

public static Vector4f fromPool(float x,
                                float y,
                                float z,
                                float w)
Allocates an Vector4f instance from the pool.


fromPool

public static Vector4f fromPool(Vector4f tuple)
Allocates an Vector4f instance from the pool.


toPool

public static void toPool(Vector4f o)
Stores the given Vector4f instance in the pool.

Parameters:
o -