two_render_widgets.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011, Willow Garage, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
33 
34 #include <QApplication>
35 #include <QTimer>
36 #include <QVBoxLayout>
37 #include <QPushButton>
38 
39 #include <OgreCamera.h>
40 #include <OgreEntity.h>
41 #include <OgreRenderWindow.h>
42 #include <OgreSceneNode.h>
43 #include <OgreViewport.h>
44 
45 using namespace rviz;
46 
47 int main(int argc, char** argv)
48 {
49  // initialize the entire render system
50  RenderSystem* render_system = RenderSystem::get();
51 
52  QApplication app(argc, argv);
53 
54 
55  // make the render window
56  RenderWidget* window = new RenderWidget(render_system);
57  window->setWindowTitle("I hope this is not all black.");
58 
59  QVBoxLayout* layout = new QVBoxLayout;
60  layout->addWidget(window);
61  QPushButton* hide_button = new QPushButton("hide");
62  layout->addWidget(hide_button);
63  QPushButton* show_button = new QPushButton("show");
64  layout->addWidget(show_button);
65 
66  QWidget container;
67  container.setLayout(layout);
68  container.resize(900, 600);
69  container.show();
70 
71  // Make a scene and show it in the window.
72 #if (OGRE_VERSION < OGRE_VERSION_CHECK(13, 0, 0))
73  Ogre::SceneManager* scene_manager = render_system->root()->createSceneManager(Ogre::ST_GENERIC);
74 #else
75  Ogre::SceneManager* scene_manager = render_system->root()->createSceneManager();
76 #endif
77 
78  Ogre::Entity* thing = scene_manager->createEntity("thing", "rviz_cone.mesh");
79  Ogre::SceneNode* node = scene_manager->getRootSceneNode()->createChildSceneNode();
80  node->attachObject(thing);
81 
82  scene_manager->setAmbientLight(Ogre::ColourValue(.5, .5, .5));
83  Ogre::Light* light = scene_manager->createLight("light");
84  light->setPosition(20, 80, 50);
85 
86  Ogre::Camera* camera = scene_manager->createCamera("SampleCam");
87  camera->setPosition(Ogre::Vector3(0, 0, 10));
88  camera->lookAt(Ogre::Vector3(0, 0, -300));
89  camera->setNearClipDistance(5);
90 
91  Ogre::Viewport* viewport = window->getRenderWindow()->addViewport(camera);
92  viewport->setBackgroundColour(Ogre::ColourValue(0, 0, 1.0));
93 
94  camera->setAspectRatio(Ogre::Real(viewport->getActualWidth()) /
95  Ogre::Real(viewport->getActualHeight()));
96 
97  // redraw every 33ms.
98  QTimer timer;
99  QObject::connect(&timer, SIGNAL(timeout()), window, SLOT(update()));
100  timer.start(33);
101 
102 
103  RenderWidget window2(render_system);
104  window2.resize(400, 400);
105  window2.setWindowTitle("I hope this is also not all black.");
106  window2.show();
107 
108  hide_button->connect(hide_button, SIGNAL(clicked()), &window2, SLOT(hide()));
109  show_button->connect(show_button, SIGNAL(clicked()), &window2, SLOT(show()));
110 
111  Ogre::Camera* camera2 = scene_manager->createCamera("SampleCam2");
112  camera2->setPosition(Ogre::Vector3(0, 10, 0));
113  camera2->setFixedYawAxis(false);
114  camera2->lookAt(Ogre::Vector3(0, 0, 0));
115  camera2->setNearClipDistance(5);
116 
117  Ogre::Viewport* viewport2 = window2.getRenderWindow()->addViewport(camera2);
118  viewport2->setBackgroundColour(Ogre::ColourValue(0, 1.0, 0));
119 
120  camera2->setAspectRatio(Ogre::Real(viewport2->getActualWidth()) /
121  Ogre::Real(viewport2->getActualHeight()));
122 
123  // redraw every 33ms.
124  QTimer timer2;
125  QObject::connect(&timer2, SIGNAL(timeout()), &window2, SLOT(update()));
126  timer2.start(33);
127 
128  // main loop
129  return app.exec();
130 }
render_system.h
compatibility.h
rviz::RenderSystem::get
static RenderSystem * get()
Definition: render_system.cpp:76
rviz::RenderWidget
Definition: render_widget.h:44
update
void update(const std::string &key, const XmlRpc::XmlRpcValue &v)
rviz
Definition: add_display_dialog.cpp:54
rviz::RenderWidget::getRenderWindow
Ogre::RenderWindow * getRenderWindow()
Definition: render_widget.h:49
rviz::RenderSystem
Definition: render_system.h:45
main
int main(int argc, char **argv)
Definition: two_render_widgets.cpp:47
app
app
rviz::RenderSystem::root
Ogre::Root * root()
Definition: render_system.h:61
render_widget.h


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust, William Woodall
autogenerated on Fri Dec 13 2024 03:31:03