Experimenting with the Bullet Engine

Was experimenting with Physics all day yesterday and here are my thoughts and conclusions:



1 - If using both a CollisionListener and PhysicsTickListener, the order of operations is

prePhysicsTick() → physicsTick() → collision() → simpleUpdate()

2 - Mesh/Hull CollisionShapes cannot be scaled using CollisionShape.setScale(Vector3f), but I think they should be able to?

3 - Setting a CollisionShape (I used a Box) to initially have a mass of 0, and then change the mass later, results in gravity no longer working, but applying forces still work, i.e:



[java]

BoxCollisionShape boxCollisionShape = new BoxCollisionShape(((BoundingBox) geometry.getWorldBound()).getExtent(null));

RigidBodyControl control = new RigidBodyControl(boxCollisionShape, 0f);

n.addControl(control);

bulletAppState.getPhysicsSpace().add(control);

control.setMass(1);

[/java]



While if you initially set the mass to >0, then change it to 0, then change it >0 gravity works as expected

[java]

BoxCollisionShape boxCollisionShape = new BoxCollisionShape(((BoundingBox) geometry.getWorldBound()).getExtent(null));

RigidBodyControl control = new RigidBodyControl(boxCollisionShape, 1f);

n.addControl(control);

bulletAppState.getPhysicsSpace().add(control);

control.setMass(0);

control.setMass(1); //Just put it here for ease of demonstration

[/java]



I spent a few hours trying to edit the source to fix #2 and #3 but failed



4 - All forces (torque, force, impulse, velocity) should be used in prePhysicsTick

5 - The only exceptions are setLinearVelocity() and setAngularVelocity() and are safe to use inside simpleUpdate(), physicsTick() and collision()

6 - To stop a physics object from moving you can use:

  • setLinearVelocity(Vector3f.ZERO);
  • setAngularVelocity(Vector3f.ZERO);



    despite the initial thought that clearForces() would do it

    7 - There is no jME documentation or tests about Physics Ray Casting and Sweep testing, I could guess what Ray Casting did, wasn’t sure about Sweep Testing, but from the research I did, I think that you put an “imaginary” CollisionShape somewhere and it detects overlapping objects.



    Nonetheless I added 2 Test Cases to the wiki, would appreciate if someone could look over them:

    https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:ray_and_sweep_tests



    8 - The Bullet Manual states that kinematic objects should have no mass, but the tutorials and docs of jME state that it should (yet both seem to work)



    9 -I made a diff for PhysicsTickListener, as the function parameters didn’t match the javadoc, and also to be more consistent



    [patch]

This patch file was generated by NetBeans IDE

It uses platform neutral UTF-8 encoding and n newlines.

— Base (BASE)

+++ Locally Modified (Based On LOCAL)

@@ -1,5 +1,5 @@

/*

    • Copyright (c) 2009-2010 jMonkeyEngine
    • Copyright (c) 2009-2012 jMonkeyEngine
  • All rights reserved.

    *
  • Redistribution and use in source and binary forms, with or without

    @@ -42,13 +42,13 @@
  • @param space the physics space
  • @param tpf the time per frame in seconds

    */
  • public void prePhysicsTick(PhysicsSpace space, float f);
  • public void prePhysicsTick(PhysicsSpace space, float tpf);



    /**
  • Called after the physics has been stepped, use to check for forces etc.
  • @param space the physics space
  • @param tpf the time per frame in seconds

    */
  • public void physicsTick(PhysicsSpace space, float f);
  • public void physicsTick(PhysicsSpace space, float tpf);

    }

    [/patch]



    btw nice work normen, I see you worked very hard integrating this :slight_smile: so thanks
4 Likes

→ 6

like ray but with a collisionobjects it moves along the ray

1 Like
  1. Is due to the possibility of the physics being run on a separate thread, the collision callback happens on the main thread.
  2. Nah not really, its a bit complicated, at any instance it would not give you much (e.g. modifying it “live” doesn’t work), just scale the mesh before you create the collision shape.
  3. Yeah, just don’t do that or at least re-add the object to the physics space.
  4. Yeah
  5. All are “safe” to use but the impulses just won’t be applied if its not the physics tick
  6. clearForces is really just for the forces applied in this tick
  7. Yeah exactly, the test look fine Edit2: found some issues (e.g. rayTest vector coords are both absolute), but I fixed them and added the tests to jme3

    8 ) Yeah its an inconsistency in bullet but really they should have mass in the end (and in future updates)
  8. wee
2 Likes

@wezrule nice!



You might wanna start writing FAQ for Physics.