Skip to content

Commit 7f7d89e

Browse files
committed
ConstVehicleConstraint: add the getWheelPositionAndRotation() method
1 parent 9ab2713 commit 7f7d89e

File tree

4 files changed

+106
-0
lines changed

4 files changed

+106
-0
lines changed

src/main/java/com/github/stephengold/joltjni/VehicleConstraint.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ of this software and associated documentation files (the "Software"), to deal
2424
import com.github.stephengold.joltjni.readonly.ConstVehicleConstraint;
2525
import com.github.stephengold.joltjni.readonly.ConstVehicleConstraintSettings;
2626
import com.github.stephengold.joltjni.readonly.Vec3Arg;
27+
import java.nio.DoubleBuffer;
2728
import java.nio.FloatBuffer;
2829

2930
/**
@@ -401,6 +402,33 @@ public RMat44 getWheelWorldTransform(
401402
return result;
402403
}
403404

405+
/**
406+
* Copy the world transform of the specified wheel. The constraint is
407+
* unaffected.
408+
*
409+
* @param wheelIndex the index of the wheel to query (≥0)
410+
* @param right the wheel's axis of rotation (a unit vector in the wheel's
411+
* model space)
412+
* @param up the "up" direction (a unit vector in the wheel's model space)
413+
* @param storePosition storage for the translation component (not null,
414+
* modified)
415+
* @param storeRotation storage for the rotation component (not null,
416+
* modified)
417+
*/
418+
@Override
419+
public void getWheelPositionAndRotation(int wheelIndex, Vec3Arg right,
420+
Vec3Arg up, RVec3 storePosition, Quat storeRotation) {
421+
long constraintVa = va();
422+
DoubleBuffer storeDoubles = Temporaries.doubleBuffer1.get();
423+
FloatBuffer storeFloats = Temporaries.floatBuffer1.get();
424+
right.copyTo(storeFloats);
425+
up.copyTo(storeFloats, 3);
426+
getWheelWorldTransformComponents(
427+
constraintVa, wheelIndex, storeDoubles, storeFloats);
428+
storePosition.set(storeDoubles);
429+
storeRotation.set(storeFloats);
430+
}
431+
404432
/**
405433
* Copy the "up" direction based on gravity. The constraint is unaffected.
406434
*
@@ -506,6 +534,9 @@ native static void getWheelLocalBasis(
506534
native static long getWheelWorldTransform(long constraintVa, int wheelIndex,
507535
float rx, float ry, float rz, float ux, float uy, float uz);
508536

537+
native static void getWheelWorldTransformComponents(long constraintVa,
538+
int wheelIndex, DoubleBuffer storeDoubles, FloatBuffer storeFloats);
539+
509540
native static void getWorldUp(long constraintVa, FloatBuffer storeFloats);
510541

511542
native static boolean isGravityOverridden(long constraintVa);

src/main/java/com/github/stephengold/joltjni/VehicleConstraintRef.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ of this software and associated documentation files (the "Software"), to deal
2626
import com.github.stephengold.joltjni.readonly.ConstVehicleConstraint;
2727
import com.github.stephengold.joltjni.readonly.Vec3Arg;
2828
import com.github.stephengold.joltjni.template.Ref;
29+
import java.nio.DoubleBuffer;
2930
import java.nio.FloatBuffer;
3031

3132
/**
@@ -378,6 +379,33 @@ public RMat44 getWheelWorldTransform(
378379
return result;
379380
}
380381

382+
/**
383+
* Copy the world transform of the specified wheel. The constraint is
384+
* unaffected.
385+
*
386+
* @param wheelIndex the index of the wheel to query (≥0)
387+
* @param right the wheel's axis of rotation (a unit vector in the wheel's
388+
* model space)
389+
* @param up the "up" direction (a unit vector in the wheel's model space)
390+
* @param storePosition storage for the translation component (not null,
391+
* modified)
392+
* @param storeRotation storage for the rotation component (not null,
393+
* modified)
394+
*/
395+
@Override
396+
public void getWheelPositionAndRotation(int wheelIndex, Vec3Arg right,
397+
Vec3Arg up, RVec3 storePosition, Quat storeRotation) {
398+
long constraintVa = targetVa();
399+
DoubleBuffer storeDoubles = Temporaries.doubleBuffer1.get();
400+
FloatBuffer storeFloats = Temporaries.floatBuffer1.get();
401+
right.copyTo(storeFloats);
402+
up.copyTo(storeFloats, 3);
403+
VehicleConstraint.getWheelWorldTransformComponents(
404+
constraintVa, wheelIndex, storeDoubles, storeFloats);
405+
storePosition.set(storeDoubles);
406+
storeRotation.set(storeFloats);
407+
}
408+
381409
/**
382410
* Copy the "up" direction based on gravity. The constraint is unaffected.
383411
*

src/main/java/com/github/stephengold/joltjni/readonly/ConstVehicleConstraint.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ of this software and associated documentation files (the "Software"), to deal
2121
*/
2222
package com.github.stephengold.joltjni.readonly;
2323

24+
import com.github.stephengold.joltjni.Quat;
2425
import com.github.stephengold.joltjni.RMat44;
26+
import com.github.stephengold.joltjni.RVec3;
2527
import com.github.stephengold.joltjni.Vec3;
2628
import com.github.stephengold.joltjni.Wheel;
2729

@@ -124,6 +126,22 @@ void getWheelLocalBasis(
124126
RMat44 getWheelWorldTransform(
125127
int wheelIndex, Vec3Arg right, Vec3Arg up);
126128

129+
/**
130+
* Copy the world transform of the specified wheel. The constraint is
131+
* unaffected.
132+
*
133+
* @param wheelIndex the index of the wheel to query (≥0)
134+
* @param right the wheel's axis of rotation (a unit vector in the wheel's
135+
* model space)
136+
* @param up the "up" direction (a unit vector in the wheel's model space)
137+
* @param storePosition storage for the translation component (not null,
138+
* modified)
139+
* @param storeRotation storage for the rotation component (not null,
140+
* modified)
141+
*/
142+
void getWheelPositionAndRotation(int wheelIndex, Vec3Arg right,
143+
Vec3Arg up, RVec3 storePosition, Quat storeRotation);
144+
127145
/**
128146
* Copy the "up" direction based on gravity. The constraint is unaffected.
129147
*

src/main/native/glue/v/VehicleConstraint.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,35 @@ JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_VehicleConstraint_ge
297297
return reinterpret_cast<jlong> (pResult);
298298
}
299299

300+
/*
301+
* Class: com_github_stephengold_joltjni_VehicleConstraint
302+
* Method: getWheelWorldTransformComponents
303+
* Signature: (JILjava/nio/DoubleBuffer;Ljava/nio/FloatBuffer;)V
304+
*/
305+
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_VehicleConstraint_getWheelWorldTransformComponents
306+
(JNIEnv *pEnv, jclass, jlong constraintVa, jint wheelIndex,
307+
jobject storeDoubles, jobject storeFloats) {
308+
const VehicleConstraint * const pConstraint
309+
= reinterpret_cast<VehicleConstraint *> (constraintVa);
310+
DIRECT_DOUBLE_BUFFER(pEnv, storeDoubles, pDoubles, capacityDoubles);
311+
JPH_ASSERT(capacityDoubles >= 3);
312+
DIRECT_FLOAT_BUFFER(pEnv, storeFloats, pFloats, capacityFloats);
313+
JPH_ASSERT(capacityFloats >= 6);
314+
const Vec3 right(pFloats[0], pFloats[1], pFloats[2]);
315+
const Vec3 up(pFloats[3], pFloats[4], pFloats[5]);
316+
const RMat44 matrix
317+
= pConstraint->GetWheelWorldTransform(wheelIndex, right, up);
318+
const RVec3 position = matrix.GetTranslation();
319+
pDoubles[0] = position.GetX();
320+
pDoubles[1] = position.GetY();
321+
pDoubles[2] = position.GetZ();
322+
const Quat rotation = matrix.GetQuaternion();
323+
pFloats[0] rotation.GetX();
324+
pFloats[1] rotation.GetY();
325+
pFloats[2] rotation.GetZ();
326+
pFloats[3] rotation.GetW();
327+
}
328+
300329
/*
301330
* Class: com_github_stephengold_joltjni_VehicleConstraint
302331
* Method: getWorldUp

0 commit comments

Comments
 (0)