Skip to content

Commit

Permalink
SoftBodySharedSettings: add the sCreateCube() method
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Jan 18, 2025
1 parent 51948d7 commit 7e1b969
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
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 @@ -173,6 +173,22 @@ public void optimize() {
optimize(settingsVa);
}

/**
* Create a cube with edge constraints, volume constraints, and faces.
*
* @param gridSize the desired number of points on each axis (≥1)
* @param gridSpacing the distance between adjacent points
* @return a counted reference to new settings
*/
public static SoftBodySharedSettingsRef sCreateCube(
int gridSize, float gridSpacing) {
long refVa = sCreateCubeNative(gridSize, gridSpacing);
SoftBodySharedSettingsRef result
= new SoftBodySharedSettingsRef(refVa, true);

return result;
}

/**
* Replace the materials. (native attribute: mMaterials)
*
Expand Down Expand Up @@ -327,6 +343,9 @@ native static void createConstraints(long settingsVa,

native private static void setEmbedded(long settingsVa);

native private static long sCreateCubeNative(
int gridSize, float gridSpacing);

native static void setMaterialsSingle(long settingsVa, long materialVa);

native private static long toRef(long settingsVa);
Expand Down
15 changes: 15 additions & 0 deletions src/main/native/glue/s/SoftBodySharedSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,21 @@ JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_SoftBodySharedSetting
pSettings->SetEmbedded();
}

/*
* Class: com_github_stephengold_joltjni_SoftBodySharedSettings
* Method: sCreateCubeNative
* Signature: (IF)J
*/
JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_SoftBodySharedSettings_sCreateCubeNative
(JNIEnv *, jclass, jint gridSize, jfloat gridSpacing) {
Ref<SoftBodySharedSettings> ref
= SoftBodySharedSettings::sCreateCube(gridSize, gridSpacing);
Ref<SoftBodySharedSettings> * const pResult
= new Ref<SoftBodySharedSettings>(ref);
TRACE_NEW("Ref<SoftBodySharedSettings>", pResult)
return reinterpret_cast<jlong> (pResult);
}

/*
* Class: com_github_stephengold_joltjni_SoftBodySharedSettings
* Method: setMaterialsSingle
Expand Down

0 comments on commit 7e1b969

Please sign in to comment.