Exemple #1
0
   void CCylinderEntity::Init(TConfigurationNode& t_tree) {
      try {
         /* Init parent */
         CEntity::Init(t_tree);
         /* Parse XML to get the radius */
         GetNodeAttribute(t_tree, "radius", m_fRadius);
         /* Parse XML to get the height */
         GetNodeAttribute(t_tree, "height", m_fHeight);
         /* Parse XML to get the movable attribute */
         GetNodeAttribute(t_tree, "movable", m_bMovable);
         if(m_bMovable) {
            /* Parse XML to get the mass */
            GetNodeAttribute(t_tree, "mass", m_fMass);
         }
         else {
            m_fMass = 0.0f;
         }
         /* Parse XML to get the visible attribute */
         GetNodeAttributeOrDefault(t_tree, "visible", m_bVisible, m_bVisible);
         /* Init LED equipped entity component */
         m_pcLEDEquippedEntity->Init(t_tree);
         if(NodeExists(t_tree, "leds")) {
            TConfigurationNode& tLEDs = GetNode(t_tree, "leds");
            /* Go through the led entries */
            CVector3 cPosition;
            CColor cColor;
            TConfigurationNodeIterator itLED("led");
            for(itLED = itLED.begin(&tLEDs);
                itLED != itLED.end();
                ++itLED) {
               GetNodeAttribute(*itLED, "position", cPosition);
               GetNodeAttribute(*itLED, "color", cColor);
               m_vecBaseLEDPositions.push_back(cPosition);
               m_pcLEDEquippedEntity->AddLed(cPosition, cColor);
            }
         }
         /* Create embodied entity using parsed data */
         m_pcEmbodiedEntity = new CCylinderEmbodiedEntity(this, m_fRadius, m_fHeight);
         m_pcEmbodiedEntity->Init(t_tree);

         UpdateComponents();
      }
      catch(CARGoSException& ex) {
         THROW_ARGOSEXCEPTION_NESTED("Failed to initialize the cylinder entity.", ex);
      }
   }
 void CDirectionalLEDEquippedEntity::Init(TConfigurationNode& t_tree) {
    try {
       /* Init parent */
       CComposableEntity::Init(t_tree);
       /* Go through the led entries */
       TConfigurationNodeIterator itLED("directional_led");
       for(itLED = itLED.begin(&t_tree);
           itLED != itLED.end();
           ++itLED) {
          /* Initialise the LED using the XML */
          CDirectionalLEDEntity* pcLED = new CDirectionalLEDEntity(this);
          pcLED->Init(*itLED);
          CVector3 cPositionOffset;
          GetNodeAttribute(*itLED, "position", cPositionOffset);
          CQuaternion cOrientationOffset;
          GetNodeAttribute(*itLED, "orientation", cOrientationOffset);
          /* Parse and look up the anchor */
          std::string strAnchorId;
          GetNodeAttribute(*itLED, "anchor", strAnchorId);
          /*
           * NOTE: here we get a reference to the embodied entity
           * This line works under the assumption that:
           * 1. the DirectionalLEDEquippedEntity has a parent;
           * 2. the parent has a child whose id is "body"
           * 3. the "body" is an embodied entity
           * If any of the above is false, this line will bomb out.
           */
          CEmbodiedEntity& cBody =
             GetParent().GetComponent<CEmbodiedEntity>("body");
          /* Add the LED to this container */
          m_vecInstances.emplace_back(*pcLED,
                                      cBody.GetAnchor(strAnchorId),
                                      cPositionOffset,
                                      cOrientationOffset);
          AddComponent(*pcLED);
       }
       UpdateComponents();
    }
    catch(CARGoSException& ex) {
       THROW_ARGOSEXCEPTION_NESTED("Failed to initialize directional LED equipped entity \"" <<
                                   GetContext() + GetId() << "\".", ex);
    }
 }