main.cpp
Go to the documentation of this file.
00001 #include <iostream>
00002 #include <boost/bind.hpp>
00003 #include <pangolin/pangolin.h>
00004 
00005 #include <pangolin/simple_math.h>
00006 
00007 using namespace pangolin;
00008 using namespace std;
00009 
00010 struct CustomType
00011 {
00012   int x;
00013   float y;
00014   string z;
00015 };
00016 
00017 std::ostream& operator<< (std::ostream& os, const CustomType& o){
00018   os << o.x << " " << o.y << " " << o.z;
00019   return os;
00020 }
00021 
00022 std::istream& operator>> (std::istream& is, CustomType& o){
00023   is >> o.x;
00024   is >> o.y;
00025   is >> o.z;
00026   return is;
00027 }
00028 
00029 void GlobalKeyHook(const std::string& example)
00030 {
00031     cout << example << endl;
00032 }
00033 
00034 int main( int /*argc*/, char* argv[] )
00035 {  
00036   // Load configuration data
00037   pangolin::ParseVarsFile("app.cfg");
00038 
00039   // Create OpenGL window in single line thanks to GLUT
00040   pangolin::CreateGlutWindowAndBind("Main",640,480);
00041   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00042 
00043   // Issue specific OpenGl we might need
00044   glEnable (GL_BLEND);
00045   glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00046 
00047   // Define Camera Render Object (for view / scene browsing)
00048   pangolin::OpenGlRenderState s_cam(
00049     ProjectionMatrix(640,480,420,420,320,240,0.1,1000),
00050     ModelViewLookAt(-0,0.5,-30, 0,0,0, AxisY)
00051   );
00052 
00053   const int UI_WIDTH = 180;
00054 
00055   // Add named OpenGL viewport to window and provide 3D Handler
00056   View& d_cam = pangolin::CreateDisplay()
00057     .SetBounds(0.0, 1.0, Attach::Pix(UI_WIDTH), 1.0, -640.0f/480.0f)
00058     .SetHandler(new Handler3D(s_cam));
00059 
00060   // Add named Panel and bind to variables beginning 'ui'
00061   // A Panel is just a View with a default layout and input handling
00062   View& d_panel = pangolin::CreatePanel("ui")
00063       .SetBounds(0.0, 1.0, 0.0, Attach::Pix(UI_WIDTH));
00064 
00065   // Demonstration of how we can register a keyboard hook to alter a Var
00066   pangolin::RegisterKeyPressCallback( 'b', SetVarFunctor<double>("ui.A Double", 3.5) );
00067 
00068   // Demonstration of how we can register a keyboard hook to trigger a method
00069   pangolin::RegisterKeyPressCallback( PANGO_CTRL + 'r', boost::bind(GlobalKeyHook, "You Pushed ctrl-r!" ) );
00070 
00071   // Default hooks for exiting (Esc) and fullscreen (tab).
00072   while( !pangolin::ShouldQuit() )
00073   {
00074     if(pangolin::HasResized())
00075       DisplayBase().ActivateScissorAndClear();
00076 
00077     // Safe and efficient binding of named variables.
00078     // Specialisations mean no conversions take place for exact types
00079     // and conversions between scalar types are cheap.
00080     static Var<bool> a_button("ui.A Button",false,false);
00081     static Var<double> a_double("ui.A Double",3,0,5);
00082     static Var<int> an_int("ui.An Int",2,0,5);
00083     static Var<double> a_double_log("ui.Log scale var",3,1,1E4, true);
00084     static Var<bool> a_checkbox("ui.A Checkbox",false,true);
00085     static Var<int> an_int_no_input("ui.An Int No Input",2);
00086     static Var<CustomType> any_type("ui.Some Type",(CustomType){0,1.2,"Hello"});
00087 
00088     if( Pushed(a_button) )
00089       cout << "You Pushed a button!" << endl;
00090 
00091     // Overloading of Var<T> operators allows us to treat them like
00092     // their wrapped types, eg:
00093     if( a_checkbox )
00094       an_int = a_double;
00095 
00096     if( !any_type->z.compare("robot"))
00097         any_type = (CustomType){1,2.3,"Boogie"};
00098 
00099     an_int_no_input = an_int;
00100 
00101     // Activate efficiently by object
00102     // (3D Handler requires depth testing to be enabled)
00103     d_cam.ActivateScissorAndClear(s_cam);
00104 
00105     glEnable(GL_DEPTH_TEST);
00106     glColor3f(1.0,1.0,1.0);
00107 
00108     // Render some stuff
00109     glutWireTeapot(1.0);
00110 
00111     // Render our UI panel when we receive input
00112     if(HadInput())
00113       d_panel.Render();
00114 
00115     // Swap frames and Process Events
00116     pangolin::FinishGlutFrame();
00117   }
00118 
00119   return 0;
00120 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


pangolin_wrapper
Author(s): Todor Stoyanov
autogenerated on Wed Feb 13 2013 14:03:25