====== Physics ======
This contains functions to use Nvidia PhysX using StillDesign’s wrapper.
==== PhysicsEngine ====
Helps initializing PhysX by creating a core and scene, and setting some standard settings.
This class is rather temporary. It is quite possible that this class will not be used in the final version. It is useful for testing purposes.
==== PhysicsDebugRenderer ====
This takes the debug output (lines) from a PhysicsEngine’s PhysX output and provides methods to render the lines to an IXNAGame.
==== PhysicsHelper ====
This class is static and contains some helper methods to create basic actors for PhysX (eg: sphere, box, …)
TODO: this is not yet implemented
===== Client =====
The current implementation of the quadtree.
Each IPhysicsObject is in exactly one QuadTreeNode.
If physics in a node is activated, all IPhysicsObjects in that node and in all parent nodes are activated.
Dynamic objects are also in one treenode, but set flags on all the nodes they intersect (so lowest level nodes) that they are in those nodes.
Every lowest level node that intersects a dynamic IPhysicsObject is flagged as having physics enabled, and parent nodes get enabled too.
**The dynamic objects themselves are required to flag the nodes they enable physics in.**
The tree does not ask the objects directly whether they are dynamic or not.
IMPORTANT NOTE: when changing the dynamic objects count of the tree, be sure to always first increase and then decrease the count. When an object moves, it doesn’t change the count every frame. When you would decrease and increase, the decrease could make the count go to 0, making all the physics to unload and reload on the increase in one frame (=not good).
IMPORTANT NOTE: if the tree request an ClientPhysics object to enable its physics, **physics has to be enabled that same frame**,
if not dynamic objects will most likely get inside the unloaded physics objects, and cause jumping or walking through objects.
Unloading physics however, can be done at any time. Maybe putting a delay on the disabler could increase performance, when physics is enabled and disabled a lot.
**To implement a dynamic IClientPhysicsObject: watch the example in the ClientTest.ClientTestPhysicsSphere class.**
==== IClientPhysicsObject ====
This interface represents an object that has physics and interacts with other IClientPhysics objects.
This interface is used by the ClientPhysicsQuadTreeNode.
These objects have a dynamic/active status, that can change during runtime.
**EDIT:** currently, this status is not required by the quadtree,
the objects are supposed to tell the quadtree themselves of their being dynamical.
A dynamic object is self responsible of telling the quadtree which nodes it enables physics in.
==== ClientPhysicsQuadTreeNode ====
This class stores IClientPhysicsObjects in a quadtree structure.
It also stores whether physics in a specific part of the QuadTree is enabled or disabled.
It should be enabled when an dynamic object is in the node or one of its children,
and should be disabled when no dynamic objects are in the node or one of its children.
Each nodes has a dynamicobjectscount, which is a number specifying howmany dynamic objects intersect that node. The dynamicobjectscount can only be non-zero in leaf nodes.
==== ClientPhysicsTestSphere ====
This is simply a class for easy testing. It represents an IClientPhysicsObject sphere. It is an dynamic actor that can be driven by a physics actor or moved without physics.
It has been extended to a dynamic/static actor. When the actor stops moving it enters a sleeping state. It is no longer dynamic (so physics in that block will be disabled) until it exits it sleeping state.
IDEA: If I were to add the static/dynamic flag to the IClientPhysicsObject,
I could do a sweep of the entire tree, resetting the DynamicObjects reference count to zero,
if no dynamic objects are in that node. This will be necessary if round-off errors occur.
ADD this as a debug-security check
NOTE: fast moving (dynamic)objects should have their bounding increased along with their speed. This will ensure that physics is enabled before a dynamic object can jump into something. (or even fly straight through)