Skip to content

Commit

Permalink
VehicleConstraintSettings: add 2 public methods
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Jan 17, 2025
1 parent 578f575 commit 8fc85a9
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,21 @@ public void addWheels(WheelSettings... wheelSettingsArray) {
}
}

/**
* Access the settings for the specified anti-roll bar. (native field:
* mAntiRollBars)
*
* @param index the index of the anti-roll bar to access (≥0)
* @return a new JVM object with the pre-existing native object assigned
*/
public VehicleAntiRollBar getAntiRollBar(int index) {
long settingsVa = va();
long barVa = getAntiRollBar(settingsVa, index);
VehicleAntiRollBar result = new VehicleAntiRollBar(this, barVa);

return result;
}

/**
* Access the controller settings.
*
Expand Down Expand Up @@ -212,6 +227,16 @@ public void setMaxPitchRollAngle(float angle) {
setMaxPitchRollAngle(constraintSettingsVa, angle);
}

/**
* Alter the number of anti-roll bars. (native attribute: mAntiRollBars)
*
* @param count the desired number (≥0)
*/
public void setNumAntiRollBars(int count) {
long settingsVa = va();
setNumAntiRollBars(settingsVa, count);
}

/**
* Alter the up direction. (native attribute: mUp)
*
Expand All @@ -233,6 +258,8 @@ native private static void addWheel(

native private static long createDefault();

native private static long getAntiRollBar(long settingsVa, int index);

native private static float getForwardX(long settingsVa);

native private static float getForwardY(long settingsVa);
Expand All @@ -256,6 +283,8 @@ native private static void setForward(
native private static void setMaxPitchRollAngle(
long constraintSettingsVa, float angle);

native private static void setNumAntiRollBars(long settingsVa, int count);

native private static void setUp(
long settingsVa, float dx, float dy, float dz);
}
28 changes: 27 additions & 1 deletion src/main/native/glue/v/VehicleConstraintSettings.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2024 Stephen Gold
Copyright (c) 2024-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
Expand Down Expand Up @@ -57,6 +57,20 @@ JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_VehicleConstraintSet
return reinterpret_cast<jlong> (pResult);
}

/*
* Class: com_github_stephengold_joltjni_VehicleConstraintSettings
* Method: getAntiRollBar
* Signature: (JI)J
*/
JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_VehicleConstraintSettings_getAntiRollBar
(JNIEnv *, jclass, jlong settingsVa, jint index) {
VehicleConstraintSettings * const pSettings
= reinterpret_cast<VehicleConstraintSettings *> (settingsVa);
VehicleAntiRollBar * const pResult
= &pSettings->mAntiRollBars[index];
return reinterpret_cast<jlong> (pResult);
}

/*
* Class: com_github_stephengold_joltjni_VehicleConstraintSettings
* Method: getMaxPitchRollAngle
Expand Down Expand Up @@ -188,6 +202,18 @@ JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_VehicleConstraintSett
pSettings->mMaxPitchRollAngle = angle;
}

/*
* Class: com_github_stephengold_joltjni_VehicleConstraintSettings
* Method: setNumAntiRollBars
* Signature: (JI)V
*/
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_VehicleConstraintSettings_setNumAntiRollBars
(JNIEnv *, jclass, jlong settingsVa, int count) {
VehicleConstraintSettings * const pSettings
= reinterpret_cast<VehicleConstraintSettings *> (settingsVa);
pSettings->mAntiRollBars.resize(count);
}

/*
* Class: com_github_stephengold_joltjni_VehicleConstraintSettings
* Method: setUp
Expand Down

0 comments on commit 8fc85a9

Please sign in to comment.