Skip to content

Commit

Permalink
add the RVec3Arg interface
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Jun 29, 2024
1 parent 03b8d99 commit 013badb
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand Down
39 changes: 25 additions & 14 deletions src/main/java/com/github/stephengold/joltjni/RVec3.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ of this software and associated documentation files (the "Software"), to deal
*
* @author Stephen Gold [email protected]
*/
final public class RVec3 {
final public class RVec3 implements RVec3Arg {
// *************************************************************************
// fields

Expand Down Expand Up @@ -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()) {
Expand All @@ -93,6 +109,7 @@ public Object getX() {
*
* @return the component value
*/
@Override
public Object getY() {
Object result;
if (Jolt.isDoublePrecision()) {
Expand All @@ -110,6 +127,7 @@ public Object getY() {
*
* @return the component value
*/
@Override
public Object getZ() {
Object result;
if (Jolt.isDoublePrecision()) {
Expand All @@ -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;
}
Expand All @@ -150,6 +156,7 @@ public float x() {
*
* @return the component value
*/
@Override
public double xx() {
return xx;
}
Expand All @@ -160,6 +167,7 @@ public double xx() {
*
* @return the component value
*/
@Override
public float y() {
return (float) yy;
}
Expand All @@ -170,6 +178,7 @@ public float y() {
*
* @return the component value
*/
@Override
public double yy() {
return yy;
}
Expand All @@ -180,6 +189,7 @@ public double yy() {
*
* @return the component value
*/
@Override
public float z() {
return (float) zz;
}
Expand All @@ -190,6 +200,7 @@ public float z() {
*
* @return the component value
*/
@Override
public double zz() {
return zz;
}
Expand Down
104 changes: 104 additions & 0 deletions src/main/java/com/github/stephengold/joltjni/RVec3Arg.java
Original file line number Diff line number Diff line change
@@ -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 [email protected]
*/
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();
}

0 comments on commit 013badb

Please sign in to comment.