我有以下代码。我从教程中得到了这个想法,但我的代码在运行时没有显示任何内容。目标是在3d中绘制Wall。我的猜测是我的分数可能会被关闭,但我不确定如何最好地选择积分,并且还可以扩展。
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 );
}