diff --git a/src/main/java/com/github/stephengold/joltjni/WheelSettings.java b/src/main/java/com/github/stephengold/joltjni/WheelSettings.java new file mode 100644 index 00000000..f5c4cf6b --- /dev/null +++ b/src/main/java/com/github/stephengold/joltjni/WheelSettings.java @@ -0,0 +1,147 @@ +/* +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; + +import com.github.stephengold.joltjni.readonly.Vec3Arg; +import com.github.stephengold.joltjni.template.Ref; + +/** + * Settings used to construct a {@code Wheel}. + * + * @author Stephen Gold sgold@sonic.net + */ +abstract public class WheelSettings extends SerializableObject { + // ************************************************************************* + // constructors + + /** + * Instantiate settings with no native object assigned. + * + * @param dummy unused argument to distinguish from the zero-arg constructor + */ + WheelSettings(boolean dummy) { + } + // ************************************************************************* + // new methods exposed + + /** + * Copy the location of the attachment point. The settings are unaffected. + * (native attribute: mPosition) + * + * @return a new location vector (in the body's local system) + */ + public Vec3 getPosition() { + long settingsVa = va(); + float x = getPositionX(settingsVa); + float y = getPositionY(settingsVa); + float z = getPositionZ(settingsVa); + Vec3 result = new Vec3(x, y, z); + + return result; + } + + /** + * Return the radius of the wheel. The settings are unaffected. (native + * attribute: mRadius) + * + * @return the radius (in maters) + */ + public float getRadius() { + long settingsVa = va(); + float result = getRadius(settingsVa); + + return result; + } + + /** + * Return the width of the wheel. The settings are unaffected. (native + * attribute: mWidth) + * + * @return the width (in maters) + */ + public float getWidth() { + long settingsVa = va(); + float result = getWidth(settingsVa); + + return result; + } + + /** + * Alter the location of the attachment point. (native attribute: mPosition) + * + * @param position the location of the attachment point (in the body's local + * system, not null, unaffected, default=(0,0,0)) + */ + public void setPosition(Vec3Arg position) { + long settingsVa = va(); + float x = position.getX(); + float y = position.getY(); + float z = position.getZ(); + setPosition(settingsVa, x, y, z); + } + + /** + * Alter the radius of the wheel. (native attribute: mRadius) + * + * @param radius the desired radius (in meters, default=0.3) + */ + public void setRadius(float radius) { + long settingsVa = va(); + setRadius(settingsVa, radius); + } + + /** + * Alter the width of the wheel. (native attribute: mWidth) + * + * @param width the desired width (in meters, default=0.1) + */ + public void setWidth(float width) { + long settingsVa = va(); + setWidth(settingsVa, width); + } + + /** + * Create a counted reference to the native {@code WheelSettings}. + * + * @return a new JVM object with a new native object assigned + */ + abstract public Ref toRef(); + // ************************************************************************* + // native private methods + + native private static float getPositionX(long settingsVa); + + native private static float getPositionY(long settingsVa); + + native private static float getPositionZ(long settingsVa); + + native private static float getRadius(long settingsVa); + + native private static float getWidth(long settingsVa); + + native private static void setPosition( + long settingsVa, float x, float y, float z); + + native private static void setRadius(long settingsVa, float radius); + + native private static void setWidth(long settingsVa, float width); +} diff --git a/src/main/native/glue/w/WheelSettings.cpp b/src/main/native/glue/w/WheelSettings.cpp new file mode 100644 index 00000000..1ac9cc1a --- /dev/null +++ b/src/main/native/glue/w/WheelSettings.cpp @@ -0,0 +1,132 @@ +/* +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. + */ + +/* + * Author: Stephen Gold + */ +#include "Jolt/Jolt.h" +#include "Jolt/Physics/Vehicle/Wheel.h" +#include "auto/com_github_stephengold_joltjni_WheelSettings.h" + +using namespace JPH; + +/* + * Class: com_github_stephengold_joltjni_WheelSettings + * Method: getPositionX + * Signature: (J)F + */ +JNIEXPORT jfloat JNICALL Java_com_github_stephengold_joltjni_WheelSettings_getPositionX + (JNIEnv *, jclass, jlong settingsVa) { + const WheelSettings * const pSettings + = reinterpret_cast (settingsVa); + const float result = pSettings->mPosition.GetX(); + return result; +} + +/* + * Class: com_github_stephengold_joltjni_WheelSettings + * Method: getPositionY + * Signature: (J)F + */ +JNIEXPORT jfloat JNICALL Java_com_github_stephengold_joltjni_WheelSettings_getPositionY + (JNIEnv *, jclass, jlong settingsVa) { + const WheelSettings * const pSettings + = reinterpret_cast (settingsVa); + const float result = pSettings->mPosition.GetY(); + return result; +} + +/* + * Class: com_github_stephengold_joltjni_WheelSettings + * Method: getPositionZ + * Signature: (J)F + */ +JNIEXPORT jfloat JNICALL Java_com_github_stephengold_joltjni_WheelSettings_getPositionZ + (JNIEnv *, jclass, jlong settingsVa) { + const WheelSettings * const pSettings + = reinterpret_cast (settingsVa); + const float result = pSettings->mPosition.GetZ(); + return result; +} + +/* + * Class: com_github_stephengold_joltjni_WheelSettings + * Method: getRadius + * Signature: (J)F + */ +JNIEXPORT jfloat JNICALL Java_com_github_stephengold_joltjni_WheelSettings_getRadius + (JNIEnv *, jclass, jlong settingsVa) { + const WheelSettings * const pSettings + = reinterpret_cast (settingsVa); + const float result = pSettings->mRadius; + return result; +} + +/* + * Class: com_github_stephengold_joltjni_WheelSettings + * Method: getWidth + * Signature: (J)F + */ +JNIEXPORT jfloat JNICALL Java_com_github_stephengold_joltjni_WheelSettings_getWidth + (JNIEnv *, jclass, jlong settingsVa) { + const WheelSettings * const pSettings + = reinterpret_cast (settingsVa); + const float result = pSettings->mWidth; + return result; +} + +/* + * Class: com_github_stephengold_joltjni_WheelSettings + * Method: setPosition + * Signature: (JFFF)V + */ +JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_WheelSettings_setPosition + (JNIEnv *, jclass, jlong settingsVa, jfloat x, jfloat y, jfloat z) { + WheelSettings * const pSettings + = reinterpret_cast (settingsVa); + const Vec3 position(x, y, z); + pSettings->mPosition = position; +} + +/* + * Class: com_github_stephengold_joltjni_WheelSettings + * Method: setRadius + * Signature: (JF)V + */ +JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_WheelSettings_setRadius + (JNIEnv *, jclass, jlong settingsVa, jfloat radius) { + WheelSettings * const pSettings + = reinterpret_cast (settingsVa); + pSettings->mRadius = radius; +} + +/* + * Class: com_github_stephengold_joltjni_WheelSettings + * Method: setWidth + * Signature: (JF)V + */ +JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_WheelSettings_setWidth + (JNIEnv *, jclass, jlong settingsVa, jfloat width) { + WheelSettings * const pSettings + = reinterpret_cast (settingsVa); + pSettings->mWidth = width; +} \ No newline at end of file