Пример #1
0
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
void ChTrackTestRig::AddVisualize_post(std::shared_ptr<ChBody> post_body,
                                       std::shared_ptr<ChBody> chassis_body,
                                       double length,
                                       double width,
                                       double height,
                                       const ChColor& color) {
    // Platform (on post body)
    auto base_box = std::make_shared<ChBoxShape>();
    base_box->GetBoxGeometry().SetLengths(ChVector<>(length, width, height));
    post_body->AddAsset(base_box);

    auto col = std::make_shared<ChColorAsset>();
    col->SetColor(color);
    post_body->AddAsset(col);

    // Piston (on post body)
    auto piston = std::make_shared<ChCylinderShape>();
    piston->GetCylinderGeometry().rad = width / 6.0;
    piston->GetCylinderGeometry().p1 = ChVector<>(0, 0, -height / 2.0);
    piston->GetCylinderGeometry().p2 = ChVector<>(0, 0, -height * 12.0);
    post_body->AddAsset(piston);  // add asset to post body

    // Post sleeve (on chassis/ground body)
    auto cyl = std::make_shared<ChCylinderShape>();
    cyl->GetCylinderGeometry().rad = width / 4.0;
    cyl->GetCylinderGeometry().p1 = post_body->GetPos() - ChVector<>(0, 0, 8 * height);
    cyl->GetCylinderGeometry().p2 = post_body->GetPos() - ChVector<>(0, 0, 16 * height);
    chassis_body->AddAsset(cyl);
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
void ChLinearDamperRWAssembly::AddVisualizationAssets(VisualizationType vis) {
    if (vis == VisualizationType::NONE)
        return;

    static const double threshold2 = 1e-6;
    double radius = GetArmVisRadius();

    if ((m_pA - m_pAW).Length2() > threshold2) {
        auto cyl = std::make_shared<ChCylinderShape>();
        cyl->GetCylinderGeometry().p1 = m_pA;
        cyl->GetCylinderGeometry().p2 = m_pAW;
        cyl->GetCylinderGeometry().rad = radius;
        m_arm->AddAsset(cyl);
    }

    if ((m_pA - m_pAC).Length2() > threshold2) {
        auto cyl = std::make_shared<ChCylinderShape>();
        cyl->GetCylinderGeometry().p1 = m_pA;
        cyl->GetCylinderGeometry().p2 = m_pAC;
        cyl->GetCylinderGeometry().rad = radius;
        m_arm->AddAsset(cyl);
    }

    if ((m_pA - m_pAS).Length2() > threshold2) {
        auto cyl = std::make_shared<ChCylinderShape>();
        cyl->GetCylinderGeometry().p1 = m_pA;
        cyl->GetCylinderGeometry().p2 = m_pAS;
        cyl->GetCylinderGeometry().rad = 0.75 * radius;
        m_arm->AddAsset(cyl);
    }

    // Revolute joint (arm-chassis)
    {
        auto cyl = std::make_shared<ChCylinderShape>();
        cyl->GetCylinderGeometry().p1 = m_pAC - radius * m_dY;
        cyl->GetCylinderGeometry().p2 = m_pAC + radius * m_dY;
        cyl->GetCylinderGeometry().rad = 1.5 * radius;
        m_arm->AddAsset(cyl);
    }

    // Revolute joint (arm-wheel)
    if ((m_pO - m_pAW).Length2() > threshold2) {
        auto cyl = std::make_shared<ChCylinderShape>();
        double len = (m_pO - m_pAW).Length();
        cyl->GetCylinderGeometry().p1 = m_pO;
        cyl->GetCylinderGeometry().p2 = m_pAW + (m_pAW - m_pO) * radius/len;
        cyl->GetCylinderGeometry().rad = radius;
        m_arm->AddAsset(cyl);
    }

    auto col = std::make_shared<ChColorAsset>();
    col->SetColor(ChColor(0.2f, 0.6f, 0.3f));
    m_arm->AddAsset(col);

    // Visualization of the shock (with default color)
    if (m_has_shock) {
        m_shock->AddAsset(std::make_shared<ChPointPointSegment>());
    }
}
void ChTrackShoeBandBushing::AddWebVisualization(std::shared_ptr<ChBody> segment) {
    segment->AddAsset(std::make_shared<ChColorAsset>(GetColor(m_index)));

    auto box = std::make_shared<ChBoxShape>();
    box->GetBoxGeometry().SetLengths(ChVector<>(m_seg_length, GetBeltWidth(), GetWebThickness()));
    segment->AddAsset(box);

    auto cyl = std::make_shared<ChCylinderShape>();
    double radius = GetWebThickness() / 4;
    cyl->GetCylinderGeometry().rad = radius;
    cyl->GetCylinderGeometry().p1 = ChVector<>(m_seg_length / 2, -GetBeltWidth() / 2 - 2 * radius, 0);
    cyl->GetCylinderGeometry().p2 = ChVector<>(m_seg_length / 2, +GetBeltWidth() / 2 + 2 * radius, 0);
    segment->AddAsset(cyl);
}
Пример #4
0
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
void ChSingleIdler::AddVisualizationAssets(VisualizationType vis) {
    ChIdler::AddVisualizationAssets(vis);

    if (vis != VisualizationType::PRIMITIVES)
        return;

    double radius = GetWheelRadius();
    double width = GetWheelWidth();

    auto cyl = std::make_shared<ChCylinderShape>();
    cyl->GetCylinderGeometry().p1 = ChVector<>(0, width / 2, 0);
    cyl->GetCylinderGeometry().p2 = ChVector<>(0, -width / 2, 0);
    cyl->GetCylinderGeometry().rad = radius;
    m_wheel->AddAsset(cyl);

    auto tex = std::make_shared<ChTexture>();
    tex->SetTextureFilename(chrono::GetChronoDataFile("bluwhite.png"));
    m_wheel->AddAsset(tex);
}
Пример #5
0
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
void ChPitmanArm::AddVisualizationAssets(VisualizationType vis) {
    if (vis == VisualizationType::NONE)
        return;

    // Visualization for link
    {
        auto cyl = std::make_shared<ChCylinderShape>();
        cyl->GetCylinderGeometry().p1 = m_pP;
        cyl->GetCylinderGeometry().p2 = m_pI;
        cyl->GetCylinderGeometry().rad = getSteeringLinkRadius();
        m_link->AddAsset(cyl);

        auto cyl_P = std::make_shared<ChCylinderShape>();
        cyl_P->GetCylinderGeometry().p1 = m_pP;
        cyl_P->GetCylinderGeometry().p2 = m_pTP;
        cyl_P->GetCylinderGeometry().rad = getSteeringLinkRadius();
        m_link->AddAsset(cyl_P);

        auto cyl_I = std::make_shared<ChCylinderShape>();
        cyl_I->GetCylinderGeometry().p1 = m_pI;
        cyl_I->GetCylinderGeometry().p2 = m_pTI;
        cyl_I->GetCylinderGeometry().rad = getSteeringLinkRadius();
        m_link->AddAsset(cyl_I);

        auto col = std::make_shared<ChColorAsset>();
        col->SetColor(ChColor(0.2f, 0.7f, 0.7f));
        m_link->AddAsset(col);
    }

    // Visualization for arm
    {
        auto cyl = std::make_shared<ChCylinderShape>();
        cyl->GetCylinderGeometry().p1 = m_pC;
        cyl->GetCylinderGeometry().p2 = m_pL;
        cyl->GetCylinderGeometry().rad = getPitmanArmRadius();
        m_arm->AddAsset(cyl);

        auto col = std::make_shared<ChColorAsset>();
        col->SetColor(ChColor(0.7f, 0.7f, 0.2f));
        m_arm->AddAsset(col);
    }

    // Visualization for rev-sph link
    m_revsph->AddAsset(std::make_shared<ChPointPointSegment>());
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
void ChDoubleWishboneReduced::AddVisualizationUpright(std::shared_ptr<ChBody> upright,
                                                      const ChVector<> pt_C,
                                                      const ChVector<> pt_U,
                                                      const ChVector<> pt_L,
                                                      const ChVector<> pt_T,
                                                      double radius) {
    static const double threshold2 = 1e-6;

    // Express hardpoint locations in body frame.
    ChVector<> p_C = upright->TransformPointParentToLocal(pt_C);
    ChVector<> p_U = upright->TransformPointParentToLocal(pt_U);
    ChVector<> p_L = upright->TransformPointParentToLocal(pt_L);
    ChVector<> p_T = upright->TransformPointParentToLocal(pt_T);

    if ((p_L - p_C).Length2() > threshold2) {
        auto cyl_L = std::make_shared<ChCylinderShape>();
        cyl_L->GetCylinderGeometry().p1 = p_L;
        cyl_L->GetCylinderGeometry().p2 = p_C;
        cyl_L->GetCylinderGeometry().rad = radius;
        upright->AddAsset(cyl_L);
    }

    if ((p_U - p_C).Length2() > threshold2) {
        auto cyl_U = std::make_shared<ChCylinderShape>();
        cyl_U->GetCylinderGeometry().p1 = p_U;
        cyl_U->GetCylinderGeometry().p2 = p_C;
        cyl_U->GetCylinderGeometry().rad = radius;
        upright->AddAsset(cyl_U);
    }

    if ((p_T - p_C).Length2() > threshold2) {
        auto cyl_T = std::make_shared<ChCylinderShape>();
        cyl_T->GetCylinderGeometry().p1 = p_T;
        cyl_T->GetCylinderGeometry().p2 = p_C;
        cyl_T->GetCylinderGeometry().rad = radius;
        upright->AddAsset(cyl_T);
    }

    auto col = std::make_shared<ChColorAsset>();
    col->SetColor(ChColor(0.2f, 0.2f, 0.6f));
    upright->AddAsset(col);
}
Пример #7
0
    float csBulletCollider::GetVolume ()
    {
        switch (geomType)
        {
        case BOX_COLLIDER_GEOMETRY:
        {
            csVector3 size;
            GetBoxGeometry (size);
            return size[0] * size[1] * size[2];
        }

        case SPHERE_COLLIDER_GEOMETRY:
        {
            csSphere sphere;
            GetSphereGeometry (sphere);
            return 1.333333f * PI * sphere.GetRadius () * sphere.GetRadius ()
                   * sphere.GetRadius ();
        }

        case CYLINDER_COLLIDER_GEOMETRY:
        {
            float length;
            float radius;
            GetCylinderGeometry (length, radius);
            return PI * radius * radius * length;
        }

        case CAPSULE_COLLIDER_GEOMETRY:
        {
            float length;
            float radius;
            GetCapsuleGeometry (length, radius);
            return PI * radius * radius * length
                   + 1.333333f * PI * radius * radius * radius;
        }

        case CONVEXMESH_COLLIDER_GEOMETRY:
        {
            if (vertexCount == 0)
                return 0.0f;

            float volume = 0.0f;
            int faceCount = (int)vertexCount / 3;
            btVector3 origin = vertices[indices[0]];
            for (int i = 1; i < faceCount; i++)
            {
                int index = i * 3;
                volume += fabsl (btDot
                                 (vertices[indices[index]] - origin,
                                  btCross (vertices[indices[index + 1]] - origin,
                                           vertices[indices[index + 2]] - origin)));
            }

            return volume / 6.0f;
        }

        case TRIMESH_COLLIDER_GEOMETRY:
        {
            if (vertexCount == 0)
                return 0.0f;

            // TODO: this is a really rough estimation
            btVector3 center;
            btScalar radius;
            shape->getBoundingSphere (center, radius);
            return 1.333333f * PI * radius * radius * radius;
        }

        default:
            return 0.0f;
        }

        return 0.0f;
    }
Пример #8
0
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
void ChTrackShoeSinglePin::AddVisualizationAssets(VisualizationType vis) {
    if (vis == VisualizationType::NONE)
        return;

    double pitch = GetPitch();

    double front_cyl_loc = GetFrontCylinderLoc();
    double rear_cyl_loc = GetRearCylinderLoc();
    double cyl_radius = GetCylinderRadius();

    const ChVector<>& pad_box_dims = GetPadBoxDimensions();
    const ChVector<>& guide_box_dims = GetGuideBoxDimensions();

    double p0y = 2.1 * (pad_box_dims.y() / 2);
    double p1y = 1.5 * (pad_box_dims.y() / 2);
    double p2y = 0.5 * (pad_box_dims.y() / 2);

    // Render the revolute pin
    auto rev_axis = std::make_shared<ChCylinderShape>();
    rev_axis->GetCylinderGeometry().p1 = ChVector<>(pitch / 2, -p0y, 0);
    rev_axis->GetCylinderGeometry().p2 = ChVector<>(pitch / 2, p0y, 0);
    rev_axis->GetCylinderGeometry().rad = cyl_radius / 1.5;
    m_shoe->AddAsset(rev_axis);

    // Render boxes between pins
    auto box_L = std::make_shared<ChBoxShape>();
    box_L->GetBoxGeometry().SetLengths(ChVector<>(pitch - 1.5 * cyl_radius, 0.95 * (p0y - p1y), pad_box_dims.z() / 3));
    box_L->GetBoxGeometry().Pos = ChVector<>(0, +0.95 * (p0y + p1y) / 2, 0);
    m_shoe->AddAsset(box_L);

    auto box_R = std::make_shared<ChBoxShape>();
    box_R->GetBoxGeometry().SetLengths(ChVector<>(pitch - 1.5 * cyl_radius, 0.95 * (p0y - p1y), pad_box_dims.z() / 3));
    box_R->GetBoxGeometry().Pos = ChVector<>(0, -0.95 * (p0y + p1y) / 2, 0);
    m_shoe->AddAsset(box_R);

    // Render the contact cylinders (for contact with sprocket)
    auto cyl_FR = std::make_shared<ChCylinderShape>();
    cyl_FR->GetCylinderGeometry().p1 = ChVector<>(front_cyl_loc, -p1y, 0);
    cyl_FR->GetCylinderGeometry().p2 = ChVector<>(front_cyl_loc, -p2y, 0);
    cyl_FR->GetCylinderGeometry().rad = cyl_radius;
    m_shoe->AddAsset(cyl_FR);

    auto cyl_RR = std::make_shared<ChCylinderShape>();
    cyl_RR->GetCylinderGeometry().p1 = ChVector<>(rear_cyl_loc, -p1y, 0);
    cyl_RR->GetCylinderGeometry().p2 = ChVector<>(rear_cyl_loc, -p2y, 0);
    cyl_RR->GetCylinderGeometry().rad = cyl_radius;
    m_shoe->AddAsset(cyl_RR);

    auto cyl_FL = std::make_shared<ChCylinderShape>();
    cyl_FL->GetCylinderGeometry().p1 = ChVector<>(front_cyl_loc, p1y, 0);
    cyl_FL->GetCylinderGeometry().p2 = ChVector<>(front_cyl_loc, p2y, 0);
    cyl_FL->GetCylinderGeometry().rad = cyl_radius;
    m_shoe->AddAsset(cyl_FL);

    auto cyl_RL = std::make_shared<ChCylinderShape>();
    cyl_RL->GetCylinderGeometry().p1 = ChVector<>(rear_cyl_loc, p1y, 0);
    cyl_RL->GetCylinderGeometry().p2 = ChVector<>(rear_cyl_loc, p2y, 0);
    cyl_RL->GetCylinderGeometry().rad = cyl_radius;
    m_shoe->AddAsset(cyl_RL);

    // Render the pad contact box
    auto box_shoe = std::make_shared<ChBoxShape>();
    box_shoe->GetBoxGeometry().SetLengths(pad_box_dims);
    box_shoe->GetBoxGeometry().Pos = GetPadBoxLocation();
    m_shoe->AddAsset(box_shoe);

    // Render the guiding pin contact box
    auto box_pin = std::make_shared<ChBoxShape>();
    box_pin->GetBoxGeometry().SetLengths(guide_box_dims);
    box_pin->GetBoxGeometry().Pos = GetGuideBoxLocation();
    m_shoe->AddAsset(box_pin);

    // Assign color (based on track shoe index)
    auto col = std::make_shared<ChColorAsset>();
    if (m_index == 0)
        col->SetColor(ChColor(0.6f, 0.3f, 0.3f));
    else if (m_index % 2 == 0)
        col->SetColor(ChColor(0.3f, 0.6f, 0.3f));
    else
        col->SetColor(ChColor(0.3f, 0.3f, 0.6f));
    m_shoe->AddAsset(col);
}