1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array(8);
(*vertices)[0].set(0.0f, 0.0f, 0.0f);
(*vertices)[1].set(10.f, 0.f, 0.0f);
(*vertices)[2].set(10.f, 0.f, 10.f);
(*vertices)[3].set(0.f, 0.f, 10.0f);
(*vertices)[4].set(10.f, 10.f, 0.0f);
(*vertices)[5].set(0.0f, 10.0f, 0.0f);
(*vertices)[6].set(0.0f, 10.0f, 10.0f);
(*vertices)[7].set(10.0f, 10.0f, 10.0f);
osg::ref_ptr<osg::DrawElementsUInt> indices =
new osg::DrawElementsUInt(GL_TRIANGLES, 36);
(*indices)[0] = 0; (*indices)[1] = 1; (*indices)[2] = 2;
(*indices)[3] = 0; (*indices)[4] = 3; (*indices)[5] = 2;
(*indices)[6] = 1; (*indices)[7] = 4; (*indices)[8] = 7;
(*indices)[9] = 1; (*indices)[10] = 2; (*indices)[11] = 7;
(*indices)[12] = 0; (*indices)[13] = 5; (*indices)[14] = 4;
(*indices)[15] = 0; (*indices)[16] = 1; (*indices)[17] = 4;
(*indices)[18] = 3; (*indices)[19] = 6; (*indices)[20] = 2;
(*indices)[21] = 2; (*indices)[22] = 6; (*indices)[23] = 7;
(*indices)[24] = 0; (*indices)[25] = 3; (*indices)[26] = 5;
(*indices)[27] = 3; (*indices)[28] = 6; (*indices)[29] = 5;
(*indices)[30] = 6; (*indices)[31] = 7; (*indices)[32] = 5;
(*indices)[33] = 5; (*indices)[34] = 4; (*indices)[35] = 4;
osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array;
colors->push_back(osg::Vec4(1.0f, 0.0f, 0.0f, 1.0f));
colors->push_back(osg::Vec4(1.0f, 0.0f, 0.0f, 1.0f));
colors->push_back(osg::Vec4(1.0f, 0.0f, 0.0f, 1.0f));
colors->push_back(osg::Vec4(1.0f, 0.0f, 0.0f, 1.0f));
osg::ref_ptr<osg::Vec3Array> normals = new osg::Vec3Array;
normals->push_back(osg::Vec3(0.0f, -1.0f, 0.0f));
osg::ref_ptr<osg::Geometry> geom = new osg::Geometry;
geom->setVertexArray(vertices.get());
geom->addPrimitiveSet(indices.get());
geom->setNormalArray(normals.get());
geom->setNormalBinding(osg::Geometry::BIND_OVERALL);
geom->setColorArray(colors.get());
geom->setColorBinding(osg::Geometry::BIND_OVERALL); |
Partager