summaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com/jogamp/opengl/math
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2023-04-28 11:16:51 +0200
committerSven Gothel <[email protected]>2023-04-28 11:16:51 +0200
commit02fd04ed37e710f639b9e76f6a93137c7b2b61c2 (patch)
tree82e6863d4a92ffa918ad19b9467950a9296f4373 /src/jogl/classes/com/jogamp/opengl/math
parentb4b6061918d73bce53f5bcc4faf994b8a42c2c7d (diff)
[PMV]Matrix[4f]: Clarify 'mulVec[34]f' in-place arg properties, add pure in-place variant and use it in PMVMatrix dropping temporary
Diffstat (limited to 'src/jogl/classes/com/jogamp/opengl/math')
-rw-r--r--src/jogl/classes/com/jogamp/opengl/math/Matrix4f.java37
1 files changed, 35 insertions, 2 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/math/Matrix4f.java b/src/jogl/classes/com/jogamp/opengl/math/Matrix4f.java
index 67d7d48c1..77971b72d 100644
--- a/src/jogl/classes/com/jogamp/opengl/math/Matrix4f.java
+++ b/src/jogl/classes/com/jogamp/opengl/math/Matrix4f.java
@@ -800,7 +800,7 @@ public class Matrix4f {
}
/**
- * @param v_in 4-component column-vector
+ * @param v_in 4-component column-vector, can be v_out for in-place transformation
* @param v_out this * v_in
* @returns v_out for chaining
*/
@@ -815,13 +815,27 @@ public class Matrix4f {
}
/**
+ * @param v_inout 4-component column-vector input and output, i.e. in-place transformation
+ * @returns v_inout for chaining
+ */
+ public final Vec4f mulVec4f(final Vec4f v_inout) {
+ // (one matrix row in column-major order) X (column vector)
+ final float x = v_inout.x(), y = v_inout.y(), z = v_inout.z(), w = v_inout.w();
+ v_inout.set( x * m00 + y * m01 + z * m02 + w * m03,
+ x * m10 + y * m11 + z * m12 + w * m13,
+ x * m20 + y * m21 + z * m22 + w * m23,
+ x * m30 + y * m31 + z * m32 + w * m33 );
+ return v_inout;
+ }
+
+ /**
* Affine 3f-vector transformation by 4x4 matrix
*
* 4x4 matrix multiplication with 3-component vector,
* using {@code 1} for for {@code v_in.w()} and dropping {@code v_out.w()},
* which shall be {@code 1}.
*
- * @param v_in 3-component column-vector {@link Vec3f}
+ * @param v_in 3-component column-vector {@link Vec3f}, can be v_out for in-place transformation
* @param v_out m_in * v_in, 3-component column-vector {@link Vec3f}
* @returns v_out for chaining
*/
@@ -834,6 +848,25 @@ public class Matrix4f {
return v_out;
}
+ /**
+ * Affine 3f-vector transformation by 4x4 matrix
+ *
+ * 4x4 matrix multiplication with 3-component vector,
+ * using {@code 1} for for {@code v_inout.w()} and dropping {@code v_inout.w()},
+ * which shall be {@code 1}.
+ *
+ * @param v_inout 3-component column-vector {@link Vec3f} input and output, i.e. in-place transformation
+ * @returns v_inout for chaining
+ */
+ public final Vec3f mulVec3f(final Vec3f v_inout) {
+ // (one matrix row in column-major order) X (column vector)
+ final float x = v_inout.x(), y = v_inout.y(), z = v_inout.z();
+ v_inout.set( x * m00 + y * m01 + z * m02 + 1f * m03,
+ x * m10 + y * m11 + z * m12 + 1f * m13,
+ x * m20 + y * m21 + z * m22 + 1f * m23 );
+ return v_inout;
+ }
+
//
// Matrix setTo...(), affine + basic
//