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-2010 jMonkeyEngine
-
- Copyright (c) 2009-2012 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 thisso thanks