+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
#include "Atmosphere.hpp"
#include "Thruster.hpp"
#include "Math.hpp"
#include "Surface.hpp"
#include "Rotor.hpp"
#include "Rotorpart.hpp"
+#include "Hitch.hpp"
#include "Glue.hpp"
#include "Ground.hpp"
delete _ground_cb;
delete _hook;
delete _launchbar;
+ for(int i=0; i<_hitches.size();i++)
+ delete (Hitch*)_hitches.get(i);
+
}
void Model::getThrust(float* out)
_turb->offset(toff);
}
+ for(i=0; i<_hitches.size(); i++) {
+ Hitch* h = (Hitch*)_hitches.get(i);
+ h->integrate(_integrator.getInterval());
+ }
+
}
_launchbar = launchbar;
}
+int Model::addHitch(Hitch* hitch)
+{
+ return _hitches.add(hitch);
+}
+
void Model::setGroundCallback(Ground* ground_cb)
{
delete _ground_cb;
double pt[3];
s->posLocalToGlobal(pos, pt);
+ // Ask for the ground plane in the global coordinate system
+ double global_ground[4];
+ float global_vel[3];
+ const simgear::BVHMaterial* material;
+ _ground_cb->getGroundPlane(pt, global_ground, global_vel, &material);
+ g->setGlobalGround(global_ground, global_vel, pt[0], pt[1], material);
+ }
+
+ for(i=0; i<_hitches.size(); i++) {
+ Hitch* h = (Hitch*)_hitches.get(i);
+
+ // Get the point of interest
+ float pos[3];
+ h->getPosition(pos);
+
+ // Transform the local coordinates of the contact point to
+ // global coordinates.
+ double pt[3];
+ s->posLocalToGlobal(pos, pt);
+
// Ask for the ground plane in the global coordinate system
double global_ground[4];
float global_vel[3];
_ground_cb->getGroundPlane(pt, global_ground, global_vel);
- g->setGlobalGround(global_ground, global_vel);
+ h->setGlobalGround(global_ground, global_vel);
}
+
for(i=0; i<_rotorgear.getRotors()->size(); i++) {
Rotor* r = (Rotor*)_rotorgear.getRotors()->get(i);
r->findGroundEffectAltitude(_ground_cb,s);
_body.addForce(contactlb, forcelb);
_body.addForce(contacthb, forcehb);
}
-}
+// The hitches
+ for(i=0; i<_hitches.size(); i++) {
+ float force[3], contact[3];
+ Hitch* h = (Hitch*)_hitches.get(i);
+ h->calcForce(_ground_cb,&_body, s);
+ h->getForce(force, contact);
+ _body.addForce(contact, force);
+ }
+}
void Model::newState(State* s)
{
_s = s;
for(i=0; i<_gears.size(); i++) {
Gear* g = (Gear*)_gears.get(i);
- // Get the point of ground contact
- float pos[3], cmpr[3];
- g->getPosition(pos);
- g->getCompression(cmpr);
- Math::mul3(g->getCompressFraction(), cmpr, cmpr);
- Math::add3(cmpr, pos, pos);
-
- // The plane transformed to local coordinates.
- double global_ground[4];
- g->getGlobalGround(global_ground);
- float ground[4];
- s->planeGlobalToLocal(global_ground, ground);
- float dist = ground[3] - Math::dot3(pos, ground);
-
- // Find the lowest one
- if(dist < min)
- min = dist;
+ if (!g->getSubmergable())
+ {
+ // Get the point of ground contact
+ float pos[3], cmpr[3];
+ g->getPosition(pos);
+ g->getCompression(cmpr);
+ Math::mul3(g->getCompressFraction(), cmpr, cmpr);
+ Math::add3(cmpr, pos, pos);
+
+ // The plane transformed to local coordinates.
+ double global_ground[4];
+ g->getGlobalGround(global_ground);
+ float ground[4];
+ s->planeGlobalToLocal(global_ground, ground);
+ float dist = ground[3] - Math::dot3(pos, ground);
+
+ // Find the lowest one
+ if(dist < min)
+ min = dist;
+ }
}
_agl = min;
if(_agl < -1) // Allow for some integration slop