diff --git a/src/main/java/com/github/stephengold/joltjni/DebugRenderer.java b/src/main/java/com/github/stephengold/joltjni/DebugRenderer.java index 19385ae5..f388ffc0 100644 --- a/src/main/java/com/github/stephengold/joltjni/DebugRenderer.java +++ b/src/main/java/com/github/stephengold/joltjni/DebugRenderer.java @@ -21,6 +21,13 @@ of this software and associated documentation files (the "Software"), to deal */ package com.github.stephengold.joltjni; +import com.github.stephengold.joltjni.readonly.ConstAaBox; +import com.github.stephengold.joltjni.readonly.ConstColor; +import com.github.stephengold.joltjni.readonly.ConstOrientedBox; +import com.github.stephengold.joltjni.readonly.RMat44Arg; +import com.github.stephengold.joltjni.readonly.RVec3Arg; +import com.github.stephengold.joltjni.readonly.Vec3Arg; + /** * Visualization for debugging purposes. * @@ -51,6 +58,193 @@ abstract public class DebugRenderer extends NonCopyable { instance = this; } // ************************************************************************* + // new methods exposed + + /** + * Draw the specified 3-D arrow. + * + * @param from the desired starting point (not null, unaffected) + * @param to the desired ending point (not null, unaffected) + * @param color the desired color (not null, unaffected) + * @param size the desired size + */ + public void drawArrow( + RVec3Arg from, RVec3Arg to, ConstColor color, float size) { + double fromX = from.xx(); + double fromY = from.yy(); + double fromZ = from.zz(); + double toX = to.xx(); + double toY = to.yy(); + double toZ = to.zz(); + int colorInt = color.getUInt32(); + drawArrow(fromX, fromY, fromZ, toX, toY, toZ, colorInt, size); + } + + /** + * Draw the specified 3-D coordinate axes. + * + * @param transform the desired coordinate transform (not null, unaffected) + * @param size the desired size + */ + public void drawCoordinateSystem(RMat44Arg transform, float size) { + long transformVa = transform.va(); + drawCoordinateSystem(transformVa, size); + } + + /** + * Draw the specified 3-D line. + * + * @param from the desired first endpoint (not null, unaffected) + * @param to the desired 2nd endpoint (not null, unaffected) + * @param color the desired color (not null, unaffected) + */ + public void drawLine(RVec3Arg from, RVec3Arg to, ConstColor color) { + double fromX = from.xx(); + double fromY = from.yy(); + double fromZ = from.zz(); + double toX = to.xx(); + double toY = to.yy(); + double toZ = to.zz(); + int colorInt = color.getUInt32(); + drawLine(fromX, fromY, fromZ, toX, toY, toZ, colorInt); + } + + /** + * Draw a marker at the specified location. + * + * @param location the desired location (not null, unaffected) + * @param color the desired color (not null, unaffected) + * @param size the desired size + */ + public void drawMarker(RVec3Arg location, ConstColor color, float size) { + double locX = location.xx(); + double locY = location.yy(); + double locZ = location.zz(); + int colorInt = color.getUInt32(); + drawMarker(locX, locY, locZ, colorInt, size); + } + + /** + * Draw the specified plane. + * + * @param location the location of a point through which the plane passes + * (not null, unaffected) + * @param normal a direction normal to the plane's surface (not null, + * unaffected) + * @param color the desired color (not null, unaffected) + * @param size the desired size + */ + public void drawPlane( + RVec3Arg location, Vec3Arg normal, ConstColor color, float size) { + double locX = location.xx(); + double locY = location.yy(); + double locZ = location.zz(); + float normX = normal.getX(); + float normY = normal.getY(); + float normZ = normal.getZ(); + int colorInt = color.getUInt32(); + drawPlane(locX, locY, locZ, normX, normY, normZ, colorInt, size); + } + + /** + * Draw a wire-frame of the specified axis-aligned box. + * + * @param box the desired geometric properties (not null, unaffected) + * @param color the desired color (not null, unaffected) + */ + public void drawWireBox(ConstAaBox box, ConstColor color) { + long boxVa = box.va(); + int colorInt = color.getUInt32(); + drawWireBoxAligned(boxVa, colorInt); + } + + /** + * Draw a wire-frame of the specified 3-D box. + * + * @param box the desired geometric properties (not null, unaffected) + * @param color the desired color (not null, unaffected) + */ + public void drawWireBox(ConstOrientedBox box, ConstColor color) { + long boxVa = box.va(); + int colorInt = color.getUInt32(); + drawWireBoxOriented(boxVa, colorInt); + } + + /** + * Draw a wire frame of the specified 3-D box. + * + * @param transform the desired coordinate transform (not null, unaffected) + * @param box the desired geometric properties (not null, unaffected) + * @param color the desired color (not null, unaffected) + */ + public void drawWireBox( + RMat44Arg transform, ConstAaBox box, ConstColor color) { + long transformVa = transform.va(); + long boxVa = box.va(); + int colorInt = color.getUInt32(); + drawWireBoxTransformed(transformVa, boxVa, colorInt); + } + + /** + * Draw a wire frame of the specified sphere. + * + * @param location the location of the sphere's center (not null, + * unaffected) + * @param radius the desired radius + * @param color the desired color (not null, unaffected) + * @param level the desired level of detail + */ + public void drawWireSphere( + RVec3Arg location, float radius, ConstColor color, int level) { + double locX = location.xx(); + double locY = location.yy(); + double locZ = location.zz(); + int colorInt = color.getUInt32(); + drawWireSphere(locX, locY, locZ, radius, colorInt, level); + } + + /** + * Draw a wire frame of the specified 3-D triangle. + * + * @param v1 the location of the first vertex (not null, unaffected) + * @param v2 the location of the 2nd vertex (not null, unaffected) + * @param v3 the location of the 3rd vertex (not null, unaffected) + * @param color the desired color (not null, unaffected) + */ + public void drawWireTriangle( + RVec3Arg v1, RVec3Arg v2, RVec3Arg v3, ConstColor color) { + double v1x = v1.xx(); + double v1y = v1.yy(); + double v1z = v1.zz(); + double v2x = v2.xx(); + double v2y = v2.yy(); + double v2z = v2.zz(); + double v3x = v3.xx(); + double v3y = v3.yy(); + double v3z = v3.zz(); + int colorInt = color.getUInt32(); + drawWireTriangle(v1x, v1y, v1z, v2x, v2y, v2z, v3x, v3y, v3z, colorInt); + } + + /** + * Draw a wire frame of the specified unit sphere. + * + * @param transform the desired coordinate transform (not null, unaffected) + * @param color the desired color (not null, unaffected) + * @param level the desired level of detail + */ + public void drawWireUnitSphere( + RMat44Arg transform, ConstColor color, int level) { + long transformVa = transform.va(); + int colorInt = color.getUInt32(); + drawWireUnitSphere(transformVa, colorInt, level); + } + + /** + * Notify that the current frame is complete. + */ + native public void nextFrame(); + // ************************************************************************* // NonCopyable methods /** @@ -69,5 +263,38 @@ void setVirtualAddress(long rendererVa, boolean owner) { // ************************************************************************* // native private methods + native private static void drawArrow( + double fromX, double fromY, double fromZ, double toX, double toY, + double toZ, int colorInt, float size); + + native private static void drawCoordinateSystem( + long transformVa, float size); + + native private static void drawLine(double fromX, double fromY, + double fromZ, double toX, double toY, double toZ, int colorInt); + + native private static void drawMarker( + double locX, double locY, double locZ, int colorInt, float size); + + native private static void drawPlane(double locX, double locY, double locZ, + float normX, float normY, float normZ, int colorInt, float size); + + native private static void drawWireBoxAligned(long boxVa, int colorInt); + + native private static void drawWireBoxOriented(long boxVa, int colorInt); + + native private static void drawWireBoxTransformed( + long transformVa, long boxVa, int colorInt); + + native private static void drawWireSphere(double locX, double locY, + double locZ, float radius, int colorInt, int level); + + native private static void drawWireTriangle(double v1x, double v1y, + double v1z, double v2x, double v2y, double v2z, double v3x, + double v3y, double v3z, int colorInt); + + native private static void drawWireUnitSphere( + long transformVa, int colorInt, int level); + native private static void free(long rendererVa); } diff --git a/src/main/native/glue/d/DebugRenderer.cpp b/src/main/native/glue/d/DebugRenderer.cpp index 1205a459..98123e0c 100644 --- a/src/main/native/glue/d/DebugRenderer.cpp +++ b/src/main/native/glue/d/DebugRenderer.cpp @@ -25,13 +25,191 @@ SOFTWARE. */ #include #ifdef JPH_DEBUG_RENDERER -#include +#include #endif #include "auto/com_github_stephengold_joltjni_DebugRenderer.h" #include "glue/glue.h" using namespace JPH; +/* + * Class: com_github_stephengold_joltjni_DebugRenderer + * Method: nextFrame + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_DebugRenderer_nextFrame + (JNIEnv *, jobject) { +#ifdef JPH_DEBUG_RENDERER + DebugRenderer::sInstance->NextFrame(); +#endif +} + +/* + * Class: com_github_stephengold_joltjni_DebugRenderer + * Method: drawArrow + * Signature: (DDDDDDIF)V + */ +JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_DebugRenderer_drawArrow + (JNIEnv *, jclass, jdouble startX, jdouble startY, jdouble startZ, + jdouble endX, jdouble endY, jdouble endZ, jint colorInt, jfloat size) { +#ifdef JPH_DEBUG_RENDERER + const RVec3 start(startX, startY, startZ); + const RVec3 end(endX, endY, endZ); + const Color color(colorInt); + DebugRenderer::sInstance->DrawArrow(start, end, color, size); +#endif +} + +/* + * Class: com_github_stephengold_joltjni_DebugRenderer + * Method: drawCoordinateSystem + * Signature: (JF)V + */ +JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_DebugRenderer_drawCoordinateSystem + (JNIEnv *, jclass, jlong transformVa, jfloat size) { +#ifdef JPH_DEBUG_RENDERER + const RMat44 * const pTransform = reinterpret_cast (transformVa); + DebugRenderer::sInstance->DrawCoordinateSystem(*pTransform, size); +#endif +} + +/* + * Class: com_github_stephengold_joltjni_DebugRenderer + * Method: drawLine + * Signature: (DDDDDDI)V + */ +JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_DebugRenderer_drawLine + (JNIEnv *, jclass, jdouble startX, jdouble startY, jdouble startZ, + jdouble endX, jdouble endY, jdouble endZ, jint colorInt) { +#ifdef JPH_DEBUG_RENDERER + const RVec3 start(startX, startY, startZ); + const RVec3 end(endX, endY, endZ); + const Color color(colorInt); + DebugRenderer::sInstance->DrawLine(start, end, color); +#endif +} + +/* + * Class: com_github_stephengold_joltjni_DebugRenderer + * Method: drawMarker + * Signature: (DDDIF)V + */ +JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_DebugRenderer_drawMarker + (JNIEnv *, jclass, jdouble locX, jdouble locY, jdouble locZ, jint colorInt, + jfloat size) { +#ifdef JPH_DEBUG_RENDERER + const RVec3 location(locX, locY, locZ); + const Color color(colorInt); + DebugRenderer::sInstance->DrawMarker(location, color, size); +#endif +} + +/* + * Class: com_github_stephengold_joltjni_DebugRenderer + * Method: drawPlane + * Signature: (DDDFFFIF)V + */ +JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_DebugRenderer_drawPlane + (JNIEnv *, jclass, jdouble locX, jdouble locY, jdouble locZ, jfloat normX, + jfloat normY, jfloat normZ, jint colorInt, jfloat size) { +#ifdef JPH_DEBUG_RENDERER + const RVec3 location(locX, locY, locZ); + const Vec3 normal(normX, normY, normZ); + const Color color(colorInt); + DebugRenderer::sInstance->DrawPlane(location, normal, color, size); +#endif +} + +/* + * Class: com_github_stephengold_joltjni_DebugRenderer + * Method: drawWireBoxAligned + * Signature: (JI)V + */ +JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_DebugRenderer_drawWireBoxAligned + (JNIEnv *, jclass, jlong boxVa, jint colorInt) { +#ifdef JPH_DEBUG_RENDERER + const AABox * pBox = reinterpret_cast (boxVa); + const Color color(colorInt); + DebugRenderer::sInstance->DrawWireBox(*pBox, color); +#endif +} + +/* + * Class: com_github_stephengold_joltjni_DebugRenderer + * Method: drawWireBoxOriented + * Signature: (JI)V + */ +JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_DebugRenderer_drawWireBoxOriented + (JNIEnv *, jclass, jlong boxVa, jint colorInt) { +#ifdef JPH_DEBUG_RENDERER + const OrientedBox * pBox = reinterpret_cast (boxVa); + const Color color(colorInt); + DebugRenderer::sInstance->DrawWireBox(*pBox, color); +#endif +} + +/* + * Class: com_github_stephengold_joltjni_DebugRenderer + * Method: drawWireBoxTransformed + * Signature: (JJI)V + */ +JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_DebugRenderer_drawWireBoxTransformed + (JNIEnv *, jclass, jlong transformVa, jlong boxVa, jint colorInt) { +#ifdef JPH_DEBUG_RENDERER + const RMat44 * const pTransform = reinterpret_cast (transformVa); + const AABox * const pBox = reinterpret_cast (boxVa); + const Color color(colorInt); + DebugRenderer::sInstance->DrawWireBox(*pTransform, *pBox, color); +#endif +} + +/* + * Class: com_github_stephengold_joltjni_DebugRenderer + * Method: drawWireSphere + * Signature: (DDDFII)V + */ +JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_DebugRenderer_drawWireSphere + (JNIEnv *, jclass, jdouble locX, jdouble locY, jdouble locZ, jfloat radius, + jint colorInt, jint level) { +#ifdef JPH_DEBUG_RENDERER + const RVec3 location(locX, locY, locZ); + const Color color(colorInt); + DebugRenderer::sInstance->DrawWireSphere(location, radius, color, level); +#endif +} + +/* + * Class: com_github_stephengold_joltjni_DebugRenderer + * Method: drawWireTriangle + * Signature: (DDDDDDDDDI)V + */ +JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_DebugRenderer_drawWireTriangle + (JNIEnv *, jclass, jdouble v1x, jdouble v1y, jdouble v1z, jdouble v2x, + jdouble v2y, jdouble v2z, jdouble v3x, jdouble v3y, jdouble v3z, + jint colorInt) { +#ifdef JPH_DEBUG_RENDERER + const RVec3 v1(v1x, v1y, v1z); + const RVec3 v2(v2x, v2y, v2z); + const RVec3 v3(v3x, v3y, v3z); + const Color color(colorInt); + DebugRenderer::sInstance->DrawWireTriangle(v1, v2, v3, color); +#endif +} + +/* + * Class: com_github_stephengold_joltjni_DebugRenderer + * Method: drawWireUnitSphere + * Signature: (JII)V + */ +JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_DebugRenderer_drawWireUnitSphere + (JNIEnv *, jclass, jlong transformVa, jint colorInt, jint level) { +#ifdef JPH_DEBUG_RENDERER + const RMat44 * const pTransform = reinterpret_cast (transformVa); + const Color color(colorInt); + DebugRenderer::sInstance->DrawWireUnitSphere(*pTransform, color, level); +#endif +} + /* * Class: com_github_stephengold_joltjni_DebugRenderer * Method: free