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
24 for(int i=0; i<3; i++) {
25 pos[i] = v[i] = rot[i] = acc[i] = racc[i] = 0;
26 for(int j=0; j<3; j++)
27 orient[3*i+j] = i==j ? 1 : 0;
33 // Objects implementing this interface are responsible for calculating
34 // external forces on a RigidBody object. These will then be used by
35 // an Integrator to decide on a new solution to the state equations,
36 // which will be reported to the BodyEnvironment for further action.
41 // This method inspects the "environment" in which a RigidBody
42 // exists, calculates forces and torques on the body, and sets
43 // them via addForce()/addTorque(). Because this method is called
44 // multiple times ("trials") as part of a Runge-Kutta integration,
45 // this is NOT the place to make decisions about anything but the
46 // forces on the object. Note that the acc and racc fields of the
47 // passed-in State object are undefined! (They are calculed BY
49 virtual void calcForces(State* state) = 0;
51 // Called when the RK4 integrator has determined a "real" new
52 // point on the curve of life. Any side-effect producing checks
53 // of body state vs. the environment can happen here (crashes,
55 virtual void newState(State* state) = 0;
59 #endif // _BODYENVIRONMENT_HPP