Team Guardian Physics
Physics System Overview
By 'northWind'
Major Classes
- Physics
- iPhysicsFrame
- iRigidBody
- RBDynamics
- Physics Coordinator
- iPhysicsScene
- Collision Information
- iCollisionGeometry
- iCSphere
- iCOBB
- Collision Notification
- iCollisionListener
- Collision Space
- iCollisionSpace
- iSimpleCollisionSpace
How to Use
iPhysicsFrame* f = CreatePhysicsFrame(); // Create base physics frame RBDynamics* d = f->getDynamics(); // Obtain handle to physics frame
iObject* o = CreateSphere(…..); o->attachTo(f); // Create graphical object and attach to pframe
d.velocity += Vector(0, 0, 500); // Set some of the physics properties
// OPTIONAL – Attach collision primitive iCollisionGeometry* c = CreateCSphere(f->getRB(), 50);
// At this point the object is simulating in the world and no further action is *necessary* // Other dynamics properties can also be changed for further effects // Although the physics simulator keeps track of collision geometries and rigid bodies and will dispose of // them upon shutdown (it does not track PhysicsFrame objects), it is good practice to clear bodies that // are out of use since physics computations, especially collision, are quite costly.
// To release, call delete on the allocated elements. Generally, the elements can be disallocated in any // order. Note here that I did NOT need to delete the Object created but I am deleting it since I attached // it to my PhysicsFrame and I do not want to delete the parent of the object prior to deleting the // object. o->Delete(); f->Delete(); c->Delete(); RBDynamics Properties Reference
Vector position; // Current position of COM Vector velocity; // Current velocity of COM
Vector lastVelocity; // Used to help detect velocity spikes Vector acceleration; // Additive acceleration of COM Vector force; // Constant force applied to COM Vector temporalForce; // Force that will be applied at the nexttick
// and then reset to 0. // Total linear acceleration is equal to: // acceleration + ((force + temporalForce)/mass)
float mass; // Mass, defaults to 1, the more mass present
// the more force required to move the object. // Set this to INFINITE_MASS (#include // “ModelSettings.h”) to prevent the object from // moving.
float dragCoefficient; // The drag coefficient, 0 implies no drag,
// 0.25~0.45 is the drag of a car, etc...
float restitution; // How much energy does the object keep after a
// collision? // 1 - Superball, the object loses none // 0 - Clay, the object loses all
float friction; // Tangential impulse applied during a collision that
// hinders movement // along the plane of the collision normal. // Coefficient of friction of // a given collision is calculated by adding together // the friction values of the two objects colliding.
Vector com; // Center of Mass offset
PhysicsType physicsType; // Type of physics applied to body, defaults to
// Falling – BUGGY, can reliably use PHYS_Falling and // PHYS_Floating
Matrix orientation; // Matrix representing rotation in XYZ Vector angularVelocity; // Angular velocity in radians/sec in XYZ Vector angularMomentum; // Angular momentum on the COM Vector torque; // Torque force on the COM Vector temporalTorque; // Torque force that will be applied at the next tick
// and then reset to 0; // Total angular acceleration is equal to: // aAcceleration + ((torque + // temporalTorque)/inertiaMoment)
RBDynamics Functions Reference
Vector getWorldCOM() const // Returns the world position of the COM with respect
// to this body
Vector getVelocityAtWorldPoint(const Vector& p) const
// Given a point in worldspace, returns its speed // taking into account velocity and angular velocity
Void setInverseInertiaTensor(const Matrix& i)
// Sets the inverse inertia tensor of this body. // Automatically sets the inertia tensor as well by // inversing the incoming matrix. // DOES NOT NEED TO BE CALLED AFTER CALLING // setInertiaTensor()
Void setInertiaTensor(const Matrix& i)
// Opposite of setInverseInertiaTensor. // DOES NOT NEED TO BE CALLED AFTER CALLING // setInverseInertiaTensor()
Matrix& getInertiaTensor() Matrix& getInverseInertiaTensor()
// Returns the inertia tensor or inverse inertia // tensor contained by this object.
Void ApplyImpulse(const Vector& impulse, const Vector& pointOfApplication)
// Applies a given impulse instantaneously onto this // object at a given world point of application. Can // be used to shoot or prod objects.
Other Topics Reference
Inertia Tensor
The inertia tensor is a Matrix representation of the distribution of mass within an object. This property is important in that it determines how objects rotate in reaction to given impulses. Provided are two methods to create them:
1) Use the quick inertia tensor calculators (getBoxInertiaTensor, getSphereInertiaTensor, #include “MathDefinitions.h”)
2) Create a sequence of PointMass objects and calculate the inertia tensor on them by using getInertiaTensor (const PointMass* points, size_t n). If possible, please use method 1 as method 2 has been returning somewhat exaggerated results.
Impulse
A force that is applied to an object over a very small time period. Practically, this force is applied instantaneously in the case of this engine.
Collision Geometry
The collision representation of an object. Typically in the form of boxes or spheres but may be other shapes. Currently implemented shapes are spheres and boxes, future additions include planes (possibly although use appears limited since no graphical representation of infinite plane) and compound objects.
Collision Space
A geometric space that contains a set of collision geometries. It is responsible for weeding out impossible collisions and generally controls the number of maximum collision calculations in a frame. Currently, the “simple” collision space is implemented ((N^2)/2 collisions) but the octree collision space is being currently implemented and should alleviate the number of objects bottleneck currently plaguing the system.
Matrix Inverse
Has a similar effect to the traditional division operation when multiplied by a float or vector (ie it acts as the divisor). This explanation is not rigorous in any way shape or form J