root/OpenSceneGraph/trunk/src/osgWidget/Util.cpp @ 13041

Revision 13041, 2.5 kB (checked in by robert, 2 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
Line 
1// -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008
2
3#include <stdlib.h>
4
5#include <osg/io_utils>
6
7#include <osgGA/TrackballManipulator>
8#include <osgGA/StateSetManipulator>
9#include <osgDB/FileUtils>
10#include <osgDB/WriteFile>
11#include <osgViewer/ViewerEventHandlers>
12#include <osgWidget/Util>
13#include <osgWidget/ViewerEventHandlers>
14#include <osgWidget/WindowManager>
15
16namespace osgWidget {
17
18std::string getFilePath(const std::string& filename) {
19    osgDB::FilePathList path;
20
21    char* fp = getenv("OSGWIDGET_FILE_PATH");
22
23    osgDB::convertStringPathIntoFilePathList(fp ? fp : ".", path);
24
25    return osgDB::findFileInPath(filename, path);
26}
27
28std::string generateRandomName(const std::string& base) {
29    static unsigned int count = 0;
30
31    std::stringstream ss;
32
33    ss << base << "_" << count;
34
35    count++;
36
37    return ss.str();
38}
39
40osg::Camera* createOrthoCamera(matrix_type width, matrix_type height) {
41    osg::Camera* camera = new osg::Camera();
42
43    camera->getOrCreateStateSet()->setMode(
44        GL_LIGHTING,
45        osg::StateAttribute::PROTECTED | osg::StateAttribute::OFF
46    );
47
48    camera->setProjectionMatrix(osg::Matrix::ortho2D(0.0, width, 0.0f, height));
49    camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
50    camera->setViewMatrix(osg::Matrix::identity());
51    camera->setClearMask(GL_DEPTH_BUFFER_BIT);
52    camera->setRenderOrder(osg::Camera::POST_RENDER);
53
54    return camera;
55}
56
57int createExample(osgViewer::Viewer& viewer, WindowManager* wm, osg::Node* node) {
58    if(!wm) return 1;
59
60    viewer.setUpViewInWindow(
61        50,
62        50,
63        static_cast<int>(wm->getWidth()),
64        static_cast<int>(wm->getHeight())
65    );
66
67    osg::Group*  group  = new osg::Group();
68    osg::Camera* camera = wm->createParentOrthoCamera();
69
70    group->addChild(camera);
71
72    if(node) group->addChild(node);
73
74    viewer.addEventHandler(new osgWidget::MouseHandler(wm));
75    viewer.addEventHandler(new osgWidget::KeyboardHandler(wm));
76    viewer.addEventHandler(new osgWidget::ResizeHandler(wm, camera));
77    viewer.addEventHandler(new osgWidget::CameraSwitchHandler(wm, camera));
78    viewer.addEventHandler(new osgViewer::StatsHandler());
79    viewer.addEventHandler(new osgViewer::WindowSizeHandler());
80    viewer.addEventHandler(new osgGA::StateSetManipulator(
81        viewer.getCamera()->getOrCreateStateSet()
82    ));
83
84    wm->resizeAllWindows();
85
86    viewer.setSceneData(group);
87
88    return viewer.run();
89}
90
91bool writeWindowManagerNode(WindowManager* wm) {
92    osgDB::writeNodeFile(*wm->getParent(0), "osgWidget.osg");
93
94    return true;
95}
96
97}
Note: See TracBrowser for help on using the browser.