]> git.mxchange.org Git - flightgear.git/blob - src/FDM/YASim/BodyEnvironment.hpp
Initial revision of Andy Ross's YASim code. This is (Y)et (A)nother Flight
[flightgear.git] / src / FDM / YASim / BodyEnvironment.hpp
1 #ifndef _BODYENVIRONMENT_HPP
2 #define _BODYENVIRONMENT_HPP
3
4 #include "RigidBody.hpp"
5
6 namespace yasim {
7
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.
14 struct State {
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
21
22     // Simple initialization
23     State() {
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;
28         }
29     }
30 };
31
32 //
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.
37 //
38 class BodyEnvironment
39 {
40 public:
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
48     // this method).
49     virtual void calcForces(State* state) = 0;
50
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,
54     // etc...).
55     virtual void newState(State* state) = 0;
56 };
57
58 }; // namespace yasim
59 #endif // _BODYENVIRONMENT_HPP