Skip to content

Commit

Permalink
ConstShape: add the draw() method
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Sep 25, 2024
1 parent f2a5494 commit 7e5a9bd
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/main/java/com/github/stephengold/joltjni/Shape.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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);
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/com/github/stephengold/joltjni/ShapeRefC.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*
Expand Down
22 changes: 22 additions & 0 deletions src/main/native/glue/s/Shape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Shape *> (shapeVa);
DebugRenderer * const pRenderer
= reinterpret_cast<DebugRenderer *> (rendererVa);
const RMat44 * const pTransform
= reinterpret_cast<RMat44 *> (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
Expand Down

0 comments on commit 7e5a9bd

Please sign in to comment.