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 , char* argv[] )
00035 {
00036
00037 pangolin::ParseVarsFile("app.cfg");
00038
00039
00040 pangolin::CreateGlutWindowAndBind("Main",640,480);
00041 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00042
00043
00044 glEnable (GL_BLEND);
00045 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00046
00047
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
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
00061
00062 View& d_panel = pangolin::CreatePanel("ui")
00063 .SetBounds(0.0, 1.0, 0.0, Attach::Pix(UI_WIDTH));
00064
00065
00066 pangolin::RegisterKeyPressCallback( 'b', SetVarFunctor<double>("ui.A Double", 3.5) );
00067
00068
00069 pangolin::RegisterKeyPressCallback( PANGO_CTRL + 'r', boost::bind(GlobalKeyHook, "You Pushed ctrl-r!" ) );
00070
00071
00072 while( !pangolin::ShouldQuit() )
00073 {
00074 if(pangolin::HasResized())
00075 DisplayBase().ActivateScissorAndClear();
00076
00077
00078
00079
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
00092
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
00102
00103 d_cam.ActivateScissorAndClear(s_cam);
00104
00105 glEnable(GL_DEPTH_TEST);
00106 glColor3f(1.0,1.0,1.0);
00107
00108
00109 glutWireTeapot(1.0);
00110
00111
00112 if(HadInput())
00113 d_panel.Render();
00114
00115
00116 pangolin::FinishGlutFrame();
00117 }
00118
00119 return 0;
00120 }