Example #1
0
void InventorBuilder::addSingleArrow(const Vector3f& pt1, const Vector3f& pt2, short lineSize,
                                     float color_r,float color_g,float color_b, unsigned short /*linePattern*/)
{
    float l = (pt2 - pt1).Length();
    float cl = l / 10.0f;
    float cr = cl / 2.0f;

    Vector3f dir = pt2 - pt1;
    dir.Normalize();
    dir.Scale(l-cl, l-cl, l-cl);
    Vector3f pt2s = pt1 + dir;
    dir.Normalize();
    dir.Scale(l-cl/2.0f, l-cl/2.0f, l-cl/2.0f);
    Vector3f cpt = pt1 + dir;

    Vector3f rot = Vector3f(0.0f, 1.0f, 0.0f) % dir;
    rot.Normalize();
    float a = Vector3f(0.0f, 1.0f, 0.0f).GetAngle(dir);

    result << Base::blanks(indent) << "Separator { " << std::endl
           << Base::blanks(indent) << "  Material { diffuseColor "
           << color_r << " "<< color_g << " "<< color_b << "} "  << std::endl
           << Base::blanks(indent) << "  DrawStyle { lineWidth "
           << lineSize << "} " << std::endl
           << Base::blanks(indent) << "  Coordinate3 { " << std::endl
           << Base::blanks(indent) << "    point [ "
           <<        pt1.x << " " << pt1.y << " " << pt1.z << ","
           <<        pt2s.x << " " << pt2s.y << " " << pt2s.z
           << " ] " << std::endl
           << Base::blanks(indent) << "  } " << std::endl
           << Base::blanks(indent) << "  LineSet { } " << std::endl
           << Base::blanks(indent) << "  Transform { " << std::endl
           << Base::blanks(indent) << "    translation "
           << cpt.x << " " << cpt.y << " " << cpt.z << " " << std::endl
           << Base::blanks(indent) << "    rotation "
           << rot.x << " " << rot.y << " " << rot.z << " " << a << std::endl
           << Base::blanks(indent) << "  } " << std::endl
           << Base::blanks(indent) << "  Cone { bottomRadius " << cr << " height " << cl << "} " << std::endl
           << Base::blanks(indent) << "} " << std::endl;
}