From bbc988e65c96829caa49926a6932948c84dfa49e Mon Sep 17 00:00:00 2001 From: httpdigest Date: Fri, 30 Jun 2023 16:54:00 +0200 Subject: [PATCH] Add Vector4.xyz(Vector3) swizzle --- src/main/java/org/joml/Vector4d.java | 27 +++++++++++++++++++++ src/main/java/org/joml/Vector4f.java | 24 +++++++++++++++++++ src/main/java/org/joml/Vector4i.java | 36 ++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+) diff --git a/src/main/java/org/joml/Vector4d.java b/src/main/java/org/joml/Vector4d.java index 77b10bf1..842f20f8 100644 --- a/src/main/java/org/joml/Vector4d.java +++ b/src/main/java/org/joml/Vector4d.java @@ -336,6 +336,33 @@ public double x() { return this.x; } + /** + * Copy the (x, y, z) components of this into the supplied dest vector + * and return it. + *

+ * Note that due to the given vector dest storing the components in float-precision, + * there is the possibility to lose precision. + * + * @param dest + * will hold the result + * @return dest + */ + public Vector3f xyz(Vector3f dest) { + return dest.set(x, y, z); + } + + /** + * Copy the (x, y, z) components of this into the supplied dest vector + * and return it. + * + * @param dest + * will hold the result + * @return dest + */ + public Vector3d xyz(Vector3d dest) { + return dest.set(x, y, z); + } + public double y() { return this.y; } diff --git a/src/main/java/org/joml/Vector4f.java b/src/main/java/org/joml/Vector4f.java index 77f08600..21920461 100644 --- a/src/main/java/org/joml/Vector4f.java +++ b/src/main/java/org/joml/Vector4f.java @@ -298,6 +298,30 @@ public float x() { return this.x; } + /** + * Copy the (x, y, z) components of this into the supplied dest vector + * and return it. + * + * @param dest + * will hold the result + * @return dest + */ + public Vector3f xyz(Vector3f dest) { + return dest.set(x, y, z); + } + + /** + * Copy the (x, y, z) components of this into the supplied dest vector + * and return it. + * + * @param dest + * will hold the result + * @return dest + */ + public Vector3d xyz(Vector3d dest) { + return dest.set(x, y, z); + } + public float y() { return this.y; } diff --git a/src/main/java/org/joml/Vector4i.java b/src/main/java/org/joml/Vector4i.java index a1f08cdd..186c0ca5 100644 --- a/src/main/java/org/joml/Vector4i.java +++ b/src/main/java/org/joml/Vector4i.java @@ -292,6 +292,42 @@ public int x() { return this.x; } + /** + * Copy the (x, y, z) components of this into the supplied dest vector + * and return it. + * + * @param dest + * will hold the result + * @return dest + */ + public Vector3f xyz(Vector3f dest) { + return dest.set(x, y, z); + } + + /** + * Copy the (x, y, z) components of this into the supplied dest vector + * and return it. + * + * @param dest + * will hold the result + * @return dest + */ + public Vector3d xyz(Vector3d dest) { + return dest.set(x, y, z); + } + + /** + * Copy the (x, y, z) components of this into the supplied dest vector + * and return it. + * + * @param dest + * will hold the result + * @return dest + */ + public Vector3i xyz(Vector3i dest) { + return dest.set(x, y, z); + } + public int y() { return this.y; }