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 
32 
33 #include <QApplication>
34 #include <QTimer>
35 #include <QVBoxLayout>
36 #include <QPushButton>
37 
38 #include <OgreCamera.h>
39 #include <OgreEntity.h>
40 #include <OgreRenderWindow.h>
41 #include <OgreSceneNode.h>
42 #include <OgreViewport.h>
43 
44 using namespace rviz;
45 
46 int main( int argc, char** argv )
47 {
48  // initialize the entire render system
49  RenderSystem* render_system = RenderSystem::get();
50 
51  QApplication app( argc, argv );
52 
53 
54  // make the render window
55  RenderWidget* window = new RenderWidget( render_system );
56  window->setWindowTitle( "I hope this is not all black." );
57 
58  QVBoxLayout* layout = new QVBoxLayout;
59  layout->addWidget( window );
60  QPushButton* hide_button = new QPushButton( "hide" );
61  layout->addWidget( hide_button );
62  QPushButton* show_button = new QPushButton( "show" );
63  layout->addWidget( show_button );
64 
65  QWidget container;
66  container.setLayout( layout );
67  container.resize( 900, 600 );
68  container.show();
69 
70  // Make a scene and show it in the window.
71  Ogre::SceneManager* scene_manager = render_system->root()->createSceneManager( Ogre::ST_GENERIC );
72 
73  Ogre::Entity* thing = scene_manager->createEntity( "thing", "rviz_cone.mesh" );
74  Ogre::SceneNode* node = scene_manager->getRootSceneNode()->createChildSceneNode();
75  node->attachObject( thing );
76 
77  scene_manager->setAmbientLight( Ogre::ColourValue( .5, .5, .5 ));
78  Ogre::Light* light = scene_manager->createLight( "light" );
79  light->setPosition( 20, 80, 50 );
80 
81  Ogre::Camera* camera = scene_manager->createCamera( "SampleCam" );
82  camera->setPosition( Ogre::Vector3( 0, 0, 10 ));
83  camera->lookAt( Ogre::Vector3( 0, 0, -300 ));
84  camera->setNearClipDistance( 5 );
85 
86  Ogre::Viewport* viewport = window->getRenderWindow()->addViewport( camera );
87  viewport->setBackgroundColour( Ogre::ColourValue( 0, 0, 1.0 ));
88 
89  camera->setAspectRatio( Ogre::Real( viewport->getActualWidth() ) / Ogre::Real( viewport->getActualHeight() ));
90 
91  // redraw every 33ms.
92  QTimer timer;
93  QObject::connect( &timer, SIGNAL(timeout()), window, SLOT(update()) );
94  timer.start( 33 );
95 
96 
97  RenderWidget window2( render_system );
98  window2.resize( 400, 400 );
99  window2.setWindowTitle( "I hope this is also not all black." );
100  window2.show();
101 
102  hide_button->connect( hide_button, SIGNAL( clicked() ), &window2, SLOT( hide() ));
103  show_button->connect( show_button, SIGNAL( clicked() ), &window2, SLOT( show() ));
104 
105  Ogre::Camera* camera2 = scene_manager->createCamera( "SampleCam2" );
106  camera2->setPosition( Ogre::Vector3( 0, 10, 0 ));
107  camera2->setFixedYawAxis( false );
108  camera2->lookAt( Ogre::Vector3( 0, 0, 0 ));
109  camera2->setNearClipDistance( 5 );
110 
111  Ogre::Viewport* viewport2 = window2.getRenderWindow()->addViewport( camera2 );
112  viewport2->setBackgroundColour( Ogre::ColourValue( 0, 1.0, 0 ));
113 
114  camera2->setAspectRatio( Ogre::Real( viewport2->getActualWidth() ) / Ogre::Real( viewport2->getActualHeight() ));
115 
116  // redraw every 33ms.
117  QTimer timer2;
118  QObject::connect( &timer2, SIGNAL(timeout()), &window2, SLOT(update()) );
119  timer2.start( 33 );
120 
121  // main loop
122  return app.exec();
123 }
app
static RenderSystem * get()
int main(int argc, char **argv)
Ogre::Root * root()
Definition: render_system.h:62
void update(const std::string &key, const XmlRpc::XmlRpcValue &v)
Ogre::RenderWindow * getRenderWindow()
Definition: render_widget.h:50


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Wed Aug 28 2019 04:01:51