Skip to content

Commit

Permalink
samples.general: add 3 more test classes
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Nov 25, 2024
1 parent dd88486 commit 5a69813
Show file tree
Hide file tree
Showing 4 changed files with 173 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/test/java/testjoltjni/app/samples/SmokeTestAll.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ public static void main(String... arguments) {
smokeTest(new FunnelTest());
smokeTest(new GravityFactorTest());
smokeTest(new GyroscopicForceTest());
smokeTest(new HeavyOnLightTest());
smokeTest(new HighSpeedTest());
smokeTest(new IslandTest());
smokeTest(new KinematicTest());
smokeTest(new RestitutionTest());

// shapes package:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
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.*;
/**
* A line-for-line Java translation of the Jolt Physics heavy-on-light test.
* <p>
* Compare with the original by Jorrit Rouwe at
* https://github.com/jrouwe/JoltPhysics/blob/master/Samples/Tests/General/HeavyOnLightTest.cpp
*/
public class HeavyOnLightTest extends Test{

public void Initialize()
{
// Floor
CreateFloor();

BoxShape box = new BoxShape(Vec3.sReplicate(5));
box.setDensity(1000.0f);

for (int i = 1; i <= 10; ++i)
{
mBodyInterface.createAndAddBody(new BodyCreationSettings(box,new RVec3(-75.0f + i * 15.0f, 10.0f, 0.0f), Quat.sIdentity(), EMotionType.Dynamic, Layers.MOVING), EActivation.Activate);

BoxShape box2 = new BoxShape(Vec3.sReplicate(5));
box2.setDensity(5000.0f * i);

mBodyInterface.createAndAddBody(new BodyCreationSettings(box2,new RVec3(-75.0f + i * 15.0f, 30.0f, 0.0f), Quat.sIdentity(), EMotionType.Dynamic, Layers.MOVING), EActivation.Activate);
}
}
}
50 changes: 50 additions & 0 deletions src/test/java/testjoltjni/app/samples/general/IslandTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
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.*;
/**
* A line-for-line Java translation of the Jolt Physics island test.
* <p>
* Compare with the original by Jorrit Rouwe at
* https://github.com/jrouwe/JoltPhysics/blob/master/Samples/Tests/General/IslandTest.cpp
*/
public class IslandTest extends Test{

public void Initialize()
{
// Floor
CreateFloor();

ShapeRefC box_shape = new BoxShape(new Vec3(1.0f, 1.0f, 1.0f)).toRefC();

// Walls
for (int i = 0; i < 10; ++i)
for (int j = i / 2; j < 10 - (i + 1) / 2; ++j)
for (int k = 0; k < 8; ++k)
{
RVec3 position=new RVec3(-10 + j * 2.0f + ((i & 1)!=0? 1.0f : 0.0f), 1.0f + i * 2.0f, 8.0f * (k - 4));
mBodyInterface.createAndAddBody(new BodyCreationSettings(box_shape, position, Quat.sIdentity(), EMotionType.Dynamic, Layers.MOVING), EActivation.Activate);
}
}
}
68 changes: 68 additions & 0 deletions src/test/java/testjoltjni/app/samples/general/KinematicTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
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.*;
/**
* A line-for-line Java translation of the Jolt Physics kinematic test.
* <p>
* Compare with the original by Jorrit Rouwe at
* https://github.com/jrouwe/JoltPhysics/blob/master/Samples/Tests/General/KinematicTest.cpp
*/
public class KinematicTest extends Test{
Body[] mKinematic=new Body[2];

public void Initialize()
{
// Floor
CreateFloor();

// Wall
ShapeRefC box_shape = new BoxShape(new Vec3(1.0f, 1.0f, 1.0f)).toRefC();
for (int i = 0; i < 3; ++i)
for (int j = i / 2; j < 10 - (i + 1) / 2; ++j)
{
RVec3 position=new RVec3(-10.0f + j * 2.0f + ((i & 1)!=0? 1.0f : 0.0f), 1.0f + i * 2.0f, 0);
mBodyInterface.createAndAddBody(new BodyCreationSettings(box_shape, position, Quat.sIdentity(), EMotionType.Dynamic, Layers.MOVING), EActivation.DontActivate);
}

// Kinematic object
for (int i = 0; i < 2; ++i)
{
mKinematic[i] = mBodyInterface.createBody(new BodyCreationSettings(new SphereShape(1.0f),new RVec3(-10.0f, 2.0f, i == 0? 5.0f : -5.0f), Quat.sIdentity(), EMotionType.Kinematic, Layers.MOVING));
mBodyInterface.addBody(mKinematic[i].getId(), EActivation.Activate);
}
}

public void PrePhysicsUpdate( PreUpdateParams inParams)
{
for (int i = 0; i < 2; ++i)
{
RVec3 com = mKinematic[i].getCenterOfMassPosition();
if (com.z() >= 5.0f)
mKinematic[i].setLinearVelocity(new Vec3(2.0f, 0, -10.0f));
else if (com.z() <= -5.0f)
mKinematic[i].setLinearVelocity(new Vec3(2.0f, 0, 10.0f));
}
}
}

0 comments on commit 5a69813

Please sign in to comment.