Skip to content

Commit

Permalink
add the WheelSettings class
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Sep 27, 2024
1 parent 177cde3 commit bbcc630
Show file tree
Hide file tree
Showing 2 changed files with 279 additions and 0 deletions.
147 changes: 147 additions & 0 deletions src/main/java/com/github/stephengold/joltjni/WheelSettings.java
Original file line number Diff line number Diff line change
@@ -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 [email protected]
*/
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);
}
132 changes: 132 additions & 0 deletions src/main/native/glue/w/WheelSettings.cpp
Original file line number Diff line number Diff line change
@@ -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<WheelSettings *> (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<WheelSettings *> (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<WheelSettings *> (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<WheelSettings *> (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<WheelSettings *> (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<WheelSettings *> (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<WheelSettings *> (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<WheelSettings *> (settingsVa);
pSettings->mWidth = width;
}

0 comments on commit bbcc630

Please sign in to comment.