two_render_widgets.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2011, Willow Garage, Inc.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of the Willow Garage, Inc. nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 #include "rviz/ogre_helpers/render_system.h"
00031 #include "rviz/ogre_helpers/render_widget.h"
00032 
00033 #include <QApplication>
00034 #include <QTimer>
00035 #include <QVBoxLayout>
00036 #include <QPushButton>
00037 
00038 #include <OgreRenderWindow.h>
00039 #include <OgreEntity.h>
00040 
00041 using namespace rviz;
00042 
00043 int main( int argc, char** argv )
00044 {
00045   // initialize the entire render system
00046   RenderSystem* render_system = RenderSystem::get();
00047 
00048   QApplication app( argc, argv );
00049 
00050 
00051   // make the render window
00052   RenderWidget* window = new RenderWidget( render_system );
00053   window->setWindowTitle( "I hope this is not all black." );
00054 
00055   QVBoxLayout* layout = new QVBoxLayout;
00056   layout->addWidget( window );
00057   QPushButton* hide_button = new QPushButton( "hide" );
00058   layout->addWidget( hide_button );
00059   QPushButton* show_button = new QPushButton( "show" );
00060   layout->addWidget( show_button );
00061 
00062   QWidget container;
00063   container.setLayout( layout );
00064   container.resize( 900, 600 );
00065   container.show();
00066 
00067   // Make a scene and show it in the window.
00068   Ogre::SceneManager* scene_manager = render_system->root()->createSceneManager( Ogre::ST_GENERIC );
00069 
00070   Ogre::Entity* thing = scene_manager->createEntity( "thing", "rviz_cone.mesh" );
00071   Ogre::SceneNode* node = scene_manager->getRootSceneNode()->createChildSceneNode();
00072   node->attachObject( thing );
00073 
00074   scene_manager->setAmbientLight( Ogre::ColourValue( .5, .5, .5 ));
00075   Ogre::Light* light = scene_manager->createLight( "light" );
00076   light->setPosition( 20, 80, 50 );
00077 
00078   Ogre::Camera* camera = scene_manager->createCamera( "SampleCam" );
00079   camera->setPosition( Ogre::Vector3( 0, 0, 10 ));
00080   camera->lookAt( Ogre::Vector3( 0, 0, -300 ));
00081   camera->setNearClipDistance( 5 );
00082 
00083   Ogre::Viewport* viewport = window->getRenderWindow()->addViewport( camera );
00084   viewport->setBackgroundColour( Ogre::ColourValue( 0, 0, 1.0 ));
00085 
00086   camera->setAspectRatio( Ogre::Real( viewport->getActualWidth() ) / Ogre::Real( viewport->getActualHeight() ));
00087 
00088   // redraw every 33ms.
00089   QTimer timer;
00090   QObject::connect( &timer, SIGNAL(timeout()), window, SLOT(update()) );
00091   timer.start( 33 );
00092 
00093 
00094   RenderWidget window2( render_system );
00095   window2.resize( 400, 400 );
00096   window2.setWindowTitle( "I hope this is also not all black." );
00097   window2.show();
00098 
00099   hide_button->connect( hide_button, SIGNAL( clicked() ), &window2, SLOT( hide() ));
00100   show_button->connect( show_button, SIGNAL( clicked() ), &window2, SLOT( show() ));
00101 
00102   Ogre::Camera* camera2 = scene_manager->createCamera( "SampleCam2" );
00103   camera2->setPosition( Ogre::Vector3( 0, 10, 0 ));
00104   camera2->setFixedYawAxis( false );
00105   camera2->lookAt( Ogre::Vector3( 0, 0, 0 ));
00106   camera2->setNearClipDistance( 5 );
00107 
00108   Ogre::Viewport* viewport2 = window2.getRenderWindow()->addViewport( camera2 );
00109   viewport2->setBackgroundColour( Ogre::ColourValue( 0, 1.0, 0 ));
00110 
00111   camera2->setAspectRatio( Ogre::Real( viewport2->getActualWidth() ) / Ogre::Real( viewport2->getActualHeight() ));
00112 
00113   // redraw every 33ms.
00114   QTimer timer2;
00115   QObject::connect( &timer2, SIGNAL(timeout()), &window2, SLOT(update()) );
00116   timer2.start( 33 );
00117 
00118   // main loop
00119   return app.exec();
00120 }


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Thu Aug 27 2015 15:02:28