]> git.mxchange.org Git - flightgear.git/blob - src/FDM/YASim/FGGround.cpp
FGPUIDialog: fix reading from already free'd memory.
[flightgear.git] / src / FDM / YASim / FGGround.cpp
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 {
27     // Return values for the callback.
28     double cp[3], dvel[3], dangvel[3];
29     const simgear::BVHMaterial* material;
30     simgear::BVHNode::Id id;
31     _iface->get_agl_m(_toff, pos, 2, cp, plane, dvel, dangvel, material, id);
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 {
43     // Return values for the callback.
44     double cp[3], dvel[3], dangvel[3];
45     simgear::BVHNode::Id id;
46     _iface->get_agl_m(_toff, pos, 2, cp, plane, dvel, dangvel, *material, id);
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::caughtWire(const double pos[4][3])
55 {
56     return _iface->caught_wire_m(_toff, pos);
57 }
58
59 bool FGGround::getWire(double end[2][3], float vel[2][3])
60 {
61     double dvel[2][3];
62     bool ret = _iface->get_wire_ends_m(_toff, end, dvel);
63     for (int i=0; i<2; ++i)
64       for (int j=0; j<3; ++j)
65         vel[i][j] = dvel[i][j];
66     return ret;
67 }
68
69 void FGGround::releaseWire(void)
70 {
71     _iface->release_wire();
72 }
73
74 float FGGround::getCatapult(const double pos[3], double end[2][3],
75                             float vel[2][3])
76 {
77     double dvel[2][3];
78     float dist = _iface->get_cat_m(_toff, pos, end, dvel);
79     for (int i=0; i<2; ++i)
80       for (int j=0; j<3; ++j)
81         vel[i][j] = dvel[i][j];
82     return dist;
83 }
84
85 void FGGround::setTimeOffset(double toff)
86 {
87     _toff = toff;
88 }
89
90
91 }; // namespace yasim
92