public class Vector2f extends Object implements Externalizable, Vector2fc
| 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(Vector2fc v)
Create a new
Vector2f and initialize its components to the one of the given vector. |
| Modifier and Type | Method and Description |
|---|---|
Vector2f |
add(float x,
float y)
Increment the components of this vector by the given values.
|
Vector2f |
add(float x,
float y,
Vector2f dest)
Increment the components of this vector by the given values and store the result in
dest. |
Vector2f |
add(Vector2fc v)
Add
v to this vector. |
Vector2f |
add(Vector2fc v,
Vector2f dest)
Add the supplied vector to this one and store the result in
dest. |
float |
angle(Vector2fc v)
Return the angle between this vector and the supplied vector.
|
float |
distance(float x,
float y)
Return the distance between
this vector and (x, y). |
float |
distance(Vector2fc v)
Return the distance between this and
v. |
float |
distanceSquared(float x,
float y)
Return the distance squared between
this vector and (x, y). |
float |
distanceSquared(Vector2fc v)
Return the distance squared between this and
v. |
float |
dot(Vector2fc v)
Return the dot product of this vector and
v. |
boolean |
equals(Object obj) |
Vector2f |
fma(float a,
Vector2fc b)
Add the component-wise multiplication of
a * b to this vector. |
Vector2f |
fma(float a,
Vector2fc b,
Vector2f dest)
Add the component-wise multiplication of
a * b to this vector
and store the result in dest. |
Vector2f |
fma(Vector2fc a,
Vector2fc b)
Add the component-wise multiplication of
a * b to this vector. |
Vector2f |
fma(Vector2fc a,
Vector2fc 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(Vector2fc other,
float t)
Linearly interpolate
this and other using the given interpolation factor t
and store the result in this. |
Vector2f |
lerp(Vector2fc 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 x,
float y)
Multiply the components of this Vector2f by the given scalar values and store the result in
this. |
Vector2f |
mul(float x,
float y,
Vector2f dest)
Multiply the components of this Vector2f by the given scalar values and store the result in
dest. |
Vector2f |
mul(float scalar,
Vector2f dest)
Multiply the components of this vector by the given scalar and store the result in
dest. |
Vector2f |
mul(Vector2fc v)
Multiply this Vector2f component-wise by another Vector2f.
|
Vector2f |
mul(Vector2fc v,
Vector2f dest)
Multiply this Vector2f component-wise by another Vector2f 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.
|
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(Vector2dc v)
Set this
Vector2f to the values of v. |
Vector2f |
set(Vector2fc v)
Set this
Vector2f to the values of v. |
Vector2f |
sub(float x,
float y)
Subtract (x, y) from this vector.
|
Vector2f |
sub(float x,
float y,
Vector2f dest)
Subtract (x, y) from this vector and store the result in
dest. |
Vector2f |
sub(Vector2fc v)
Subtract
v from this vector. |
Vector2f |
sub(Vector2fc v,
Vector2f dest)
Subtract
v from this vector and store the result in dest. |
Vector2fc |
toImmutable()
Create a new immutable view of this
Vector2f. |
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) |
float |
x() |
float |
y() |
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(Vector2fc v)
Vector2f and initialize its components to the one of the given vector.v - the Vector2fc 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(Vector2fc v)
Vector2f to the values of v.v - the vector to copy frompublic Vector2f set(Vector2dc v)
Vector2f to the values of v.
Note that due to the given vector v storing the components in double-precision,
there is the possibility to lose precision.
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)
Vector2fcByteBuffer 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 Vector2fc.get(int, ByteBuffer), taking
the absolute position as parameter.
get in interface Vector2fcbuffer - will receive the values of this vector in x, y orderVector2fc.get(int, ByteBuffer)public ByteBuffer get(int index, ByteBuffer buffer)
Vector2fcByteBuffer starting at the specified
absolute buffer position/index.
This method will not increment the position of the given ByteBuffer.
public FloatBuffer get(FloatBuffer buffer)
Vector2fcFloatBuffer 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 Vector2fc.get(int, FloatBuffer), taking
the absolute position as parameter.
get in interface Vector2fcbuffer - will receive the values of this vector in x, y orderVector2fc.get(int, FloatBuffer)public FloatBuffer get(int index, FloatBuffer buffer)
Vector2fcFloatBuffer starting at the specified
absolute buffer position/index.
This method will not increment the position of the given FloatBuffer.
public Vector2f perpendicular()
public Vector2f sub(Vector2fc v)
v from this vector.v - the vector to subtractpublic Vector2f sub(Vector2fc v, Vector2f dest)
Vector2fcv from this vector and store the result in dest.public Vector2f sub(float x, float y)
x - the x component to subtracty - the y component to subtractpublic Vector2f sub(float x, float y, Vector2f dest)
Vector2fcdest.public float dot(Vector2fc v)
Vector2fcv.public float angle(Vector2fc v)
Vector2fcpublic float length()
Vector2fcpublic float lengthSquared()
Vector2fclengthSquared in interface Vector2fcpublic float distance(Vector2fc v)
Vector2fcv.public float distanceSquared(Vector2fc v)
Vector2fcv.distanceSquared in interface Vector2fcv - the other vectorpublic float distance(float x,
float y)
Vector2fcthis vector and (x, y).public float distanceSquared(float x,
float y)
Vector2fcthis vector and (x, y).distanceSquared in interface Vector2fcx - the x component of the other vectory - the y component of the other vectorpublic Vector2f normalize()
public Vector2f normalize(Vector2f dest)
Vector2fcdest.public Vector2f add(Vector2fc v)
v to this vector.v - the vector to addpublic Vector2f add(Vector2fc v, Vector2f dest)
Vector2fcdest.public Vector2f add(float x, float y)
x - the x component to addy - the y component to addpublic Vector2f add(float x, float y, Vector2f dest)
Vector2fcdest.public 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)
Vector2fcdest.public Vector2f mul(float scalar)
scalar - the value to multiply this vector's components bypublic Vector2f mul(float scalar, Vector2f dest)
Vector2fcdest.public Vector2f mul(float x, float y)
this.x - the x component to multiply this vector byy - the y component to multiply this vector bypublic Vector2f mul(float x, float y, Vector2f dest)
Vector2fcdest.public Vector2f mul(Vector2fc v)
v - the vector to multiply bypublic Vector2f mul(Vector2fc v, Vector2f dest)
Vector2fcdest.public Vector2f lerp(Vector2fc 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(Vector2fc other, float t, Vector2f dest)
Vector2fcthis 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.
public 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(Vector2fc a, Vector2fc b)
a * b to this vector.a - the first multiplicandb - the second multiplicandpublic Vector2f fma(float a, Vector2fc b)
a * b to this vector.a - the first multiplicandb - the second multiplicandpublic Vector2f fma(Vector2fc a, Vector2fc b, Vector2f dest)
Vector2fca * b to this vector
and store the result in dest.public Vector2f fma(float a, Vector2fc b, Vector2f dest)
Vector2fca * b to this vector
and store the result in dest.public Vector2fc toImmutable()
Vector2f.
The observable state of the returned object is the same as that of this, but casting
the returned object to Vector2f will not be possible.
This method allocates a new instance of a class implementing Vector2fc on every call.
Copyright © 2015–2016 JOML. All rights reserved.