Skip to content

Commit

Permalink
add the QuatArg interface
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Jun 29, 2024
1 parent 013badb commit 97c585c
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public class BodyCreationSettings extends JoltPhysicsObject {
* @param motionType the desired motion type (not null)
* @param objLayer the ID of the desired object layer
*/
public BodyCreationSettings(Shape shape,
RVec3Arg loc, Quat orient, EMotionType motionType, int objLayer) {
public BodyCreationSettings(Shape shape, RVec3Arg loc, QuatArg orient,
EMotionType motionType, int objLayer) {
long shapeVa = shape.va();
int motionTypeOrdinal = motionType.ordinal();
long bodySettingsVa = createBodyCreationSettingsFromShape(
Expand All @@ -59,8 +59,8 @@ public BodyCreationSettings(Shape shape,
* @param motionType the desired motion type (not null)
* @param objLayer the ID of the desired object layer
*/
public BodyCreationSettings(ShapeSettings shapeSettings,
RVec3Arg loc, Quat orient, EMotionType motionType, int objLayer) {
public BodyCreationSettings(ShapeSettings shapeSettings, RVec3Arg loc,
QuatArg orient, EMotionType motionType, int objLayer) {
long shapeSettingsVa = shapeSettings.va();
int motionTypeOrdinal = motionType.ordinal();
long bodySettingsVa = createBodyCreationSettingsFromShapeSettings(
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/com/github/stephengold/joltjni/Quat.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ of this software and associated documentation files (the "Software"), to deal
*
* @author Stephen Gold [email protected]
*/
final public class Quat {
final public class Quat implements QuatArg {
// *************************************************************************
// fields

Expand Down Expand Up @@ -95,13 +95,16 @@ public void set(float x, float y, float z, float w) {
this.z = z;
this.w = w;
}
// *************************************************************************
// QuatArg methods

/**
* Return the real (W) component in single precision. The quaternion is
* unaffected.
*
* @return the component value
*/
@Override
public float getW() {
return w;
}
Expand All @@ -112,6 +115,7 @@ public float getW() {
*
* @return the component value
*/
@Override
public float getX() {
return x;
}
Expand All @@ -122,6 +126,7 @@ public float getX() {
*
* @return the component value
*/
@Override
public float getY() {
return y;
}
Expand All @@ -132,6 +137,7 @@ public float getY() {
*
* @return the component value
*/
@Override
public float getZ() {
return z;
}
Expand Down
64 changes: 64 additions & 0 deletions src/main/java/com/github/stephengold/joltjni/QuatArg.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
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 Quat} instances.
*
* @author Stephen Gold [email protected]
*/
public interface QuatArg {
// *************************************************************************
// new methods exposed

/**
* Return the real (W) component in single precision. The quaternion is
* unaffected.
*
* @return the component value
*/
float getW();

/**
* Return the first imaginary (X) component in single precision. The
* quaternion is unaffected.
*
* @return the component value
*/
float getX();

/**
* Return the 2nd imaginary (Y) component in single precision. The
* quaternion is unaffected.
*
* @return the component value
*/
float getY();

/**
* Return the 3rd imaginary (Z) component in single precision. The
* quaternion is unaffected.
*
* @return the component value
*/
float getZ();
}

0 comments on commit 97c585c

Please sign in to comment.