-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b2e6f59
commit f61fe77
Showing
2 changed files
with
233 additions
and
0 deletions.
There are no files selected for viewing
128 changes: 128 additions & 0 deletions
128
src/main/java/com/github/stephengold/joltjni/VehicleAntiRollBar.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
/* | ||
Copyright (c) 2025 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 spring that connects two wheels and reduces a vehicle's rolling motion. | ||
* | ||
* @author Stephen Gold [email protected] | ||
*/ | ||
public class VehicleAntiRollBar extends JoltPhysicsObject { | ||
// ************************************************************************* | ||
// constructors | ||
|
||
/** | ||
* Instantiate with the specified container and native object. | ||
* | ||
* @param container the containing object, or {@code null} if none | ||
* @param barVa the virtual address of the native object to assign (not | ||
* zero) | ||
*/ | ||
VehicleAntiRollBar(JoltPhysicsObject container, long barVa) { | ||
super(container, barVa); | ||
} | ||
// ************************************************************************* | ||
// new methods exposed | ||
|
||
/** | ||
* Return the index of the left wheel. The bar is unaffected. (native | ||
* attribute: mLeftWheel) | ||
* | ||
* @return the index of the wheel | ||
*/ | ||
public int getLeftWheel() { | ||
long barVa = va(); | ||
int result = getLeftWheel(barVa); | ||
|
||
return result; | ||
} | ||
|
||
/** | ||
* Return the index of the right wheel. The bar is unaffected. (native | ||
* attribute: mRightWheel) | ||
* | ||
* @return the index of the wheel | ||
*/ | ||
public int getRightWheel() { | ||
long barVa = va(); | ||
int result = getRightWheel(barVa); | ||
return result; | ||
} | ||
|
||
/** | ||
* Return the stiffness of the bar. The bar is unaffected. (native | ||
* attribute: mStiffness) | ||
* | ||
* @return the spring constant (in Newtons per meter) | ||
*/ | ||
public float getStiffness() { | ||
long barVa = va(); | ||
float result = getStiffness(barVa); | ||
|
||
return result; | ||
} | ||
|
||
/** | ||
* Alter the index of the left wheel. (native attribute: mLeftWheel) | ||
* | ||
* @param wheelIndex the index of the desired wheel (default=0) | ||
*/ | ||
public void setLeftWheel(int wheelIndex) { | ||
long barVa = va(); | ||
setLeftWheel(barVa, wheelIndex); | ||
} | ||
|
||
/** | ||
* Alter the index of the right wheel. (native attribute: mRightWheel) | ||
* | ||
* @param wheelIndex the index of the desired wheel (default=1) | ||
*/ | ||
public void setRightWheel(int wheelIndex) { | ||
long barVa = va(); | ||
setRightWheel(barVa, wheelIndex); | ||
} | ||
|
||
/** | ||
* Alter the stiffness of the bar. (native attribute: mStiffness) | ||
* | ||
* @param stiffness the desired spring constant (in Newtons per meter, | ||
* default=1000) | ||
*/ | ||
public void setStiffness(float stiffness) { | ||
long barVa = va(); | ||
setStiffness(barVa, stiffness); | ||
} | ||
// ************************************************************************* | ||
// native private methods | ||
|
||
native private static int getLeftWheel(long barVa); | ||
|
||
native private static int getRightWheel(long barVa); | ||
|
||
native private static float getStiffness(long barVa); | ||
|
||
native private static void setLeftWheel(long barVa, int wheelIndex); | ||
|
||
native private static void setRightWheel(long barVa, int wheelIndex); | ||
|
||
native private static void setStiffness(long barVa, float stiffness); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
Copyright (c) 2025 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/VehicleAntiRollBar.h" | ||
#include "auto/com_github_stephengold_joltjni_VehicleAntiRollBar.h" | ||
|
||
using namespace JPH; | ||
|
||
/* | ||
* Class: com_github_stephengold_joltjni_VehicleAntiRollBar | ||
* Method: getLeftWheel | ||
* Signature: (J)I | ||
*/ | ||
JNIEXPORT jint JNICALL Java_com_github_stephengold_joltjni_VehicleAntiRollBar_getLeftWheel | ||
(JNIEnv *, jclass, jlong barVa) { | ||
const VehicleAntiRollBar * const pBar | ||
= reinterpret_cast<VehicleAntiRollBar *> (barVa); | ||
const int result = pBar->mLeftWheel; | ||
return result; | ||
} | ||
|
||
/* | ||
* Class: com_github_stephengold_joltjni_VehicleAntiRollBar | ||
* Method: getRightWheel | ||
* Signature: (J)I | ||
*/ | ||
JNIEXPORT jint JNICALL Java_com_github_stephengold_joltjni_VehicleAntiRollBar_getRightWheel | ||
(JNIEnv *, jclass, jlong barVa) { | ||
const VehicleAntiRollBar * const pBar | ||
= reinterpret_cast<VehicleAntiRollBar *> (barVa); | ||
const int result = pBar->mRightWheel; | ||
return result; | ||
} | ||
|
||
/* | ||
* Class: com_github_stephengold_joltjni_VehicleAntiRollBar | ||
* Method: getStiffness | ||
* Signature: (J)F | ||
*/ | ||
JNIEXPORT jfloat JNICALL Java_com_github_stephengold_joltjni_VehicleAntiRollBar_getStiffness | ||
(JNIEnv *, jclass, jlong barVa) { | ||
const VehicleAntiRollBar * const pBar | ||
= reinterpret_cast<VehicleAntiRollBar *> (barVa); | ||
const float result = pBar->mStiffness; | ||
return result; | ||
} | ||
|
||
/* | ||
* Class: com_github_stephengold_joltjni_VehicleAntiRollBar | ||
* Method: setLeftWheel | ||
* Signature: (JI)V | ||
*/ | ||
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_VehicleAntiRollBar_setLeftWheel | ||
(JNIEnv *, jclass, jlong barVa, jint wheelIndex) { | ||
VehicleAntiRollBar * const pBar | ||
= reinterpret_cast<VehicleAntiRollBar *> (barVa); | ||
pBar->mLeftWheel = wheelIndex; | ||
} | ||
|
||
/* | ||
* Class: com_github_stephengold_joltjni_VehicleAntiRollBar | ||
* Method: setRightWheel | ||
* Signature: (JI)V | ||
*/ | ||
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_VehicleAntiRollBar_setRightWheel | ||
(JNIEnv *, jclass, jlong barVa, jint wheelIndex) { | ||
VehicleAntiRollBar * const pBar | ||
= reinterpret_cast<VehicleAntiRollBar *> (barVa); | ||
pBar->mRightWheel = wheelIndex; | ||
} | ||
|
||
/* | ||
* Class: com_github_stephengold_joltjni_VehicleAntiRollBar | ||
* Method: setStiffness | ||
* Signature: (JF)V | ||
*/ | ||
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_VehicleAntiRollBar_setStiffness | ||
(JNIEnv *, jclass, jlong barVa, jfloat stiffness) { | ||
VehicleAntiRollBar * const pBar | ||
= reinterpret_cast<VehicleAntiRollBar *> (barVa); | ||
pBar->mStiffness = stiffness; | ||
} |