Skip to content

Commit

Permalink
refactoring and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed May 23, 2024
1 parent db4be68 commit 9d34220
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,20 @@ private HelloLibbulletjme() {
*/
public static void main(String[] arguments) {
// Load a native library from ~/Downloads directory.
boolean dist = true; // use distribution filenames
String homePath = System.getProperty("user.home");
File downloadDirectory = new File(homePath, "Downloads");
String buildType = "Release";
String flavor = "Sp";
NativeLibraryLoader.loadLibbulletjme(
true, downloadDirectory, "Release", "Sp");
dist, downloadDirectory, buildType, flavor);

physicsSpace = createSpace();
populateSpace();

float timeStep = 0.02f;
Vector3f location = new Vector3f();
for (int i = 0; i < 50; ++i) {
for (int iteration = 0; iteration < 50; ++iteration) {
updatePhysics(timeStep);

ball.getPhysicsLocation(location);
Expand Down Expand Up @@ -118,7 +121,7 @@ private static void populateSpace() {
* @param intervalSeconds the time step to simulate (in seconds, &ge;0)
*/
private static void updatePhysics(float intervalSeconds) {
int maxSteps = 0;
int maxSteps = 0; // for a single step of the specified duration
physicsSpace.update(intervalSeconds, maxSteps);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,13 @@ private HelloVehicle0() {
*/
public static void main(String[] arguments) {
// Load a native library from ~/Downloads directory.
boolean dist = true; // use distribution filenames
String homePath = System.getProperty("user.home");
File downloadDirectory = new File(homePath, "Downloads");
String buildType = "Release";
String flavor = "Sp";
NativeLibraryLoader.loadLibbulletjme(
true, downloadDirectory, "Release", "Sp");
dist, downloadDirectory, buildType, flavor);

// Create a PhysicsSpace using DBVT for broadphase.
PhysicsSpace.BroadphaseType bPhase = PhysicsSpace.BroadphaseType.DBVT;
Expand Down Expand Up @@ -131,9 +134,10 @@ public static void main(String[] arguments) {

// 150 iterations with a 16.7-msec timestep
float timeStep = 1 / 60f;
int maxSteps = 0; // for a single step of the specified duration
Vector3f location = new Vector3f();
for (int i = 0; i < 150; ++i) {
physicsSpace.update(timeStep, 0);
for (int iteration = 0; iteration < 150; ++iteration) {
physicsSpace.update(timeStep, maxSteps);
vehicle.getPhysicsLocation(location);
System.out.println(location);
}
Expand Down
3 changes: 2 additions & 1 deletion docs/en/modules/ROOT/pages/add.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ To simulate a single 20-millisecond step:
[source,java]
----
float timeStep = 0.02f; // in seconds
physicsSpace.update(timeStep, 0);
int maxSteps = 0; // for a single step of the specified duration
physicsSpace.update(timeStep, maxSteps);
----

In real-time simulation, the interval between updates will vary.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,19 @@ private var physicsSpace: PhysicsSpace? = null
*/
fun main() {
// Load a native library from ~/Downloads directory.
val dist = true // use distribution filenames
val homePath = System.getProperty("user.home")
val downloadDirectory = File(homePath, "Downloads")
val downloadDirectory = new File(homePath, "Downloads")
val buildType = "Release"
val flavor = "Sp"
NativeLibraryLoader.loadLibbulletjme(
true, downloadDirectory, "Release", "Sp")
dist, downloadDirectory, buildType, flavor)

physicsSpace = createSpace()
populateSpace()

val location = Vector3f()
for (i in 0 ..< 50) {
for (iteration in 0 ..< 50) {
updatePhysics(intervalSeconds = 0.02f)

ball!!.getPhysicsLocation(location)
Expand Down Expand Up @@ -103,6 +106,6 @@ private fun populateSpace() {
* intervalSeconds: the time step to simulate (in seconds, >=0)
*/
private fun updatePhysics(intervalSeconds : Float) {
val maxSteps = 0
val maxSteps = 0 // for a single step of the specified duration
physicsSpace!!.update(intervalSeconds, maxSteps)
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,18 @@ import java.util.Collection
*/
fun main() {
// Load a native library from ~/Downloads directory.
val dist = true // use distribution filenames
val homePath = System.getProperty("user.home")
val downloadDirectory = File(homePath, "Downloads")
val downloadDirectory = new File(homePath, "Downloads")
val buildType = "Release"
val flavor = "Sp"
NativeLibraryLoader.loadLibbulletjme(
true, downloadDirectory, "Release", "Sp")
dist, downloadDirectory, buildType, flavor)

// Create a PhysicsSpace using DBVT for broadphase.
val physicsSpace = PhysicsSpace(PhysicsSpace.BroadphaseType.DBVT)
// Add a horizontal plane at y=-0.65 to represent the ground.

// Add a static horizontal plane at y=-0.65 to represent the ground.
val groundY = -0.65f
val plane = Plane(Vector3f.UNIT_Y, groundY)
val planeShape = PlaneCollisionShape(plane)
Expand Down Expand Up @@ -120,9 +123,9 @@ fun main() {

// 150 iterations with a 16.7-msec timestep
val timeStep = 1 / 60f
val maxSteps = 0
val maxSteps = 0 // for a single step of the specified duration
val location = Vector3f()
for (i in 0 ..< 150) {
for (iteration in 0 ..< 150) {
physicsSpace.update(timeStep, maxSteps)
vehicle.getPhysicsLocation(location)
println(location)
Expand Down

0 comments on commit 9d34220

Please sign in to comment.