diff --git a/src/main/java/com/github/stephengold/joltjni/Shape.java b/src/main/java/com/github/stephengold/joltjni/Shape.java index 6b2fc3eb..ec8a6f88 100644 --- a/src/main/java/com/github/stephengold/joltjni/Shape.java +++ b/src/main/java/com/github/stephengold/joltjni/Shape.java @@ -23,8 +23,10 @@ of this software and associated documentation files (the "Software"), to deal import com.github.stephengold.joltjni.enumerate.EShapeSubType; import com.github.stephengold.joltjni.enumerate.EShapeType; +import com.github.stephengold.joltjni.readonly.ConstColor; import com.github.stephengold.joltjni.readonly.ConstShape; import com.github.stephengold.joltjni.readonly.Mat44Arg; +import com.github.stephengold.joltjni.readonly.RMat44Arg; import com.github.stephengold.joltjni.readonly.Vec3Arg; import com.github.stephengold.joltjni.template.RefTarget; import java.nio.FloatBuffer; @@ -170,6 +172,33 @@ public int countDebugTriangles() { return result; } + /** + * Draw the shape using the specified renderer. The shape is unaffected. + * + * @param renderer the renderer to use (not null) + * @param comTransform the coordinate transform from the shape's center of + * mass to system coordinates (not null, unaffected) + * @param scale the desired scaling (not null, unaffected) + * @param color the desired color if {@code useMaterialColors} is false (not + * null, unaffected) + * @param useMaterialColors true to use the color in the shape's material + * @param wireframe true to draw a wire frame, false for solid triangles + */ + @Override + public void draw(DebugRenderer renderer, RMat44Arg comTransform, + Vec3Arg scale, ConstColor color, boolean useMaterialColors, + boolean wireframe) { + long shapeVa = va(); + long rendererVa = renderer.va(); + long transformVa = comTransform.va(); + float scaleX = scale.getX(); + float scaleY = scale.getY(); + float scaleZ = scale.getZ(); + int colorInt = color.getUInt32(); + draw(shapeVa, rendererVa, transformVa, scaleX, scaleY, scaleZ, + colorInt, useMaterialColors, wireframe); + } + /** * Locate the shape's center of mass. The shape is unaffected. * @@ -367,6 +396,10 @@ native static void copyDebugTriangles( native static int countDebugTriangles(long shapeVa); + native static void draw(long shapeVa, long rendererVa, long transformVa, + float scaleX, float scaleY, float scaleZ, int colorInt, + boolean useMaterialColors, boolean wireframe); + native static float getCenterOfMassX(long shapeVa); native static float getCenterOfMassY(long shapeVa); diff --git a/src/main/java/com/github/stephengold/joltjni/ShapeRefC.java b/src/main/java/com/github/stephengold/joltjni/ShapeRefC.java index 78464732..96ea2730 100644 --- a/src/main/java/com/github/stephengold/joltjni/ShapeRefC.java +++ b/src/main/java/com/github/stephengold/joltjni/ShapeRefC.java @@ -23,8 +23,10 @@ of this software and associated documentation files (the "Software"), to deal import com.github.stephengold.joltjni.enumerate.EShapeSubType; import com.github.stephengold.joltjni.enumerate.EShapeType; +import com.github.stephengold.joltjni.readonly.ConstColor; import com.github.stephengold.joltjni.readonly.ConstShape; import com.github.stephengold.joltjni.readonly.Mat44Arg; +import com.github.stephengold.joltjni.readonly.RMat44Arg; import com.github.stephengold.joltjni.readonly.Vec3Arg; import java.nio.FloatBuffer; @@ -106,6 +108,34 @@ public int countDebugTriangles() { return result; } + /** + * Draw the shape using the specified renderer. The shape is unaffected. + * + * @param renderer the renderer to use (not null) + * @param comTransform the coordinate transform from the shape's center of + * mass to system coordinates (not null, unaffected) + * @param scale the desired scaling (not null, unaffected) + * @param color the desired color if {@code useMaterialColors} is false (not + * null, unaffected) + * @param useMaterialColors true to use the color in the shape's material + * @param wireframe true to draw a wire frame, false for solid triangles + */ + @Override + public void draw(DebugRenderer renderer, RMat44Arg comTransform, + Vec3Arg scale, ConstColor color, boolean useMaterialColors, + boolean wireframe) { + long refVa = va(); + long shapeVa = getPtr(refVa); + long rendererVa = renderer.va(); + long transformVa = comTransform.va(); + float scaleX = scale.getX(); + float scaleY = scale.getY(); + float scaleZ = scale.getZ(); + int colorInt = color.getUInt32(); + Shape.draw(shapeVa, rendererVa, transformVa, scaleX, scaleY, scaleZ, + colorInt, useMaterialColors, wireframe); + } + /** * Locate the shape's center of mass. The shape is unaffected. * diff --git a/src/main/java/com/github/stephengold/joltjni/readonly/ConstShape.java b/src/main/java/com/github/stephengold/joltjni/readonly/ConstShape.java index 8c644097..5571e8b6 100644 --- a/src/main/java/com/github/stephengold/joltjni/readonly/ConstShape.java +++ b/src/main/java/com/github/stephengold/joltjni/readonly/ConstShape.java @@ -22,6 +22,7 @@ of this software and associated documentation files (the "Software"), to deal package com.github.stephengold.joltjni.readonly; import com.github.stephengold.joltjni.AaBox; +import com.github.stephengold.joltjni.DebugRenderer; import com.github.stephengold.joltjni.MassProperties; import com.github.stephengold.joltjni.ShapeRefC; import com.github.stephengold.joltjni.Vec3; @@ -55,6 +56,22 @@ public interface ConstShape extends ConstJoltPhysicsObject { */ int countDebugTriangles(); + /** + * Draw the shape using the specified renderer. The shape is unaffected. + * + * @param renderer the renderer to use (not null) + * @param comTransform the coordinate transform from the shape's center of + * mass to system coordinates (not null, unaffected) + * @param scale the desired scaling (not null, unaffected) + * @param color the desired color if {@code useMaterialColors} is false (not + * null, unaffected) + * @param useMaterialColors true to use the color in the shape's material + * @param wireframe true to draw a wire frame, false for solid triangles + */ + void draw(DebugRenderer renderer, RMat44Arg comTransform, + Vec3Arg scale, ConstColor color, boolean useMaterialColors, + boolean wireframe); + /** * Locate the shape's center of mass. The shape is unaffected. * diff --git a/src/main/native/glue/s/Shape.cpp b/src/main/native/glue/s/Shape.cpp index 7e1a5cee..8fe6c81f 100644 --- a/src/main/native/glue/s/Shape.cpp +++ b/src/main/native/glue/s/Shape.cpp @@ -106,6 +106,28 @@ JNIEXPORT jint JNICALL Java_com_github_stephengold_joltjni_Shape_countDebugTrian return result; } +/* + * Class: com_github_stephengold_joltjni_Shape + * Method: draw + * Signature: (JJJFFFIZZ)V + */ +JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_Shape_draw + (JNIEnv *, jclass, jlong shapeVa, jlong rendererVa, jlong transformVa, + jfloat scaleX, jfloat scaleY, jfloat scaleZ, jint colorInt, + jboolean useMaterialColors, jboolean wireframe) { +#ifdef JPH_DEBUG_RENDERER + const Shape * const pShape = reinterpret_cast (shapeVa); + DebugRenderer * const pRenderer + = reinterpret_cast (rendererVa); + const RMat44 * const pTransform + = reinterpret_cast (transformVa); + const Vec3 scale(scaleX, scaleY, scaleZ); + const Color color(colorInt); + pShape->Draw( + pRenderer, *pTransform, scale, color, useMaterialColors, wireframe); +#endif +} + /* * Class: com_github_stephengold_joltjni_Shape * Method: getCenterOfMassX