]> git.mxchange.org Git - flightgear.git/commitdiff
Automatically generate "contact" points for collision detection. Implemented
authorandy <andy>
Wed, 20 Feb 2002 07:12:27 +0000 (07:12 +0000)
committerandy <andy>
Wed, 20 Feb 2002 07:12:27 +0000 (07:12 +0000)
as extra (and invisible) gear objects.

src/FDM/YASim/Airplane.cpp
src/FDM/YASim/Airplane.hpp
src/FDM/YASim/Wing.cpp
src/FDM/YASim/Wing.hpp

index da81beba2a6c01ab973b1ca0610725297c1cd9be..7515dc6392594aaf316e08d2c64e7a2127b5b0f0 100644 (file)
@@ -46,6 +46,8 @@ Airplane::~Airplane()
        delete (GearRec*)_gears.get(i);
     for(i=0; i<_surfs.size(); i++)
        delete (Surface*)_surfs.get(i);    
+    for(i=0; i<_contacts.size(); i++)
+        delete[] (float*)_contacts.get(i);
 }
 
 void Airplane::iterate(float dt)
@@ -350,8 +352,26 @@ void Airplane::setupState(float aoa, float speed, State* s)
     s->pos[2] = 1;
 }
 
+void Airplane::addContactPoint(float* pos)
+{
+    float* cp = new float[3];
+    cp[0] = pos[0];
+    cp[1] = pos[1];
+    cp[2] = pos[2];
+    _contacts.add(cp);
+}
+
 float Airplane::compileWing(Wing* w)
 {
+    // The tip of the wing is a contact point
+    float tip[3];
+    w->getTip(tip);
+    addContactPoint(tip);
+    if(w->isMirrored()) {
+        tip[1] *= -1;
+        addContactPoint(tip);
+    }
+
     // Make sure it's initialized.  The surfaces will pop out with
     // total drag coefficients equal to their areas, which is what we
     // want.
@@ -379,6 +399,10 @@ float Airplane::compileWing(Wing* w)
 
 float Airplane::compileFuselage(Fuselage* f)
 {
+    // The front and back are contact points
+    addContactPoint(f->front);
+    addContactPoint(f->back);
+
     float wgt = 0;
     float fwd[3];
     Math::sub3(f->front, f->back, fwd);
@@ -456,6 +480,39 @@ void Airplane::compileGear(GearRec* gr)
     _surfs.add(s);
 }
 
+void Airplane::compileContactPoints()
+{
+    // Figure it will compress by 20cm
+    float comp[3];
+    float DIST = 0.2;
+    comp[0] = 0; comp[1] = 0; comp[2] = DIST;
+
+    // Give it a spring constant such that at full compression it will
+    // hold up 10 times the planes mass.  That's about right.  Yeah.
+    float mass = _model.getBody()->getTotalMass();
+    float spring = (1/DIST) * 9.8 * 10 * mass;
+    float damp = 2 * Math::sqrt(spring * mass);
+
+    int i;
+    for(i=0; i<_contacts.size(); i++) {
+        float *cp = (float*)_contacts.get(i);
+
+        Gear* g = new Gear();
+        g->setPosition(cp);
+        
+        g->setCompression(comp);
+        g->setSpring(spring);
+        g->setDamping(damp);
+        g->setBrake(1);
+
+        // I made these up
+        g->setStaticFriction(0.6);
+        g->setDynamicFriction(0.5);
+
+        _model.addGear(g);
+    }
+}
+
 void Airplane::compile()
 {
     double ground[3];
@@ -529,6 +586,10 @@ void Airplane::compile()
     solveGear();
     solve();
 
+    // Do this after solveGear, because it creates "gear" objects that
+    // we don't want to affect.
+    compileContactPoints();
+
     // Drop the gear (use a really big dt)
     setGearState(true, 1000000);
 }
index de0038b63058e546a7ec62502483c65be5de90f4..e1901af7696856757a21e3eeecc33145da411daa 100644 (file)
@@ -90,6 +90,8 @@ private:
     void applyDragFactor(float factor);
     void applyLiftRatio(float factor);
     float clamp(float val, float min, float max);
+    void addContactPoint(float* pos);
+    void compileContactPoints();
     float normFactor(float f);
 
     Model _model;
@@ -108,6 +110,7 @@ private:
     float _ballast;
 
     Vector _gears;
+    Vector _contacts; // non-gear ground contact points
     Vector _weights;
     Vector _surfs; // NON-wing Surfaces
 
index 22cc84a663dcb89b864eb82b97fed1ddcb97bb0e..bd8ecb9793991d3da58e665cd414422052fe0f8f 100644 (file)
@@ -208,6 +208,21 @@ float Wing::getGroundEffect(float* posOut)
     return span;
 }
 
+void Wing::getTip(float* tip)
+{
+    tip[0] = -Math::tan(_sweep);
+    tip[1] = Math::cos(_dihedral);
+    tip[2] = Math::sin(_dihedral);
+    Math::unit3(tip, tip);
+    Math::mul3(_length, tip, tip);
+    Math::add3(_base, tip, tip);
+}
+
+bool Wing::isMirrored()
+{
+    return _mirror;
+}
+
 void Wing::compile()
 {
     // Have we already been compiled?
index 861436e8a99fbce16f6351b18ebbdbec32fd0362..f6353ddc9c28a49942f5f4a424295ada9e74c0cb 100644 (file)
@@ -44,6 +44,10 @@ public:
     // Compile the thing into a bunch of Surface objects
     void compile();
 
+    void getTip(float* tip);
+
+    bool isMirrored();
+
     // Ground effect information
     float getGroundEffect(float* posOut);