Exemplo n.º 1
0
//==============================================================================
void LineSegmentShapeDrawable::refresh(bool firstTime)
{
  if(mLineSegmentShape->getDataVariance() == dart::dynamics::Shape::STATIC)
    setDataVariance(osg::Object::STATIC);
  else
    setDataVariance(osg::Object::DYNAMIC);

  const std::vector<Eigen::Vector3d>& vertices =
      mLineSegmentShape->getVertices();

  const Eigen::aligned_vector<Eigen::Vector2i>& connections =
      mLineSegmentShape->getConnections();

  if(   mLineSegmentShape->checkDataVariance(dart::dynamics::Shape::DYNAMIC_ELEMENTS)
     || firstTime)
  {
    osg::ref_ptr<osg::DrawElementsUInt> elements =
        new osg::DrawElementsUInt(GL_LINES);
    elements->reserve(2*connections.size());

    for(size_t i=0; i < connections.size(); ++i)
    {
      const Eigen::Vector2i& c = connections[i];
      elements->push_back(c[0]);
      elements->push_back(c[1]);
    }

    addPrimitiveSet(elements);
  }

  if(   mLineSegmentShape->checkDataVariance(dart::dynamics::Shape::DYNAMIC_VERTICES)
     || mLineSegmentShape->checkDataVariance(dart::dynamics::Shape::DYNAMIC_ELEMENTS)
     || firstTime)
  {
    if(mVertices->size() != vertices.size())
      mVertices->resize(vertices.size());

    for(size_t i=0; i<vertices.size(); ++i)
      (*mVertices)[i] = eigToOsgVec3(vertices[i]);

    setVertexArray(mVertices);
  }

  if(   mLineSegmentShape->checkDataVariance(dart::dynamics::Shape::DYNAMIC_COLOR)
     || firstTime)
  {
    if(mColors->size() != 1)
      mColors->resize(1);

    (*mColors)[0] = eigToOsgVec4(mLineSegmentShape->getRGBA());

    setColorArray(mColors, osg::Array::BIND_OVERALL);
  }
}
Exemplo n.º 2
0
//==============================================================================
void BoxShapeDrawable::refresh(bool firstTime)
{
  if(mBoxShape->getDataVariance() == dart::dynamics::Shape::STATIC)
    setDataVariance(osg::Object::STATIC);
  else
    setDataVariance(osg::Object::DYNAMIC);

  if(mBoxShape->checkDataVariance(dart::dynamics::Shape::DYNAMIC_PRIMITIVE)
     || firstTime)
  {
    const Eigen::Vector3d& d = mBoxShape->getSize();
    osg::ref_ptr<osg::Box> osg_shape = new osg::Box(osg::Vec3(0,0,0),
                                                    d[0], d[1], d[2]);
    setShape(osg_shape);
    dirtyDisplayList();
  }

  if(mBoxShape->checkDataVariance(dart::dynamics::Shape::DYNAMIC_COLOR)
     || firstTime)
  {
    setColor(eigToOsgVec4(mBoxShape->getRGBA()));
  }
}
Exemplo n.º 3
0
//==============================================================================
void CylinderShapeDrawable::refresh(bool firstTime)
{
  if(mCylinderShape->getDataVariance() == dart::dynamics::Shape::STATIC)
    setDataVariance(osg::Object::STATIC);
  else
    setDataVariance(osg::Object::DYNAMIC);

  if(mCylinderShape->checkDataVariance(dart::dynamics::Shape::DYNAMIC_PRIMITIVE)
     || firstTime)
  {
    double R = mCylinderShape->getRadius();
    double h = mCylinderShape->getHeight();
    osg::ref_ptr<osg::Cylinder> osg_shape =
        new osg::Cylinder(osg::Vec3(0,0,0), R, h);
    setShape(osg_shape);
    dirtyDisplayList();
  }

  if(mCylinderShape->checkDataVariance(dart::dynamics::Shape::DYNAMIC_COLOR)
     || firstTime)
  {
    setColor(eigToOsgVec4(mCylinderShape->getRGBA()));
  }
}
Exemplo n.º 4
0
//==============================================================================
void EllipsoidShapeDrawable::refresh(bool firstTime)
{
  if(mEllipsoidShape->getDataVariance() == dart::dynamics::Shape::STATIC)
    setDataVariance(::osg::Object::STATIC);
  else
    setDataVariance(::osg::Object::DYNAMIC);

  if(mEllipsoidShape->checkDataVariance(dart::dynamics::Shape::DYNAMIC_PRIMITIVE)
     || firstTime)
  {
    ::osg::ref_ptr<::osg::Sphere> osg_shape = nullptr;
    osg_shape = new ::osg::Sphere(::osg::Vec3(0,0,0),
                          0.5*smallestComponent(mEllipsoidShape->getSize()));

    setShape(osg_shape);
    dirtyDisplayList();
  }

  if(mEllipsoidShape->checkDataVariance(dart::dynamics::Shape::DYNAMIC_COLOR)
     || firstTime)
  {
    setColor(eigToOsgVec4(mVisualAspect->getRGBA()));
  }
}