]> git.mxchange.org Git - flightgear.git/commitdiff
Remove carrier wire and catapult configuration from the scenario file.
authorfrohlich <frohlich>
Mon, 22 Jun 2009 18:54:29 +0000 (18:54 +0000)
committerTim Moore <timoore@redhat.com>
Tue, 23 Jun 2009 08:54:10 +0000 (10:54 +0200)
This is now included in the model xml file.
So, wires and catapults also work even if they are not loaded by an AICarrier.

Modified Files:
  AICarrier.cxx AICarrier.hxx

src/AIModel/AICarrier.cxx
src/AIModel/AICarrier.hxx

index 4e98e29acc60e299b3119514ffb39bd909a8abfc..6ed0f2d38341ab8966ee289ddbc7d1207b3775d6 100644 (file)
 #include <string>
 #include <vector>
 
-#include <osg/Geode>
-#include <osg/Drawable>
-#include <osg/Transform>
-#include <osg/NodeVisitor>
-#include <osg/TemplatePrimitiveFunctor>
-
 #include <simgear/sg_inlines.h>
 #include <simgear/math/SGMath.hxx>
 #include <simgear/math/sg_geodesy.hxx>
-#include <simgear/scene/util/SGSceneUserData.hxx>
-#include <simgear/scene/bvh/BVHGroup.hxx>
-#include <simgear/scene/bvh/BVHLineGeometry.hxx>
 
 #include <math.h>
 #include <Main/util.hxx>
 
 #include "AICarrier.hxx"
 
-/// Hmm: move that kind of configuration into the model file???
-class LineCollector : public osg::NodeVisitor {
-    struct LinePrimitiveFunctor {
-        LinePrimitiveFunctor() : _lineCollector(0)
-        { }
-        void operator() (const osg::Vec3&, bool)
-        { }
-        void operator() (const osg::Vec3& v1, const osg::Vec3& v2, bool)
-        { if (_lineCollector) _lineCollector->addLine(v1, v2); }
-        void operator() (const osg::Vec3&, const osg::Vec3&, const osg::Vec3&,
-                         bool)
-        { }
-        void operator() (const osg::Vec3&, const osg::Vec3&, const osg::Vec3&,
-                         const osg::Vec3&, bool)
-        { }
-        LineCollector* _lineCollector;
-    };
-    
-public:
-    LineCollector() :
-        osg::NodeVisitor(osg::NodeVisitor::NODE_VISITOR,
-                         osg::NodeVisitor::TRAVERSE_ALL_CHILDREN)
-    { }
-    virtual void apply(osg::Geode& geode)
-    {
-        osg::TemplatePrimitiveFunctor<LinePrimitiveFunctor> pf;
-        pf._lineCollector = this;
-        for (unsigned i = 0; i < geode.getNumDrawables(); ++i) {
-            geode.getDrawable(i)->accept(pf);
-        }
-    }
-    virtual void apply(osg::Node& node)
-    {
-        traverse(node);
-    }
-    virtual void apply(osg::Transform& transform)
-    {
-        osg::Matrix matrix = _matrix;
-        if (transform.computeLocalToWorldMatrix(_matrix, this))
-            traverse(transform);
-        _matrix = matrix;
-    }
-    
-    const std::vector<SGLineSegmentf>& getLineSegments() const
-    { return _lineSegments; }
-    
-    void addLine(const osg::Vec3& v1, const osg::Vec3& v2)
-    {
-        // Trick to get the ends in the right order.
-        // Use the x axis in the original coordinate system. Choose the
-        // most negative x-axis as the one pointing forward
-        SGVec3f tv1(_matrix.preMult(v1));
-        SGVec3f tv2(_matrix.preMult(v2));
-        if (tv1[0] > tv2[0])
-            _lineSegments.push_back(SGLineSegmentf(tv1, tv2));
-        else
-            _lineSegments.push_back(SGLineSegmentf(tv2, tv1));
-    }
-
-    void addBVHElements(osg::Node& node, simgear::BVHLineGeometry::Type type)
-    {
-        if (_lineSegments.empty())
-            return;
-
-        SGSceneUserData* userData;
-        userData = SGSceneUserData::getOrCreateSceneUserData(&node);
-
-        simgear::BVHNode* bvNode = userData->getBVHNode();
-        if (!bvNode && _lineSegments.size() == 1) {
-            simgear::BVHLineGeometry* bvLine;
-            bvLine = new simgear::BVHLineGeometry(_lineSegments.front(), type);
-            userData->setBVHNode(bvLine);
-            return;
-        }
-
-        simgear::BVHGroup* group = new simgear::BVHGroup;
-        if (bvNode)
-            group->addChild(bvNode);
-
-        for (unsigned i = 0; i < _lineSegments.size(); ++i) {
-            simgear::BVHLineGeometry* bvLine;
-            bvLine = new simgear::BVHLineGeometry(_lineSegments[i], type);
-            group->addChild(bvLine);
-        }
-        userData->setBVHNode(group);
-    }
-    
-private:
-    osg::Matrix _matrix;
-    std::vector<SGLineSegmentf> _lineSegments;
-};
-
-class FGCarrierVisitor : public osg::NodeVisitor {
-public:
-    FGCarrierVisitor(FGAICarrier* carrier,
-                     const std::list<std::string>& wireObjects,
-                     const std::list<std::string>& catapultObjects) :
-        osg::NodeVisitor(osg::NodeVisitor::NODE_VISITOR,
-                         osg::NodeVisitor::TRAVERSE_ALL_CHILDREN),
-        mWireObjects(wireObjects),
-        mCatapultObjects(catapultObjects)
-    { }
-    virtual void apply(osg::Node& node)
-    {
-        if (std::find(mWireObjects.begin(), mWireObjects.end(), node.getName())
-            != mWireObjects.end()) {
-            LineCollector lineCollector;
-            node.accept(lineCollector);
-            simgear::BVHLineGeometry::Type type;
-            type = simgear::BVHLineGeometry::CarrierWire;
-            lineCollector.addBVHElements(node, type);
-        }
-        if (std::find(mCatapultObjects.begin(), mCatapultObjects.end(),
-                      node.getName()) != mCatapultObjects.end()) {
-            LineCollector lineCollector;
-            node.accept(lineCollector);
-            simgear::BVHLineGeometry::Type type;
-            type = simgear::BVHLineGeometry::CarrierCatapult;
-            lineCollector.addBVHElements(node, type);
-        }
-        
-        traverse(node);
-    }
-    
-private:
-    std::list<std::string> mWireObjects;
-    std::list<std::string> mCatapultObjects;
-};
-
 FGAICarrier::FGAICarrier() : FGAIShip(otCarrier) {
 }
 
@@ -207,22 +69,8 @@ void FGAICarrier::readFromScenario(SGPropertyNode* scFileNode) {
   } else
     flols_off = SGVec3d::zeros();
 
-  std::vector<SGPropertyNode_ptr> props = scFileNode->getChildren("wire");
+  std::vector<SGPropertyNode_ptr> props = scFileNode->getChildren("parking-pos");
   std::vector<SGPropertyNode_ptr>::const_iterator it;
-  for (it = props.begin(); it != props.end(); ++it) {
-    std::string s = (*it)->getStringValue();
-    if (!s.empty())
-      wire_objects.push_back(s);
-  }
-
-  props = scFileNode->getChildren("catapult");
-  for (it = props.begin(); it != props.end(); ++it) {
-    std::string s = (*it)->getStringValue();
-    if (!s.empty())
-      catapult_objects.push_back(s);
-  }
-
-  props = scFileNode->getChildren("parking-pos");
   for (it = props.begin(); it != props.end(); ++it) {
     string name = (*it)->getStringValue("name", "unnamed");
     // Transform to the right coordinate frame, configuration is done in
@@ -387,16 +235,6 @@ bool FGAICarrier::init(bool search_in_AI_path) {
     return true;
 }
 
-void FGAICarrier::initModel(osg::Node *node)
-{
-    // SG_LOG(SG_GENERAL, SG_BULK, "AICarrier::initModel()" );
-    FGAIShip::initModel(node);
-    // process the 3d model here
-    // mark some objects solid, mark the wires ...
-    FGCarrierVisitor carrierVisitor(this, wire_objects, catapult_objects);
-    node->accept(carrierVisitor);
-}
-
 void FGAICarrier::bind() {
     FGAIShip::bind();
 
index bd7bc405d578f2a8b46cbcafa37b5509f8a4d918..2bf64003a4e3a753eb3d3d8b888e8fde09c7254d 100644 (file)
@@ -68,7 +68,6 @@ public:
     bool OutsideBox();
 
     bool init(bool search_in_AI_path=false);
-    void initModel(osg::Node *node);
 
     virtual const char* getTypeString(void) const { return "carrier"; }
 
@@ -99,8 +98,6 @@ private:
 
 
 
-    list<string> wire_objects;        // List of wire object names
-    list<string> catapult_objects;    // List of catapult object names
     list<ParkPosition> ppositions;    // List of positions where an aircraft can start.
     string sign;                      // The sign of this carrier.