-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9cad9ec
commit f42e122
Showing
4 changed files
with
190 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/test/java/testjoltjni/app/samples/softbody/SoftBodyFrictionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
Copyright (c) 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 | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
*/ | ||
package testjoltjni.app.samples.softbody; | ||
import com.github.stephengold.joltjni.*; | ||
import com.github.stephengold.joltjni.enumerate.*; | ||
import testjoltjni.app.samples.*; | ||
/** | ||
* A line-for-line Java translation of the Jolt Physics soft-body friction test. | ||
* <p> | ||
* Compare with the original by Jorrit Rouwe at | ||
* https://github.com/jrouwe/JoltPhysics/blob/master/Samples/Tests/SoftBody/SoftBodyFrictionTest.cpp | ||
*/ | ||
public class SoftBodyFrictionTest extends Test{ | ||
|
||
public void Initialize() | ||
{ | ||
// Floor | ||
Body floor = CreateFloor(); | ||
floor.setFriction(1.0f); | ||
|
||
// Bodies with increasing friction | ||
SoftBodySharedSettingsRef sphere_settings = SoftBodyCreator.CreateSphere(); | ||
for (Vertex v : sphere_settings.getPtr().getVertices()) | ||
v.setVelocity (new Float3(0, 0, 10)); | ||
SoftBodyCreationSettings sphere=new SoftBodyCreationSettings(sphere_settings, RVec3.sZero(), Quat.sIdentity(), Layers.MOVING); | ||
sphere.setPressure ( 2000.0f); | ||
|
||
for (int i = 0; i <= 10; ++i) | ||
{ | ||
sphere.setPosition (new RVec3(-50.0f + i * 10.0f, 1.0f, 0)); | ||
sphere.setFriction ( 0.1f * i); | ||
mBodyInterface.createAndAddSoftBody(sphere, EActivation.Activate); | ||
} | ||
|
||
SoftBodySharedSettingsRef cube_settings = SoftBodySharedSettings.sCreateCube(5, 0.5f); | ||
for (Vertex v : cube_settings.getPtr().getVertices()) | ||
v.setVelocity (new Float3(0, 0, 10)); | ||
SoftBodyCreationSettings cube=new SoftBodyCreationSettings(cube_settings, RVec3.sZero(), Quat.sIdentity(), Layers.MOVING); | ||
|
||
for (int i = 0; i <= 10; ++i) | ||
{ | ||
cube.setPosition (new RVec3(-50.0f + i * 10.0f, 1.0f, -5.0f)); | ||
cube.setFriction ( 0.1f * i); | ||
mBodyInterface.createAndAddSoftBody(cube, EActivation.Activate); | ||
} | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
src/test/java/testjoltjni/app/samples/softbody/SoftBodyGravityFactorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
Copyright (c) 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 | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
*/ | ||
package testjoltjni.app.samples.softbody; | ||
import com.github.stephengold.joltjni.*; | ||
import com.github.stephengold.joltjni.enumerate.*; | ||
import testjoltjni.app.samples.*; | ||
/** | ||
* A line-for-line Java translation of the Jolt Physics soft-body gravity-factor test. | ||
* <p> | ||
* Compare with the original by Jorrit Rouwe at | ||
* https://github.com/jrouwe/JoltPhysics/blob/master/Samples/Tests/SoftBody/SoftBodyGravityFactorTest.cpp | ||
*/ | ||
public class SoftBodyGravityFactorTest extends Test{ | ||
|
||
public void Initialize() | ||
{ | ||
// Floor | ||
CreateFloor(); | ||
|
||
// Bodies with increasing gravity factor | ||
SoftBodyCreationSettings sphere=new SoftBodyCreationSettings(SoftBodyCreator.CreateSphere(), RVec3.sZero(), Quat.sIdentity(), Layers.MOVING); | ||
sphere.setPressure ( 2000.0f); | ||
|
||
for (int i = 0; i <= 10; ++i) | ||
{ | ||
sphere.setPosition (new RVec3(-50.0f + i * 10.0f, 10.0f, 0)); | ||
sphere.setGravityFactor ( 0.1f * i); | ||
mBodyInterface.createAndAddSoftBody(sphere, EActivation.Activate); | ||
} | ||
|
||
SoftBodyCreationSettings cube=new SoftBodyCreationSettings(SoftBodySharedSettings.sCreateCube(5, 0.5f), RVec3.sZero(), Quat.sIdentity(), Layers.MOVING); | ||
|
||
for (int i = 0; i <= 10; ++i) | ||
{ | ||
cube.setPosition (new RVec3(-50.0f + i * 10.0f, 10.0f, -5.0f)); | ||
cube.setGravityFactor ( 0.1f * i); | ||
mBodyInterface.createAndAddSoftBody(cube, EActivation.Activate); | ||
} | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
src/test/java/testjoltjni/app/samples/softbody/SoftBodyLRAConstraintTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
Copyright (c) 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 | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
*/ | ||
package testjoltjni.app.samples.softbody; | ||
import com.github.stephengold.joltjni.*; | ||
import com.github.stephengold.joltjni.enumerate.*; | ||
import java.util.function.BiFunction; | ||
import testjoltjni.app.samples.*; | ||
/** | ||
* A line-for-line Java translation of the Jolt Physics soft-body LRA-constraint test. | ||
* <p> | ||
* Compare with the original by Jorrit Rouwe at | ||
* https://github.com/jrouwe/JoltPhysics/blob/master/Samples/Tests/SoftBody/SoftBodyLRAConstraintTest.cpp | ||
*/ | ||
public class SoftBodyLRAConstraintTest extends Test{ | ||
float cVertexSpacing=.5f; | ||
int cNumVerticesX=10,cNumVerticesZ = 50; | ||
|
||
public void Initialize() | ||
{ | ||
CreateFloor(); | ||
|
||
for (int i = 0; i < 2; ++i) | ||
{ | ||
BiFunction<Integer,Integer,Float> inv_mass = (Integer inX, Integer inZ)-> { return inZ < 2? 0.0f : 1.0f; }; | ||
BiFunction<Integer,Integer,Vec3> perturbation = (Integer inX, Integer inZ)-> { return Vec3.sZero(); }; | ||
|
||
VertexAttributes va=new VertexAttributes(); | ||
va.setShearCompliance ( va.setCompliance ( 1.0e-3f)); // Soften the edges a bit so that the effect of the LRA constraints is more visible | ||
va.setLraType ( i == 0? ELraType.None : ELraType.EuclideanDistance); | ||
|
||
SoftBodySharedSettingsRef cloth_settings = SoftBodyCreator.CreateCloth(cNumVerticesX, cNumVerticesZ, cVertexSpacing, inv_mass, perturbation, EBendType.None, va); | ||
|
||
SoftBodyCreationSettings cloth=new SoftBodyCreationSettings(cloth_settings,new RVec3(-10.0f + i * 20.0f, 25.0f, 0), Quat.sIdentity(), Layers.MOVING); | ||
mBodyInterface.createAndAddSoftBody(cloth, EActivation.Activate); | ||
} | ||
} | ||
|
||
public void PrePhysicsUpdate(PreUpdateParams inParams) | ||
{ | ||
mDebugRenderer.drawText3D(new RVec3(-10, 26, -0.5f * cNumVerticesZ * cVertexSpacing), "Without LRA constraints", Color.sWhite); | ||
mDebugRenderer.drawText3D(new RVec3(10, 26, -0.5f * cNumVerticesZ * cVertexSpacing), "With LRA constraints", Color.sWhite); | ||
} | ||
} |