1

I have the code below. I got the idea from a tutorial but my code does not show anything when run. The goal is to draw Wall in 3d. My guess is that my points may be off but I am not sure how best to pick points, and also scale.

void BuildWall(osg::Group* root)
{

    osg::Geode* WallGeode = new osg::Geode();
    osg::Geometry* WallGeometry = new osg::Geometry();

    WallGeode->addDrawable(WallGeometry);
    //add the Node to the root Node
    root->addChild(WallGeode);
    //specify vertices
    osg::Vec3Array* WallVertices = new osg::Vec3Array;
    WallVertices->push_back( osg::Vec3(0, 0, 0) ); // front left
    WallVertices->push_back( osg::Vec3(10, 0, 0) ); // front right
    WallVertices->push_back( osg::Vec3(10,10, 0) ); // back right
    WallVertices->push_back( osg::Vec3(0,10, 0) ); // back left 
    WallGeometry->setVertexArray( WallVertices );

    //specify the kind of geometry we want to draw here
    osg::DrawElementsUInt* WallBase = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0);
    //specify the order we want to draw the base of our geometry
    WallBase->push_back(3);
    WallBase->push_back(2);
    WallBase->push_back(1);
    WallBase->push_back(0);
    WallGeometry->addPrimitiveSet(WallBase);

    //Declare and load an array of Vec4 elements to store colors.
    osg::Vec4Array* colors = new osg::Vec4Array;
    colors->push_back(osg::Vec4(1.0f, 0.0f, 0.0f, 1.0f) ); //index 0 red
    colors->push_back(osg::Vec4(0.0f, 1.0f, 0.0f, 1.0f) ); //index 1 green
    colors->push_back(osg::Vec4(0.0f, 0.0f, 1.0f, 1.0f) ); //index 2 blue
    colors->push_back(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f) ); //index 3 white
    //colors->push_back(osg::Vec4(1.0f, 0.0f, 0.0f, 1.0f) ); //index 4 red

    WallGeometry->setColorArray(colors);
    WallGeometry->setColorBinding(osg::Geometry::BIND_PER_VERTEX);

    // Declare and initialize a transform node.
    osg::PositionAttitudeTransform* WallTwoXForm = new osg::PositionAttitudeTransform();

    // Use the 'addChild' method of the osg::Group class to
    // add the transform as a child of the root node and the
    // pyramid node as a child of the transform.
    root->addChild(WallTwoXForm);
    WallTwoXForm->addChild(WallGeode);
    float scale=root->getBound().radius();
    WallTwoXForm->setScale(osg::Vec3d(scale,scale,scale));

    // Declare and initialize a Vec3 instance to change the
    // position of the tank model in the scene
    osg::Vec3 WallTwoPosition(15,0,0);

    WallTwoXForm->setPosition(WallTwoPosition );

}
Kobojunkie
  • 6,375
  • 31
  • 109
  • 164
  • osg's viewer defaults to Z-up. You could be drawing a floor, not a wall, unless you are already changing the view matrix elsewhere. – Ruan Caiman Jul 16 '12 at 13:08
  • The corners of your wall are x=0, y=0, z=0 and x=10, y=10, z=0. This is a square of the z=0 plane. If you are using the default osgViewer (in which z is up), then the square is on the ground like a floor, not upright like a wall. Do you see it if you swap y and z? – Ruan Caiman Jul 17 '12 at 20:19

0 Answers0