当前位置: 首页>>代码示例>>C++>>正文


C++ BoundingBox::getLength方法代码示例

本文整理汇总了C++中BoundingBox::getLength方法的典型用法代码示例。如果您正苦于以下问题:C++ BoundingBox::getLength方法的具体用法?C++ BoundingBox::getLength怎么用?C++ BoundingBox::getLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BoundingBox的用法示例。


在下文中一共展示了BoundingBox::getLength方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: osgColor

osg::Drawable *ClampNode::createBrick(void) const {
    // Get the brick
    Clamp* clamp = static_cast<Clamp*>(_lego);
    
    // Get brick color
    QColor color = clamp->getColor();

    // Get clamp bounding box
    clamp->calculateBoundingBox();
    BoundingBox bb = clamp->getBoundingBox();
    // Get integer sizes
    int width = bb.getWidth();
    int length = bb.getLength();
    int height = bb.getHeight();

    // Get real position, according to tile size
    double mw = (-width)*Lego::length_unit/2;
    double mwpm = (-width)*Lego::length_unit/2+Lego::height_unit/2;
    double mwp = (-width)*Lego::length_unit/2+0.93*Lego::height_unit;
    double pw = (width)*Lego::length_unit/2;
    double pwm = (width)*Lego::length_unit/2-Lego::height_unit/2;
    double ml = (-length)*Lego::length_unit/2;
    double mlp = (-length+0.5)*Lego::length_unit/2;
    double pl = (length)*Lego::length_unit/2;
    double plm = (length-0.5)*Lego::length_unit/2;
    double mh = (-height)*Lego::height_unit/2;
    double mhp = (-height)*Lego::height_unit/2+2*Lego::plot_top_height;
    double mhpm = (-height)*Lego::height_unit/2+Lego::plot_top_height;
    double phm = (height)*Lego::height_unit/2-Lego::height_unit/2;
    double phmp = (height)*Lego::height_unit/2-0.5*Lego::height_unit/2;
    
    // Create 3 vertices
    osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array;
    osg::Vec3 v0(ml, mw, mh);
    osg::Vec3 v1(pl, mw, mh);
    osg::Vec3 v2(pl, pw, mh);
    osg::Vec3 v3(ml, pw, mh);
    osg::Vec3 v4(ml, pw, mhp);
    osg::Vec3 v5(pl, pw, mhp);
    osg::Vec3 v6(pl, mw, mhp);
    osg::Vec3 v7(ml, mw, mhp);
    osg::Vec3 v8(mlp, mw, mhp);
    osg::Vec3 v9(mlp, mw, phm);
    osg::Vec3 v10(ml, mw, phm);
    osg::Vec3 v11(ml, mwp, phmp);
    osg::Vec3 v12(mlp, mwp, phmp);
    osg::Vec3 v13(mlp, pw, mhp);
    osg::Vec3 v14(plm, mw, mhp);
    osg::Vec3 v15(plm, mw, phm);
    osg::Vec3 v16(pl, mw, phm);
    osg::Vec3 v17(pl, mwp, phmp);
    osg::Vec3 v18(plm, mwp, phmp);
    osg::Vec3 v19(plm, pw, mhp);
    osg::Vec3 v20(mlp, mwpm, mh);
    osg::Vec3 v21(plm, mwpm, mh);
    osg::Vec3 v22(plm, pwm, mh);
    osg::Vec3 v23(mlp, pwm, mh);
    osg::Vec3 v24(mlp, mwpm, mhpm);
    osg::Vec3 v25(plm, mwpm, mhpm);
    osg::Vec3 v26(plm, pwm, mhpm);
    osg::Vec3 v27(mlp, pwm, mhpm);
    
    // Create 1 faces, 0 faces are quads splitted into two triangles
    // NB: Down face is transparent, we don't even create it

    // Bottom
    vertices->push_back(v3);
    vertices->push_back(v2);
    vertices->push_back(v1);
    vertices->push_back(v0);
    // Bottom hole
    vertices->push_back(v20);
    vertices->push_back(v21);
    vertices->push_back(v22);
    vertices->push_back(v23);
    // Bottom far
    vertices->push_back(v24);
    vertices->push_back(v25);
    vertices->push_back(v26);
    vertices->push_back(v27);

    // Front face
    vertices->push_back(v2);
    vertices->push_back(v3);
    vertices->push_back(v4);
    vertices->push_back(v5);

    // Back face
    vertices->push_back(v0);
    vertices->push_back(v1);
    vertices->push_back(v6);
    vertices->push_back(v7);

    // Left bottom face
    vertices->push_back(v0);
    vertices->push_back(v3);
    vertices->push_back(v4);
    vertices->push_back(v7);

    // Right bottom face
//.........这里部分代码省略.........
开发者ID:vmichele,项目名称:LEGO_CREATOR,代码行数:101,代码来源:ClampNode.cpp

示例2: createGeode

void ClampNode::createGeode(void) {
    // Remove children
    removeChildren(0, getNumChildren());
    
    // Create geode
    osg::ref_ptr<osg::Geode> geode = new osg::Geode;
    addChild(geode);
    geode->addDrawable(createBrick());

    // Distance between two plot center
    double distPlot = Lego::length_unit;

    // Get the brick
    Clamp* clamp = static_cast<Clamp*>(_lego);

    // Get clamp bounding box
    clamp->calculateBoundingBox();
    BoundingBox bb = clamp->getBoundingBox();
    // Get integer sizes
    int width = bb.getWidth();
    int length = bb.getLength();
    int height = bb.getHeight();

    // Calculate x max and y max for plots
    double xminb = -(length-2)*Lego::length_unit/2;
    double yminb = -(width-1)*Lego::length_unit/2;

    double w = (-width)*Lego::length_unit/2+Lego::height_unit/2;
    double h = (height)*Lego::height_unit/2-Lego::height_unit/2;

    // Add cylinder parts

    // Create geode
    osg::ref_ptr<osg::Geode> cylinderGeode = new osg::Geode;

    // Create drawable cylinder
    osg::Drawable* cylinderPart = makeCylinder(0, w, h, length*Lego::length_unit, Lego::height_unit/2);
    // Add drawable to geode
    cylinderGeode->addDrawable(cylinderPart);

    // Create top and bottom cylinder
    osg::Drawable* topPart = makeDisk(0, w, h, Lego::height_unit/2, length*Lego::length_unit, true);
    osg::Drawable* bottomPart = makeDisk(0, w, h, Lego::height_unit/2, length*Lego::length_unit, false);
    // Add drawables to geode
    cylinderGeode->addDrawable(topPart);
    cylinderGeode->addDrawable(bottomPart);

    // Create matrix transform to rotate cylinder
    osg::ref_ptr<osg::MatrixTransform> mt = new osg::MatrixTransform;
    // Create matrix to handle rotation
    osg::Matrix matRot, matTrans;
    // Make PI/2 rotation according to y axis
    matRot.makeRotate(M_PI_2, osg::Vec3(0.f, 1.f, 0.f));
    // Translate
    matTrans.makeTranslate(-length*Lego::length_unit/4-Lego::height_unit/4, 0, 3*height*Lego::height_unit/8);
    // Set matrix transform matrix
    mt->setMatrix(matRot*matTrans);
    // Add geode to matrix transform
    mt->addChild(cylinderGeode.get());
    // Add matrix transform
    addChild(mt);

    // Add bottom cylinders iteratively
    for (int i = 0; i < length-1; i++) {
        for (int j = 0; j < width; j++) {
            double radiusX = xminb + i*distPlot;
            double radiusY = yminb + j*distPlot;

            addChild(createBottomCylinder(radiusX, radiusY, 0.5, true, (-height+0.5)*Lego::height_unit/2));
        }
    }
}
开发者ID:vmichele,项目名称:LEGO_CREATOR,代码行数:72,代码来源:ClampNode.cpp


注:本文中的BoundingBox::getLength方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。