public class Vector2f extends Object implements Externalizable
| Modifier and Type | Field and Description |
|---|---|
float |
x
The x component of the vector.
|
float |
y
The y component of the vector.
|
| Constructor and Description |
|---|
Vector2f()
Create a new
Vector2f and initialize its components to zero. |
Vector2f(ByteBuffer buffer)
Create a new
Vector2f and read this vector from the supplied ByteBuffer
at the current buffer position. |
Vector2f(float d)
Create a new
Vector2f and initialize both of its components with the given value. |
Vector2f(FloatBuffer buffer)
Create a new
Vector2f and read this vector from the supplied FloatBuffer
at the current buffer position. |
Vector2f(float x,
float y)
Create a new
Vector2f and initialize its components to the given values. |
Vector2f(int index,
ByteBuffer buffer)
Create a new
Vector2f and read this vector from the supplied ByteBuffer
starting at the specified absolute buffer position/index. |
Vector2f(int index,
FloatBuffer buffer)
Create a new
Vector2f and read this vector from the supplied FloatBuffer
starting at the specified absolute buffer position/index. |
Vector2f(Vector2f v)
Create a new
Vector2f and initialize its components to the one of the given vector. |
| Modifier and Type | Method and Description |
|---|---|
Vector2f |
add(Vector2f v)
Add
v to this vector. |
static void |
add(Vector2f a,
Vector2f b,
Vector2f dest)
Add
a to b and store the result in dest. |
float |
angle(Vector2f v)
Return the angle between this vector and the supplied vector.
|
float |
distance(Vector2f v)
Return the distance between this and
v. |
float |
dot(Vector2f v)
Return the dot product of this vector and
v. |
boolean |
equals(Object obj) |
Vector2f |
fma(float a,
Vector2f b)
Add the component-wise multiplication of
a * b to this vector. |
Vector2f |
fma(float a,
Vector2f b,
Vector2f dest)
Add the component-wise multiplication of
a * b to this vector
and store the result in dest. |
Vector2f |
fma(Vector2f a,
Vector2f b)
Add the component-wise multiplication of
a * b to this vector. |
Vector2f |
fma(Vector2f a,
Vector2f b,
Vector2f dest)
Add the component-wise multiplication of
a * b to this vector
and store the result in dest. |
ByteBuffer |
get(ByteBuffer buffer)
Store this vector into the supplied
ByteBuffer at the current
buffer position. |
FloatBuffer |
get(FloatBuffer buffer)
Store this vector into the supplied
FloatBuffer at the current
buffer position. |
ByteBuffer |
get(int index,
ByteBuffer buffer)
Store this vector into the supplied
ByteBuffer starting at the specified
absolute buffer position/index. |
FloatBuffer |
get(int index,
FloatBuffer buffer)
Store this vector into the supplied
FloatBuffer starting at the specified
absolute buffer position/index. |
int |
hashCode() |
float |
length()
Return the length of this vector.
|
float |
lengthSquared()
Return the length squared of this vector.
|
Vector2f |
lerp(Vector2f other,
float t)
Linearly interpolate
this and other using the given interpolation factor t
and store the result in this. |
Vector2f |
lerp(Vector2f other,
float t,
Vector2f dest)
Linearly interpolate
this and other using the given interpolation factor t
and store the result in dest. |
Vector2f |
mul(float scalar)
Multiply the components of this vector by the given scalar.
|
Vector2f |
mul(float scalar,
Vector2f dest)
Multiply the components of this vector by the given scalar and store the result in
dest. |
Vector2f |
mul(Matrix3f m)
Multiply this vector by the given matrix.
|
Vector2f |
mul(Matrix3f m,
Vector2f dest)
Multiply this vector by the given matrix and store the result in
dest. |
Vector2f |
negate()
Negate this vector.
|
Vector2f |
negate(Vector2f dest)
Negate this vector and store the result in
dest. |
Vector2f |
normalize()
Normalize this vector.
|
Vector2f |
normalize(Vector2f dest)
Normalize this vector and store the result in
dest. |
Vector2f |
perpendicular()
Set this vector to be one of its perpendicular vectors.
|
static void |
perpendicular(Vector2f v,
Vector2f dest)
Store one perpendicular vector of
v in dest. |
void |
readExternal(ObjectInput in) |
Vector2f |
set(ByteBuffer buffer)
Read this vector from the supplied
ByteBuffer at the current
buffer position. |
Vector2f |
set(float d)
Set the x and y components to the supplied value.
|
Vector2f |
set(FloatBuffer buffer)
Read this vector from the supplied
FloatBuffer at the current
buffer position. |
Vector2f |
set(float x,
float y)
Set the x and y components to the supplied values.
|
Vector2f |
set(int index,
ByteBuffer buffer)
Read this vector from the supplied
ByteBuffer starting at the specified
absolute buffer position/index. |
Vector2f |
set(int index,
FloatBuffer buffer)
Read this vector from the supplied
FloatBuffer starting at the specified
absolute buffer position/index. |
Vector2f |
set(Vector2f v)
Set this
Vector2f to the values of v. |
Vector2f |
sub(float x,
float y)
Subtract (x, y) from this vector.
|
Vector2f |
sub(Vector2f v)
Subtract
v from this vector. |
static void |
sub(Vector2f a,
Vector2f b,
Vector2f dest)
Subtract
b from a and store the result in dest. |
String |
toString()
Return a string representation of this vector.
|
String |
toString(NumberFormat formatter)
Return a string representation of this vector by formatting the vector components with the given
NumberFormat. |
void |
writeExternal(ObjectOutput out) |
Vector2f |
zero()
Set all components to zero.
|
public float x
public float y
public Vector2f()
Vector2f and initialize its components to zero.public Vector2f(float d)
Vector2f and initialize both of its components with the given value.d - the value of both componentspublic Vector2f(float x,
float y)
Vector2f and initialize its components to the given values.x - the x componenty - the y componentpublic Vector2f(Vector2f v)
Vector2f and initialize its components to the one of the given vector.v - the Vector2f to copy the values frompublic Vector2f(ByteBuffer buffer)
Vector2f and read this vector from the supplied ByteBuffer
at the current buffer position.
This method will not increment the position of the given ByteBuffer.
In order to specify the offset into the ByteBuffer at which
the vector is read, use Vector2f(int, ByteBuffer), taking
the absolute position as parameter.
buffer - values will be read in x, y orderVector2f(int, ByteBuffer)public Vector2f(int index,
ByteBuffer buffer)
Vector2f and read this vector from the supplied ByteBuffer
starting at the specified absolute buffer position/index.
This method will not increment the position of the given ByteBuffer.
index - the absolute position into the ByteBufferbuffer - values will be read in x, y orderpublic Vector2f(FloatBuffer buffer)
Vector2f and read this vector from the supplied FloatBuffer
at the current buffer position.
This method will not increment the position of the given FloatBuffer.
In order to specify the offset into the FloatBuffer at which
the vector is read, use Vector2f(int, FloatBuffer), taking
the absolute position as parameter.
buffer - values will be read in x, y orderVector2f(int, FloatBuffer)public Vector2f(int index,
FloatBuffer buffer)
Vector2f and read this vector from the supplied FloatBuffer
starting at the specified absolute buffer position/index.
This method will not increment the position of the given FloatBuffer.
index - the absolute position into the FloatBufferbuffer - values will be read in x, y orderpublic Vector2f set(float d)
d - the value of both componentspublic Vector2f set(float x, float y)
x - the x componenty - the y componentpublic Vector2f set(Vector2f v)
Vector2f to the values of v.v - the vector to copy frompublic Vector2f set(ByteBuffer buffer)
ByteBuffer at the current
buffer position.
This method will not increment the position of the given ByteBuffer.
In order to specify the offset into the ByteBuffer at which
the vector is read, use set(int, ByteBuffer), taking
the absolute position as parameter.
buffer - values will be read in x, y orderset(int, ByteBuffer)public Vector2f set(int index, ByteBuffer buffer)
ByteBuffer starting at the specified
absolute buffer position/index.
This method will not increment the position of the given ByteBuffer.
index - the absolute position into the ByteBufferbuffer - values will be read in x, y orderpublic Vector2f set(FloatBuffer buffer)
FloatBuffer at the current
buffer position.
This method will not increment the position of the given FloatBuffer.
In order to specify the offset into the FloatBuffer at which
the vector is read, use set(int, FloatBuffer), taking
the absolute position as parameter.
buffer - values will be read in x, y orderset(int, FloatBuffer)public Vector2f set(int index, FloatBuffer buffer)
FloatBuffer starting at the specified
absolute buffer position/index.
This method will not increment the position of the given FloatBuffer.
index - the absolute position into the FloatBufferbuffer - values will be read in x, y orderpublic ByteBuffer get(ByteBuffer buffer)
ByteBuffer at the current
buffer position.
This method will not increment the position of the given ByteBuffer.
In order to specify the offset into the ByteBuffer at which
the vector is stored, use get(int, ByteBuffer), taking
the absolute position as parameter.
buffer - will receive the values of this vector in x, y orderget(int, ByteBuffer)public ByteBuffer get(int index, ByteBuffer buffer)
ByteBuffer starting at the specified
absolute buffer position/index.
This method will not increment the position of the given ByteBuffer.
index - the absolute position into the ByteBufferbuffer - will receive the values of this vector in x, y orderpublic FloatBuffer get(FloatBuffer buffer)
FloatBuffer at the current
buffer position.
This method will not increment the position of the given FloatBuffer.
In order to specify the offset into the FloatBuffer at which
the vector is stored, use get(int, FloatBuffer), taking
the absolute position as parameter.
buffer - will receive the values of this vector in x, y orderget(int, FloatBuffer)public FloatBuffer get(int index, FloatBuffer buffer)
FloatBuffer starting at the specified
absolute buffer position/index.
This method will not increment the position of the given FloatBuffer.
index - the absolute position into the FloatBufferbuffer - will receive the values of this vector in x, y orderpublic static void perpendicular(Vector2f v, Vector2f dest)
v in dest.v - the vector to build one perpendicular vector ofdest - will hold the resultpublic Vector2f perpendicular()
public static void sub(Vector2f a, Vector2f b, Vector2f dest)
b from a and store the result in dest.a - the first operandb - the second operanddest - will hold the result of a - bpublic Vector2f sub(Vector2f v)
v from this vector.v - the vector to subtract from thispublic Vector2f sub(float x, float y)
x - the x component to subtracty - the y component to subtractpublic float dot(Vector2f v)
v.v - the other vectorpublic float angle(Vector2f v)
v - the other vectorpublic float length()
public float lengthSquared()
public float distance(Vector2f v)
v.v - the other vectorpublic Vector2f normalize()
public Vector2f normalize(Vector2f dest)
dest.dest - will hold the resultpublic Vector2f add(Vector2f v)
v to this vector.v - the vector to addpublic static void add(Vector2f a, Vector2f b, Vector2f dest)
a to b and store the result in dest.a - the first addendb - the second addenddest - will hold the resultpublic Vector2f zero()
public void writeExternal(ObjectOutput out) throws IOException
writeExternal in interface ExternalizableIOExceptionpublic void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
readExternal in interface ExternalizableIOExceptionClassNotFoundExceptionpublic Vector2f negate()
public Vector2f negate(Vector2f dest)
dest.dest - will hold the resultpublic Vector2f mul(float scalar)
scalar - the value to multiply this vector's components bypublic Vector2f mul(float scalar, Vector2f dest)
dest.scalar - the value to multiply this vector's components bydest - will hold the resultpublic Vector2f mul(Matrix3f m)
m - the matrix to multiply this vector bypublic Vector2f mul(Matrix3f m, Vector2f dest)
dest.m - the matrix to multiply this vector bydest - will hold the resultpublic Vector2f lerp(Vector2f other, float t)
this and other using the given interpolation factor t
and store the result in this.
If t is 0.0 then the result is this. If the interpolation factor is 1.0
then the result is other.
other - the other vectort - the interpolation factor between 0.0 and 1.0public Vector2f lerp(Vector2f other, float t, Vector2f dest)
this and other using the given interpolation factor t
and store the result in dest.
If t is 0.0 then the result is this. If the interpolation factor is 1.0
then the result is other.
other - the other vectort - the interpolation factor between 0.0 and 1.0dest - will hold the resultpublic String toString()
This method creates a new DecimalFormat on every invocation with the format string " 0.000E0;-".
public String toString(NumberFormat formatter)
NumberFormat.formatter - the NumberFormat used to format the vector components withpublic Vector2f fma(Vector2f a, Vector2f b)
a * b to this vector.a - the first multiplicandb - the second multiplicandpublic Vector2f fma(float a, Vector2f b)
a * b to this vector.a - the first multiplicandb - the second multiplicandpublic Vector2f fma(Vector2f a, Vector2f b, Vector2f dest)
a * b to this vector
and store the result in dest.a - the first multiplicandb - the second multiplicanddest - will hold the resultCopyright © 2015 JOML. All rights reserved.