1 #ifndef _BODYENVIRONMENT_HPP
2 #define _BODYENVIRONMENT_HPP
4 #include "RigidBody.hpp"
8 // The values for position and orientation within the global reference
9 // frame, along with their first and second time derivatives. The
10 // orientation is stored as a matrix for simplicity. Note that
11 // because it is orthonormal, its inverse is simply its transpose.
12 // You can get local->global transformations by calling Math::tmul33()
13 // and using the same matrix.
15 double pos[3]; // position
16 float orient[9]; // global->local xform matrix
17 float v[3]; // velocity
18 float rot[3]; // rotational velocity
19 float acc[3]; // acceleration
20 float racc[3]; // rotational acceleration
22 // Simple initialization
26 pos[i] = v[i] = rot[i] = acc[i] = racc[i] = 0;
29 orient[3*i+j] = i==j ? 1.0f : 0.0f;
35 // Objects implementing this interface are responsible for calculating
36 // external forces on a RigidBody object. These will then be used by
37 // an Integrator to decide on a new solution to the state equations,
38 // which will be reported to the BodyEnvironment for further action.
43 // This method inspects the "environment" in which a RigidBody
44 // exists, calculates forces and torques on the body, and sets
45 // them via addForce()/addTorque(). Because this method is called
46 // multiple times ("trials") as part of a Runge-Kutta integration,
47 // this is NOT the place to make decisions about anything but the
48 // forces on the object. Note that the acc and racc fields of the
49 // passed-in State object are undefined! (They are calculed BY
51 virtual void calcForces(State* state) = 0;
53 // Called when the RK4 integrator has determined a "real" new
54 // point on the curve of life. Any side-effect producing checks
55 // of body state vs. the environment can happen here (crashes,
57 virtual void newState(State* state) = 0;
61 #endif // _BODYENVIRONMENT_HPP