From 013badb09771e1672643d433ffd440cc18dda217 Mon Sep 17 00:00:00 2001 From: stephengold Date: Fri, 28 Jun 2024 19:37:52 -0700 Subject: [PATCH] add the RVec3Arg interface --- .../joltjni/BodyCreationSettings.java | 4 +- .../com/github/stephengold/joltjni/RVec3.java | 39 ++++--- .../github/stephengold/joltjni/RVec3Arg.java | 104 ++++++++++++++++++ 3 files changed, 131 insertions(+), 16 deletions(-) create mode 100644 src/main/java/com/github/stephengold/joltjni/RVec3Arg.java diff --git a/src/main/java/com/github/stephengold/joltjni/BodyCreationSettings.java b/src/main/java/com/github/stephengold/joltjni/BodyCreationSettings.java index d0afd20c..793db7bb 100644 --- a/src/main/java/com/github/stephengold/joltjni/BodyCreationSettings.java +++ b/src/main/java/com/github/stephengold/joltjni/BodyCreationSettings.java @@ -40,7 +40,7 @@ public class BodyCreationSettings extends JoltPhysicsObject { * @param objLayer the ID of the desired object layer */ public BodyCreationSettings(Shape shape, - RVec3 loc, Quat orient, EMotionType motionType, int objLayer) { + RVec3Arg loc, Quat orient, EMotionType motionType, int objLayer) { long shapeVa = shape.va(); int motionTypeOrdinal = motionType.ordinal(); long bodySettingsVa = createBodyCreationSettingsFromShape( @@ -60,7 +60,7 @@ public BodyCreationSettings(Shape shape, * @param objLayer the ID of the desired object layer */ public BodyCreationSettings(ShapeSettings shapeSettings, - RVec3 loc, Quat orient, EMotionType motionType, int objLayer) { + RVec3Arg loc, Quat orient, EMotionType motionType, int objLayer) { long shapeSettingsVa = shapeSettings.va(); int motionTypeOrdinal = motionType.ordinal(); long bodySettingsVa = createBodyCreationSettingsFromShapeSettings( diff --git a/src/main/java/com/github/stephengold/joltjni/RVec3.java b/src/main/java/com/github/stephengold/joltjni/RVec3.java index 4ac0f5a6..b38ea3b3 100644 --- a/src/main/java/com/github/stephengold/joltjni/RVec3.java +++ b/src/main/java/com/github/stephengold/joltjni/RVec3.java @@ -27,7 +27,7 @@ of this software and associated documentation files (the "Software"), to deal * * @author Stephen Gold sgold@sonic.net */ -final public class RVec3 { +final public class RVec3 implements RVec3Arg { // ************************************************************************* // fields @@ -70,12 +70,28 @@ public RVec3(double x, double y, double z) { // ************************************************************************* // new methods exposed + /** + * Set all 3 components to specified values. + * + * @param x the desired X component + * @param y the desired Y component + * @param z the desired Z component + */ + public void set(double x, double y, double z) { + this.xx = x; + this.yy = y; + this.zz = z; + } + // ************************************************************************* + // RVec3Arg methods + /** * Return the first (X) component at positional precision. The vector is * unaffected. * * @return the component value */ + @Override public Object getX() { Object result; if (Jolt.isDoublePrecision()) { @@ -93,6 +109,7 @@ public Object getX() { * * @return the component value */ + @Override public Object getY() { Object result; if (Jolt.isDoublePrecision()) { @@ -110,6 +127,7 @@ public Object getY() { * * @return the component value */ + @Override public Object getZ() { Object result; if (Jolt.isDoublePrecision()) { @@ -121,25 +139,13 @@ public Object getZ() { return result; } - /** - * Set all 3 components to specified values. - * - * @param x the desired X component - * @param y the desired Y component - * @param z the desired Z component - */ - public void set(double x, double y, double z) { - this.xx = x; - this.yy = y; - this.zz = z; - } - /** * Return the first (X) component in single precision. The vector is * unaffected. * * @return the component value */ + @Override public float x() { return (float) xx; } @@ -150,6 +156,7 @@ public float x() { * * @return the component value */ + @Override public double xx() { return xx; } @@ -160,6 +167,7 @@ public double xx() { * * @return the component value */ + @Override public float y() { return (float) yy; } @@ -170,6 +178,7 @@ public float y() { * * @return the component value */ + @Override public double yy() { return yy; } @@ -180,6 +189,7 @@ public double yy() { * * @return the component value */ + @Override public float z() { return (float) zz; } @@ -190,6 +200,7 @@ public float z() { * * @return the component value */ + @Override public double zz() { return zz; } diff --git a/src/main/java/com/github/stephengold/joltjni/RVec3Arg.java b/src/main/java/com/github/stephengold/joltjni/RVec3Arg.java new file mode 100644 index 00000000..47b15a43 --- /dev/null +++ b/src/main/java/com/github/stephengold/joltjni/RVec3Arg.java @@ -0,0 +1,104 @@ +/* +Copyright (c) 2024 Stephen Gold + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + */ +package com.github.stephengold.joltjni; + +/** + * A read-only interface to {@code RVec3} instances. + * + * @author Stephen Gold sgold@sonic.net + */ +public interface RVec3Arg { + // ************************************************************************* + // new methods exposed + + /** + * Return the first (X) component at positional precision. The vector is + * unaffected. + * + * @return the component value + */ + Object getX(); + + /** + * Return the 2nd (Y) component at positional precision. The vector is + * unaffected. + * + * @return the component value + */ + Object getY(); + + /** + * Return the 3rd (Z) component at positional precision. The vector is + * unaffected. + * + * @return the component value + */ + Object getZ(); + + /** + * Return the first (X) component in single precision. The vector is + * unaffected. + * + * @return the component value + */ + float x(); + + /** + * Return the first (X) component in double precision. The vector is + * unaffected. + * + * @return the component value + */ + double xx(); + + /** + * Return the 2nd (Y) component in single precision. The vector is + * unaffected. + * + * @return the component value + */ + float y(); + + /** + * Return the 2nd (Y) component in double precision. The vector is + * unaffected. + * + * @return the component value + */ + double yy(); + + /** + * Return the 3rd (Z) component in single precision. The vector is + * unaffected. + * + * @return the component value + */ + float z(); + + /** + * Return the 3rd (Z) component in double precision. The vector is + * unaffected. + * + * @return the component value + */ + double zz(); +}