Beispiel #1
0
TrackingBody::TrackingBody(const std::string &name)
    : InputSource(name, "Body")
    , m_valid(false)
    , m_oldValid(m_valid)
    , m_baseBody(NULL)
{
    const std::string conf = config();

    m_idx = coCoviseConfig::getInt("bodyIndex", conf, 0);
    if (m_idx >= device()->numBodies())
    {
        std::cerr << "TrackingBody: body index " << m_idx << " out of range - " << device()->numBodies() << " bodies" << std::endl;
    }

    //Offset&Orientation reading and matrix creating

    float trans[3];
    float rot[3];

    trans[0] = coCoviseConfig::getFloat("x", conf + ".Offset", 0);
    trans[1] = coCoviseConfig::getFloat("y", conf + ".Offset", 0);
    trans[2] = coCoviseConfig::getFloat("z", conf + ".Offset", 0);

    rot[0] = coCoviseConfig::getFloat("h", conf + ".Orientation", 0);
    rot[1] = coCoviseConfig::getFloat("p", conf + ".Orientation", 0);
    rot[2] = coCoviseConfig::getFloat("r", conf + ".Orientation", 0);

    std::string baseBody = coCoviseConfig::getEntry("bodyOffset", conf);
    if (!baseBody.empty())
    {
        std::cout << "body " << name << " is based on " << baseBody << std::endl;
        m_baseBody = Input::instance()->getBody(baseBody);
        if (!m_baseBody)
        {
            std::cout << "did not find base body " << baseBody << " for body " << name << std::endl;
            std::cerr << "did not find base body " << baseBody << " for body " << name << std::endl;
        }
    }

#if 0
   std::cout<<name<<" is "<<device<<"; dev body no "<<m_idx
      <<" Offset=("<<trans[0]<<" "<<trans[1]<<" "<<trans[2]<<") "
      <<" Orientation=("<<rot[0]<<" "<<rot[1]<<" "<<rot[2]<<") "<<std::endl;
#endif

    //Create rotation matrix (from OpenVRUI/osg/mathUtils.h)
    MAKE_EULER_MAT(m_deviceOffsetMat, rot[0], rot[1], rot[2]);
    //fprintf(stderr, "offset from device('%d) %f %f %f\n", device_ID, deviceOffsets[device_ID].trans[0], deviceOffsets[device_ID].trans[1], deviceOffsets[device_ID].trans[2]);

    osg::Matrix translationMat;
    translationMat.makeTranslate(trans[0], trans[1], trans[2]);
    m_deviceOffsetMat.postMult(translationMat); //add translation
    m_mat = m_deviceOffsetMat;
    m_oldMat = m_mat;

    updateRelative();
}
Beispiel #2
0
void TempoText::textChanged()
      {
      if (!_followText)
            return;
      // cache regexp, they are costly to create
      static QHash<QString, QRegExp> regexps;
      static QHash<QString, QRegExp> regexps2;
      QString s = plainText();
      s.replace(",", ".");
      s.replace("<sym>space</sym>"," ");
      for (const TempoPattern& pa : tp) {
            QRegExp re;
            if (!regexps.contains(pa.pattern)) {
                  re = QRegExp(QString("%1\\s*=\\s*(\\d+[.]{0,1}\\d*)\\s*").arg(pa.pattern));
                  regexps[pa.pattern] = re;
                  }
            re = regexps.value(pa.pattern);
            if (re.indexIn(s) != -1) {
                  QStringList sl = re.capturedTexts();
                  if (sl.size() == 2) {
                        qreal nt = qreal(sl[1].toDouble()) * pa.f;
                        if (nt != _tempo) {
                              setTempo(qreal(sl[1].toDouble()) * pa.f);
                              _relative = 1.0;
                              _isRelative = false;
                              updateScore();
                              }
                        break;
                        }
                  }
            else {
                 for (const TempoPattern& pa2 : tp) {
                       QString key = QString("%1_%2").arg(pa.pattern).arg(pa2.pattern);
                       QRegExp re2;
                       if (!regexps2.contains(key)) {
                             re2 = QRegExp(QString("%1\\s*=\\s*%2\\s*").arg(pa.pattern).arg(pa2.pattern));
                             regexps2[key] = re2;
                             }
                       re2 = regexps2.value(key);
                       if (re2.indexIn(s) != -1) {
                             _relative = pa2.f / pa.f;
                             _isRelative = true;
                             updateRelative();
                             updateScore();
                             return;
                             }
                       }
                  }
            }
      }
Beispiel #3
0
void TempoText::textChanged()
      {
      if (!_followText)
            return;
      QString s = plainText();
      s.replace(",", ".");
      s.replace("<sym>space</sym>"," ");
      for (const TempoPattern& pa : tp) {
            QRegExp re(QString(pa.pattern)+"\\s*=\\s*(\\d+[.]{0,1}\\d*)\\s*");
            if (re.indexIn(s) != -1) {
                  QStringList sl = re.capturedTexts();
                  if (sl.size() == 2) {
                        qreal nt = qreal(sl[1].toDouble()) * pa.f;
                        if (nt != _tempo) {
                              setTempo(qreal(sl[1].toDouble()) * pa.f);
                              _relative = 1.0;
                              _isRelative = false;
                              updateScore();
                              }
                        break;
                        }
                  }
            else {
                 for (const TempoPattern& pa2 : tp) {
                       QRegExp re(QString("%1\\s*=\\s*%2\\s*").arg(pa.pattern).arg(pa2.pattern));
                       if (re.indexIn(s) != -1) {
                             _relative = pa2.f / pa.f;
                             _isRelative = true;
                             updateRelative();
                             updateScore();
                             return;
                             }
                       }
                  }
            }
      }