mirror of
https://github.com/shadowfacts/lwjgl2-arm64.git
synced 2026-04-03 03:54:53 +02:00
vector utils standardized to radians
This commit is contained in:
parent
f190078ad0
commit
7fffdd2602
|
|
@ -487,7 +487,7 @@ public class Matrix4f extends Matrix implements Serializable {
|
|||
|
||||
/**
|
||||
* Rotates the matrix around the given axis the specified angle
|
||||
* @param angle the angle, in degrees.
|
||||
* @param angle the angle, in radians.
|
||||
* @param axis The vector representing the rotation axis. Must be normalized.
|
||||
* @return this
|
||||
*/
|
||||
|
|
@ -539,7 +539,7 @@ public class Matrix4f extends Matrix implements Serializable {
|
|||
|
||||
/**
|
||||
* Rotates the matrix around the given axis the specified angle, and stores it in the specified destination
|
||||
* @param angle the angle, in degrees.
|
||||
* @param angle the angle, in radians.
|
||||
* @param axis The vector representing the rotation axis. Must be normalized.
|
||||
* @param dest The destination matrix or null if a new matrix is to be created
|
||||
* @return The rotated matrix
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ import java.nio.FloatBuffer;
|
|||
*/
|
||||
|
||||
public class Vector2f extends Vector implements Serializable, ReadableVector2f, WritableVector2f {
|
||||
|
||||
|
||||
public float x, y;
|
||||
|
||||
/**
|
||||
|
|
@ -53,7 +53,7 @@ public class Vector2f extends Vector implements Serializable, ReadableVector2f,
|
|||
public Vector2f() {
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
|
|
@ -86,14 +86,14 @@ public class Vector2f extends Vector implements Serializable, ReadableVector2f,
|
|||
y = src.getY();
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the length squared of the vector
|
||||
*/
|
||||
public float lengthSquared() {
|
||||
return x * x + y * y;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Translate a vector
|
||||
* @param x The translation in x
|
||||
|
|
@ -105,7 +105,7 @@ public class Vector2f extends Vector implements Serializable, ReadableVector2f,
|
|||
this.y += y;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Negate a vector
|
||||
* @return this
|
||||
|
|
@ -115,7 +115,7 @@ public class Vector2f extends Vector implements Serializable, ReadableVector2f,
|
|||
y = -y;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Negate a vector and place the result in a destination vector.
|
||||
* @param dest The destination vector or null if a new vector is to be created
|
||||
|
|
@ -128,8 +128,8 @@ public class Vector2f extends Vector implements Serializable, ReadableVector2f,
|
|||
dest.y = -y;
|
||||
return dest;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Normalise this vector and place the result in another vector.
|
||||
* @param dest The destination vector, or null if a new vector is to be created
|
||||
|
|
@ -137,12 +137,12 @@ public class Vector2f extends Vector implements Serializable, ReadableVector2f,
|
|||
*/
|
||||
public Vector2f normalise(Vector2f dest) {
|
||||
float l = length();
|
||||
|
||||
|
||||
if (dest == null)
|
||||
dest = new Vector2f(x / l, y / l);
|
||||
else
|
||||
dest.set(x / l, y / l);
|
||||
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
|
|
@ -158,86 +158,86 @@ public class Vector2f extends Vector implements Serializable, ReadableVector2f,
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Calculate the angle between two vectors, in degrees
|
||||
* Calculate the angle between two vectors, in radians
|
||||
* @param a A vector
|
||||
* @param b The other vector
|
||||
* @return the angle between the two vectors, in degrees
|
||||
* @return the angle between the two vectors, in radians
|
||||
*/
|
||||
public static float angle(Vector2f a, Vector2f b) {
|
||||
float dls = dot(a, b) / (a.length() * b.length());
|
||||
if (dls < -1f)
|
||||
dls = -1f;
|
||||
else if (dls > 1.0f)
|
||||
dls = 1.0f;
|
||||
return (float) Math.toDegrees(Math.acos(dls));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a vector to another vector and place the result in a destination
|
||||
* vector.
|
||||
* @param left The LHS vector
|
||||
* @param right The RHS vector
|
||||
* @param dest The destination vector, or null if a new vector is to be created
|
||||
* @return the sum of left and right in dest
|
||||
*/
|
||||
public static Vector2f add(Vector2f left, Vector2f right, Vector2f dest) {
|
||||
if (dest == null)
|
||||
return new Vector2f(left.x + right.x, left.y + right.y);
|
||||
else {
|
||||
public static float angle(Vector2f a, Vector2f b) {
|
||||
float dls = dot(a, b) / (a.length() * b.length());
|
||||
if (dls < -1f)
|
||||
dls = -1f;
|
||||
else if (dls > 1.0f)
|
||||
dls = 1.0f;
|
||||
return (float)Math.acos(dls);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a vector to another vector and place the result in a destination
|
||||
* vector.
|
||||
* @param left The LHS vector
|
||||
* @param right The RHS vector
|
||||
* @param dest The destination vector, or null if a new vector is to be created
|
||||
* @return the sum of left and right in dest
|
||||
*/
|
||||
public static Vector2f add(Vector2f left, Vector2f right, Vector2f dest) {
|
||||
if (dest == null)
|
||||
return new Vector2f(left.x + right.x, left.y + right.y);
|
||||
else {
|
||||
dest.set(left.x + right.x, left.y + right.y);
|
||||
return dest;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract a vector from another vector and place the result in a destination
|
||||
* vector.
|
||||
* @param left The LHS vector
|
||||
* @param right The RHS vector
|
||||
* @param dest The destination vector, or null if a new vector is to be created
|
||||
* @return left minus right in dest
|
||||
*/
|
||||
public static Vector2f sub(Vector2f left, Vector2f right, Vector2f dest) {
|
||||
if (dest == null)
|
||||
return new Vector2f(left.x - right.x, left.y - right.y);
|
||||
else {
|
||||
/**
|
||||
* Subtract a vector from another vector and place the result in a destination
|
||||
* vector.
|
||||
* @param left The LHS vector
|
||||
* @param right The RHS vector
|
||||
* @param dest The destination vector, or null if a new vector is to be created
|
||||
* @return left minus right in dest
|
||||
*/
|
||||
public static Vector2f sub(Vector2f left, Vector2f right, Vector2f dest) {
|
||||
if (dest == null)
|
||||
return new Vector2f(left.x - right.x, left.y - right.y);
|
||||
else {
|
||||
dest.set(left.x - right.x, left.y - right.y);
|
||||
return dest;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Store this vector in a FloatBuffer
|
||||
* @param buf The buffer to store it in, at the current position
|
||||
* @return this
|
||||
*/
|
||||
public Vector store(FloatBuffer buf) {
|
||||
buf.put(x);
|
||||
buf.put(y);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load this vector from a FloatBuffer
|
||||
* @param buf The buffer to load it from, at the current position
|
||||
* @return this
|
||||
*/
|
||||
public Vector load(FloatBuffer buf) {
|
||||
x = buf.get();
|
||||
y = buf.get();
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Store this vector in a FloatBuffer
|
||||
* @param buf The buffer to store it in, at the current position
|
||||
* @return this
|
||||
*/
|
||||
public Vector store(FloatBuffer buf) {
|
||||
buf.put(x);
|
||||
buf.put(y);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load this vector from a FloatBuffer
|
||||
* @param buf The buffer to load it from, at the current position
|
||||
* @return this
|
||||
*/
|
||||
public Vector load(FloatBuffer buf) {
|
||||
x = buf.get();
|
||||
y = buf.get();
|
||||
return this;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.lwjgl.vector.Vector#scale(float)
|
||||
*/
|
||||
public Vector scale(float scale) {
|
||||
|
||||
|
||||
x *= scale;
|
||||
y *= scale;
|
||||
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
@ -254,21 +254,21 @@ public class Vector2f extends Vector implements Serializable, ReadableVector2f,
|
|||
sb.append(']');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return x
|
||||
*/
|
||||
public final float getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return y
|
||||
*/
|
||||
public final float getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set X
|
||||
* @param x
|
||||
|
|
@ -276,7 +276,7 @@ public class Vector2f extends Vector implements Serializable, ReadableVector2f,
|
|||
public final void setX(float x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set Y
|
||||
* @param y
|
||||
|
|
|
|||
|
|
@ -53,14 +53,14 @@ public class Vector3f extends Vector implements Serializable, ReadableVector3f,
|
|||
public Vector3f() {
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public Vector3f(ReadableVector3f src) {
|
||||
set(src);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
|
|
@ -96,14 +96,14 @@ public class Vector3f extends Vector implements Serializable, ReadableVector3f,
|
|||
z = src.getZ();
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the length squared of the vector
|
||||
*/
|
||||
public float lengthSquared() {
|
||||
return x * x + y * y + z * z;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Translate a vector
|
||||
* @param x The translation in x
|
||||
|
|
@ -116,41 +116,41 @@ public class Vector3f extends Vector implements Serializable, ReadableVector3f,
|
|||
this.z += z;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a vector to another vector and place the result in a destination
|
||||
* vector.
|
||||
* @param left The LHS vector
|
||||
* @param right The RHS vector
|
||||
* @param dest The destination vector, or null if a new vector is to be created
|
||||
* @return the sum of left and right in dest
|
||||
*/
|
||||
public static Vector3f add(Vector3f left, Vector3f right, Vector3f dest) {
|
||||
if (dest == null)
|
||||
return new Vector3f(left.x + right.x, left.y + right.y, left.z + right.z);
|
||||
else {
|
||||
|
||||
/**
|
||||
* Add a vector to another vector and place the result in a destination
|
||||
* vector.
|
||||
* @param left The LHS vector
|
||||
* @param right The RHS vector
|
||||
* @param dest The destination vector, or null if a new vector is to be created
|
||||
* @return the sum of left and right in dest
|
||||
*/
|
||||
public static Vector3f add(Vector3f left, Vector3f right, Vector3f dest) {
|
||||
if (dest == null)
|
||||
return new Vector3f(left.x + right.x, left.y + right.y, left.z + right.z);
|
||||
else {
|
||||
dest.set(left.x + right.x, left.y + right.y, left.z + right.z);
|
||||
return dest;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract a vector from another vector and place the result in a destination
|
||||
* vector.
|
||||
* @param left The LHS vector
|
||||
* @param right The RHS vector
|
||||
* @param dest The destination vector, or null if a new vector is to be created
|
||||
* @return left minus right in dest
|
||||
*/
|
||||
public static Vector3f sub(Vector3f left, Vector3f right, Vector3f dest) {
|
||||
if (dest == null)
|
||||
return new Vector3f(left.x - right.x, left.y - right.y, left.z - right.z);
|
||||
else {
|
||||
/**
|
||||
* Subtract a vector from another vector and place the result in a destination
|
||||
* vector.
|
||||
* @param left The LHS vector
|
||||
* @param right The RHS vector
|
||||
* @param dest The destination vector, or null if a new vector is to be created
|
||||
* @return left minus right in dest
|
||||
*/
|
||||
public static Vector3f sub(Vector3f left, Vector3f right, Vector3f dest) {
|
||||
if (dest == null)
|
||||
return new Vector3f(left.x - right.x, left.y - right.y, left.z - right.z);
|
||||
else {
|
||||
dest.set(left.x - right.x, left.y - right.y, left.z - right.z);
|
||||
return dest;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The cross product of two vectors.
|
||||
*
|
||||
|
|
@ -160,25 +160,25 @@ public class Vector3f extends Vector implements Serializable, ReadableVector3f,
|
|||
* @return left cross right
|
||||
*/
|
||||
public static Vector3f cross(
|
||||
Vector3f left,
|
||||
Vector3f right,
|
||||
Vector3f dest)
|
||||
Vector3f left,
|
||||
Vector3f right,
|
||||
Vector3f dest)
|
||||
{
|
||||
|
||||
if (dest == null)
|
||||
dest = new Vector3f();
|
||||
|
||||
dest.set(
|
||||
left.y * right.z - left.z * right.y,
|
||||
right.x * left.z - right.z * left.x,
|
||||
left.x * right.y - left.y * right.x
|
||||
);
|
||||
|
||||
left.y * right.z - left.z * right.y,
|
||||
right.x * left.z - right.z * left.x,
|
||||
left.x * right.y - left.y * right.x
|
||||
);
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Negate a vector
|
||||
* @return this
|
||||
|
|
@ -189,7 +189,7 @@ public class Vector3f extends Vector implements Serializable, ReadableVector3f,
|
|||
z = -z;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Negate a vector and place the result in a destination vector.
|
||||
* @param dest The destination vector or null if a new vector is to be created
|
||||
|
|
@ -203,8 +203,8 @@ public class Vector3f extends Vector implements Serializable, ReadableVector3f,
|
|||
dest.z = -z;
|
||||
return dest;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Normalise this vector and place the result in another vector.
|
||||
* @param dest The destination vector, or null if a new vector is to be created
|
||||
|
|
@ -212,12 +212,12 @@ public class Vector3f extends Vector implements Serializable, ReadableVector3f,
|
|||
*/
|
||||
public Vector3f normalise(Vector3f dest) {
|
||||
float l = length();
|
||||
|
||||
|
||||
if (dest == null)
|
||||
dest = new Vector3f(x / l, y / l, z / l);
|
||||
else
|
||||
dest.set(x / l, y / l, z / l);
|
||||
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
|
|
@ -231,41 +231,41 @@ public class Vector3f extends Vector implements Serializable, ReadableVector3f,
|
|||
public static float dot(Vector3f left, Vector3f right) {
|
||||
return left.x * right.x + left.y * right.y + left.z * right.z;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculate the angle between two vectors, in degrees
|
||||
* Calculate the angle between two vectors, in radians
|
||||
* @param a A vector
|
||||
* @param b The other vector
|
||||
* @return the angle between the two vectors, in degrees
|
||||
* @return the angle between the two vectors, in radians
|
||||
*/
|
||||
public static float angle(Vector3f a, Vector3f b) {
|
||||
float dls = dot(a, b) / (a.length() * b.length());
|
||||
if (dls < -1f)
|
||||
dls = -1f;
|
||||
else if (dls > 1.0f)
|
||||
dls = 1.0f;
|
||||
return (float) Math.toDegrees(Math.acos(dls));
|
||||
}
|
||||
|
||||
public static float angle(Vector3f a, Vector3f b) {
|
||||
float dls = dot(a, b) / (a.length() * b.length());
|
||||
if (dls < -1f)
|
||||
dls = -1f;
|
||||
else if (dls > 1.0f)
|
||||
dls = 1.0f;
|
||||
return (float)Math.acos(dls);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.lwjgl.vector.Vector#load(FloatBuffer)
|
||||
*/
|
||||
public Vector load(FloatBuffer buf) {
|
||||
x = buf.get();
|
||||
y = buf.get();
|
||||
z = buf.get();
|
||||
return this;
|
||||
x = buf.get();
|
||||
y = buf.get();
|
||||
z = buf.get();
|
||||
return this;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.lwjgl.vector.Vector#scale(float)
|
||||
*/
|
||||
public Vector scale(float scale) {
|
||||
|
||||
|
||||
x *= scale;
|
||||
y *= scale;
|
||||
z *= scale;
|
||||
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
|
@ -274,20 +274,20 @@ public class Vector3f extends Vector implements Serializable, ReadableVector3f,
|
|||
* @see org.lwjgl.vector.Vector#store(FloatBuffer)
|
||||
*/
|
||||
public Vector store(FloatBuffer buf) {
|
||||
|
||||
|
||||
buf.put(x);
|
||||
buf.put(y);
|
||||
buf.put(z);
|
||||
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public String toString() {
|
||||
StringBuffer sb = new StringBuffer(64);
|
||||
|
||||
|
||||
sb.append("Vector3f[");
|
||||
sb.append(x);
|
||||
sb.append(", ");
|
||||
|
|
@ -304,14 +304,14 @@ public class Vector3f extends Vector implements Serializable, ReadableVector3f,
|
|||
public final float getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return y
|
||||
*/
|
||||
public final float getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set X
|
||||
* @param x
|
||||
|
|
@ -319,7 +319,7 @@ public class Vector3f extends Vector implements Serializable, ReadableVector3f,
|
|||
public final void setX(float x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set Y
|
||||
* @param y
|
||||
|
|
|
|||
|
|
@ -53,14 +53,14 @@ public class Vector4f extends Vector implements Serializable, ReadableVector4f,
|
|||
public Vector4f() {
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public Vector4f(ReadableVector4f src) {
|
||||
set(src);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
|
|
@ -107,14 +107,14 @@ public class Vector4f extends Vector implements Serializable, ReadableVector4f,
|
|||
w = src.getW();
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the length squared of the vector
|
||||
*/
|
||||
public float lengthSquared() {
|
||||
return x * x + y * y + z * z + w * w;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Translate a vector
|
||||
* @param x The translation in x
|
||||
|
|
@ -128,42 +128,42 @@ public class Vector4f extends Vector implements Serializable, ReadableVector4f,
|
|||
this.w += w;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a vector to another vector and place the result in a destination
|
||||
* vector.
|
||||
* @param left The LHS vector
|
||||
* @param right The RHS vector
|
||||
* @param dest The destination vector, or null if a new vector is to be created
|
||||
* @return the sum of left and right in dest
|
||||
*/
|
||||
public static Vector4f add(Vector4f left, Vector4f right, Vector4f dest) {
|
||||
if (dest == null)
|
||||
return new Vector4f(left.x + right.x, left.y + right.y, left.z + right.z, left.w + right.w);
|
||||
else {
|
||||
|
||||
/**
|
||||
* Add a vector to another vector and place the result in a destination
|
||||
* vector.
|
||||
* @param left The LHS vector
|
||||
* @param right The RHS vector
|
||||
* @param dest The destination vector, or null if a new vector is to be created
|
||||
* @return the sum of left and right in dest
|
||||
*/
|
||||
public static Vector4f add(Vector4f left, Vector4f right, Vector4f dest) {
|
||||
if (dest == null)
|
||||
return new Vector4f(left.x + right.x, left.y + right.y, left.z + right.z, left.w + right.w);
|
||||
else {
|
||||
dest.set(left.x + right.x, left.y + right.y, left.z + right.z, left.w + right.w);
|
||||
return dest;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtract a vector from another vector and place the result in a destination
|
||||
* vector.
|
||||
* @param left The LHS vector
|
||||
* @param right The RHS vector
|
||||
* @param dest The destination vector, or null if a new vector is to be created
|
||||
* @return left minus right in dest
|
||||
*/
|
||||
public static Vector4f sub(Vector4f left, Vector4f right, Vector4f dest) {
|
||||
if (dest == null)
|
||||
return new Vector4f(left.x - right.x, left.y - right.y, left.z - right.z, left.w - right.w);
|
||||
else {
|
||||
/**
|
||||
* Subtract a vector from another vector and place the result in a destination
|
||||
* vector.
|
||||
* @param left The LHS vector
|
||||
* @param right The RHS vector
|
||||
* @param dest The destination vector, or null if a new vector is to be created
|
||||
* @return left minus right in dest
|
||||
*/
|
||||
public static Vector4f sub(Vector4f left, Vector4f right, Vector4f dest) {
|
||||
if (dest == null)
|
||||
return new Vector4f(left.x - right.x, left.y - right.y, left.z - right.z, left.w - right.w);
|
||||
else {
|
||||
dest.set(left.x - right.x, left.y - right.y, left.z - right.z, left.w - right.w);
|
||||
return dest;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Negate a vector
|
||||
* @return this
|
||||
|
|
@ -175,7 +175,7 @@ public class Vector4f extends Vector implements Serializable, ReadableVector4f,
|
|||
w = -w;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Negate a vector and place the result in a destination vector.
|
||||
* @param dest The destination vector or null if a new vector is to be created
|
||||
|
|
@ -190,8 +190,8 @@ public class Vector4f extends Vector implements Serializable, ReadableVector4f,
|
|||
dest.w = -w;
|
||||
return dest;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Normalise this vector and place the result in another vector.
|
||||
* @param dest The destination vector, or null if a new vector is to be created
|
||||
|
|
@ -199,12 +199,12 @@ public class Vector4f extends Vector implements Serializable, ReadableVector4f,
|
|||
*/
|
||||
public Vector4f normalise(Vector4f dest) {
|
||||
float l = length();
|
||||
|
||||
|
||||
if (dest == null)
|
||||
dest = new Vector4f(x / l, y / l, z / l, w / l);
|
||||
else
|
||||
dest.set(x / l, y / l, z / l, w / l);
|
||||
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
|
|
@ -218,31 +218,31 @@ public class Vector4f extends Vector implements Serializable, ReadableVector4f,
|
|||
public static float dot(Vector4f left, Vector4f right) {
|
||||
return left.x * right.x + left.y * right.y + left.z * right.z + left.w * right.w;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculate the angle between two vectors, in degrees
|
||||
* Calculate the angle between two vectors, in radians
|
||||
* @param a A vector
|
||||
* @param b The other vector
|
||||
* @return the angle between the two vectors, in degrees
|
||||
* @return the angle between the two vectors, in radians
|
||||
*/
|
||||
public static float angle(Vector4f a, Vector4f b) {
|
||||
float dls = dot(a, b) / (a.length() * b.length());
|
||||
if (dls < -1f)
|
||||
dls = -1f;
|
||||
else if (dls > 1.0f)
|
||||
dls = 1.0f;
|
||||
return (float) Math.toDegrees(Math.acos(dls));
|
||||
}
|
||||
|
||||
public static float angle(Vector4f a, Vector4f b) {
|
||||
float dls = dot(a, b) / (a.length() * b.length());
|
||||
if (dls < -1f)
|
||||
dls = -1f;
|
||||
else if (dls > 1.0f)
|
||||
dls = 1.0f;
|
||||
return (float)Math.acos(dls);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.lwjgl.vector.Vector#load(FloatBuffer)
|
||||
*/
|
||||
public Vector load(FloatBuffer buf) {
|
||||
x = buf.get();
|
||||
y = buf.get();
|
||||
z = buf.get();
|
||||
w = buf.get();
|
||||
return this;
|
||||
x = buf.get();
|
||||
y = buf.get();
|
||||
z = buf.get();
|
||||
w = buf.get();
|
||||
return this;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
|
@ -260,33 +260,33 @@ public class Vector4f extends Vector implements Serializable, ReadableVector4f,
|
|||
* @see org.lwjgl.vector.Vector#store(FloatBuffer)
|
||||
*/
|
||||
public Vector store(FloatBuffer buf) {
|
||||
|
||||
|
||||
buf.put(x);
|
||||
buf.put(y);
|
||||
buf.put(z);
|
||||
buf.put(w);
|
||||
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Vector4f: " + x + " " + y + " " + z + " " + w;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return x
|
||||
*/
|
||||
public final float getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return y
|
||||
*/
|
||||
public final float getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set X
|
||||
* @param x
|
||||
|
|
@ -294,7 +294,7 @@ public class Vector4f extends Vector implements Serializable, ReadableVector4f,
|
|||
public final void setX(float x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set Y
|
||||
* @param y
|
||||
|
|
@ -318,7 +318,7 @@ public class Vector4f extends Vector implements Serializable, ReadableVector4f,
|
|||
public float getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set W
|
||||
* @param w
|
||||
|
|
@ -333,6 +333,6 @@ public class Vector4f extends Vector implements Serializable, ReadableVector4f,
|
|||
public float getW() {
|
||||
return w;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue