Skip to content

Commit

Permalink
BodyCreationSettings: add 18 public accessors
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Jul 7, 2024
1 parent 5ad6a5d commit c3697b2
Show file tree
Hide file tree
Showing 3 changed files with 650 additions and 1 deletion.
2 changes: 1 addition & 1 deletion config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<!-- Checks for size violations -->
<!-- See https://checkstyle.org/checks/sizes -->
<module name="FileLength">
<property name="max" value="350"/>
<property name="max" value="600"/>
</module>
<module name="LineLength">
<property name="fileExtensions" value="java"/>
Expand Down
301 changes: 301 additions & 0 deletions src/main/java/com/github/stephengold/joltjni/BodyCreationSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,186 @@ public BodyCreationSettings(ShapeSettings shapeSettings, RVec3Arg loc,
// *************************************************************************
// new methods exposed

/**
* Return the angular damping constant. (native field: mAngularDamping)
*
* @return the constant (in units of 1/second, &ge;0, &le;1)
*/
public float getAngularDamping() {
long bodySettingsVa = va();
float result = getAngularDamping(bodySettingsVa);

return result;
}

/**
* Copy the (initial) angular velocity. (native field: mAngularVelocity)
*
* @return a new velocity vector (radians per second in physics-system
* coordinates)
*/
public Vec3 getAngularVelocity() {
long bodySettingsVa = va();
float vx = getAngularVelocityX(bodySettingsVa);
float vy = getAngularVelocityY(bodySettingsVa);
float vz = getAngularVelocityZ(bodySettingsVa);
Vec3 result = new Vec3(vx, vy, vz);

return result;
}

/**
* Return the friction ratio. (native field: mFriction)
*
* @return the ratio (typically &ge;0 and &le;1)
*/
public float getFriction() {
long bodySettingsVa = va();
float result = getFriction(bodySettingsVa);

return result;
}

/**
* Return the gravity factor.
*
* @return the factor
*/
public float getGravityFactor() {
long bodySettingsVa = va();
float result = getGravityFactor(bodySettingsVa);

return result;
}

/**
* Return the linear damping constant. (native field: mLinearDamping)
*
* @return the constant (in units of 1/second, &ge;0, &le;1)
*/
public float getLinearDamping() {
long bodySettingsVa = va();
float result = getLinearDamping(bodySettingsVa);

return result;
}

/**
* Copy the (initial) linear velocity. (native field: mLinearVelocity)
*
* @return a new velocity vector (meters per second in physics-system
* coordinates)
*/
public Vec3 getLinearVelocity() {
long bodySettingsVa = va();
float vx = getLinearVelocityX(bodySettingsVa);
float vy = getLinearVelocityY(bodySettingsVa);
float vz = getLinearVelocityZ(bodySettingsVa);
Vec3 result = new Vec3(vx, vy, vz);

return result;
}

/**
* Calculate the mass and inertia.
*
* @return a new instance
*/
public MassProperties getMassProperties() {
long bodySettingsVa = va();
long propertiesVa = getMassProperties(bodySettingsVa);
MassProperties result = new MassProperties(propertiesVa);

return result;
}

/**
* Return the motion quality. (native field: mMotionQuality)
*
* @return an enum value (not null)
*/
public EMotionQuality getMotionQuality() {
long bodySettingsVa = va();
int ordinal = getMotionQuality(bodySettingsVa);
EMotionQuality result = EMotionQuality.values()[ordinal];

return result;
}

/**
* Return the motion type. (native field: mMotionType)
*
* @return an enum value (not null)
*/
public EMotionType getMotionType() {
long bodySettingsVa = va();
int ordinal = getMotionType(bodySettingsVa);
EMotionType result = EMotionType.values()[ordinal];

return result;
}

/**
* Return the index of the object layer. (native field: mObjectLayer)
*
* @return the index (&ge;0, &lt;numObjectLayers)
*/
public int getObjectLayer() {
long bodySettingsVa = va();
int result = getObjectLayer(bodySettingsVa);

return result;
}

/**
* Return the (initial) location. (native field: mPosition)
*
* @return a new location vector (in physics-system coordinates)
*/
public RVec3 getPosition() {
long bodySettingsVa = va();

double xx = getPositionX(bodySettingsVa);
assert Double.isFinite(xx) : "xx = " + xx;

double yy = getPositionY(bodySettingsVa);
assert Double.isFinite(yy) : "yy = " + yy;

double zz = getPositionZ(bodySettingsVa);
assert Double.isFinite(zz) : "zz = " + zz;

RVec3 result = new RVec3(xx, yy, zz);
return result;
}

/**
* Return the restitution ratio. (native field: mRestitution)
*
* @return the ratio (typically &ge;0 and &le;1)
*/
public float getRestitution() {
long bodySettingsVa = va();
float result = getRestitution(bodySettingsVa);
return result;
}

/**
* Copy the (initial) orientation of the body's axes. (native field:
* mRotation)
*
* @return a new rotation quaternion (relative to the physics-system axes)
*/
public Quat getRotation() {
long bodySettingsVa = va();
float qw = getRotationW(bodySettingsVa);
float qx = getRotationX(bodySettingsVa);
float qy = getRotationY(bodySettingsVa);
float qz = getRotationZ(bodySettingsVa);
Quat result = new Quat(qx, qy, qz, qw);

return result;
}

/**
* Access the shape.
*
Expand All @@ -92,6 +272,29 @@ public Shape getShape() {
return result;
}

/**
* Alter the angular damping constant. (native field: mAngularDamping)
*
* @param damping the desired value (in units of 1/second, &ge;0, &le;1,
* default=0.05)
*/
public void setAngularDamping(float damping) {
long bodySettingsVa = va();
setAngularDamping(bodySettingsVa, damping);
}

/**
* Alter the (initial) angular velocity. (native field: mAngularVelocity)
*
* @param omega the desired angular velocity (radians per second in
* physics-system coordinates, not null, unaffected)
*/
public void setAngularVelocity(Vec3Arg omega) {
long bodySettingsVa = va();
setAngularVelocity(bodySettingsVa,
omega.getX(), omega.getY(), omega.getZ());
}

/**
* Alter the friction ratio.
*
Expand All @@ -112,6 +315,29 @@ public void setGravityFactor(float factor) {
setGravityFactor(bodySettingsVa, factor);
}

/**
* Alter the linear damping constant. (native field: mLinearDamping)
*
* @param damping the desired value (in units of 1/second, &ge;0, &le;1,
* default=0.05)
*/
public void setLinearDamping(float damping) {
long bodySettingsVa = va();
setLinearDamping(bodySettingsVa, damping);
}

/**
* Alter the (initial) linear velocity. (native field: mLinearVelocity)
*
* @param velocity the desired velocity (in physics-system coordinates, not
* null, unaffected, default=(0,0,0))
*/
public void setLinearVelocity(Vec3Arg velocity) {
long bodySettingsVa = va();
setLinearVelocity(bodySettingsVa,
velocity.getX(), velocity.getY(), velocity.getZ());
}

/**
* Alter the motion quality.
*
Expand Down Expand Up @@ -165,6 +391,22 @@ public void setRestitution(float restitution) {
setRestitution(bodySettingsVa, restitution);
}

/**
* Alter the (initial) orientation of the body's axes. (native field:
* mRotation)
*
* @param quat the desired rotation (relative to the physics-system axes,
* not null, unaffected, default=(0,0,0,1))
*/
public void setRotation(Quat quat) {
long bodySettingsVa = va();
float qw = quat.getW();
float qx = quat.getX();
float qy = quat.getY();
float qz = quat.getZ();
setRotation(bodySettingsVa, qx, qy, qz, qw);
}

/**
* Alter the shape.
*
Expand Down Expand Up @@ -219,13 +461,69 @@ native private static long createBodyCreationSettingsFromShapeSettings(

native private static void free(long bodySettingsVa);

native private static float getAngularDamping(long bodySettingsVa);

native private static float getAngularVelocityX(long bodySettingsVa);

native private static float getAngularVelocityY(long bodySettingsVa);

native private static float getAngularVelocityZ(long bodySettingsVa);

native private static float getFriction(long bodySettingsVa);

native private static float getGravityFactor(long bodySettingsVa);

native private static float getLinearDamping(long bodySettingsVa);

native private static float getLinearVelocityX(long bodySettingsVa);

native private static float getLinearVelocityY(long bodySettingsVa);

native private static float getLinearVelocityZ(long bodySettingsVa);

native private static long getMassProperties(long bodySettingsVa);

native private static int getMotionQuality(long bodySettingsVa);

native private static int getMotionType(long bodySettingsVa);

native private static int getObjectLayer(long bodySettingsVa);

native private static double getPositionX(long bodySettingsVa);

native private static double getPositionY(long bodySettingsVa);

native private static double getPositionZ(long bodySettingsVa);

native private static float getRestitution(long bodySettingsVa);

native private static float getRotationW(long bodySettingsVa);

native private static float getRotationX(long bodySettingsVa);

native private static float getRotationY(long bodySettingsVa);

native private static float getRotationZ(long bodySettingsVa);

native private static long getShape(long bodySettingsVa);

native private static void setAngularDamping(
long bodySettingsVa, float damping);

native private static void setAngularVelocity(long bodySettingsVa,
float wx, float wy, float wz);

native private static void setFriction(long bodySettingsVa, float friction);

native private static void setGravityFactor(
long bodySettingsVa, float factor);

native private static void setLinearDamping(
long bodySettingsVa, float damping);

native private static void setLinearVelocity(long bodySettingsVa,
float vx, float vy, float vz);

native private static void setMotionQuality(
long bodySettingsVa, int motionQualityOrdinal);

Expand All @@ -241,6 +539,9 @@ native private static void setPosition(
native private static void setRestitution(
long bodySettingsVa, float restitution);

native private static void setRotation(long bodySettingsVa,
float qx, float qy, float qz, float qw);

native private static void setShape(long bodySettingsVa, long shapeVa);

native private static void setShapeSettings(
Expand Down
Loading

0 comments on commit c3697b2

Please sign in to comment.