| 1 | #ifdef HAVE_CONFIG_H |
| 2 | #include <config.h> |
| 3 | #endif |
| 4 | |
| 5 | #include <simgear/scene/material/mat.hxx> |
| 6 | |
| 7 | #include <FDM/flight.hxx> |
| 8 | |
| 9 | #include "Glue.hpp" |
| 10 | #include "Ground.hpp" |
| 11 | |
| 12 | #include "FGGround.hpp" |
| 13 | namespace yasim { |
| 14 | |
| 15 | FGGround::FGGround(FGInterface *iface) : _iface(iface) |
| 16 | { |
| 17 | _toff = 0.0; |
| 18 | } |
| 19 | |
| 20 | FGGround::~FGGround() |
| 21 | { |
| 22 | } |
| 23 | |
| 24 | void FGGround::getGroundPlane(const double pos[3], |
| 25 | double plane[4], float vel[3], |
| 26 | unsigned int &body) |
| 27 | { |
| 28 | // Return values for the callback. |
| 29 | double cp[3], dvel[3], dangvel[3]; |
| 30 | const simgear::BVHMaterial* material; |
| 31 | _iface->get_agl_m(_toff, pos, 2, cp, plane, dvel, dangvel, material, body); |
| 32 | |
| 33 | // The plane below the actual contact point. |
| 34 | plane[3] = plane[0]*cp[0] + plane[1]*cp[1] + plane[2]*cp[2]; |
| 35 | |
| 36 | for(int i=0; i<3; i++) vel[i] = dvel[i]; |
| 37 | } |
| 38 | |
| 39 | void FGGround::getGroundPlane(const double pos[3], |
| 40 | double plane[4], float vel[3], |
| 41 | const simgear::BVHMaterial **material, |
| 42 | unsigned int &body) |
| 43 | { |
| 44 | // Return values for the callback. |
| 45 | double cp[3], dvel[3], dangvel[3]; |
| 46 | _iface->get_agl_m(_toff, pos, 2, cp, plane, dvel, dangvel, *material, body); |
| 47 | |
| 48 | // The plane below the actual contact point. |
| 49 | plane[3] = plane[0]*cp[0] + plane[1]*cp[1] + plane[2]*cp[2]; |
| 50 | |
| 51 | for(int i=0; i<3; i++) vel[i] = dvel[i]; |
| 52 | } |
| 53 | |
| 54 | bool FGGround::getBody(double t, double bodyToWorld[16], double linearVel[3], |
| 55 | double angularVel[3], unsigned int &body) |
| 56 | { |
| 57 | if (!_iface->get_body_m(_toff + t , body, bodyToWorld, linearVel, angularVel)) |
| 58 | return false; |
| 59 | |
| 60 | return true; |
| 61 | } |
| 62 | |
| 63 | bool FGGround::caughtWire(const double pos[4][3]) |
| 64 | { |
| 65 | return _iface->caught_wire_m(_toff, pos); |
| 66 | } |
| 67 | |
| 68 | bool FGGround::getWire(double end[2][3], float vel[2][3]) |
| 69 | { |
| 70 | double dvel[2][3]; |
| 71 | bool ret = _iface->get_wire_ends_m(_toff, end, dvel); |
| 72 | for (int i=0; i<2; ++i) |
| 73 | for (int j=0; j<3; ++j) |
| 74 | vel[i][j] = dvel[i][j]; |
| 75 | return ret; |
| 76 | } |
| 77 | |
| 78 | void FGGround::releaseWire(void) |
| 79 | { |
| 80 | _iface->release_wire(); |
| 81 | } |
| 82 | |
| 83 | float FGGround::getCatapult(const double pos[3], double end[2][3], |
| 84 | float vel[2][3]) |
| 85 | { |
| 86 | double dvel[2][3]; |
| 87 | float dist = _iface->get_cat_m(_toff, pos, end, dvel); |
| 88 | for (int i=0; i<2; ++i) |
| 89 | for (int j=0; j<3; ++j) |
| 90 | vel[i][j] = dvel[i][j]; |
| 91 | return dist; |
| 92 | } |
| 93 | |
| 94 | void FGGround::setTimeOffset(double toff) |
| 95 | { |
| 96 | _toff = toff; |
| 97 | } |
| 98 | |
| 99 | |
| 100 | }; // namespace yasim |
| 101 |