transforms.cpp 866 B

1234567891011121314151617181920212223242526272829303132
  1. #include <osgViewer/Viewer>
  2. #include <osgDB/ReadFile>
  3. #include <osg/Group>
  4. #include <osg/MatrixTransform>
  5. #include <osg/Matrix>
  6. #include <osgGA/TrackballManipulator>
  7. int main(int argc, char** argv)
  8. {
  9. // Root node of the scene
  10. osg::ref_ptr<osg::Group> root = new osg::Group;
  11. // Create the viewer
  12. osgViewer::Viewer viewer;
  13. viewer.setSceneData(root);
  14. viewer.realize();
  15. // Add axesNode under root
  16. osg::ref_ptr<osg::Node> axesNode = osgDB::readNodeFile("test.stl");
  17. if (!axesNode)
  18. {
  19. printf("Origin node not loaded, model not found\n");
  20. return 1;
  21. }
  22. root->addChild(axesNode);
  23. // Attach a manipulator (it's usually done for us when we use viewer.run())
  24. osg::ref_ptr<osgGA::TrackballManipulator> tm = new osgGA::TrackballManipulator;
  25. viewer.setCameraManipulator(tm);
  26. return viewer.run();
  27. }