From Jeremy Moles, updates to osgwidget examples.

Merged by Robert Osfield from OpenSceneGraph-osgWidget-dev
This commit is contained in:
Robert Osfield
2008-11-28 14:36:39 +00:00
parent 16bae8830e
commit 9b1841d009
18 changed files with 1116 additions and 230 deletions

View File

@@ -45,6 +45,19 @@ struct Object {
}
};
// This is the more "traditional" method of creating a callback.
struct CallbackObject: public osgWidget::Callback {
CallbackObject(osgWidget::EventType evType):
osgWidget::Callback(evType) {
}
virtual bool operator()(osgWidget::Event& ev) {
std::cout << "here" << std::endl;
return false;
}
};
int main(int argc, char** argv) {
osgViewer::Viewer viewer;
@@ -65,8 +78,7 @@ int main(int argc, char** argv) {
MASK_2D,
osgWidget::WindowManager::WM_USE_LUA |
osgWidget::WindowManager::WM_USE_PYTHON |
osgWidget::WindowManager::WM_PICK_DEBUG |
osgWidget::WindowManager::WM_NO_BETA_WARN
osgWidget::WindowManager::WM_PICK_DEBUG
);
// An actual osgWidget::Window is pure virtual, so we've got to use the osgWidget::Box
@@ -81,13 +93,17 @@ int main(int argc, char** argv) {
static std::string data = "lol ur face!";
box->addCallback(osgWidget::Callback(&windowClicked, osgWidget::EVENT_MOUSE_PUSH, &data));
box->addCallback(osgWidget::Callback(&windowScrolled, osgWidget::EVENT_MOUSE_SCROLL));
/*
box->addCallback(new osgWidget::Callback(&windowClicked, osgWidget::EVENT_MOUSE_PUSH, &data));
box->addCallback(new osgWidget::Callback(&windowScrolled, osgWidget::EVENT_MOUSE_SCROLL));
box->addCallback(osgWidget::Callback(
&Object::windowClicked,
&obj,
osgWidget::EVENT_MOUSE_PUSH
));
*/
box->addCallback(new CallbackObject(osgWidget::EVENT_MOUSE_PUSH));
// Create some of our "testing" Widgets; included are two Widget subclasses I made
// during testing which I've kept around for testing purposes. You'll notice
@@ -124,7 +140,7 @@ int main(int argc, char** argv) {
// Now, lets clone our existing box and create a new copy of of it, also adding that
// to the WindowManager. This demonstrates the usages of OSG's ->clone() support,
// though that is abstracted by our META_UIObject macro.
osgWidget::Window* boxCopy = osg::clone(box,"newBox");
osgWidget::Window* boxCopy = osg::clone(box, "newBox", osg::CopyOp::DEEP_COPY_ALL);
// Move our copy to make it visible.
boxCopy->setOrigin(0.0f, 125.0f);
@@ -145,16 +161,6 @@ int main(int argc, char** argv) {
// creation.
// std::cout << *box << std::endl << *boxCopy << std::endl;
// Add our event handler; is this better as a MatrixManipulator? Add a few other
// helpful ViewerEventHandlers.
viewer.addEventHandler(new osgWidget::MouseHandler(wm));
viewer.addEventHandler(new osgWidget::KeyboardHandler(wm));
viewer.addEventHandler(new osgViewer::StatsHandler());
viewer.addEventHandler(new osgViewer::WindowSizeHandler());
viewer.addEventHandler(new osgGA::StateSetManipulator(
viewer.getCamera()->getOrCreateStateSet()
));
// Setup our OSG objects for our scene; note the use of the utility function
// createOrthoCamera, which is just a helper for setting up a proper viewing area.
// An alternative (and a MUCH easier alternative at that!) is to
@@ -162,9 +168,21 @@ int main(int argc, char** argv) {
// which will wrap the calls to createOrthoCamera and addChild for us! Check out
// some of the other examples to see this in action...
osg::Group* group = new osg::Group();
osg::Camera* camera = osgWidget::createInvertedYOrthoCamera(1280.0f, 1024.0f);
osg::Camera* camera = osgWidget::createOrthoCamera(1280.0f, 1024.0f);
osg::Node* model = osgDB::readNodeFile("cow.osg");
// Add our event handler; is this better as a MatrixManipulator? Add a few other
// helpful ViewerEventHandlers.
viewer.addEventHandler(new osgWidget::MouseHandler(wm));
viewer.addEventHandler(new osgWidget::KeyboardHandler(wm));
viewer.addEventHandler(new osgWidget::ResizeHandler(wm, camera));
viewer.addEventHandler(new osgWidget::CameraSwitchHandler(wm, camera));
viewer.addEventHandler(new osgViewer::StatsHandler());
viewer.addEventHandler(new osgViewer::WindowSizeHandler());
viewer.addEventHandler(new osgGA::StateSetManipulator(
viewer.getCamera()->getOrCreateStateSet()
));
// Set our first non-UI node to be something other than the mask we created our
// WindowManager with to avoid picking.
// TODO: Do I need to create a mechanism for doing this automatically, or should