osg--transform
#include <osg/Geometry>
#include <osg/Geode>
#include <osgViewer/Viewer>
#include <osg/Transform>
#include <osg/MatrixTransform>
int main(int argc, char** argv)
{
osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array;
vertices->push_back(osg::Vec3(0.0f, 0.0f, 0.0f));
vertices->push_back(osg::Vec3(1.0f, 0.0f, 0.0f));
vertices->push_back(osg::Vec3(1.0f, 0.0f, 1.0f));
vertices->push_back(osg::Vec3(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::Vec4Array> colors = new osg::Vec4Array;
colors->push_back(osg::Vec4(1.0f, 0.0f, 0.0f, 1.0f));
colors->push_back(osg::Vec4(0.0f, 1.0f, 0.0f, 1.0f));
colors->push_back(osg::Vec4(0.0f, 0.0f, 1.0f, 1.0f));
colors->push_back(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f));
osg::ref_ptr<osg::Transform> transform = new osg::Transform;
osg::ref_ptr<osg::MatrixTransform> matricTransform = new osg::MatrixTransform;
osg::Matrix matrix = (osg::Matrix)osg::Matrixf(0.732,0.5,0,0,
-0.5,0.732,0,0,
0,0,1,0,
0,0,0,1);
matricTransform->setMatrix(matrix);
osg::ref_ptr<osg::Geometry> quad = new osg::Geometry;
quad->setVertexArray(vertices.get());
quad->setNormalArray(normals.get());
quad->setNormalBinding(osg::Geometry::BIND_OVERALL);
quad->setColorArray(colors.get());
quad->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
quad->addPrimitiveSet(new osg::DrawArrays(GL_QUADS, 0, 4));
osg::ref_ptr<osg::Group> group = new osg::Group;
group->addChild(matricTransform.get());
osg::ref_ptr<osg::Geode> root = new osg::Geode;
matricTransform->addChild(root);
root->addDrawable(quad.get());
osgViewer::Viewer viewer;
viewer.setSceneData(group.get());
return viewer.run();
}

浙公网安备 33010602011771号