diff --git a/src/test/java/testjoltjni/app/samples/SmokeTestAll.java b/src/test/java/testjoltjni/app/samples/SmokeTestAll.java index 6094ed02..d7193f9f 100644 --- a/src/test/java/testjoltjni/app/samples/SmokeTestAll.java +++ b/src/test/java/testjoltjni/app/samples/SmokeTestAll.java @@ -128,6 +128,11 @@ public static void main(String... arguments) { smokeTest(new DampingTest()); smokeTest(new DynamicMeshTest()); smokeTest(new EnhancedInternalEdgeRemovalTest()); + smokeTest(new FrictionPerTriangleTest()); + smokeTest(new FrictionTest()); + smokeTest(new FunnelTest()); + smokeTest(new GravityFactorTest()); + smokeTest(new GyroscopicForceTest()); smokeTest(new HighSpeedTest()); smokeTest(new RestitutionTest()); diff --git a/src/test/java/testjoltjni/app/samples/general/FrictionPerTriangleTest.java b/src/test/java/testjoltjni/app/samples/general/FrictionPerTriangleTest.java new file mode 100644 index 00000000..b9924c69 --- /dev/null +++ b/src/test/java/testjoltjni/app/samples/general/FrictionPerTriangleTest.java @@ -0,0 +1,123 @@ +/* +Copyright (c) 2024 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.general; +import com.github.stephengold.joltjni.*; +import com.github.stephengold.joltjni.enumerate.*; +import com.github.stephengold.joltjni.readonly.*; +import java.util.*; +import testjoltjni.app.samples.*; +import static com.github.stephengold.joltjni.Jolt.*; +import static com.github.stephengold.joltjni.std.Std.*; +/** + * A line-for-line Java translation of the Jolt Physics friction per-triangle test. + *
+ * Compare with the original by Jorrit Rouwe at
+ * https://github.com/jrouwe/JoltPhysics/blob/master/Samples/Tests/General/FrictionPerTriangleTest.cpp
+ */
+public class FrictionPerTriangleTest extends Test{
+static class MyMaterial extends PhysicsMaterialSimple{
+ float mFriction,mRestitution;
+ MyMaterial(String inName,ConstColor inColor,float inFriction,float inRestitution){
+ super(inName, inColor);
+ mFriction=inFriction;
+ mRestitution=inRestitution;
+ };
+}
+
+public void Initialize()
+{
+ final int num_sections = 5;
+ final float section_size = 50.0f;
+
+ // Create a strip of triangles
+ List
+ * Compare with the original by Jorrit Rouwe at
+ * https://github.com/jrouwe/JoltPhysics/blob/master/Samples/Tests/General/FrictionTest.cpp
+ */
+public class FrictionTest extends Test{
+
+public void Initialize()
+{
+ // Floor
+ Body floor = mBodyInterface.createBody(new BodyCreationSettings(new BoxShape(new Vec3(100.0f, 1.0f, 100.0f), 0.0f), RVec3.sZero(), Quat.sRotation(Vec3.sAxisX(), 0.25f * JPH_PI), EMotionType.Static, Layers.NON_MOVING));
+ floor.setFriction(1.0f);
+ mBodyInterface.addBody(floor.getId(), EActivation.DontActivate);
+
+ ShapeRefC box = new BoxShape(new Vec3(2.0f, 2.0f, 2.0f)).toRefC();
+ ShapeRefC sphere = new SphereShape(2.0f).toRefC();
+
+ // Bodies with increasing friction
+ for (int i = 0; i <= 10; ++i)
+ {
+ Body body = mBodyInterface.createBody(new BodyCreationSettings(box,new RVec3(-50.0f + i * 10.0f, 55.0f, -50.0f), Quat.sRotation(Vec3.sAxisX(), 0.25f * JPH_PI), EMotionType.Dynamic, Layers.MOVING));
+ body.setFriction(0.1f * i);
+ mBodyInterface.addBody(body.getId(), EActivation.Activate);
+ }
+
+ for (int i = 0; i <= 10; ++i)
+ {
+ Body body = mBodyInterface.createBody(new BodyCreationSettings(sphere,new RVec3(-50.0f + i * 10.0f, 47.0f, -40.0f), Quat.sRotation(Vec3.sAxisX(), 0.25f * JPH_PI), EMotionType.Dynamic, Layers.MOVING));
+ body.setFriction(0.1f * i);
+ mBodyInterface.addBody(body.getId(), EActivation.Activate);
+ }
+}
+}
diff --git a/src/test/java/testjoltjni/app/samples/general/FunnelTest.java b/src/test/java/testjoltjni/app/samples/general/FunnelTest.java
new file mode 100644
index 00000000..5580f079
--- /dev/null
+++ b/src/test/java/testjoltjni/app/samples/general/FunnelTest.java
@@ -0,0 +1,172 @@
+/*
+Copyright (c) 2024 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.general;
+import com.github.stephengold.joltjni.*;
+import com.github.stephengold.joltjni.enumerate.*;
+import com.github.stephengold.joltjni.readonly.*;
+import com.github.stephengold.joltjni.std.*;
+import java.util.*;
+import testjoltjni.app.samples.*;
+import testjoltjni.app.testframework.CameraState;
+import static com.github.stephengold.joltjni.Jolt.*;
+import static com.github.stephengold.joltjni.operator.Op.*;
+/**
+ * A line-for-line Java translation of the Jolt Physics funnel test.
+ *
+ * Compare with the original by Jorrit Rouwe at
+ * https://github.com/jrouwe/JoltPhysics/blob/master/Samples/Tests/General/FunnelTest.cpp
+ */
+public class FunnelTest extends Test{
+
+public void Initialize()
+{
+ ShapeRefC box = new BoxShape(new Vec3(50, 1, 50), 0.0f).toRefC();
+
+ // Funnel
+ for (int i = 0; i < 4; ++i)
+ {
+ Quat rotation = Quat.sRotation(Vec3.sAxisY(), 0.5f * JPH_PI * i);
+
+ mBodyInterface.createAndAddBody(new BodyCreationSettings(box,new RVec3(star(rotation ,new Vec3(25, 25, 0))), star(rotation , Quat.sRotation(Vec3.sAxisZ(), 0.25f * JPH_PI)), EMotionType.Static, Layers.NON_MOVING), EActivation.DontActivate);
+ }
+
+ DefaultRandomEngine random=new DefaultRandomEngine();
+ UniformRealDistribution feature_size=new UniformRealDistribution(0.1f, 2.0f);
+ UniformRealDistribution position_variation=new UniformRealDistribution(-40, 40);
+ UniformRealDistribution scale_variation=new UniformRealDistribution(-1.5f, 1.5f);
+
+ // Random scale
+ Vec3 scale=new Vec3(scale_variation.nextFloat(random), scale_variation.nextFloat(random), scale_variation.nextFloat(random));
+
+ // Make it minimally -0.5 or 0.5 depending on the sign
+ plusEquals(scale , Vec3.sSelect(Vec3.sReplicate(-0.5f), Vec3.sReplicate(0.5f), Vec3.sGreaterOrEqual(scale, Vec3.sZero())));
+
+ ShapeRefC shape=new ShapeRefC();
+ for (int i = 0; i < 1000; ++i)
+ {
+ switch (random.nextInt() % 10)
+ {
+ case 0:
+ {
+ shape = new SphereShape(feature_size.nextFloat(random)).toRefC();
+ scale = scale.swizzle(0,0,0); // Only uniform scale supported
+ break;
+ }
+
+ case 1:
+ {
+ shape = new BoxShape(new Vec3(feature_size.nextFloat(random), feature_size.nextFloat(random), feature_size.nextFloat(random))).toRefC();
+ break;
+ }
+
+ case 2:
+ {
+ // Create random points
+ List
+ * Compare with the original by Jorrit Rouwe at
+ * https://github.com/jrouwe/JoltPhysics/blob/master/Samples/Tests/General/GravityFactorTest.cpp
+ */
+public class GravityFactorTest extends Test{
+
+public void Initialize()
+{
+ // Floor
+ CreateFloor();
+
+ ShapeRefC box = new BoxShape(new Vec3(2.0f, 2.0f, 2.0f)).toRefC();
+
+ // Bodies with increasing gravity fraction
+ for (int i = 0; i <= 10; ++i)
+ {
+ Body body = mBodyInterface.createBody(new BodyCreationSettings(box,new RVec3(-50.0f + i * 10.0f, 25.0f, 0), Quat.sIdentity(), EMotionType.Dynamic, Layers.MOVING));
+ body.getMotionProperties().setGravityFactor(0.1f * i);
+ mBodyInterface.addBody(body.getId(), EActivation.Activate);
+ }
+}
+}
diff --git a/src/test/java/testjoltjni/app/samples/general/GyroscopicForceTest.java b/src/test/java/testjoltjni/app/samples/general/GyroscopicForceTest.java
new file mode 100644
index 00000000..bc3baae6
--- /dev/null
+++ b/src/test/java/testjoltjni/app/samples/general/GyroscopicForceTest.java
@@ -0,0 +1,58 @@
+/*
+Copyright (c) 2024 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.general;
+import com.github.stephengold.joltjni.*;
+import com.github.stephengold.joltjni.enumerate.*;
+import testjoltjni.app.samples.*;
+import static com.github.stephengold.joltjni.operator.Op.*;
+/**
+ * A line-for-line Java translation of the Jolt Physics gyroscopic-force test.
+ *
+ * Compare with the original by Jorrit Rouwe at
+ * https://github.com/jrouwe/JoltPhysics/blob/master/Samples/Tests/General/GyroscopicForceTest.cpp
+ */
+public class GyroscopicForceTest extends Test{
+
+public void Initialize()
+{
+ // Floor
+ CreateFloor();
+
+ StaticCompoundShapeSettings compound=new StaticCompoundShapeSettings();
+ compound.addShape(Vec3.sZero(), Quat.sIdentity(), new BoxShape(new Vec3(0.5f, 5.0f, 0.5f)));
+ compound.addShape(new Vec3(1.5f, 0, 0), Quat.sIdentity(), new BoxShape(new Vec3(1.0f, 0.5f, 0.5f)));
+ compound.setEmbedded();
+
+ // One body without gyroscopic force
+ BodyCreationSettings bcs=new BodyCreationSettings(compound,new RVec3(0, 10, 0), Quat.sIdentity(), EMotionType.Dynamic, Layers.MOVING);
+ bcs.setLinearDamping ( 0.0f);
+ bcs.setAngularDamping ( 0.0f);
+ bcs.setAngularVelocity (new Vec3(10, 1, 0));
+ bcs.setGravityFactor ( 0.0f);
+ mBodyInterface.createAndAddBody(bcs, EActivation.Activate);
+
+ // One body with gyroscopic force
+ bcs.setPosition (plus(bcs.getPosition(),new RVec3(10, 0, 0)));
+ bcs.setApplyGyroscopicForce ( true);
+ mBodyInterface.createAndAddBody(bcs, EActivation.Activate);
+}
+}