├── .gitignore ├── CMakeLists.txt ├── Examples ├── CMakeLists.txt ├── ConstraintDemo │ ├── BulletWrapper.h │ ├── CMakeLists.txt │ ├── CVarHelpers.h │ ├── GetPot │ ├── PhysicsClass.h │ ├── RenderClass.h │ └── main.cpp ├── Display │ ├── CMakeLists.txt │ └── main.cpp ├── DisplayImage │ ├── CMakeLists.txt │ └── main.cpp ├── DisplayMultiView │ ├── CMakeLists.txt │ └── main.cpp ├── DisplayShadowTest │ ├── CMakeLists.txt │ └── main.cpp ├── ModelPhysics │ ├── BulletWrapper.h │ ├── CMakeLists.txt │ ├── CVarHelpers.h │ ├── CarDemo.cpp │ ├── GLBulletDebugDrawer.cpp │ ├── GLBulletDebugDrawer.h │ └── main.cpp ├── ModelViewer │ ├── CMakeLists.txt │ └── main.cpp ├── OffscreenRender │ ├── CMakeLists.txt │ └── main.cpp ├── SimCam │ ├── CMakeLists.txt │ ├── CVarHelpers.h │ └── SimCamDEMO.cpp └── Widgets │ ├── CMakeLists.txt │ └── main.cpp ├── LICENSE ├── README ├── cmake_modules ├── .gitignore ├── FindASSIMP.cmake ├── FindAndroidKernel.cmake ├── FindAvahi.cmake ├── FindCeresSolver.cmake ├── FindDNSSD.cmake ├── FindEigen3.cmake ├── FindFREEGLUT.cmake ├── FindGFlags.cmake ├── FindGLEW.cmake ├── FindGLUES.cmake ├── FindGLog.cmake ├── FindOpenCL.cmake ├── FindOpenCV2.cmake ├── FindPCAN.cmake ├── FindPackage.cmake.in ├── FindPkgMacros.cmake ├── FindTBB.cmake ├── FindTinyXML2.cmake ├── FindUSB1.cmake ├── FindZeroMQ.cmake ├── LICENSE.md ├── LibFindMacros.cmake ├── PackageConfig.cmake.in ├── PackageConfigVersion.cmake.in ├── PkgConfig.pc.in ├── README.md ├── cmake_uninstall.cmake.in ├── def_test.cmake └── install_package.cmake ├── include └── SceneGraph │ ├── AxisAlignedBoundingBox.h │ ├── FBO.h │ ├── GLAxis.h │ ├── GLAxisAlignedBox.h │ ├── GLAxisHistory.h │ ├── GLBox.h │ ├── GLColor.h │ ├── GLCube.h │ ├── GLCylinder.h │ ├── GLDynamicGrid.h │ ├── GLES_compat.h │ ├── GLGrid.h │ ├── GLGroup.h │ ├── GLHeightmap.h │ ├── GLHelpers.h │ ├── GLHelpersDevil.h │ ├── GLHelpersLoadTextures.h │ ├── GLImage.h │ ├── GLLight.h │ ├── GLLineStrip.h │ ├── GLMesh.h │ ├── GLMovableAxis.h │ ├── GLObject.h │ ├── GLOpenBox.h │ ├── GLPointCloud.h │ ├── GLPrimitives.h │ ├── GLSLHelpers.h │ ├── GLSceneGraph.h │ ├── GLShadowLight.h │ ├── GLSphereGrid.h │ ├── GLTeapot.h │ ├── GLText.h │ ├── GLVbo.h │ ├── GLWaypoint.h │ ├── GLWireSphere.h │ ├── GLinclude.h │ ├── Gui.h │ ├── LineSegment.h │ ├── PangolinDrawGLObject.h │ ├── PangolinGlCachedSizeableBuffer.h │ ├── PangolinImageView.h │ ├── PangolinSceneGraphHandler.h │ ├── SceneGraph.h │ ├── SimCam.h │ ├── Widgets │ ├── GLWidgetView.h │ ├── nvGLWidgets.h │ ├── nvGlutWidgets.h │ ├── nvShaderUtils.h │ └── nvWidgets.h │ └── config.h.in ├── models ├── 2floor.mtl ├── 2floor.obj ├── allrooms4.3DS ├── bench.mtl ├── bench.obj ├── chair.3DS ├── chair.mtl └── chair.obj └── src ├── FBO.cpp ├── GLAxis.cpp ├── GLCube.cpp ├── GLDynamicGrid.cpp ├── GLGrid.cpp ├── GLHelpers.cpp ├── GLLight.cpp ├── GLMesh.cpp ├── GLObject.cpp ├── GLSceneGraph.cpp ├── GetPot ├── SimCam.cpp └── Widgets ├── nvGLWidgets.cpp ├── nvGlutWidgets.cpp └── nvWidgets.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | debug 3 | .DS_Store 4 | CMakeLists.txt.user 5 | *~ -------------------------------------------------------------------------------- /Examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_SUBDIRECTORY(Display) 2 | ADD_SUBDIRECTORY(DisplayImage) 3 | ADD_SUBDIRECTORY(DisplayMultiView) 4 | 5 | if(NOT _ANDROID_) 6 | if(HAVE_CVARS) 7 | include_directories(${CVars_INCLUDE_DIRS}) 8 | endif(HAVE_CVARS) 9 | ADD_SUBDIRECTORY(DisplayShadowTest) 10 | ADD_SUBDIRECTORY(ModelPhysics) 11 | ADD_SUBDIRECTORY(Widgets) 12 | ADD_SUBDIRECTORY(ModelViewer) 13 | 14 | FIND_PACKAGE( PNG QUIET ) 15 | IF(PNG_FOUND) 16 | ADD_SUBDIRECTORY(OffscreenRender) 17 | ENDIF() 18 | 19 | endif() 20 | -------------------------------------------------------------------------------- /Examples/ConstraintDemo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Find Pangolin (https://github.com/stevenlovegrove/Pangolin) 2 | FIND_PACKAGE(Pangolin REQUIRED) 3 | INCLUDE_DIRECTORIES(${Pangolin_INCLUDE_DIRS}) 4 | LINK_DIRECTORIES(${Pangolin_LIBRARY_DIRS}) 5 | LINK_LIBRARIES(${Pangolin_LIBRARIES}) 6 | 7 | # include SceneGraph dirs 8 | INCLUDE_DIRECTORIES(${SceneGraph_INCLUDE_DIRS}) 9 | LINK_LIBRARIES(${SceneGraph_LIBRARIES}) 10 | 11 | find_package(ModelGraph REQUIRED) 12 | include_directories(${RPG_INCLUDE_DIRS}) 13 | 14 | find_package( Bullet REQUIRED ) 15 | include_directories(${BULLET_INCLUDE_DIRS}) 16 | link_libraries(${BULLET_LIBRARIES}) 17 | 18 | 19 | ADD_EXECUTABLE(ContsraintDemo main.cpp) 20 | 21 | # In your own code, you can ommit these lines 22 | IF( ${SceneGraph_EXAMPLE} ) 23 | add_dependencies(ContsraintDemo scenegraph) 24 | ENDIF() 25 | -------------------------------------------------------------------------------- /Examples/ConstraintDemo/CVarHelpers.h: -------------------------------------------------------------------------------- 1 | #ifndef _CVAR_HELPERS_ 2 | #define _CVAR_HELPERS_ 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | //////////////////////////////////////////////////////////////////////////// 10 | // Overloading Eigen for CVars 11 | namespace CVarUtils 12 | { 13 | template 14 | inline std::ostream& operator<<( std::ostream& Stream, const Eigen::Matrix& Mat ) 15 | { 16 | unsigned int nRows = Mat.rows(); 17 | unsigned int nCols = Mat.cols(); 18 | 19 | Stream << "[ "; 20 | 21 | for( unsigned int ii = 0; ii < nRows-1; ii++ ) { 22 | for( unsigned int jj = 0; jj < nCols-1; jj++ ) { 23 | Stream << Mat(ii, jj); 24 | Stream << ", "; 25 | } 26 | Stream << Mat(ii, nCols-1); 27 | Stream << "; "; 28 | } 29 | for( unsigned int jj = 0; jj < nCols-1; jj++ ) { 30 | Stream << Mat(nRows-1, jj); 31 | Stream << ", "; 32 | } 33 | Stream << Mat(nRows-1, nCols-1); 34 | Stream << " ]"; 35 | 36 | return Stream; 37 | } 38 | 39 | //////////////////////////////////////////////////////////////////////////// 40 | template 41 | inline std::istream& operator>>( std::istream& Stream, Eigen::Matrix& Mat ) 42 | { 43 | 44 | unsigned int nRows = Mat.rows(); 45 | unsigned int nCols = Mat.cols(); 46 | char str[256]; 47 | 48 | Stream.getline(str, 255, '['); 49 | if( Stream.gcount() > 1 ) { 50 | return Stream; 51 | } 52 | for( unsigned int ii = 0; ii < nRows-1; ii++ ) { 53 | for( unsigned int jj = 0; jj < nCols-1; jj++ ) { 54 | Stream.getline(str, 255, ','); 55 | Mat(ii, jj) = std::strtod(str, NULL); 56 | } 57 | Stream.getline(str, 255, ';'); 58 | Mat(ii, nCols-1) = std::strtod(str, NULL); 59 | } 60 | for( unsigned int jj = 0; jj < nCols-1; jj++ ) { 61 | Stream.getline(str, 255, ','); 62 | Mat(nRows-1, jj) = std::strtod(str, NULL); 63 | } 64 | Stream.getline(str, 255, ']'); 65 | Mat(nRows-1, nCols-1) = std::strtod(str, NULL); 66 | return Stream; 67 | } 68 | 69 | //////////////////////////////////////////////////////////////////////////// 70 | inline std::ostream& operator<<( std::ostream& Stream, const Sophus::SO3d& R ) 71 | { 72 | Stream << R.unit_quaternion().coeffs(); 73 | return Stream; 74 | } 75 | 76 | //////////////////////////////////////////////////////////////////////////// 77 | inline std::ostream& operator<<( std::ostream& Stream, const Sophus::SE3d& T ) 78 | { 79 | Stream << "[" << T.so3() << "," << T.translation() << "]"; 80 | return Stream; 81 | } 82 | 83 | //////////////////////////////////////////////////////////////////////////// 84 | inline std::istream& operator>>( std::istream& Stream, Sophus::SO3d& R ) 85 | { 86 | Eigen::Matrix coeffs; 87 | Stream >> coeffs; 88 | R.setQuaternion(Eigen::Quaterniond(coeffs)); 89 | return Stream; 90 | } 91 | 92 | //////////////////////////////////////////////////////////////////////////// 93 | inline std::istream& operator>>( std::istream& Stream, Sophus::SE3d& T ) 94 | { 95 | char str[256]; 96 | 97 | Stream.getline(str, 255, '['); 98 | if( Stream.gcount() > 1 ) { 99 | return Stream; 100 | } 101 | Stream >> T.so3(); 102 | Stream.getline(str, 255, ','); 103 | Stream >> T.translation(); 104 | Stream.getline(str, 255, ']'); 105 | return Stream; 106 | } 107 | 108 | } 109 | 110 | #endif 111 | -------------------------------------------------------------------------------- /Examples/ConstraintDemo/RenderClass.h: -------------------------------------------------------------------------------- 1 | #ifndef RENDERCLASS_H 2 | #define RENDERCLASS_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | class SceneEntity { 11 | 12 | }; 13 | 14 | class Render 15 | { 16 | public: 17 | Render() 18 | { 19 | } 20 | 21 | 22 | ~Render() 23 | { 24 | // write code to delete the Map 25 | // for ( int count = 0; count < objects.size(); count++ ){ 26 | // delete objects[count]; 27 | // } 28 | } 29 | 30 | // void AddShape( Shape *pShape, Eigen::Vector6d WorldPose ) 31 | // { 32 | // if (dynamic_cast(pShape) != NULL) 33 | // { 34 | // BoxShape* pbShape = (BoxShape *) pShape; 35 | // SceneGraph::GLBox* new_box = new SceneGraph::GLBox(); 36 | // new_box->SetExtent(pbShape->m_dDims[0], pbShape->m_dDims[1], pbShape->m_dDims[2]); 37 | // new_box->SetPose(WorldPose); 38 | // m_mSceneEntities.insert( pbShape , new_box); 39 | 40 | // std::cout<<"Rendering a Box at "<m_dDims[0]<<", "<< pbShape->m_dDims[1]<<", "<< pbShape->m_dDims[2]<<" " <ObjectBounds().Min().transpose() << "-" << new_box->ObjectBounds().Max().transpose() << std::endl; 43 | // } 44 | // } 45 | 46 | void AddNode( ModelNode *pNode, Eigen::Vector6d WorldPose ) 47 | { 48 | if (dynamic_cast(pNode) != NULL){ 49 | Body* pBody = (Body*)(pNode); 50 | if (dynamic_cast(pBody->m_RenderShape) != NULL) 51 | { 52 | BoxShape* pbShape = (BoxShape *) pBody->m_RenderShape; 53 | SceneGraph::GLBox* new_box = new SceneGraph::GLBox(); 54 | new_box->SetExtent(pbShape->m_dDims[0]*2, pbShape->m_dDims[1]*2, pbShape->m_dDims[2]*2); 55 | new_box->SetPose(WorldPose); 56 | m_mSceneEntities[pNode] = new_box; 57 | 58 | pBody->SetWPose(_Cart2T(WorldPose)); 59 | 60 | std::cout<<"Rendering a Box at "<m_dDims[0]*2<<", "<< pbShape->m_dDims[1]*2<<", "<< pbShape->m_dDims[2]*2<<" " <ObjectBounds().Min().transpose() << "-" << new_box->ObjectBounds().Max().transpose() << std::endl; 63 | } 64 | else if (dynamic_cast(pBody->m_RenderShape) != NULL) 65 | { 66 | CylinderShape* pbShape = (CylinderShape *) pBody->m_RenderShape; 67 | SceneGraph::GLCylinder* new_cylinder = new SceneGraph::GLCylinder(); 68 | new_cylinder->Init(pbShape->m_dRadius, pbShape->m_dRadius, pbShape->m_dThickness, 32, 1); 69 | 70 | 71 | // Eigen::Matrix4d Rx; 72 | // Rx << 1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1; 73 | 74 | // WorldPose = _T2Cart( *Rx ); 75 | 76 | Eigen::Vector6d temp; 77 | temp << 0, 0, 0, M_PI / 2, 0, 0; 78 | new_cylinder->SetPose((Eigen::Matrix4d)(_Cart2T(WorldPose)*_Cart2T(temp))); 79 | m_mSceneEntities[pNode] = new_cylinder; 80 | 81 | pBody->SetWPose(_Cart2T(WorldPose)); 82 | 83 | std::cout<<"Rendering a Cylinder at "<m_dRadius<<", "<< pbShape->m_dThickness<ObjectBounds().Min().transpose() << "-" << new_box->ObjectBounds().Max().transpose() << std::endl; 86 | } 87 | 88 | } 89 | } 90 | 91 | 92 | void AddToScene( SceneGraph::GLSceneGraph *glGraph ) 93 | { 94 | // for ( int count = 0; count < objects.size(); count++ ){ 95 | // glGraph->AddChild( objects[count] ); 96 | // } 97 | std::map::iterator it; 98 | for(it=m_mSceneEntities.begin(); it != m_mSceneEntities.end(); it++) { 99 | SceneGraph::GLObject* p = it->second; 100 | glGraph->AddChild( p ); 101 | } 102 | 103 | } 104 | 105 | void UpdateScene( void ) 106 | { 107 | std::map::iterator it; 108 | for(it=m_mSceneEntities.begin(); it != m_mSceneEntities.end(); it++) { 109 | ModelNode* mn = it->first; 110 | SceneGraph::GLObject* p = it->second; 111 | p->SetPose( mn->GetWPose() ); 112 | } 113 | } 114 | 115 | //std::vector objects; 116 | std::map m_mSceneEntities; 117 | 118 | }; 119 | 120 | #endif // RENDERCLASS_H 121 | -------------------------------------------------------------------------------- /Examples/Display/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Find Pangolin (https://github.com/stevenlovegrove/Pangolin) 2 | find_package(Pangolin REQUIRED) 3 | include_directories(${Pangolin_INCLUDE_DIRS}) 4 | 5 | # Find SceneGraph 6 | include_directories(${CMAKE_BINARY_DIR}/Examples/Display ${SceneGraph_INCLUDE_DIRS}) 7 | 8 | # Set GCC style compiler flags 9 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") 10 | 11 | add_executable(Display main.cpp) 12 | target_link_libraries(Display ${Pangolin_LIBRARIES}) 13 | target_link_libraries(Display ${SceneGraph_LIBRARIES}) 14 | -------------------------------------------------------------------------------- /Examples/Display/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | using namespace std; 10 | 11 | int main( int /*argc*/, char** /*argv[]*/ ) 12 | { 13 | // Create OpenGL window in single line thanks to GLUT 14 | pangolin::CreateWindowAndBind("Main",640,480); 15 | SceneGraph::GLSceneGraph::ApplyPreferredGlSettings(); 16 | 17 | // Scenegraph to hold GLObjects and relative transformations 18 | SceneGraph::GLSceneGraph glGraph; 19 | 20 | // Define grid object 21 | SceneGraph::GLGrid glGrid( 50, 2.0, true ); 22 | glGraph.AddChild(&glGrid); 23 | 24 | // Define axis object, and set its pose 25 | SceneGraph::GLAxis glAxis; 26 | glAxis.SetPose( 0, 0, 0, 0, 0, 0); 27 | glAxis.SetScale(0.25); 28 | glGraph.AddChild(&glAxis); 29 | 30 | // Define 3D spiral using a GLCachedPrimitives object 31 | SceneGraph::GLCachedPrimitives glSpiral(GL_LINE_STRIP, SceneGraph::GLColor(1.0f,0.7f,0.2f) ); 32 | for(double t=0; t < 10*M_PI; t+= M_PI/50) { 33 | glSpiral.AddVertex(Eigen::Vector3d(cos(t)+2, sin(t)+2, -0.1*t) ); 34 | } 35 | glGraph.AddChild(&glSpiral); 36 | 37 | // Define 3D floating text object 38 | SceneGraph::GLText glText3d("3D Floating Text", -1, 1, -1); 39 | glGraph.AddChild(&glText3d); 40 | 41 | #ifndef HAVE_GLES 42 | SceneGraph::GLMovableAxis glMovableAxis; 43 | glMovableAxis.SetPosition(-3,3,-1); 44 | glGraph.AddChild(&glMovableAxis); 45 | 46 | SceneGraph::GLAxisAlignedBox glBox; 47 | glBox.SetResizable(); 48 | glMovableAxis.AddChild(&glBox); 49 | 50 | // Define movable waypoint object with velocity 51 | SceneGraph::GLWayPoint glWaypoint; 52 | glWaypoint.SetPose(0.5,0.5,-0.1,0,0,0); 53 | glGraph.AddChild(&glWaypoint); 54 | 55 | // Optionally clamp waypoint to specific plane 56 | glWaypoint.ClampToPlane(Eigen::Vector4d(0,0,1,0)); 57 | #endif 58 | 59 | // Define Camera Render Object (for view / scene browsing) 60 | pangolin::OpenGlRenderState stacks3d( 61 | pangolin::ProjectionMatrix(640,480,420,420,320,240,0.1,1000), 62 | pangolin::ModelViewLookAt(0,-2,-4, 0,1,0, pangolin::AxisNegZ) 63 | ); 64 | 65 | // We define a new view which will reside within the container. 66 | pangolin::View view3d; 67 | 68 | // We set the views location on screen and add a handler which will 69 | // let user input update the model_view matrix (stacks3d) and feed through 70 | // to our scenegraph 71 | view3d.SetBounds(0.0, 1.0, 0.0, 1.0, 640.0f/480.0f) 72 | .SetHandler(new SceneGraph::HandlerSceneGraph(glGraph,stacks3d,pangolin::AxisNegZ)) 73 | .SetDrawFunction(SceneGraph::ActivateDrawFunctor(glGraph, stacks3d)); 74 | 75 | // Add our views as children to the base container. 76 | pangolin::DisplayBase().AddDisplay(view3d); 77 | 78 | // Default hooks for exiting (Esc) and fullscreen (tab). 79 | while( !pangolin::ShouldQuit() ) 80 | { 81 | // Clear whole screen 82 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 83 | 84 | // Swap frames and Process Events 85 | pangolin::FinishFrame(); 86 | 87 | // Pause for 1/60th of a second. 88 | std::this_thread::sleep_for(std::chrono::milliseconds(1000/60)); 89 | } 90 | 91 | return 0; 92 | } 93 | -------------------------------------------------------------------------------- /Examples/DisplayImage/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Find Pangolin (https://github.com/stevenlovegrove/Pangolin) 2 | find_package(Pangolin 0.1 REQUIRED) 3 | include_directories(${Pangolin_INCLUDE_DIRS}) 4 | 5 | # Find Scenegraph 6 | include_directories(${CMAKE_BINARY_DIR}/Examples/DisplayImage ${SceneGraph_INCLUDE_DIRS}) 7 | 8 | # Set GCC style compiler flags 9 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") 10 | 11 | add_executable(DisplayImage main.cpp) 12 | target_link_libraries(DisplayImage ${Pangolin_LIBRARIES}) 13 | target_link_libraries(DisplayImage ${SceneGraph_LIBRARIES}) 14 | -------------------------------------------------------------------------------- /Examples/DisplayImage/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | using namespace std; 12 | 13 | template 14 | void setRandomImageData(T* imageArray, int width, int height, int channels){ 15 | for(int i = 0 ; i < channels*width*height;i++) { 16 | imageArray[i] = std::numeric_limits::max() * ((float)rand()/RAND_MAX); 17 | } 18 | } 19 | 20 | // Draw in pixel units (center of image pixels) 21 | struct ExampleDrawSomethingInPixelCoords 22 | { 23 | void doTest( void ) 24 | { 25 | pangolin::GlState glstate; 26 | glstate.glShadeModel(GL_FLAT); 27 | GLfloat verts[] = {0, 0, 0,20, 20, 20}; 28 | GLfloat colors[] = {1,0,0,1, 0,1,0,1, 0,0,1,1}; 29 | glEnableClientState(GL_VERTEX_ARRAY); 30 | glEnableClientState(GL_COLOR_ARRAY); 31 | glVertexPointer(2, GL_FLOAT, 0, verts); 32 | glColorPointer(4, GL_FLOAT, 0, colors); 33 | glDrawArrays(GL_TRIANGLES, 0, 3); 34 | glDisableClientState(GL_VERTEX_ARRAY); 35 | glDisableClientState(GL_COLOR_ARRAY); 36 | } 37 | 38 | void doTest2( void ) 39 | { 40 | GLfloat verts[] = {20, 20, 20,0, 0, 0}; 41 | GLfloat colors[] = {1,0,0,1, 0,1,0,1, 0,0,1,1}; 42 | glEnableClientState(GL_VERTEX_ARRAY); 43 | glEnableClientState(GL_COLOR_ARRAY); 44 | glVertexPointer(2, GL_FLOAT, 0, verts); 45 | glColorPointer(4, GL_FLOAT, 0, colors); 46 | glDrawArrays(GL_TRIANGLES, 0, 3); 47 | glDisableClientState(GL_VERTEX_ARRAY); 48 | glDisableClientState(GL_COLOR_ARRAY); 49 | } 50 | 51 | void operator()(pangolin::View&) { 52 | glColor3f(1,1,1); 53 | pangolin::glDrawRectPerimeter(10,10, 40,40); 54 | doTest(); 55 | doTest2(); 56 | } 57 | }; 58 | 59 | void GlobalKeyHook(std::string str) 60 | { 61 | cout << str << endl; 62 | } 63 | 64 | int main( int /*argc*/, char** /*argv[]*/ ) 65 | { 66 | // Create OpenGL window in single line thanks to GLUT 67 | pangolin::CreateWindowAndBind("Main",640*2,480); 68 | SceneGraph::GLSceneGraph::ApplyPreferredGlSettings(); 69 | glClearColor(0, 0, 0, 0); 70 | 71 | // Scenegraph to hold GLObjects and relative transformations 72 | SceneGraph::GLSceneGraph glGraph; 73 | 74 | SceneGraph::GLLight light(10,10,-100); 75 | glGraph.AddChild(&light); 76 | 77 | // Define grid object 78 | SceneGraph::GLGrid glGrid( 50, 2.0, true ); 79 | glGraph.AddChild(&glGrid); 80 | 81 | // Define axis object, and set its pose 82 | SceneGraph::GLAxis glAxis; 83 | glAxis.SetPose(-1,-2,-1, 0, 0, M_PI/4); 84 | glAxis.SetScale(0.25); 85 | glGraph.AddChild(&glAxis); 86 | 87 | // Define 3D spiral using a line strip object 88 | SceneGraph::GLCachedPrimitives glSpiral(GL_LINE_STRIP, SceneGraph::GLColor(1.0f,0.7f,0.2f)); 89 | for(double t=0; t < 10*M_PI; t+= M_PI/50) { 90 | glSpiral.AddVertex(Eigen::Vector3d(cos(t)+2, sin(t)+2, -0.1*t) ); 91 | } 92 | glGraph.AddChild(&glSpiral); 93 | 94 | SceneGraph::GLWireSphere sphere(5); 95 | sphere.SetPose(5, 6, -7, M_PI / 3, M_PI / 3, M_PI / 3); 96 | glGraph.AddChild(&sphere); 97 | 98 | 99 | #ifndef HAVE_GLES 100 | // Define 3D floating text object 101 | SceneGraph::GLText glText3d("3D Floating Text", -1, 1, -1); 102 | glGraph.AddChild(&glText3d); 103 | #endif 104 | 105 | // Synthetic random image for demonstration 106 | const int w = 64; 107 | const int h = 48; 108 | unsigned char uImage[w*h*3]; 109 | setRandomImageData(uImage,w,h,3); 110 | 111 | // Define Camera Render Object (for view / scene browsing) 112 | pangolin::OpenGlRenderState stacks3d( 113 | pangolin::ProjectionMatrix(640,480,420,420,320,240,0.1,1000), 114 | pangolin::ModelViewLookAt(0,-2,-4, 0,1,0, pangolin::AxisNegZ) 115 | ); 116 | 117 | // Pangolin abstracts the OpenGL viewport as a View. 118 | // Here we get a reference to the default 'base' view. 119 | pangolin::View& container = pangolin::DisplayBase(); 120 | 121 | // We define a new view which will reside within the container. 122 | pangolin::View view3d; 123 | 124 | // We set the views location on screen and add a handler which will 125 | // let user input update the model_view matrix (stacks3d) and feed through 126 | // to our scenegraph 127 | view3d.SetBounds(0.0, 1.0, 0.0, 1.0/2.0, 640.0f/480.0f) 128 | .SetHandler(new SceneGraph::HandlerSceneGraph(glGraph,stacks3d,pangolin::AxisNegZ)) 129 | .SetDrawFunction(SceneGraph::ActivateDrawFunctor(glGraph, stacks3d)); 130 | 131 | // We define a special type of view which will accept image data 132 | // to display and set its bounds on screen. 133 | SceneGraph::ImageView viewImage(true,false); 134 | viewImage.SetBounds(0.0, 1.0, 1.0/2.0, 1.0, (double)w/h); 135 | viewImage.SetDrawFunction(ExampleDrawSomethingInPixelCoords()); 136 | 137 | // Add our views as children to the base container. 138 | container.AddDisplay(view3d); 139 | container.AddDisplay(viewImage); 140 | 141 | // Demonstration of how we can register a keyboard hook to trigger a method 142 | pangolin::RegisterKeyPressCallback( pangolin::PANGO_CTRL + 'r', std::bind(GlobalKeyHook, "You Pushed ctrl-r!" ) ); 143 | 144 | // // Default hooks for exiting (Esc) and fullscreen (tab). 145 | while( !pangolin::ShouldQuit() ) 146 | { 147 | // Clear whole screen 148 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 149 | 150 | // These calls can safely be made outside of the OpenGL thread. 151 | setRandomImageData(uImage,w,h,3); 152 | viewImage.SetImage(uImage, w,h, GL_RGB, GL_RGB, GL_UNSIGNED_BYTE); 153 | 154 | // Swap frames and Process Events 155 | pangolin::FinishFrame(); 156 | 157 | // Pause for 1/60th of a second. 158 | std::this_thread::sleep_for(std::chrono::milliseconds(1000 / 60)); 159 | } 160 | 161 | return 0; 162 | } 163 | -------------------------------------------------------------------------------- /Examples/DisplayMultiView/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Find Pangolin (https://github.com/stevenlovegrove/Pangolin) 2 | find_package(Pangolin 0.1 REQUIRED) 3 | include_directories(${Pangolin_INCLUDE_DIRS}) 4 | 5 | # Find Scenegraph 6 | include_directories(${CMAKE_BINARY_DIR}/Examples/DisplayMultiView ${SceneGraph_INCLUDE_DIRS}) 7 | 8 | # Set GCC style compiler flags 9 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") 10 | 11 | add_executable(DisplayMultiView main.cpp) 12 | target_link_libraries(DisplayMultiView ${Pangolin_LIBRARIES}) 13 | target_link_libraries(DisplayMultiView ${SceneGraph_LIBRARIES}) 14 | -------------------------------------------------------------------------------- /Examples/DisplayMultiView/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | using namespace std; 11 | 12 | void GlobalKeyHook(std::string str) 13 | { 14 | cout << str << endl; 15 | } 16 | 17 | int main( int /*argc*/, char** /*argv[]*/ ) 18 | { 19 | // Create OpenGL window in single line thanks to GLUT 20 | pangolin::CreateWindowAndBind("Main",640*2,480); 21 | SceneGraph::GLSceneGraph::ApplyPreferredGlSettings(); 22 | 23 | // Disable line smooth so that we can have transparent objects without 24 | // far-to-near ordered rendering. 25 | glDisable(GL_LINE_SMOOTH); 26 | 27 | // Scenegraph to hold GLObjects and relative transformations 28 | SceneGraph::GLSceneGraph glGraph; 29 | 30 | SceneGraph::GLLight light(10,10,-100); 31 | glGraph.AddChild(&light); 32 | 33 | // Define axis object, and set its pose 34 | SceneGraph::GLAxis glAxis; 35 | glAxis.SetPose( 0, 0, 0, 0, 0, 0); 36 | glAxis.SetScale(0.25); 37 | glGraph.AddChild(&glAxis); 38 | 39 | #ifndef HAVE_GLES 40 | // Define movable waypoint object with velocity 41 | SceneGraph::GLWayPoint glWaypoint; 42 | glWaypoint.SetPose(0.5,0.5,-0.1,0,0,0); 43 | glGraph.AddChild(&glWaypoint); 44 | 45 | // Optionally clamp waypoint to specific plane 46 | glWaypoint.ClampToPlane(Eigen::Vector4d(0,0,1,0)); 47 | #endif 48 | 49 | 50 | // Define 3D spiral using a GLCachedPrimitives object 51 | SceneGraph::GLCachedPrimitives glSpiral(GL_LINE_STRIP, SceneGraph::GLColor(1.0f,0.7f,0.2f)); 52 | for(double t=0; t < 10*M_PI; t+= M_PI/50) { 53 | glSpiral.AddVertex(Eigen::Vector3d(cos(t)+2, sin(t)+2, -0.1*t) ); 54 | } 55 | glGraph.AddChild(&glSpiral); 56 | 57 | // Define grid object -- this will be alpha transparent; 58 | // TODO: Always render near to far. 59 | SceneGraph::GLGrid glGrid( 50, 2.0, true ); 60 | glGrid.SetColors( 61 | SceneGraph::GLColor(1.0f, 1.0f, 1.0f, 0.3f), 62 | SceneGraph::GLColor(0.5f, 0.5f, 0.5f, 1.0f) 63 | ); 64 | glGraph.AddChild(&glGrid); 65 | 66 | // Define Camera Render Object (for view / scene browsing) 67 | pangolin::OpenGlRenderState stacks3d( 68 | pangolin::ProjectionMatrix(640,480,420,420,320,240,0.1,1000), 69 | pangolin::ModelViewLookAt(0,-2,-4, 0,1,0, pangolin::AxisNegZ) 70 | ); 71 | 72 | // Define second camera render object 73 | pangolin::OpenGlRenderState stacks3d_2( 74 | pangolin::ProjectionMatrix(640,480,420,420,320,240,0.1,1000), 75 | pangolin::ModelViewLookAt(2,-1,-2, 0,1,0, pangolin::AxisNegZ) 76 | ); 77 | 78 | // Pangolin abstracts the OpenGL viewport as a View. 79 | // Here we get a reference to the default 'base' view. 80 | pangolin::View& container = pangolin::DisplayBase(); 81 | 82 | // We define a new view which will reside within the container. 83 | pangolin::View view3d; 84 | 85 | // We set the views location on screen and add a handler which will 86 | // let user input update the model_view matrix (stacks3d) and feed through 87 | // to our scenegraph 88 | view3d.SetBounds(0.0, 1.0, 0.0, 1.0/2.0, 640.0f/480.0f) 89 | .SetHandler(new SceneGraph::HandlerSceneGraph(glGraph,stacks3d,pangolin::AxisNegZ)) 90 | .SetDrawFunction(SceneGraph::ActivateDrawFunctor(glGraph, stacks3d)); 91 | 92 | // We can define another view on the same scenegraph. We can also 93 | // render a second scenegraph as a 2D overlay using the different 94 | // 2D ModelView and Projection matrices (stacks3d) 95 | pangolin::View view3d_2d; 96 | view3d_2d.SetBounds(0.0,1.0, 1.0/2.0, 1.0, 640.0f/480.0f) 97 | .SetHandler(new SceneGraph::HandlerSceneGraph(glGraph,stacks3d_2,pangolin::AxisNegZ)) 98 | .SetDrawFunction(SceneGraph::ActivateDrawFunctor(glGraph, stacks3d_2)); 99 | 100 | // Add our views as children to the base container. 101 | container.AddDisplay(view3d); 102 | container.AddDisplay(view3d_2d); 103 | 104 | // Demonstration of how we can register a keyboard hook to trigger a method 105 | pangolin::RegisterKeyPressCallback( pangolin::PANGO_CTRL + 'r', std::bind(GlobalKeyHook, "You Pushed ctrl-r!" ) ); 106 | 107 | // Add keyhook to save window contents (including alpha). The framebuffer is saved just before it is swapped 108 | pangolin::RegisterKeyPressCallback( 's', std::bind(&pangolin::View::SaveOnRender, &pangolin::DisplayBase(), "window_OnRender" ) ); 109 | 110 | // Add keyhook to save a particular view (including alpha) at 4 times the resolution of the screen. This creates an FBO and renders into it straight away. 111 | pangolin::RegisterKeyPressCallback( 'r', std::bind(&pangolin::View::SaveRenderNow, &view3d, "view3d_RenderNow", 4 ) ); 112 | 113 | glClearColor( 0, 0, 0, 0 ); 114 | glEnable( GL_BLEND ); 115 | glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); 116 | 117 | 118 | // Default hooks for exiting (Esc) and fullscreen (tab). 119 | while( !pangolin::ShouldQuit() ) 120 | { 121 | // Clear whole screen 122 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 123 | 124 | // Swap frames and Process Events 125 | pangolin::FinishFrame(); 126 | 127 | // Pause for 1/60th of a second. 128 | std::this_thread::sleep_for(std::chrono::milliseconds(1000 / 60)); 129 | } 130 | 131 | return 0; 132 | } 133 | -------------------------------------------------------------------------------- /Examples/DisplayShadowTest/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Find Pangolin (https://github.com/stevenlovegrove/Pangolin) 2 | find_package(Pangolin 0.1 REQUIRED) 3 | include_directories(${Pangolin_INCLUDE_DIRS}) 4 | 5 | # Find Scenegraph 6 | include_directories(${CMAKE_BINARY_DIR}/Examples/DisplayShadowTest ${SceneGraph_INCLUDE_DIRS}) 7 | 8 | # Set GCC style compiler flags 9 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") 10 | 11 | add_executable(DisplayShadowTest main.cpp) 12 | target_link_libraries(DisplayShadowTest ${Pangolin_LIBRARIES}) 13 | target_link_libraries(DisplayShadowTest ${SceneGraph_LIBRARIES}) 14 | -------------------------------------------------------------------------------- /Examples/DisplayShadowTest/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | using namespace std; 10 | 11 | int main( int /*argc*/, char** /*argv[]*/ ) 12 | { 13 | // Create OpenGL window in single line thanks to GLUT 14 | pangolin::CreateGlutWindowAndBind("Main",640,480, GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_MULTISAMPLE); 15 | SceneGraph::GLSceneGraph::ApplyPreferredGlSettings(); 16 | glewInit(); 17 | 18 | // Scenegraph to hold GLObjects and relative transformations 19 | SceneGraph::GLSceneGraph glGraph; 20 | 21 | // Create shadow light to illuminate scene. Shadow casters 22 | // and receivers must be set up individually. 23 | SceneGraph::GLShadowLight shadowLight(10,10,-100, 2048,2048); 24 | glGraph.AddChild(&shadowLight); 25 | 26 | // Define grid object 27 | SceneGraph::GLGrid glGrid(20,1.0, true); 28 | glGraph.AddChild(&glGrid); 29 | shadowLight.AddShadowReceiver(&glGrid); 30 | 31 | // Define axis object, and set its pose 32 | SceneGraph::GLAxis glAxis; 33 | glAxis.SetPose(-1,-2,-0.1, 0, 0, M_PI/4); 34 | glAxis.SetScale(0.25); 35 | glGraph.AddChild(&glAxis); 36 | 37 | // Define 3D spiral using a GLCachedPrimitives object 38 | SceneGraph::GLCachedPrimitives glSpiral(GL_LINE_STRIP, SceneGraph::GLColor(1.0f,0.7f,0.2f)); 39 | for(double t=0; t < 10*M_PI; t+= M_PI/50) { 40 | glSpiral.AddVertex(Eigen::Vector3d(cos(t)+2, sin(t)+2, -0.2*t) ); 41 | } 42 | glGraph.AddChild(&glSpiral); 43 | 44 | SceneGraph::GLCube glCube; 45 | glCube.SetPose(1.5,1.5,-sqrt(3), M_PI/4, M_PI/4, M_PI/4); 46 | glGraph.AddChild(&glCube); 47 | shadowLight.AddShadowCaster(&glCube); 48 | 49 | #ifdef HAVE_ASSIMP 50 | // Define a mesh object and try to load model 51 | SceneGraph::GLMesh glMesh; 52 | try { 53 | glMesh.Init("./model.blend"); 54 | glMesh.SetPosition(0,0,-1); 55 | glMesh.SetScale(4.0f); 56 | glGraph.AddChild(&glMesh); 57 | shadowLight.AddShadowCasterAndReceiver(&glMesh); 58 | }catch(exception e) { 59 | cerr << "Cannot load mesh. Check file exists" << endl; 60 | } 61 | #endif // HAVE_ASSIMP 62 | 63 | // Define Camera Render Object (for view / scene browsing) 64 | pangolin::OpenGlRenderState stacks3d( 65 | pangolin::ProjectionMatrix(640,480,420,420,320,240,0.1,1000), 66 | pangolin::ModelViewLookAt(0,-2,-4, 0,1,0, pangolin::AxisNegZ) 67 | ); 68 | 69 | 70 | 71 | // Pangolin abstracts the OpenGL viewport as a View. 72 | // Here we get a reference to the default 'base' view. 73 | pangolin::View& container = pangolin::DisplayBase(); 74 | 75 | // We define a new view which will reside within the container. 76 | pangolin::View view3d; 77 | 78 | // We set the views location on screen and add a handler which will 79 | // let user input update the model_view matrix (stacks3d) and feed through 80 | // to our scenegraph 81 | view3d.SetBounds(0.0, 1.0, 0.0, 1.0, 640.0f/480.0f) 82 | .SetHandler(new SceneGraph::HandlerSceneGraph(glGraph,stacks3d,pangolin::AxisNegZ)) 83 | .SetDrawFunction(SceneGraph::ActivateDrawFunctor(glGraph, stacks3d)); 84 | 85 | pangolin::View& viewLight = pangolin::CreateDisplay() 86 | .SetBounds(0.0, 0.3, 0, 0.3) 87 | .SetDrawFunction(SceneGraph::ActivateScissorClearDrawFunctor(glGraph,shadowLight.GetRenderState())); 88 | 89 | 90 | // Add our view as children to the base container. 91 | container.AddDisplay(view3d); 92 | container.AddDisplay(viewLight); 93 | 94 | // Default hooks for exiting (Esc) and fullscreen (tab). 95 | for(int frame=0; !pangolin::ShouldQuit(); ++frame ) 96 | { 97 | // Clear whole screen 98 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 99 | 100 | // Animate position of light over time. 101 | shadowLight.SetPosition(100*cos(frame/100.0), 100*sin(frame/100.0), -100 ); 102 | 103 | // Swap frames and Process Events 104 | pangolin::FinishFrame(); 105 | 106 | // Pause for 1/60th of a second. 107 | std::this_thread::sleep_for(std::chrono::milliseconds(1000 / 60)); 108 | } 109 | 110 | return 0; 111 | } 112 | -------------------------------------------------------------------------------- /Examples/ModelPhysics/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Find Pangolin (https://github.com/stevenlovegrove/Pangolin) 2 | find_package(Pangolin 0.1 REQUIRED) 3 | include_directories(${Pangolin_INCLUDE_DIRS}) 4 | 5 | # Find Scenegraph 6 | include_directories(${CMAKE_BINARY_DIR}/Examples/ModelPhysics ${SceneGraph_INCLUDE_DIRS}) 7 | 8 | # Set GCC style compiler flags 9 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") 10 | 11 | find_package(Bullet QUIET) 12 | if(BULLET_FOUND) 13 | include_directories(${BULLET_INCLUDE_DIRS}) 14 | 15 | # We require Bullet to be built with double precision# 16 | add_definitions(-DBT_USE_DOUBLE_PRECISION) 17 | add_definitions(-DBT_BUILD_SHARED_LIBS) 18 | add_executable(ModelPhysics main.cpp) 19 | target_link_libraries(ModelPhysics ${Pangolin_LIBRARIES}) 20 | target_link_libraries(ModelPhysics ${SceneGraph_LIBRARIES}) 21 | target_link_libraries(ModelPhysics ${BULLET_LIBRARIES}) 22 | 23 | add_executable( CarDemo CarDemo.cpp ) 24 | target_link_libraries(CarDemo ${Pangolin_LIBRARIES}) 25 | target_link_libraries(CarDemo ${SceneGraph_LIBRARIES}) 26 | target_link_libraries(CarDemo ${BULLET_LIBRARIES}) 27 | target_link_libraries(CarDemo ${CVars_LIBRARIES}) 28 | endif() 29 | -------------------------------------------------------------------------------- /Examples/ModelPhysics/GLBulletDebugDrawer.cpp: -------------------------------------------------------------------------------- 1 | #include "GLBulletDebugDrawer.h" 2 | 3 | GLBulletDebugDrawer::GLBulletDebugDrawer() 4 | { 5 | } 6 | 7 | 8 | void GLBulletDebugDrawer::Init(BulletCarModel* pModel) 9 | { 10 | m_pModel = pModel; 11 | } 12 | 13 | void GLBulletDebugDrawer::DrawCanonicalObject() 14 | { 15 | m_pModel->DebugDrawWorld(0); 16 | } 17 | -------------------------------------------------------------------------------- /Examples/ModelPhysics/GLBulletDebugDrawer.h: -------------------------------------------------------------------------------- 1 | #ifndef GLBULLETDEBUGDRAWER_H 2 | #define GLBULLETDEBUGDRAWER_H 3 | 4 | #include "LocalPlanner.h" 5 | #include "pangolin/pangolin.h" 6 | #include "SceneGraph/SceneGraph.h" 7 | 8 | 9 | using namespace SceneGraph; 10 | 11 | class GLBulletDebugDrawer : public GLObject 12 | { 13 | public: 14 | GLBulletDebugDrawer(); 15 | void Init(BulletCarModel* pModel); 16 | virtual void DrawCanonicalObject(); 17 | 18 | private: 19 | BulletCarModel* m_pModel; 20 | }; 21 | 22 | #endif // GLBULLETDEBUGDRAWER_H 23 | -------------------------------------------------------------------------------- /Examples/ModelPhysics/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include "BulletWrapper.h" 9 | 10 | using namespace std; 11 | 12 | int main( int /*argc*/, char** /*argv*/ ) 13 | { 14 | // Create OpenGL window in single line thanks to GLUT 15 | pangolin::CreateWindowAndBind("Main",640,480); 16 | SceneGraph::GLSceneGraph::ApplyPreferredGlSettings(); 17 | glewInit(); 18 | 19 | // Scenegraph to hold GLObjects and relative transformations 20 | SceneGraph::GLSceneGraph glGraph; 21 | 22 | SceneGraph::GLLight light(10,10,-100); 23 | glGraph.AddChild(&light); 24 | 25 | SceneGraph::GLGrid grid(10,1,true); 26 | glGraph.AddChild(&grid); 27 | 28 | SceneGraph::GLCube cube; 29 | cube.SetPose(0,0,20,M_PI_4,M_PI_4,0.1); 30 | glGraph.AddChild(&cube); 31 | 32 | const SceneGraph::AxisAlignedBoundingBox bbox = glGraph.ObjectAndChildrenBounds(); 33 | const Eigen::Vector3d center = bbox.Center(); 34 | const double size = bbox.Size().norm(); 35 | const double far = 10*size; 36 | const double near = far / 1E3; 37 | 38 | // Define Camera Render Object (for view / scene browsing) 39 | pangolin::OpenGlRenderState stacks3d( 40 | pangolin::ProjectionMatrix(640,480,420,420,320,240,near,far), 41 | pangolin::ModelViewLookAt(center(0), center(1) + size, center(2) + size/4, center(0), center(1), center(2), pangolin::AxisZ) 42 | ); 43 | 44 | // We define a new view which will reside within the container. 45 | pangolin::View view3d; 46 | 47 | // We set the views location on screen and add a handler which will 48 | // let user input update the model_view matrix (stacks3d) and feed through 49 | // to our scenegraph 50 | view3d.SetBounds(0.0, 1.0, 0.0, 1.0, -640.0f/480.0f) 51 | .SetHandler(new SceneGraph::HandlerSceneGraph(glGraph,stacks3d)) 52 | .SetDrawFunction(SceneGraph::ActivateDrawFunctor(glGraph, stacks3d)); 53 | 54 | // Add our views as children to the base container. 55 | pangolin::DisplayBase().AddDisplay(view3d); 56 | 57 | // Physics stuff 58 | // Build the broadphase (approximate collision detection) 59 | btDbvtBroadphase broadphase; 60 | btDefaultCollisionConfiguration collisionConfiguration; 61 | btCollisionDispatcher dispatcher(&collisionConfiguration); 62 | btSequentialImpulseConstraintSolver solver; 63 | btDiscreteDynamicsWorld dynamicsWorld(&dispatcher,&broadphase,&solver,&collisionConfiguration); 64 | dynamicsWorld.setGravity(btVector3(0,0,-10)); 65 | 66 | btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0,0,1),0); 67 | btCollisionShape* fallShape = new btBoxShape(toBulletVec3( cube.ObjectBounds().HalfSizeFromOrigin() ) ); 68 | 69 | btDefaultMotionState* groundMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,0,0))); 70 | btRigidBody::btRigidBodyConstructionInfo 71 | groundRigidBodyCI(0,groundMotionState,groundShape,btVector3(0,0,0)); 72 | btRigidBody* groundRigidBody = new btRigidBody(groundRigidBodyCI); 73 | groundRigidBody->setRestitution(0.1); 74 | dynamicsWorld.addRigidBody(groundRigidBody); 75 | 76 | 77 | SceneGraphMotionState* fallMotionState = new SceneGraphMotionState(cube); 78 | btScalar mass = 1; 79 | btVector3 fallInertia(0,0,0); 80 | fallShape->calculateLocalInertia(mass,fallInertia); 81 | btRigidBody::btRigidBodyConstructionInfo fallRigidBodyCI(mass,fallMotionState,fallShape,fallInertia); 82 | btRigidBody* fallRigidBody = new btRigidBody(fallRigidBodyCI); 83 | fallRigidBody->setRestitution(5); 84 | dynamicsWorld.addRigidBody(fallRigidBody); 85 | 86 | // Default hooks for exiting (Esc) and fullscreen (tab). 87 | while( !pangolin::ShouldQuit() ) 88 | { 89 | // Clear whole screen 90 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 91 | 92 | // Swap frames and Process Events 93 | pangolin::FinishFrame(); 94 | 95 | // Pause for 1/60th of a second. 96 | usleep(1E6 / 60); 97 | dynamicsWorld.stepSimulation(1/60.f,10); 98 | } 99 | 100 | dynamicsWorld.removeRigidBody(fallRigidBody); 101 | delete fallRigidBody->getMotionState(); 102 | delete fallRigidBody; 103 | 104 | dynamicsWorld.removeRigidBody(groundRigidBody); 105 | delete groundRigidBody->getMotionState(); 106 | delete groundRigidBody; 107 | 108 | 109 | delete fallShape; 110 | 111 | delete groundShape; 112 | 113 | return 0; 114 | } 115 | -------------------------------------------------------------------------------- /Examples/ModelViewer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Find Pangolin (https://github.com/stevenlovegrove/Pangolin) 2 | find_package(Pangolin 0.1 REQUIRED) 3 | include_directories(${Pangolin_INCLUDE_DIRS}) 4 | 5 | # Find Scenegraph 6 | include_directories(${CMAKE_BINARY_DIR}/Examples/ModelViewer ${SceneGraph_INCLUDE_DIRS}) 7 | 8 | # Set GCC style compiler flags 9 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") 10 | 11 | add_executable(ModelViewer main.cpp) 12 | target_link_libraries(ModelViewer ${Pangolin_LIBRARIES}) 13 | target_link_libraries(ModelViewer ${SceneGraph_LIBRARIES}) 14 | -------------------------------------------------------------------------------- /Examples/ModelViewer/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | using namespace std; 10 | 11 | void Usage() { 12 | cout << "Usage: ModelViewer filename" << endl; 13 | } 14 | 15 | int main( int argc, char* argv[] ) 16 | { 17 | if(argc != 2) { 18 | Usage(); 19 | exit(-1); 20 | } 21 | 22 | const std::string model_filename(argv[1]); 23 | 24 | // Create OpenGL window in single line thanks to GLUT 25 | pangolin::CreateWindowAndBind("Main",640,480); 26 | SceneGraph::GLSceneGraph::ApplyPreferredGlSettings(); 27 | glClearColor( 0,0,0,0); 28 | glewInit(); 29 | 30 | // Scenegraph to hold GLObjects and relative transformations 31 | SceneGraph::GLSceneGraph glGraph; 32 | 33 | SceneGraph::GLLight light(10,10,-100); 34 | glGraph.AddChild(&light); 35 | 36 | SceneGraph::GLGrid grid(10,1,true); 37 | glGraph.AddChild(&grid); 38 | 39 | SceneGraph::AxisAlignedBoundingBox bbox; 40 | 41 | #ifdef HAVE_ASSIMP 42 | // Define a mesh object and try to load model 43 | SceneGraph::GLMesh glMesh; 44 | try { 45 | glMesh.Init(model_filename); 46 | glGraph.AddChild(&glMesh); 47 | bbox = glMesh.ObjectAndChildrenBounds(); 48 | }catch(exception e) { 49 | cerr << "Cannot load mesh." << endl; 50 | cerr << e.what() << std::endl; 51 | exit(-1); 52 | } 53 | #endif // HAVE_ASSIMP 54 | 55 | 56 | const Eigen::Vector3d center = bbox.Center(); 57 | double size = bbox.Size().norm(); 58 | 59 | // Define Camera Render Object (for view / scene browsing) 60 | pangolin::OpenGlRenderState stacks3d( 61 | pangolin::ProjectionMatrix(640,480,420,420,320,240, 0.01, 1000), 62 | pangolin::ModelViewLookAt(center(0), center(1) + size, center(2) + size/4, center(0), center(1), center(2), pangolin::AxisZ) 63 | ); 64 | 65 | // We define a new view which will reside within the container. 66 | pangolin::View view3d; 67 | 68 | // We set the views location on screen and add a handler which will 69 | // let user input update the model_view matrix (stacks3d) and feed through 70 | // to our scenegraph 71 | view3d.SetBounds(0.0, 1.0, 0.0, 1.0, -640.0f/480.0f) 72 | .SetHandler(new SceneGraph::HandlerSceneGraph(glGraph,stacks3d)) 73 | .SetDrawFunction(SceneGraph::ActivateDrawFunctor(glGraph, stacks3d)); 74 | 75 | // Add our views as children to the base container. 76 | pangolin::DisplayBase().AddDisplay(view3d); 77 | 78 | // Default hooks for exiting (Esc) and fullscreen (tab). 79 | while( !pangolin::ShouldQuit() ) 80 | { 81 | // Clear whole screen 82 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 83 | 84 | // Swap frames and Process Events 85 | pangolin::FinishFrame(); 86 | 87 | // Pause for 1/60th of a second. 88 | std::this_thread::sleep_for(std::chrono::milliseconds(1000 / 60)); 89 | } 90 | 91 | return 0; 92 | } 93 | -------------------------------------------------------------------------------- /Examples/OffscreenRender/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Find Pangolin (https://github.com/stevenlovegrove/Pangolin) 2 | find_package(Pangolin 0.1 REQUIRED) 3 | include_directories(${Pangolin_INCLUDE_DIRS}) 4 | 5 | # Find Scenegraph 6 | include_directories(${CMAKE_BINARY_DIR}/Examples/OffscreenRender ${SceneGraph_INCLUDE_DIRS}) 7 | 8 | # Set GCC style compiler flags 9 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") 10 | 11 | add_executable(OffscreenRender main.cpp) 12 | target_link_libraries(OffscreenRender ${Pangolin_LIBRARIES}) 13 | target_link_libraries(OffscreenRender ${SceneGraph_LIBRARIES}) 14 | -------------------------------------------------------------------------------- /Examples/SimCam/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required( VERSION 2.8 ) 2 | 3 | project( SimCamDEMO ) 4 | 5 | find_package( Pangolin REQUIRED ) 6 | 7 | include_directories( ${Pangolin_INCLUDE_DIRS} ) 8 | 9 | link_directories( ${Pangolin_LIBRARY_DIRS} ) 10 | 11 | list(APPEND HDRS 12 | CVarHelpers.h 13 | ) 14 | 15 | list(APPEND SRCS 16 | SimCamDEMO.cpp 17 | ) 18 | 19 | add_executable( SimCamDEMO ${HDRS} ${SRCS} ) 20 | 21 | target_link_libraries( SimCamDEMO 22 | ${Pangolin_LIBRARIES} 23 | ${SceneGraph_LIBRARIES} 24 | ${MVL_LIBRARIES} 25 | ) 26 | 27 | # In your own code, you can ommit these lines 28 | IF( ${SceneGraph_EXAMPLE} ) 29 | add_dependencies(SimCamDEMO scenegraph ) 30 | ENDIF() 31 | -------------------------------------------------------------------------------- /Examples/SimCam/CVarHelpers.h: -------------------------------------------------------------------------------- 1 | #ifndef _CVAR_HELPERS_ 2 | #define _CVAR_HELPERS_ 3 | 4 | #include 5 | 6 | #include 7 | 8 | //////////////////////////////////////////////////////////////////////////// 9 | // Overloading Eigen for CVars 10 | namespace CVarUtils 11 | { 12 | inline std::ostream& operator<<( std::ostream& Stream, Eigen::Vector6d& Mat ) 13 | { 14 | unsigned int nRows = Mat.rows(); 15 | unsigned int nCols = Mat.cols(); 16 | 17 | Stream << "[ "; 18 | 19 | for( unsigned int ii = 0; ii < nRows-1; ii++ ) { 20 | for( unsigned int jj = 0; jj < nCols-1; jj++ ) { 21 | Stream << Mat(ii, jj); 22 | Stream << ", "; 23 | } 24 | Stream << Mat(ii, nCols-1); 25 | Stream << "; "; 26 | } 27 | for( unsigned int jj = 0; jj < nCols-1; jj++ ) { 28 | Stream << Mat(nRows-1, jj); 29 | Stream << ", "; 30 | } 31 | Stream << Mat(nRows-1, nCols-1); 32 | Stream << " ]"; 33 | 34 | return Stream; 35 | } 36 | 37 | //////////////////////////////////////////////////////////////////////////// 38 | inline std::istream& operator>>( std::istream& Stream, Eigen::Vector6d& Mat ) 39 | { 40 | 41 | unsigned int nRows = Mat.rows(); 42 | unsigned int nCols = Mat.cols(); 43 | char str[256]; 44 | 45 | Stream.getline(str, 255, '['); 46 | if( Stream.gcount() > 1 ) { 47 | return Stream; 48 | } 49 | for( unsigned int ii = 0; ii < nRows-1; ii++ ) { 50 | for( unsigned int jj = 0; jj < nCols-1; jj++ ) { 51 | Stream.getline(str, 255, ','); 52 | Mat(ii, jj) = std::strtod(str, NULL); 53 | } 54 | Stream.getline(str, 255, ';'); 55 | Mat(ii, nCols-1) = std::strtod(str, NULL); 56 | } 57 | for( unsigned int jj = 0; jj < nCols-1; jj++ ) { 58 | Stream.getline(str, 255, ','); 59 | Mat(nRows-1, jj) = std::strtod(str, NULL); 60 | } 61 | Stream.getline(str, 255, ']'); 62 | Mat(nRows-1, nCols-1) = std::strtod(str, NULL); 63 | return Stream; 64 | } 65 | 66 | } 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /Examples/Widgets/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Find Pangolin (https://github.com/stevenlovegrove/Pangolin) 2 | find_package(Pangolin 0.1 REQUIRED) 3 | include_directories(${Pangolin_INCLUDE_DIRS}) 4 | 5 | # Find Scenegraph 6 | include_directories(${CMAKE_BINARY_DIR}/Examples/Widgets ${SceneGraph_INCLUDE_DIRS}) 7 | 8 | # Set GCC style compiler flags 9 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") 10 | 11 | add_executable(Widgets main.cpp) 12 | target_link_libraries(Widgets ${Pangolin_LIBRARIES}) 13 | target_link_libraries(Widgets ${SceneGraph_LIBRARIES}) 14 | -------------------------------------------------------------------------------- /Examples/Widgets/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #define WINDOW_HEIGHT 480.0f 11 | #define WINDOW_WIDTH 640.0f 12 | 13 | #define UI_PANEL_HEIGHT WINDOW_HEIGHT 14 | #define UI_PANEL_WIDTH 200 15 | 16 | using namespace std; 17 | 18 | void Usage() { 19 | cout << "Usage: ModelViewer filename" << endl; 20 | } 21 | 22 | bool g_bCheckbox1 = false; 23 | bool g_bCheckbox2 = true; 24 | 25 | void WidgetDrawFunction (nv::GlutUIContext& context,nv::Rect& rect) 26 | { 27 | context.beginFrame(nv::GroupFlags_GrowDownFromLeft,rect); 28 | context.doCheckButton(nv::Rect(),"Checkbox1:", &g_bCheckbox1); 29 | context.doCheckButton(nv::Rect(),"Checkbox2:", &g_bCheckbox2); 30 | context.beginGroup(nv::GroupFlags_GrowRightFromTop); 31 | context.doLabel(nv::Rect(),"123"); 32 | context.doLabel(nv::Rect(),"456"); 33 | context.endGroup(); 34 | context.endFrame(); 35 | } 36 | 37 | void GlobalKeyHook(std::string str) 38 | { 39 | cout << str << endl; 40 | } 41 | 42 | int main( int argc, char* argv[] ) 43 | { 44 | // Create OpenGL window in single line thanks to GLUT 45 | pangolin::CreateWindowAndBind("Main",640,480); 46 | SceneGraph::GLSceneGraph::ApplyPreferredGlSettings(); 47 | glewInit(); 48 | 49 | // Scenegraph to hold GLObjects and relative transformations 50 | SceneGraph::GLSceneGraph glGraph; 51 | 52 | SceneGraph::GLLight light(10,10,-100); 53 | glGraph.AddChild(&light); 54 | 55 | // Define grid object 56 | SceneGraph::GLGrid glGrid(50,2.0, true); 57 | 58 | // Define axis object, and set its pose 59 | SceneGraph::GLAxis glAxis; 60 | glAxis.SetPose(-1,-2,-0.1, 0, 0, M_PI/4); 61 | glAxis.SetScale(0.25); 62 | 63 | SceneGraph::GLMovableAxis glMovableAxis; 64 | glMovableAxis.SetPosition(-3,3,-1); 65 | 66 | SceneGraph::GLAxisAlignedBox glBox; 67 | glBox.SetResizable(); 68 | 69 | // Define movable waypoint object with velocity 70 | SceneGraph::GLWayPoint glWaypoint; 71 | glWaypoint.SetPose(0.5,0.5,-0.1,0,0,0); 72 | 73 | // Optionally clamp waypoint to specific plane 74 | glWaypoint.ClampToPlane(Eigen::Vector4d(0,0,1,0)); 75 | 76 | // Define 3D spiral using a GLCachedPrimitives object 77 | SceneGraph::GLCachedPrimitives glSpiral(GL_LINE_STRIP, SceneGraph::GLColor(1.0f,0.7f,0.2f)); 78 | for(double t=0; t < 10*M_PI; t+= M_PI/50) { 79 | glSpiral.AddVertex(Eigen::Vector3d(cos(t)+2, sin(t)+2, -0.1*t) ); 80 | } 81 | 82 | // Define 3D floating text object 83 | SceneGraph::GLText glText3d("3D Floating Text", -1, 1, -1); 84 | 85 | 86 | // Add objects to scenegraph 87 | glGraph.AddChild(&glGrid); 88 | glGraph.AddChild(&glWaypoint); 89 | glGraph.AddChild(&glSpiral); 90 | glGraph.AddChild(&glAxis); 91 | glGraph.AddChild(&glText3d); 92 | glGraph.AddChild(&glMovableAxis); 93 | glMovableAxis.AddChild(&glBox); 94 | 95 | 96 | // Define Camera Render Object (for view / scene browsing) 97 | pangolin::OpenGlRenderState stacks3d( 98 | pangolin::ProjectionMatrix(640,480,420,420,320,240,0.1,1000), 99 | pangolin::ModelViewLookAt(0,-2,-4, 0,1,0, pangolin::AxisNegZ) 100 | ); 101 | 102 | // Pangolin abstracts the OpenGL viewport as a View. 103 | // Here we get a reference to the default 'base' view. 104 | pangolin::View& container = pangolin::DisplayBase(); 105 | 106 | // We define a new view which will reside within the container. 107 | pangolin::View view3d; 108 | 109 | // We set the views location on screen and add a handler which will 110 | // let user input update the model_view matrix (stacks3d) and feed through 111 | // to our scenegraph 112 | view3d.SetBounds(0.0, 1.0, 0.0, 1.0, 640.0f/480.0f) 113 | .SetHandler(new SceneGraph::HandlerSceneGraph(glGraph,stacks3d,pangolin::AxisNegZ)) 114 | .SetDrawFunction(SceneGraph::ActivateDrawFunctor(glGraph, stacks3d)); 115 | 116 | // Add our views as children to the base container. 117 | container.AddDisplay(view3d); 118 | 119 | 120 | GLWidgetView panel; 121 | panel.Init(0,1,0,Attach::Pix(200),&WidgetDrawFunction); 122 | 123 | container.AddDisplay(panel); 124 | 125 | // Demonstration of how we can register a keyboard hook to trigger a method 126 | pangolin::RegisterKeyPressCallback( pangolin::PANGO_CTRL + 'r', std::bind(GlobalKeyHook, "You Pushed ctrl-r!" ) ); 127 | 128 | // Add keyhook to save window contents (including alpha). The framebuffer is saved just before it is swapped 129 | pangolin::RegisterKeyPressCallback( 's', std::bind(&pangolin::View::SaveOnRender, &pangolin::DisplayBase(), "window_OnRender" ) ); 130 | 131 | // Add keyhook to save a particular view (including alpha) at 4 times the resolution of the screen. This creates an FBO and renders into it straight away. 132 | pangolin::RegisterKeyPressCallback( 'r', std::bind(&pangolin::View::SaveRenderNow, &view3d, "view3d_RenderNow", 4 ) ); 133 | 134 | // Default hooks for exiting (Esc) and fullscreen (tab). 135 | while( !pangolin::ShouldQuit() ) 136 | { 137 | // Clear whole screen 138 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 139 | 140 | // Swap frames and Process Events 141 | pangolin::FinishFrame(); 142 | 143 | // Pause for 1/60th of a second. 144 | std::this_thread::sleep_for(std::chrono::milliseconds(1000 / 60)); 145 | } 146 | 147 | 148 | return 0; 149 | } 150 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2013 Autonomous Robotics & Perception Group 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | 2 | SceneGraph is a rudimentary scene graph, the nodes of which are C++ classes 3 | inherited from "GLObject". These objects must have a "DrawCanonicalObject()" 4 | funciton. 5 | 6 | Presently, SceneGraph is used with Pangolin. 7 | 8 | Dependencies: 9 | CVars (https://github.com/arpg/CVars) 10 | OpenGL 11 | ASSIMP 12 | Eigen3 13 | Pangolin (https://github.com/arpg/Pangolin) 14 | 15 | -------------------------------------------------------------------------------- /cmake_modules/.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | -------------------------------------------------------------------------------- /cmake_modules/FindASSIMP.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find Assimp 2 | # Once done, this will define 3 | # 4 | # ASSIMP_FOUND - system has Assimp 5 | # ASSIMP_INCLUDE_DIR - the Assimp include directories 6 | # ASSIMP_LIBRARIES - link these to use Assimp 7 | 8 | FIND_PATH( ASSIMP_INCLUDE_DIR assimp/mesh.h 9 | /usr/include 10 | /usr/local/include 11 | /opt/local/include 12 | ) 13 | 14 | FIND_LIBRARY( ASSIMP_LIBRARY assimp 15 | /usr/lib64 16 | /usr/lib 17 | /usr/local/lib 18 | /opt/local/lib 19 | ) 20 | 21 | IF(ASSIMP_INCLUDE_DIR AND ASSIMP_LIBRARY) 22 | SET( ASSIMP_FOUND TRUE ) 23 | SET( ASSIMP_LIBRARIES ${ASSIMP_LIBRARY} ) 24 | ENDIF(ASSIMP_INCLUDE_DIR AND ASSIMP_LIBRARY) 25 | 26 | IF(ASSIMP_FOUND) 27 | IF(NOT ASSIMP_FIND_QUIETLY) 28 | MESSAGE(STATUS "Found ASSIMP: ${ASSIMP_LIBRARY}") 29 | ENDIF(NOT ASSIMP_FIND_QUIETLY) 30 | ELSE(ASSIMP_FOUND) 31 | IF(ASSIMP_FIND_REQUIRED) 32 | MESSAGE(FATAL_ERROR "Could not find libASSIMP") 33 | ENDIF(ASSIMP_FIND_REQUIRED) 34 | ENDIF(ASSIMP_FOUND) 35 | -------------------------------------------------------------------------------- /cmake_modules/FindAndroidKernel.cmake: -------------------------------------------------------------------------------- 1 | # FindAndroidKernel.cmake 2 | # AndroidKernel_FOUND 3 | # AndroidKernel_INCLUDE_DIRS 4 | # AndroidKernel_LIBRARIES 5 | # 6 | # Copy android kernel headers onto ${CMAKE_FIND_ROOT_PATH} path 7 | # e.g. TOOLCHAIN_DIR/user/kernel 8 | 9 | SET(AndroidKernel_POSSIBLE_ROOT_DIRS 10 | /kernel/frameworks/av/include 11 | /kernel/frameworks/native/include 12 | /kernel/system/core/include 13 | /kernel/system/media/camera/include 14 | /kernel/hardware/libhardware/include 15 | ) 16 | 17 | FIND_PATH(AndroidKernel_AV_INCLUDE_DIR 18 | NAMES camera/ICamera.h gestures/IGestureDevice.h media/IMediaPlayer.h 19 | PATHS ${AndroidKernel_POSSIBLE_ROOT_DIRS}) 20 | FIND_PATH(AndroidKernel_NATIVE_INCLUDE_DIR 21 | NAMES gui/IGraphicBufferProducer.h 22 | PATHS ${AndroidKernel_POSSIBLE_ROOT_DIRS}) 23 | FIND_PATH(AndroidKernel_HARDWARE_INCLUDE_DIR 24 | NAMES hardware/camera.h hardware/lights.h 25 | PATHS ${AndroidKernel_POSSIBLE_ROOT_DIRS}) 26 | FIND_PATH(AndroidKernel_CORE_INCLUDE_DIR 27 | NAMES cutils/atomic.h 28 | PATHS ${AndroidKernel_POSSIBLE_ROOT_DIRS}) 29 | FIND_PATH(AndroidKernel_CAMERA_INCLUDE_DIR 30 | NAMES system/camera_metadata.h 31 | PATHS ${AndroidKernel_POSSIBLE_ROOT_DIRS}) 32 | 33 | SET(AndroidKernel_INCLUDE_DIRS 34 | ${AndroidKernel_AV_INCLUDE_DIR} 35 | ${AndroidKernel_NATIVE_INCLUDE_DIR} 36 | ${AndroidKernel_HARDWARE_INCLUDE_DIR} 37 | ${AndroidKernel_CORE_INCLUDE_DIR} 38 | ${AndroidKernel_CAMERA_INCLUDE_DIR} 39 | ) 40 | 41 | SET(AndroidKernel_LIBRARIES 42 | cameraservice camera_client 43 | utils cutils 44 | gui binder 45 | ) 46 | 47 | SET(AndroidKernel_FOUND ON) 48 | 49 | FOREACH(NAME ${AndroidKernel_INCLUDE_DIRS}) 50 | IF(NOT EXISTS ${NAME}) 51 | SET(AndroidKernel_FOUND OFF) 52 | ENDIF(NOT EXISTS ${NAME}) 53 | ENDFOREACH(NAME) 54 | 55 | MARK_AS_ADVANCED(FORCE 56 | AndroidKernel_AV_INCLUDE_DIR 57 | AndroidKernel_NATIVE_INCLUDE_DIR 58 | AndroidKernel_HARDWARE_INCLUDE_DIR 59 | AndroidKernel_CORE_INCLUDE_DIR 60 | AndroidKernel_CAMERA_INCLUDE_DIR 61 | ) 62 | 63 | IF(AndroidKernel_FOUND) 64 | IF(NOT AndroidKernel_FIND_QUIETLY) 65 | MESSAGE(STATUS "Found Android Kernel headers.") 66 | ENDIF (NOT AndroidKernel_FIND_QUIETLY) 67 | ELSE(AndroidKernel_FOUND) 68 | IF(AndroidKernel_FIND_REQUIRED) 69 | MESSAGE(FATAL_ERROR "Could not find AndroidKernel. Please specify it's location.") 70 | ENDIF(AndroidKernel_FIND_REQUIRED) 71 | ENDIF(AndroidKernel_FOUND) 72 | -------------------------------------------------------------------------------- /cmake_modules/FindAvahi.cmake: -------------------------------------------------------------------------------- 1 | find_library(AVAHI_LIBRARY-COMMON NAMES avahi-common) 2 | find_library(AVAHI_LIBRARY-CLIENT NAMES avahi-client) 3 | find_path(AVAHI_INCLUDE_DIR avahi-client/publish.h) 4 | include(FindPackageHandleStandardArgs) 5 | find_package_handle_standard_args(Avahi DEFAULT_MSG AVAHI_LIBRARY-COMMON AVAHI_LIBRARY-CLIENT AVAHI_INCLUDE_DIR) 6 | if(AVAHI_FOUND) 7 | set(AVAHI_LIBRARIES ${AVAHI_LIBRARY-COMMON} ${AVAHI_LIBRARY-CLIENT}) 8 | set(AVAHI_INCLUDE_DIRS ${AVAHI_INCLUDE_DIR}) 9 | endif() 10 | -------------------------------------------------------------------------------- /cmake_modules/FindDNSSD.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2011 Stefan Eilemann 3 | # 4 | # Redistribution and use in source and binary forms, with or without 5 | # modification, are permitted provided that the following conditions are met: 6 | # 7 | # - Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # - Redistributions in binary form must reproduce the above copyright notice, 10 | # this list of conditions and the following disclaimer in the documentation 11 | # and/or other materials provided with the distribution. 12 | # - Neither the name of Eyescale Software GmbH nor the names of its 13 | # contributors may be used to endorse or promote products derived from this 14 | # software without specific prior written permission. 15 | # 16 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | # POSSIBILITY OF SUCH DAMAGE. 27 | # 28 | #================================== 29 | # 30 | # - Find ZeroConf headers 31 | # 32 | #================================== 33 | # 34 | # The following environment variables are respected for finding Dnssd. 35 | # CMAKE_PREFIX_PATH can also be used for this (see find_library() CMake 36 | # documentation). 37 | # 38 | # DNSSD_ROOT 39 | # 40 | # This module defines the following output variables: 41 | # 42 | # DNSSD_FOUND - Was Dnssd and all of the specified components found? 43 | # 44 | # DNSSD_INCLUDE_DIRS - Where to find the headers 45 | # 46 | # DNSSD_LIBRARIES - The Dnssd libraries 47 | # 48 | #================================== 49 | # Example Usage: 50 | # 51 | # find_package(DNSSD REQUIRED) 52 | # include_directories(${DNSSD_INCLUDE_DIRS}) 53 | # 54 | # add_executable(foo foo.cc) 55 | # target_link_libraries(foo ${DNSSD_LIBRARIES}) 56 | # 57 | #================================== 58 | # Naming convention: 59 | # Local variables of the form _dnssd_foo 60 | # Output variables of the form DNSSD_FOO 61 | # 62 | 63 | if(WIN32) 64 | if("$ENV{ProgramW6432}" STREQUAL "") 65 | set(_dnssd_lib_paths "$ENV{ProgramFiles}/Bonjour SDK") 66 | else() 67 | set(_dnssd_lib_paths "$ENV{ProgramW6432}/Bonjour SDK") 68 | endif() 69 | else() 70 | list(APPEND _dnssd_lib_paths /usr /usr/local /opt/local /opt) 71 | endif() 72 | 73 | find_path(_dnssd_INCLUDE_DIR dns_sd.h 74 | HINTS $ENV{DNSSD_ROOT} ${DNSSD_ROOT} 75 | PATH_SUFFIXES include 76 | PATHS ${_dnssd_lib_paths} 77 | ) 78 | 79 | if(DNSSD_FIND_REQUIRED) 80 | set(_dnssd_output_type FATAL_ERROR) 81 | set(_dnssd_output 1) 82 | else() 83 | set(_dnssd_output_type STATUS) 84 | if(NOT DNSSD_FIND_QUIETLY) 85 | set(_dnssd_output 1) 86 | endif() 87 | endif() 88 | 89 | if(NOT _dnssd_INCLUDE_DIR) 90 | set(_dnssd_EPIC_FAIL TRUE) 91 | if(_dnssd_output) 92 | message(${_dnssd_output_type} "Can't find dns_sd.h header file.") 93 | endif() 94 | endif() 95 | 96 | if(APPLE) 97 | find_library(_dnssd_LIBRARY System 98 | HINTS $ENV{DNSSD_ROOT} ${DNSSD_ROOT} 99 | PATH_SUFFIXES lib PATHS ${_dnssd_lib_paths} 100 | ) 101 | elseif(WIN32) 102 | if("${CMAKE_GENERATOR}" MATCHES "Win64") 103 | set(_dnssd_lib_postfix "x64") 104 | else() 105 | set(_dnssd_lib_postfix "Win32") 106 | endif() 107 | find_library(_dnssd_LIBRARY dnssd.lib 108 | HINTS $ENV{DNSSD_ROOT} ${DNSSD_ROOT} 109 | PATH_SUFFIXES lib 110 | PATHS ${_dnssd_lib_paths}/Lib/${_dnssd_lib_postfix}) 111 | else() 112 | find_library(_dnssd_LIBRARY dns_sd 113 | HINTS $ENV{DNSSD_ROOT} ${DNSSD_ROOT} 114 | PATH_SUFFIXES lib PATHS ${_dnssd_lib_paths} 115 | ) 116 | endif() 117 | 118 | if(DNSSD_FIND_REQUIRED) 119 | if(_dnssd_LIBRARY MATCHES "_dnssd_LIBRARY-NOTFOUND") 120 | set(_dnssd_EPIC_FAIL TRUE) 121 | message(FATAL_ERROR "Missing the ZeroConf library.\n" 122 | "Consider using CMAKE_PREFIX_PATH or the DNSSD_ROOT environment variable. " 123 | "See the ${CMAKE_CURRENT_LIST_FILE} for more details.") 124 | endif() 125 | endif() 126 | 127 | include(FindPackageHandleStandardArgs) 128 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(DNSSD DEFAULT_MSG 129 | _dnssd_LIBRARY _dnssd_INCLUDE_DIR) 130 | 131 | if(_dnssd_EPIC_FAIL) 132 | # Zero out everything, we didn't meet version requirements 133 | set(DNSSD_FOUND FALSE) 134 | set(_dnssd_LIBRARY) 135 | set(_dnssd_INCLUDE_DIR) 136 | endif() 137 | 138 | set(DNSSD_INCLUDE_DIRS ${_dnssd_INCLUDE_DIR}) 139 | set(DNSSD_LIBRARIES ${_dnssd_LIBRARY}) 140 | 141 | if(DNSSD_FOUND AND _dnssd_output) 142 | message(STATUS "Found ZeroConf in ${DNSSD_INCLUDE_DIRS};${DNSSD_LIBRARIES}") 143 | endif() 144 | -------------------------------------------------------------------------------- /cmake_modules/FindEigen3.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find Eigen3 lib 2 | # Once done this will define 3 | # 4 | # EIGEN3_FOUND - system has eigen lib 5 | # EIGEN3_INCLUDE_DIR - the eigen include directory 6 | 7 | # Copyright (c) 2006, 2007 Montel Laurent, 8 | # Redistribution and use is allowed according to the terms of the BSD license. 9 | # For details see the accompanying COPYING-CMAKE-SCRIPTS file. 10 | 11 | if (EIGEN3_INCLUDE_DIR) 12 | 13 | # in cache already 14 | set(EIGEN3_FOUND TRUE) 15 | 16 | else (EIGEN3_INCLUDE_DIR) 17 | 18 | find_path(EIGEN3_INCLUDE_DIR NAMES Eigen/Core 19 | PATHS 20 | ${INCLUDE_INSTALL_DIR} 21 | ${KDE4_INCLUDE_DIR} 22 | PATH_SUFFIXES eigen3 23 | ) 24 | 25 | include(FindPackageHandleStandardArgs) 26 | find_package_handle_standard_args(Eigen3 DEFAULT_MSG EIGEN3_INCLUDE_DIR ) 27 | 28 | 29 | mark_as_advanced(EIGEN3_INCLUDE_DIR) 30 | 31 | endif(EIGEN3_INCLUDE_DIR) 32 | 33 | -------------------------------------------------------------------------------- /cmake_modules/FindFREEGLUT.cmake: -------------------------------------------------------------------------------- 1 | # Try to find the FREEGLUT library 2 | # 3 | # FREEGLUT_INCLUDE_DIR 4 | # FREEGLUT_LIBRARY 5 | # FREEGLUT_FOUND 6 | 7 | FIND_PATH( 8 | FREEGLUT_INCLUDE_DIR GL/freeglut.h 9 | ${CMAKE_INCLUDE_PATH} 10 | $ENV{include} 11 | ${OPENGL_INCLUDE_DIR} 12 | /usr/include 13 | /usr/local/include 14 | ) 15 | FIND_LIBRARY( 16 | FREEGLUT_LIBRARY 17 | NAMES freeglut_static freeglut glut 18 | PATH 19 | ${CMAKE_LIBRARY_PATH} 20 | $ENV{lib} 21 | /usr/lib 22 | /usr/local/lib 23 | ) 24 | 25 | IF (FREEGLUT_INCLUDE_DIR AND FREEGLUT_LIBRARY) 26 | SET(FREEGLUT_FOUND TRUE) 27 | ENDIF (FREEGLUT_INCLUDE_DIR AND FREEGLUT_LIBRARY) 28 | 29 | IF (FREEGLUT_FOUND) 30 | IF (NOT FREEGLUT_FIND_QUIETLY) 31 | MESSAGE(STATUS "Found FREEGLUT: ${FREEGLUT_LIBRARY}") 32 | ENDIF (NOT FREEGLUT_FIND_QUIETLY) 33 | ELSE (FREEGLUT_FOUND) 34 | IF (FREEGLUT_FIND_REQUIRED) 35 | MESSAGE(FATAL_ERROR "Could not find FREEGLUT") 36 | ENDIF (FREEGLUT_FIND_REQUIRED) 37 | ENDIF (FREEGLUT_FOUND) 38 | -------------------------------------------------------------------------------- /cmake_modules/FindGFlags.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find gflags 2 | # Once done, this will define 3 | # 4 | # GFlags_FOUND - system has gflags 5 | # GFlags_INCLUDE_DIRS - the gflags include directories 6 | # GFlags_LIBRARIES - link these to use gflags 7 | 8 | # Find header and lib 9 | find_path(GFlags_INCLUDE_DIR NAMES gflags/gflags.h) 10 | find_library(GFlags_LIBRARIES NAMES gflags) 11 | 12 | include(FindPackageHandleStandardArgs) 13 | find_package_handle_standard_args(GFlags DEFAULT_MSG GFlags_INCLUDE_DIR GFlags_LIBRARIES) 14 | set(GFLAGS_INCLUDE_DIRS ${GFlags_INCLUDE_DIRS}) 15 | set(GFLAGS_LIBRARIES ${GFlags_LIBRARIES}) 16 | -------------------------------------------------------------------------------- /cmake_modules/FindGLEW.cmake: -------------------------------------------------------------------------------- 1 | # - Find GLEW 2 | # Find the native GLEW headers and libraries. 3 | # 4 | # set( GLEW_USE_STATIC_LIBS ON ) - forces use of static library (libGLEW.a) 5 | # GLEW_INCLUDE_DIR - where to find GLEW.h, etc. 6 | # GLEW_LIBRARIES - List of libraries when using GLEW. 7 | # GLEW_FOUND - True if GLEW found. 8 | 9 | # Look for the header file. 10 | FIND_PATH(GLEW_INCLUDE_DIR NAMES GL/glew.h 11 | PATHS 12 | /opt/local/include 13 | $ENV{CPATH} ) 14 | MARK_AS_ADVANCED(GLEW_INCLUDE_DIR) 15 | 16 | # Look for the library. 17 | FIND_LIBRARY( GLEW_LIBRARY NAMES GLEW 18 | PATHS 19 | /opt/local/lib 20 | $ENV{LD_LIBRARY_PATH} 21 | $ENV{LIBRARY_PATH} 22 | /usr/lib/ 23 | ) 24 | 25 | if( GLEW_USE_STATIC_LIBS ) 26 | # a bit hacky 27 | STRING( REGEX REPLACE ".so" ".a" GLEW_LIBRARY ${GLEW_LIBRARY} ) 28 | endif() 29 | MARK_AS_ADVANCED(GLEW_LIBRARY) 30 | 31 | IF( WIN32 AND PREFER_STATIC_LIBRARIES ) 32 | FIND_LIBRARY( GLEW_STATIC_LIBRARY NAMES glew32_static 33 | PATHS $ENV{CPATH} ) 34 | MARK_AS_ADVANCED(GLEW_STATIC_LIBRARY) 35 | ENDIF( WIN32 AND PREFER_STATIC_LIBRARIES ) 36 | IF( GLEW_LIBRARY OR GLEW_STATIC_LIBRARY ) 37 | SET( GLEW_LIBRARIES_FOUND 1 ) 38 | ENDIF( GLEW_LIBRARY OR GLEW_STATIC_LIBRARY ) 39 | 40 | # Copy the results to the output variables. 41 | IF(GLEW_INCLUDE_DIR AND GLEW_LIBRARIES_FOUND) 42 | SET(GLEW_FOUND 1) 43 | IF( WIN32 AND PREFER_STATIC_LIBRARIES AND GLEW_STATIC_LIBRARY ) 44 | SET(GLEW_LIBRARIES ${GLEW_STATIC_LIBRARY}) 45 | SET( GLEW_STATIC 1 ) 46 | ELSE( WIN32 AND PREFER_STATIC_LIBRARIES AND GLEW_STATIC_LIBRARY ) 47 | SET(GLEW_LIBRARIES ${GLEW_LIBRARY}) 48 | ENDIF( WIN32 AND PREFER_STATIC_LIBRARIES AND GLEW_STATIC_LIBRARY ) 49 | SET(GLEW_INCLUDE_DIR ${GLEW_INCLUDE_DIR}) 50 | ELSE(GLEW_INCLUDE_DIR AND GLEW_LIBRARIES_FOUND) 51 | SET(GLEW_FOUND 0) 52 | SET(GLEW_LIBRARIES) 53 | SET(GLEW_INCLUDE_DIR) 54 | ENDIF(GLEW_INCLUDE_DIR AND GLEW_LIBRARIES_FOUND) 55 | 56 | IF(GLEW_FOUND) 57 | IF(NOT GLEW_FIND_QUIETLY) 58 | MESSAGE(STATUS "Found GLEW lib: ${GLEW_LIBRARY}") 59 | MESSAGE(STATUS "Found GLEW include: ${GLEW_INCLUDE_DIR}") 60 | ENDIF(NOT GLEW_FIND_QUIETLY) 61 | ELSE(GLEW_FOUND) 62 | IF(GLEW_FIND_REQUIRED) 63 | MESSAGE(FATAL_ERROR "Could not find GLEW library") 64 | ENDIF(GLEW_FIND_REQUIRED) 65 | ENDIF(GLEW_FOUND) 66 | 67 | 68 | -------------------------------------------------------------------------------- /cmake_modules/FindGLUES.cmake: -------------------------------------------------------------------------------- 1 | # Try to find the GLUES lib and include files 2 | # 3 | # GLUES_INCLUDE_DIR 4 | # GLUES_LIBRARIES 5 | # GLUES_FOUND 6 | 7 | FIND_PATH( GLUES_INCLUDE_DIR glues/glues.h 8 | /usr/include 9 | /usr/local/include 10 | /opt/include 11 | /opt/local/include 12 | ${CMAKE_INSTALL_PREFIX}/include 13 | ) 14 | 15 | FIND_LIBRARY( GLUES_LIBRARY glues 16 | /usr/lib64 17 | /usr/lib 18 | /usr/local/lib 19 | /opt/local/lib 20 | /opt/local/lib64 21 | ${CMAKE_INSTALL_PREFIX}/lib 22 | ) 23 | 24 | IF(GLUES_INCLUDE_DIR AND GLUES_LIBRARY) 25 | SET( GLUES_FOUND TRUE ) 26 | SET( GLUES_LIBRARIES ${GLUES_LIBRARY} ) 27 | ENDIF(GLUES_INCLUDE_DIR AND GLUES_LIBRARY) 28 | 29 | IF(GLUES_FOUND) 30 | IF(NOT GLUES_FIND_QUIETLY) 31 | MESSAGE(STATUS "Found GLUES: ${GLUES_LIBRARY}") 32 | ENDIF(NOT GLUES_FIND_QUIETLY) 33 | ELSE(GLUES_FOUND) 34 | IF(GLUES_FIND_REQUIRED) 35 | MESSAGE(FATAL_ERROR "Could not find GLUES") 36 | ENDIF(GLUES_FIND_REQUIRED) 37 | ENDIF(GLUES_FOUND) 38 | 39 | -------------------------------------------------------------------------------- /cmake_modules/FindGLog.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find glog (or miniglog for Android) 2 | # Once done, this will define 3 | # 4 | # GLog_FOUND - system has glog 5 | # GLog_INCLUDE_DIRS - the glog include directories 6 | # GLog_LIBRARIES - link these to use glog 7 | 8 | # Find header and lib 9 | find_path(GLog_INCLUDE_DIR NAMES glog/logging.h) 10 | find_library(GLog_LIBRARIES NAMES glog) 11 | 12 | include(FindPackageHandleStandardArgs) 13 | find_package_handle_standard_args(GLog DEFAULT_MSG GLog_INCLUDE_DIR GLog_LIBRARIES) 14 | set(GLOG_INCLUDE_DIRS ${GLog_INCLUDE_DIRS}) 15 | set(GLOG_LIBRARIES ${GLog_LIBRARIES}) 16 | -------------------------------------------------------------------------------- /cmake_modules/FindOpenCL.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # This file taken from FindOpenCL project @ http://gitorious.com/findopencl 3 | # 4 | # - Try to find OpenCL 5 | # This module tries to find an OpenCL implementation on your system. It supports 6 | # AMD / ATI, Apple and NVIDIA implementations, but shoudl work, too. 7 | # 8 | # Once done this will define 9 | # OPENCL_FOUND - system has OpenCL 10 | # OPENCL_INCLUDE_DIRS - the OpenCL include directory 11 | # OPENCL_LIBRARIES - link these to use OpenCL 12 | # 13 | # WIN32 should work, but is untested 14 | 15 | FIND_PACKAGE( PackageHandleStandardArgs ) 16 | 17 | SET (OPENCL_VERSION_STRING "0.1.0") 18 | SET (OPENCL_VERSION_MAJOR 0) 19 | SET (OPENCL_VERSION_MINOR 1) 20 | SET (OPENCL_VERSION_PATCH 0) 21 | 22 | IF (APPLE) 23 | 24 | FIND_LIBRARY(OPENCL_LIBRARIES OpenCL DOC "OpenCL lib for OSX") 25 | FIND_PATH(OPENCL_INCLUDE_DIRS OpenCL/cl.h DOC "Include for OpenCL on OSX") 26 | FIND_PATH(_OPENCL_CPP_INCLUDE_DIRS OpenCL/cl.hpp DOC "Include for OpenCL CPP bindings on OSX") 27 | 28 | ELSE (APPLE) 29 | 30 | IF (WIN32) 31 | 32 | FIND_PATH(OPENCL_INCLUDE_DIRS CL/cl.h) 33 | FIND_PATH(_OPENCL_CPP_INCLUDE_DIRS CL/cl.hpp) 34 | 35 | # The AMD SDK currently installs both x86 and x86_64 libraries 36 | # This is only a hack to find out architecture 37 | IF( ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64" ) 38 | SET(OPENCL_LIB_DIR "$ENV{ATISTREAMSDKROOT}/lib/x86_64") 39 | SET(OPENCL_LIB_DIR "$ENV{ATIINTERNALSTREAMSDKROOT}/lib/x86_64") 40 | ELSE (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64") 41 | SET(OPENCL_LIB_DIR "$ENV{ATISTREAMSDKROOT}/lib/x86") 42 | SET(OPENCL_LIB_DIR "$ENV{ATIINTERNALSTREAMSDKROOT}/lib/x86") 43 | ENDIF( ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64" ) 44 | 45 | # find out if the user asked for a 64-bit build, and use the corresponding 46 | # 64 or 32 bit NVIDIA library paths to the search: 47 | STRING(REGEX MATCH "Win64" ISWIN64 ${CMAKE_GENERATOR}) 48 | IF("${ISWIN64}" STREQUAL "Win64") 49 | FIND_LIBRARY(OPENCL_LIBRARIES OpenCL.lib ${OPENCL_LIB_DIR} $ENV{CUDA_LIB_PATH} $ENV{CUDA_PATH}/lib/x64) 50 | ELSE("${ISWIN64}" STREQUAL "Win64") 51 | FIND_LIBRARY(OPENCL_LIBRARIES OpenCL.lib ${OPENCL_LIB_DIR} $ENV{CUDA_LIB_PATH} $ENV{CUDA_PATH}/lib/Win32) 52 | ENDIF("${ISWIN64}" STREQUAL "Win64") 53 | 54 | GET_FILENAME_COMPONENT(_OPENCL_INC_CAND ${OPENCL_LIB_DIR}/../../include ABSOLUTE) 55 | 56 | # On Win32 search relative to the library 57 | FIND_PATH(OPENCL_INCLUDE_DIRS CL/cl.h PATHS "${_OPENCL_INC_CAND}" $ENV{CUDA_INC_PATH} $ENV{CUDA_PATH}/include) 58 | FIND_PATH(_OPENCL_CPP_INCLUDE_DIRS CL/cl.hpp PATHS "${_OPENCL_INC_CAND}" $ENV{CUDA_INC_PATH} $ENV{CUDA_PATH}/include) 59 | 60 | ELSE (WIN32) 61 | 62 | # Unix style platforms 63 | FIND_LIBRARY(OPENCL_LIBRARIES OpenCL 64 | ENV LD_LIBRARY_PATH 65 | ) 66 | 67 | GET_FILENAME_COMPONENT(OPENCL_LIB_DIR ${OPENCL_LIBRARIES} PATH) 68 | GET_FILENAME_COMPONENT(_OPENCL_INC_CAND ${OPENCL_LIB_DIR}/../../include ABSOLUTE) 69 | 70 | # The AMD SDK currently does not place its headers 71 | # in /usr/include, therefore also search relative 72 | # to the library 73 | FIND_PATH(OPENCL_INCLUDE_DIRS CL/cl.h PATHS ${_OPENCL_INC_CAND} "/usr/local/cuda/include") 74 | FIND_PATH(_OPENCL_CPP_INCLUDE_DIRS CL/cl.hpp PATHS ${_OPENCL_INC_CAND} "/usr/local/cuda/include") 75 | 76 | ENDIF (WIN32) 77 | 78 | ENDIF (APPLE) 79 | 80 | FIND_PACKAGE_HANDLE_STANDARD_ARGS( OpenCL DEFAULT_MSG OPENCL_LIBRARIES OPENCL_INCLUDE_DIRS ) 81 | 82 | IF( _OPENCL_CPP_INCLUDE_DIRS ) 83 | SET( OPENCL_HAS_CPP_BINDINGS TRUE ) 84 | LIST( APPEND OPENCL_INCLUDE_DIRS ${_OPENCL_CPP_INCLUDE_DIRS} ) 85 | # This is often the same, so clean up 86 | LIST( REMOVE_DUPLICATES OPENCL_INCLUDE_DIRS ) 87 | ENDIF( _OPENCL_CPP_INCLUDE_DIRS ) 88 | 89 | MARK_AS_ADVANCED( 90 | OPENCL_INCLUDE_DIRS 91 | ) 92 | -------------------------------------------------------------------------------- /cmake_modules/FindPCAN.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find peak-linux driver 2 | # Once done, this will define 3 | # 4 | # ZeroMQ_FOUND - system has pcan 5 | # ZeroMQ_INCLUDE_DIRS - the libpcan include directories 6 | 7 | include(LibFindMacros) 8 | 9 | IF(UNIX) 10 | # Include dir 11 | find_path(PCAN_INCLUDE_DIR 12 | NAMES libpcan.h 13 | PATHS /usr/include ${PCAN_PKGCONF_INCLUDE_DIRS} 14 | ) 15 | #Library Path 16 | find_library(PCAN_LIBRARY 17 | NAMES libpcan.so 18 | PATHS /usr/lib /usr/local/lib 19 | ) 20 | ENDIF() 21 | 22 | # Set the include dir variables and the libraries and let libfind_process do the rest. 23 | # NOTE: Singular variables for this library, plural for libraries this this lib depends on. 24 | set(PCAN_PROCESS_INCLUDES PCAN_INCLUDE_DIR PCAN_INCLUDE_DIRS) 25 | set(PCAN_PROCESS_LIBS PCAN_LIBRARY PCAN_LIBRARIES) 26 | libfind_process(PCAN) 27 | -------------------------------------------------------------------------------- /cmake_modules/FindPackage.cmake.in: -------------------------------------------------------------------------------- 1 | 2 | SET( @PACKAGE_PKG_NAME@_LIBRARIES @PACKAGE_LINK_LIBS@ CACHE INTERNAL "@PACKAGE_PKG_NAME@ libraries" FORCE ) 3 | SET( @PACKAGE_PKG_NAME@_INCLUDE_DIRS @PACKAGE_INCLUDE_DIRS@ CACHE INTERNAL "@PACKAGE_PKG_NAME@ include directories" FORCE ) 4 | SET( @PACKAGE_PKG_NAME@_LIBRARY_DIRS @PACKAGE_LINK_DIRS@ CACHE INTERNAL "@PACKAGE_PKG_NAME@ library directories" FORCE ) 5 | 6 | mark_as_advanced( @PACKAGE_PKG_NAME@_LIBRARIES ) 7 | mark_as_advanced( @PACKAGE_PKG_NAME@_LIBRARY_DIRS ) 8 | mark_as_advanced( @PACKAGE_PKG_NAME@_INCLUDE_DIRS ) 9 | 10 | 11 | -------------------------------------------------------------------------------- /cmake_modules/FindPkgMacros.cmake: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------- 2 | # This file is part of the CMake build system for OGRE 3 | # (Object-oriented Graphics Rendering Engine) 4 | # For the latest info, see http://www.ogre3d.org/ 5 | # 6 | # The contents of this file are placed in the public domain. Feel 7 | # free to make use of it in any way you like. 8 | #------------------------------------------------------------------- 9 | 10 | ################################################################## 11 | # Provides some common functionality for the FindPackage modules 12 | ################################################################## 13 | 14 | # Begin processing of package 15 | macro(findpkg_begin PREFIX) 16 | if (NOT ${PREFIX}_FIND_QUIETLY) 17 | message(STATUS "Looking for ${PREFIX}...") 18 | endif () 19 | endmacro(findpkg_begin) 20 | 21 | # Display a status message unless FIND_QUIETLY is set 22 | macro(pkg_message PREFIX) 23 | if (NOT ${PREFIX}_FIND_QUIETLY) 24 | message(STATUS ${ARGN}) 25 | endif () 26 | endmacro(pkg_message) 27 | 28 | # Get environment variable, define it as ENV_$var and make sure backslashes are converted to forward slashes 29 | macro(getenv_path VAR) 30 | set(ENV_${VAR} $ENV{${VAR}}) 31 | # replace won't work if var is blank 32 | if (ENV_${VAR}) 33 | string( REGEX REPLACE "\\\\" "/" ENV_${VAR} ${ENV_${VAR}} ) 34 | endif () 35 | endmacro(getenv_path) 36 | 37 | # Construct search paths for includes and libraries from a PREFIX_PATH 38 | macro(create_search_paths PREFIX) 39 | foreach(dir ${${PREFIX}_PREFIX_PATH}) 40 | set(${PREFIX}_INC_SEARCH_PATH ${${PREFIX}_INC_SEARCH_PATH} 41 | ${dir}/include ${dir}/include/${PREFIX} ${dir}/Headers) 42 | set(${PREFIX}_LIB_SEARCH_PATH ${${PREFIX}_LIB_SEARCH_PATH} 43 | ${dir}/lib ${dir}/lib/${PREFIX} ${dir}/Libs) 44 | set(${PREFIX}_BIN_SEARCH_PATH ${${PREFIX}_BIN_SEARCH_PATH} 45 | ${dir}/bin) 46 | endforeach(dir) 47 | set(${PREFIX}_FRAMEWORK_SEARCH_PATH ${${PREFIX}_PREFIX_PATH}) 48 | endmacro(create_search_paths) 49 | 50 | # clear cache variables if a certain variable changed 51 | macro(clear_if_changed TESTVAR) 52 | # test against internal check variable 53 | if (NOT "${${TESTVAR}}" STREQUAL "${${TESTVAR}_INT_CHECK}") 54 | message(STATUS "${TESTVAR} changed.") 55 | foreach(var ${ARGN}) 56 | set(${var} "NOTFOUND" CACHE STRING "x" FORCE) 57 | endforeach(var) 58 | endif () 59 | set(${TESTVAR}_INT_CHECK ${${TESTVAR}} CACHE INTERNAL "x" FORCE) 60 | endmacro(clear_if_changed) 61 | 62 | # Try to get some hints from pkg-config, if available 63 | macro(use_pkgconfig PREFIX PKGNAME) 64 | find_package(PkgConfig) 65 | if (PKG_CONFIG_FOUND) 66 | pkg_check_modules(${PREFIX} ${PKGNAME}) 67 | endif () 68 | endmacro (use_pkgconfig) 69 | 70 | # Couple a set of release AND debug libraries (or frameworks) 71 | macro(make_library_set PREFIX) 72 | if (${PREFIX}_FWK) 73 | set(${PREFIX} ${${PREFIX}_FWK}) 74 | elseif (${PREFIX}_REL AND ${PREFIX}_DBG) 75 | set(${PREFIX} optimized ${${PREFIX}_REL} debug ${${PREFIX}_DBG}) 76 | elseif (${PREFIX}_REL) 77 | set(${PREFIX} ${${PREFIX}_REL}) 78 | elseif (${PREFIX}_DBG) 79 | set(${PREFIX} ${${PREFIX}_DBG}) 80 | endif () 81 | endmacro(make_library_set) 82 | 83 | # Generate debug names from given release names 84 | macro(get_debug_names PREFIX) 85 | foreach(i ${${PREFIX}}) 86 | set(${PREFIX}_DBG ${${PREFIX}_DBG} ${i}d ${i}D ${i}_d ${i}_D ${i}_debug ${i}) 87 | endforeach(i) 88 | endmacro(get_debug_names) 89 | 90 | # Add the parent dir from DIR to VAR 91 | macro(add_parent_dir VAR DIR) 92 | get_filename_component(${DIR}_TEMP "${${DIR}}/.." ABSOLUTE) 93 | set(${VAR} ${${VAR}} ${${DIR}_TEMP}) 94 | endmacro(add_parent_dir) 95 | 96 | # Do the final processing for the package find. 97 | macro(findpkg_finish PREFIX) 98 | # skip if already processed during this run 99 | if (NOT ${PREFIX}_FOUND) 100 | if (${PREFIX}_INCLUDE_DIR AND ${PREFIX}_LIBRARY) 101 | set(${PREFIX}_FOUND TRUE) 102 | set(${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIR}) 103 | set(${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARY}) 104 | if (NOT ${PREFIX}_FIND_QUIETLY) 105 | message(STATUS "Found ${PREFIX}: ${${PREFIX}_LIBRARIES}") 106 | endif () 107 | else () 108 | if (NOT ${PREFIX}_FIND_QUIETLY) 109 | message(STATUS "Could not locate ${PREFIX}") 110 | endif () 111 | if (${PREFIX}_FIND_REQUIRED) 112 | message(FATAL_ERROR "Required library ${PREFIX} not found! Install the library (including dev packages) and try again. If the library is already installed, set the missing variables manually in cmake.") 113 | endif () 114 | endif () 115 | 116 | mark_as_advanced(${PREFIX}_INCLUDE_DIR ${PREFIX}_LIBRARY ${PREFIX}_LIBRARY_REL ${PREFIX}_LIBRARY_DBG ${PREFIX}_LIBRARY_FWK) 117 | endif () 118 | endmacro(findpkg_finish) 119 | 120 | 121 | # Slightly customised framework finder 122 | MACRO(findpkg_framework fwk) 123 | IF(APPLE) 124 | SET(${fwk}_FRAMEWORK_PATH 125 | ${${fwk}_FRAMEWORK_SEARCH_PATH} 126 | ${CMAKE_FRAMEWORK_PATH} 127 | ~/Library/Frameworks 128 | /Library/Frameworks 129 | /System/Library/Frameworks 130 | /Network/Library/Frameworks 131 | /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk/System/Library/Frameworks/ 132 | ) 133 | FOREACH(dir ${${fwk}_FRAMEWORK_PATH}) 134 | SET(fwkpath ${dir}/${fwk}.framework) 135 | IF(EXISTS ${fwkpath}) 136 | SET(${fwk}_FRAMEWORK_INCLUDES ${${fwk}_FRAMEWORK_INCLUDES} 137 | ${fwkpath}/Headers ${fwkpath}/PrivateHeaders) 138 | if (NOT ${fwk}_LIBRARY_FWK) 139 | SET(${fwk}_LIBRARY_FWK "-framework ${fwk}") 140 | endif () 141 | ENDIF(EXISTS ${fwkpath}) 142 | ENDFOREACH(dir) 143 | ENDIF(APPLE) 144 | ENDMACRO(findpkg_framework) 145 | -------------------------------------------------------------------------------- /cmake_modules/FindTinyXML2.cmake: -------------------------------------------------------------------------------- 1 | # FractalImages 2 | # Copyright (C) 2012 Sven Hertle 3 | # 4 | # This program is free software; you can redistribute it and/or modify it under 5 | # the terms of the GNU General Public License as published by the Free Software 6 | # Foundation; either version 3 of the License, or (at your option) any later 7 | # version. 8 | # 9 | # This program is distributed in the hope that it will be useful, but WITHOUT ANY 10 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 11 | # PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License along with 14 | # this program; if not, see . 15 | 16 | # Find TinyXML2 17 | # 18 | # TinyXML2_FOUND True if TinyXML2 was found 19 | # TinyXML2_INCLUDE_DIR Directory with headers 20 | # TinyXML2_LIBRARIES List of libraries 21 | # 22 | 23 | find_path(TinyXML2_INCLUDE_DIR "tinyxml2.h") 24 | 25 | find_library(TinyXML2_LIBRARIES NAMES "tinyxml2") 26 | 27 | include(FindPackageHandleStandardArgs) 28 | find_package_handle_standard_args("TinyXML2" DEFAULT_MSG TinyXML2_INCLUDE_DIR TinyXML2_LIBRARIES) 29 | set(TinyXML2_FOUND ${TINYXML2_FOUND} CACHE BOOL "TinyXML2 was found or not" FORCE) 30 | 31 | mark_as_advanced(TinyXML2_INCLUDE_DIR TinyXML2_LIBRARIES) 32 | 33 | message(STATUS "TinyXML2_INCLUDE_DIR: ${TinyXML2_INCLUDE_DIR}") 34 | message(STATUS "TinyXML2_LIBRARIES: ${TinyXML2_LIBRARIES}") 35 | -------------------------------------------------------------------------------- /cmake_modules/FindUSB1.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find USB1 2 | # Once done this will define 3 | # 4 | # USB1_FOUND - system has USB1 5 | # USB1_INCLUDE_DIRS - the USB1 include directory 6 | # USB1_LIBRARIES - Link these to use USB1 7 | # USB1_DEFINITIONS - Compiler switches required for using USB1 8 | # 9 | # Copyright (c) 2006 Andreas Schneider 10 | # Adapted for libusb1.0 by Cory Quammen 11 | # 12 | # Redistribution and use is allowed according to the terms of the New 13 | # BSD license. 14 | # For details see the accompanying COPYING-CMAKE-SCRIPTS file. 15 | # 16 | 17 | 18 | if(USB1_LIBRARIES AND USB1_INCLUDE_DIRS) 19 | # in cache already 20 | set(USB1_FOUND TRUE) 21 | else(USB1_LIBRARIES AND USB1_INCLUDE_DIRS) 22 | find_path(USB1_INCLUDE_DIR 23 | NAMES 24 | libusb.h 25 | PATHS 26 | /usr/include 27 | /usr/include/libusb-1.0 28 | /usr/local/include 29 | /opt/local/include/libusb-1.0/ 30 | /opt/local/include 31 | /sw/include 32 | ) 33 | 34 | find_library(USB1_LIBRARY 35 | NAMES 36 | usb-1.0 37 | PATHS 38 | /usr/lib 39 | /usr/lib64 40 | /usr/local/lib 41 | /opt/local/lib 42 | /sw/lib 43 | ) 44 | 45 | set(USB1_INCLUDE_DIRS 46 | ${USB1_INCLUDE_DIR} 47 | ) 48 | set(USB1_LIBRARIES 49 | ${USB1_LIBRARY} 50 | ) 51 | 52 | if(USB1_INCLUDE_DIRS AND USB1_LIBRARIES) 53 | set(USB1_FOUND TRUE) 54 | endif(USB1_INCLUDE_DIRS AND USB1_LIBRARIES) 55 | 56 | if(USB1_FOUND) 57 | if(NOT USB1_FIND_QUIETLY) 58 | message(STATUS "Found USB1: ${USB1_LIBRARIES}") 59 | endif(NOT USB1_FIND_QUIETLY) 60 | else(USB1_FOUND) 61 | if(USB1_FIND_REQUIRED) 62 | message(FATAL_ERROR "Could not find USB1") 63 | endif(USB1_FIND_REQUIRED) 64 | endif(USB1_FOUND) 65 | 66 | # show the USB1_INCLUDE_DIRS and USB1_LIBRARIES variables only in the advanced view 67 | mark_as_advanced(USB1_INCLUDE_DIRS USB1_LIBRARIES) 68 | 69 | endif(USB1_LIBRARIES AND USB1_INCLUDE_DIRS) 70 | 71 | -------------------------------------------------------------------------------- /cmake_modules/FindZeroMQ.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find libzmq 2 | # Once done, this will define 3 | # 4 | # ZeroMQ_FOUND - system has libzmq 5 | # ZeroMQ_INCLUDE_DIRS - the libzmq include directories 6 | # ZeroMQ_LIBRARIES - link these to use libzmq 7 | 8 | include(LibFindMacros) 9 | 10 | IF (UNIX) 11 | # Use pkg-config to get hints about paths 12 | libfind_pkg_check_modules(ZeroMQ_PKGCONF libzmq) 13 | 14 | # Include dir 15 | find_path(ZeroMQ_INCLUDE_DIR 16 | NAMES zmq.h 17 | PATHS ${ZEROMQ_ROOT}/include ${ZeroMQ_PKGCONF_INCLUDE_DIRS} 18 | ) 19 | 20 | # Finally the library itself 21 | find_library(ZeroMQ_LIBRARY 22 | NAMES zmq 23 | PATHS ${ZEROMQ_ROOT}/lib ${ZeroMQ_PKGCONF_LIBRARY_DIRS} 24 | ) 25 | ELSEIF (WIN32) 26 | find_path(ZeroMQ_INCLUDE_DIR 27 | NAMES zmq.h 28 | PATHS ${ZEROMQ_ROOT}/include ${CMAKE_INCLUDE_PATH} 29 | ) 30 | # Finally the library itself 31 | find_library(ZeroMQ_LIBRARY 32 | NAMES libzmq 33 | PATHS ${ZEROMQ_ROOT}/lib ${CMAKE_LIB_PATH} 34 | ) 35 | ENDIF() 36 | 37 | # Set the include dir variables and the libraries and let libfind_process do the rest. 38 | # NOTE: Singular variables for this library, plural for libraries this this lib depends on. 39 | set(ZeroMQ_PROCESS_INCLUDES ZeroMQ_INCLUDE_DIR ZeroMQ_INCLUDE_DIRS) 40 | set(ZeroMQ_PROCESS_LIBS ZeroMQ_LIBRARY ZeroMQ_LIBRARIES) 41 | libfind_process(ZeroMQ) 42 | -------------------------------------------------------------------------------- /cmake_modules/LibFindMacros.cmake: -------------------------------------------------------------------------------- 1 | # Works the same as find_package, but forwards the "REQUIRED" and "QUIET" arguments 2 | # used for the current package. For this to work, the first parameter must be the 3 | # prefix of the current package, then the prefix of the new package etc, which are 4 | # passed to find_package. 5 | macro (libfind_package PREFIX) 6 | set (LIBFIND_PACKAGE_ARGS ${ARGN}) 7 | if (${PREFIX}_FIND_QUIETLY) 8 | set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} QUIET) 9 | endif (${PREFIX}_FIND_QUIETLY) 10 | if (${PREFIX}_FIND_REQUIRED) 11 | set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} REQUIRED) 12 | endif (${PREFIX}_FIND_REQUIRED) 13 | find_package(${LIBFIND_PACKAGE_ARGS}) 14 | endmacro (libfind_package) 15 | 16 | # CMake developers made the UsePkgConfig system deprecated in the same release (2.6) 17 | # where they added pkg_check_modules. Consequently I need to support both in my scripts 18 | # to avoid those deprecated warnings. Here's a helper that does just that. 19 | # Works identically to pkg_check_modules, except that no checks are needed prior to use. 20 | macro (libfind_pkg_check_modules PREFIX PKGNAME) 21 | if (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) 22 | include(UsePkgConfig) 23 | pkgconfig(${PKGNAME} ${PREFIX}_INCLUDE_DIRS ${PREFIX}_LIBRARY_DIRS ${PREFIX}_LDFLAGS ${PREFIX}_CFLAGS) 24 | else (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) 25 | find_package(PkgConfig) 26 | if (PKG_CONFIG_FOUND) 27 | pkg_check_modules(${PREFIX} ${PKGNAME}) 28 | endif (PKG_CONFIG_FOUND) 29 | endif (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) 30 | endmacro (libfind_pkg_check_modules) 31 | 32 | # Do the final processing once the paths have been detected. 33 | # If include dirs are needed, ${PREFIX}_PROCESS_INCLUDES should be set to contain 34 | # all the variables, each of which contain one include directory. 35 | # Ditto for ${PREFIX}_PROCESS_LIBS and library files. 36 | # Will set ${PREFIX}_FOUND, ${PREFIX}_INCLUDE_DIRS and ${PREFIX}_LIBRARIES. 37 | # Also handles errors in case library detection was required, etc. 38 | macro (libfind_process PREFIX) 39 | # Skip processing if already processed during this run 40 | if (NOT ${PREFIX}_FOUND) 41 | # Start with the assumption that the library was found 42 | set (${PREFIX}_FOUND TRUE) 43 | 44 | # Process all includes and set _FOUND to false if any are missing 45 | foreach (i ${${PREFIX}_PROCESS_INCLUDES}) 46 | if (${i}) 47 | set (${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIRS} ${${i}}) 48 | mark_as_advanced(${i}) 49 | else (${i}) 50 | set (${PREFIX}_FOUND FALSE) 51 | endif (${i}) 52 | endforeach (i) 53 | 54 | # Process all libraries and set _FOUND to false if any are missing 55 | foreach (i ${${PREFIX}_PROCESS_LIBS}) 56 | if (${i}) 57 | set (${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARIES} ${${i}}) 58 | mark_as_advanced(${i}) 59 | else (${i}) 60 | set (${PREFIX}_FOUND FALSE) 61 | endif (${i}) 62 | endforeach (i) 63 | 64 | # Print message and/or exit on fatal error 65 | if (${PREFIX}_FOUND) 66 | if (NOT ${PREFIX}_FIND_QUIETLY) 67 | message (STATUS "Found ${PREFIX} ${${PREFIX}_VERSION}") 68 | endif (NOT ${PREFIX}_FIND_QUIETLY) 69 | else (${PREFIX}_FOUND) 70 | if (${PREFIX}_FIND_REQUIRED) 71 | foreach (i ${${PREFIX}_PROCESS_INCLUDES} ${${PREFIX}_PROCESS_LIBS}) 72 | message("${i}=${${i}}") 73 | endforeach (i) 74 | message (FATAL_ERROR "Required library ${PREFIX} NOT FOUND.\nInstall the library (dev version) and try again. If the library is already installed, use ccmake to set the missing variables manually.") 75 | endif (${PREFIX}_FIND_REQUIRED) 76 | endif (${PREFIX}_FOUND) 77 | endif (NOT ${PREFIX}_FOUND) 78 | endmacro (libfind_process) 79 | 80 | macro(libfind_library PREFIX basename) 81 | set(TMP "") 82 | if(MSVC80) 83 | set(TMP -vc80) 84 | endif(MSVC80) 85 | if(MSVC90) 86 | set(TMP -vc90) 87 | endif(MSVC90) 88 | set(${PREFIX}_LIBNAMES ${basename}${TMP}) 89 | if(${ARGC} GREATER 2) 90 | set(${PREFIX}_LIBNAMES ${basename}${TMP}-${ARGV2}) 91 | string(REGEX REPLACE "\\." "_" TMP ${${PREFIX}_LIBNAMES}) 92 | set(${PREFIX}_LIBNAMES ${${PREFIX}_LIBNAMES} ${TMP}) 93 | endif(${ARGC} GREATER 2) 94 | find_library(${PREFIX}_LIBRARY 95 | NAMES ${${PREFIX}_LIBNAMES} 96 | PATHS ${${PREFIX}_PKGCONF_LIBRARY_DIRS} 97 | ) 98 | endmacro(libfind_library) 99 | 100 | -------------------------------------------------------------------------------- /cmake_modules/PackageConfig.cmake.in: -------------------------------------------------------------------------------- 1 | SET( @PACKAGE_PKG_NAME@_LIBRARIES "@PACKAGE_LINK_LIBS@" CACHE INTERNAL "@PACKAGE_PKG_NAME@ libraries" FORCE ) 2 | SET( @PACKAGE_PKG_NAME@_INCLUDE_DIRS @PACKAGE_INCLUDE_DIRS@ CACHE INTERNAL "@PACKAGE_PKG_NAME@ include directories" FORCE ) 3 | SET( @PACKAGE_PKG_NAME@_LIBRARY_DIRS @PACKAGE_LINK_DIRS@ CACHE INTERNAL "@PACKAGE_PKG_NAME@ library directories" FORCE ) 4 | 5 | mark_as_advanced( @PACKAGE_PKG_NAME@_LIBRARIES ) 6 | mark_as_advanced( @PACKAGE_PKG_NAME@_LIBRARY_DIRS ) 7 | mark_as_advanced( @PACKAGE_PKG_NAME@_INCLUDE_DIRS ) 8 | 9 | 10 | 11 | # Compute paths 12 | get_filename_component( PACKAGE_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH ) 13 | 14 | # This file, when used for INSTALLED code, does not use Targets... sigh. 15 | ## Library dependencies (contains definitions for IMPORTED targets) 16 | #if(NOT TARGET "@PACKAGE_PKG_NAME@_LIBRARIES" AND NOT "@PACKAGE_PKG_NAME@_BINARY_DIR") 17 | # include( "${PACKAGE_CMAKE_DIR}/@PACKAGE_PKG_NAME@Targets.cmake" ) 18 | # include( "${PACKAGE_CMAKE_DIR}/@PACKAGE_PKG_NAME@ConfigVersion.cmake" ) 19 | #endif() 20 | 21 | #SET(@PACKAGE_PKG_NAME@_LIBRARIES @PACKAGE_LIBRARIES@) 22 | #SET(@PACKAGE_PKG_NAME@_LIBRARY @PACKAGE_LIBRARY@) 23 | #SET(@PACKAGE_PKG_NAME@_INCLUDE_DIRS @PACKAGE_INCLUDE_DIRS@) 24 | #SET(@PACKAGE_PKG_NAME@_LINK_DIRS @PACKAGE_LINK_DIRS@) 25 | -------------------------------------------------------------------------------- /cmake_modules/PackageConfigVersion.cmake.in: -------------------------------------------------------------------------------- 1 | set(PACKAGE_VERSION "@PACKAGE_VERSION@") 2 | 3 | # Check build type is valid 4 | if( "System:${CMAKE_SYSTEM_NAME},Android:${ANDROID},iOS:${IOS}" STREQUAL 5 | "System:@CMAKE_SYSTEM_NAME@,Android:@ANDROID@,iOS:@IOS@" ) 6 | # Check whether the requested PACKAGE_FIND_VERSION is compatible 7 | if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}") 8 | set(PACKAGE_VERSION_COMPATIBLE FALSE) 9 | else() 10 | set(PACKAGE_VERSION_COMPATIBLE TRUE) 11 | if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}") 12 | set(PACKAGE_VERSION_EXACT TRUE) 13 | endif() 14 | endif() 15 | else() 16 | set(PACKAGE_VERSION_COMPATIBLE FALSE) 17 | endif() 18 | -------------------------------------------------------------------------------- /cmake_modules/PkgConfig.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=${prefix} 3 | libdir=${exec_prefix}/lib 4 | includedir=${prefix}/include 5 | 6 | Name: lib@PACKAGE_LIBRARY@ 7 | Description: @PACKAGE_DESCRIPTION@ 8 | Version: @PACKAGE_VERSION@ 9 | Cflags: -I@PACKAGE_CFLAGS@ 10 | Libs: -L${libdir} @PACKAGE_PRIVATE_LIBS@ -l@PACKAGE_LIBRARY@ 11 | 12 | -------------------------------------------------------------------------------- /cmake_modules/README.md: -------------------------------------------------------------------------------- 1 | rpg-cmake 2 | ========= 3 | 4 | RPG's collection of reusable CMake scripts. 5 | -------------------------------------------------------------------------------- /cmake_modules/cmake_uninstall.cmake.in: -------------------------------------------------------------------------------- 1 | ## A simple uninstall script. 2 | ## Alternatively UNIX users can run/sudo `xargs rm < install_manifest.txt` in the build directory. 3 | 4 | set(unfile ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) 5 | file(WRITE ${unfile} "IF(NOT EXISTS \"install_manifest.txt\")\n") 6 | file(APPEND ${unfile} "MESSAGE(\"FATAL_ERROR Cannot find \\\"install manifest\\\": install_manifest.txt\")\n") 7 | file(APPEND ${unfile} "ENDIF(NOT EXISTS \"install_manifest.txt\")\n") 8 | file(APPEND ${unfile} "FILE(READ \"install_manifest.txt\" files)\n") 9 | file(APPEND ${unfile} "STRING(REGEX REPLACE \"\\n\" \";\" files \"\${files}\")\n") 10 | file(APPEND ${unfile} "FOREACH(file \${files})\n") 11 | file(APPEND ${unfile} " MESSAGE(STATUS \"Uninstalling \\\"\${file}\\\"\")\n") 12 | file(APPEND ${unfile} " IF(EXISTS \"\${file}\")\n") 13 | file(APPEND ${unfile} " EXEC_PROGRAM(\n") 14 | file(APPEND ${unfile} " \"\${CMAKE_COMMAND}\" ARGS \"-E remove \\\"\${file}\\\"\"\n") 15 | file(APPEND ${unfile} " OUTPUT_VARIABLE rm_out\n") 16 | file(APPEND ${unfile} " RETURN_VALUE rm_retval\n") 17 | file(APPEND ${unfile} " )\n") 18 | file(APPEND ${unfile} " IF(\"\${rm_retval}\" STREQUAL 0\)\n") 19 | file(APPEND ${unfile} " ELSE(\"\${rm_retval}\" STREQUAL 0\)\n") 20 | file(APPEND ${unfile} " MESSAGE(FATAL_ERROR \"Problem when removing \\\"\${file}\\\"\")\n") 21 | file(APPEND ${unfile} " ENDIF(\"\${rm_retval}\" STREQUAL 0)\n") 22 | file(APPEND ${unfile} " ELSE(EXISTS \"\${file}\")\n") 23 | file(APPEND ${unfile} " MESSAGE(STATUS \"File \\\"\${file}\\\" does not exist. \")\n") 24 | file(APPEND ${unfile} " ENDIF(EXISTS \"\${file}\")\n") 25 | file(APPEND ${unfile} "ENDFOREACH(file)\n") 26 | 27 | -------------------------------------------------------------------------------- /cmake_modules/def_test.cmake: -------------------------------------------------------------------------------- 1 | include(CMakeParseArguments) 2 | include(FindGTest) 3 | 4 | function(def_test test) 5 | 6 | string(TOUPPER ${test} TEST) 7 | 8 | set(TEST_OPTIONS) 9 | set(TEST_SINGLE_ARGS) 10 | set(TEST_MULTI_ARGS SOURCES DEPENDS CONDITIONS LINK_LIBS) 11 | cmake_parse_arguments(test 12 | "${TEST_OPTIONS}" 13 | "${TEST_SINGLE_ARGS}" 14 | "${TEST_MULTI_ARGS}" 15 | "${ARGN}" 16 | ) 17 | 18 | if(NOT test_SOURCES) 19 | message(FATAL_ERROR "def_test for ${TEST} has an empty source list.") 20 | endif() 21 | 22 | set(cache_var BUILD_${TEST}) 23 | set(${cache_var} ON CACHE BOOL "Enable ${TEST} compilation.") 24 | 25 | if(test_CONDITIONS) 26 | foreach(cond ${test_CONDITIONS}) 27 | if(NOT ${cond}) 28 | set(${cache_var} OFF) 29 | message("${cache_var} is false because ${cond} is false.") 30 | return() 31 | endif() 32 | endforeach() 33 | endif() 34 | 35 | if(test_DEPENDS) 36 | foreach(dep ${test_DEPENDS}) 37 | if(NOT TARGET ${dep}) 38 | set(${cache_var} OFF) 39 | message("${cache_var} is false because ${dep} is not being built.") 40 | return() 41 | endif() 42 | endforeach() 43 | endif() 44 | 45 | if(${cache_var}) 46 | add_executable(${test} ${test_SOURCES}) 47 | gtest_add_tests(${test} "" ${test_SOURCES}) 48 | 49 | # Always build tests debug so they can be debugged! 50 | set_target_properties(${test} PROPERTIES 51 | COMPILE_FLAGS "${CMAKE_CXX_FLAGS_DEBUG}") 52 | 53 | target_link_libraries(${test} 54 | gtest gtest_main 55 | ${test_DEPENDS} 56 | ${test_LINK_LIBS}) 57 | endif() 58 | endfunction() -------------------------------------------------------------------------------- /include/SceneGraph/GLAxis.h: -------------------------------------------------------------------------------- 1 | // Copyright 2014 ARPG 2 | 3 | #ifndef SCENEGRAPH_GLAXIS_H_ 4 | #define SCENEGRAPH_GLAXIS_H_ 5 | 6 | #include 7 | 8 | namespace SceneGraph { 9 | 10 | class SCENEGRAPH_EXPORT GLAxis : public GLObject { 11 | public: 12 | GLAxis(const float axisSize = 1.0f, const bool bPretty = false); 13 | virtual ~GLAxis(); 14 | static void DrawAxis(float fScale = 1.0f); 15 | void DrawCanonicalObject(); 16 | void SetAxisSize(float fScale) { m_fAxisScale = fScale; } 17 | float GetAxisSize() { return m_fAxisScale; } 18 | bool IsSelectable(); 19 | protected: 20 | float m_fAxisScale; 21 | bool m_bPretty; 22 | int m_iAxisID; 23 | }; 24 | 25 | } // namespace SceneGraph 26 | 27 | #endif // SCENEGRAPH_GLAXIS_H_ 28 | -------------------------------------------------------------------------------- /include/SceneGraph/GLAxisAlignedBox.h: -------------------------------------------------------------------------------- 1 | #ifndef GLAXISALIGNEDBOX_H 2 | #define GLAXISALIGNEDBOX_H 3 | 4 | #include 5 | 6 | namespace SceneGraph 7 | { 8 | 9 | /////////////////////////////////////////////////////////////////////////////// 10 | class GLAxisAlignedBox : public GLObject 11 | { 12 | public: 13 | 14 | GLAxisAlignedBox() 15 | : GLObject("AxisAlignedBox"), 16 | m_resizable(false) 17 | { 18 | m_aabb.Min() = Eigen::Vector3d(-1,-1,-1); 19 | m_aabb.Max() = Eigen::Vector3d(1,1,1); 20 | m_bPerceptable = false; 21 | m_bIsSelectable = true; 22 | x_label = AllocSelectionId(); 23 | y_label = AllocSelectionId(); 24 | z_label = AllocSelectionId(); 25 | 26 | } 27 | 28 | void SetResizable(bool resizable = true) 29 | { 30 | m_resizable = resizable; 31 | } 32 | 33 | void DrawAxisAlignedBox( const AxisAlignedBoundingBox& bbox ) { 34 | const Eigen::Vector3d mn = bbox.Min(); 35 | const Eigen::Vector3d mx = bbox.Max(); 36 | 37 | glColor4f(1, 0, 0, 1); 38 | glPushName(x_label); 39 | glBegin(GL_LINES); 40 | glVertex3d(mn(0), mn(1), mn(2)); glVertex3d(mx(0), mn(1), mn(2)); 41 | glVertex3d(mn(0), mx(1), mn(2)); glVertex3d(mx(0), mx(1), mn(2)); 42 | glVertex3d(mn(0), mx(1), mx(2)); glVertex3d(mx(0), mx(1), mx(2)); 43 | glVertex3d(mn(0), mn(1), mx(2)); glVertex3d(mx(0), mn(1), mx(2)); 44 | glEnd(); 45 | glPopName(); 46 | 47 | glColor4f(0, 1, 0, 1); 48 | glPushName(y_label); 49 | glBegin(GL_LINES); 50 | glVertex3d(mn(0), mn(1), mn(2)); glVertex3d(mn(0), mx(1), mn(2)); 51 | glVertex3d(mx(0), mn(1), mn(2)); glVertex3d(mx(0), mx(1), mn(2)); 52 | glVertex3d(mx(0), mn(1), mx(2)); glVertex3d(mx(0), mx(1), mx(2)); 53 | glVertex3d(mn(0), mn(1), mx(2)); glVertex3d(mn(0), mx(1), mx(2)); 54 | glEnd(); 55 | glPopName(); 56 | 57 | glColor4f(0, 0, 1, 1); 58 | glPushName(z_label); 59 | glBegin(GL_LINES); 60 | glVertex3d(mn(0), mn(1), mn(2)); glVertex3d(mn(0), mn(1), mx(2)); 61 | glVertex3d(mx(0), mn(1), mn(2)); glVertex3d(mx(0), mn(1), mx(2)); 62 | glVertex3d(mx(0), mx(1), mn(2)); glVertex3d(mx(0), mx(1), mx(2)); 63 | glVertex3d(mn(0), mx(1), mn(2)); glVertex3d(mn(0), mx(1), mx(2)); 64 | glEnd(); 65 | glPopName(); 66 | } 67 | 68 | bool Mouse(int button, const Eigen::Vector3d& /*win*/, const Eigen::Vector3d& /*obj*/, const Eigen::Vector3d& /*normal*/, bool /*pressed*/, int /*button_state*/, int pickId) 69 | { 70 | // TODO: Make this much better / more flexible 71 | 72 | // if(glutGetModifiers() & GLUT_ACTIVE_SHIFT){ 73 | if(m_resizable && (button == MouseWheelUp || button == MouseWheelDown) ) { 74 | const float mul = (button == MouseWheelUp) ? 1.01 : 0.99; 75 | if(pickId == x_label) { 76 | m_aabb.Min()(0) *= mul; 77 | m_aabb.Max()(0) *= mul; 78 | return true; 79 | }else if(pickId == y_label) { 80 | m_aabb.Min()(1) *= mul; 81 | m_aabb.Max()(1) *= mul; 82 | return true; 83 | }else if(pickId == z_label) { 84 | m_aabb.Min()(2) *= mul; 85 | m_aabb.Max()(2) *= mul; 86 | return true; 87 | } 88 | } 89 | // } 90 | 91 | return false; 92 | } 93 | 94 | void DrawCanonicalObject() 95 | { 96 | DrawAxisAlignedBox(m_aabb); 97 | } 98 | 99 | void SetBounds(Eigen::Vector3d boxmin, Eigen::Vector3d boxmax) 100 | { 101 | m_aabb.Min() = boxmin; 102 | m_aabb.Max() = boxmax; 103 | } 104 | 105 | void SetBounds(float minx, float miny, float minz, float maxx, float maxy, float maxz) 106 | { 107 | SetBounds(Eigen::Vector3d(minx,miny,minz), Eigen::Vector3d(maxx,maxy,maxz) ); 108 | } 109 | 110 | protected: 111 | bool m_resizable; 112 | int x_label, y_label, z_label; 113 | }; 114 | 115 | } // SceneGraph 116 | 117 | #endif // GLAXISALIGNEDBOX_H 118 | -------------------------------------------------------------------------------- /include/SceneGraph/GLAxisHistory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace SceneGraph 7 | { 8 | 9 | template 10 | class GLAxisHistory 11 | : public GLObject 12 | { 13 | public: 14 | GLAxisHistory(int initial_vert_buffer_size = 1024) 15 | : m_red(pangolin::GlArrayBuffer, initial_vert_buffer_size, GL_FLOAT, 3, GL_DYNAMIC_DRAW), 16 | m_green(pangolin::GlArrayBuffer, initial_vert_buffer_size, GL_FLOAT, 3, GL_DYNAMIC_DRAW), 17 | m_blue(pangolin::GlArrayBuffer, initial_vert_buffer_size, GL_FLOAT, 3, GL_DYNAMIC_DRAW) 18 | { 19 | } 20 | 21 | ~GLAxisHistory() 22 | { 23 | } 24 | 25 | void Clear() 26 | { 27 | GLObject::m_aabb.Clear(); 28 | m_red.Clear(); 29 | m_green.Clear(); 30 | m_blue.Clear(); 31 | } 32 | 33 | void DrawCanonicalObject() 34 | { 35 | glColor3f(1,0,0); 36 | DrawVbo(m_red); 37 | 38 | glColor3f(0,1,0); 39 | DrawVbo(m_green); 40 | 41 | glColor3f(0,0,1); 42 | DrawVbo(m_blue); 43 | } 44 | 45 | int Size() const 46 | { 47 | return m_red.size() / 2; 48 | } 49 | 50 | void AddAxis(const Eigen::Matrix& T_wp, double axis_size = 1.0) 51 | { 52 | GLObject::m_aabb.Insert(T_wp.block<3,1>(0,3)); 53 | 54 | Eigen::Matrix vs; 55 | 56 | vs.block<3,1>(0,0) = T_wp.block<3,1>(0,3).cast(); 57 | vs.block<3,1>(0,1) = (T_wp * Eigen::Vector4d(axis_size,0,0,1)).cast(); 58 | m_red.Add(vs); 59 | 60 | vs.block<3,1>(0,1) = (T_wp * Eigen::Vector4d(0,axis_size,0,1)).cast(); 61 | m_green.Add(vs); 62 | 63 | vs.block<3,1>(0,1) = (T_wp * Eigen::Vector4d(0,0,axis_size,1)).cast(); 64 | m_blue.Add(vs); 65 | } 66 | 67 | void UpdateAxis(int index, const Eigen::Matrix& T_wp, double axis_size = 1.0) 68 | { 69 | Eigen::Matrix vs; 70 | 71 | vs.block<3,1>(0,0) = T_wp.block<3,1>(0,3).cast(); 72 | vs.block<3,1>(0,1) = (T_wp * Eigen::Vector4d(axis_size,0,0,1)).cast(); 73 | m_red.Update(vs, 2*index); 74 | 75 | vs.block<3,1>(0,1) = (T_wp * Eigen::Vector4d(0,axis_size,0,1)).cast(); 76 | m_green.Update(vs, 2*index); 77 | 78 | vs.block<3,1>(0,1) = (T_wp * Eigen::Vector4d(0,0,axis_size,1)).cast(); 79 | m_blue.Update(vs, 2*index); 80 | } 81 | 82 | protected: 83 | void DrawVbo(GlBufferType& vbo) 84 | { 85 | vbo.Bind(); 86 | glVertexPointer(vbo.count_per_element, vbo.datatype, 0, 0); 87 | glEnableClientState(GL_VERTEX_ARRAY); 88 | 89 | glDrawArrays(GL_LINES, vbo.start(), vbo.size() ); 90 | 91 | glDisableClientState(GL_VERTEX_ARRAY); 92 | vbo.Unbind(); 93 | } 94 | 95 | GlBufferType m_red; 96 | GlBufferType m_green; 97 | GlBufferType m_blue; 98 | }; 99 | 100 | typedef GLAxisHistory GLCachedAxisHistory; 101 | 102 | 103 | } 104 | -------------------------------------------------------------------------------- /include/SceneGraph/GLColor.h: -------------------------------------------------------------------------------- 1 | #ifndef _SCENEGRAPH_GLCOLOR_H__ 2 | #define _SCENEGRAPH_GLCOLOR_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace SceneGraph { 10 | 11 | struct GLColor { 12 | static GLColor HsvColor(double hue, double s = 1.0, double v = 1.0) { 13 | hue *= 360.0; 14 | const double h = hue / 60.0; 15 | const int i = floor(h); 16 | const double f = (i % 2 == 0) ? 1 - (h - i) : h - i; 17 | const double m = v * (1-s); 18 | const double n = v * (1-s*f); 19 | GLColor color; 20 | switch(i) { 21 | case 0: color = GLColor(v, n, m, 1.0f); break; 22 | case 1: color = GLColor(n, v, m, 1.0f); break; 23 | case 2: color = GLColor(m, v, n, 1.0f); break; 24 | case 3: color = GLColor(m, n, v, 1.0f); break; 25 | case 4: color = GLColor(n, m, v, 1.0f); break; 26 | case 5: color = GLColor(v, m, n, 1.0f); break; 27 | default: 28 | break; 29 | } 30 | return color; 31 | } 32 | 33 | GLColor(const Eigen::Vector4d& rgba) { 34 | r = rgba[0]; 35 | g = rgba[1]; 36 | b = rgba[2]; 37 | a = rgba[3]; 38 | } 39 | 40 | GLColor(float tr = 1.0f, float tg = 1.0f, float tb = 1.0f, float ta = 1.0f) { 41 | r = tr; 42 | g = tg; 43 | b = tb; 44 | a = ta; 45 | } 46 | 47 | GLColor(int tr, int tg, int tb, int ta = 255) { 48 | r = tr/255.0f; 49 | g = tg/255.0f; 50 | b = tb/255.0f; 51 | a = ta/255.0f; 52 | } 53 | 54 | void Apply() const { 55 | glColor4f(r,g,b,a); 56 | } 57 | 58 | struct { 59 | float r; 60 | float g; 61 | float b; 62 | float a; 63 | }; 64 | }; 65 | 66 | #ifndef NAME_MAX 67 | # define NAME_MAX 1024 68 | #endif 69 | 70 | /// All types you wish to use with CVars must overload << and >>. 71 | inline std::ostream &operator<<(std::ostream &stream, GLColor &color) { 72 | int r = int(255*color.r); 73 | int g = int(255*color.g); 74 | int b = int(255*color.b); 75 | int a = int(255*color.a); 76 | 77 | stream << "[ " << r << ", " << g << ", " << b << ", " << a << " ]"; 78 | return stream; 79 | } 80 | 81 | /// All types you wish to use with CVars must overload << and >>. 82 | inline std::istream &operator>>(std::istream &stream, GLColor &color) { 83 | int r = 0, g = 0, b = 0, a = 0; 84 | 85 | char str[NAME_MAX] = {0}; 86 | stream.readsome(str, NAME_MAX); 87 | sscanf(str, "[ %d, %d, %d, %d ]", &r, &g, &b, &a); 88 | 89 | color.r = (float)r/255.0f; 90 | color.g = (float)g/255.0f; 91 | color.b = (float)b/255.0f; 92 | color.a = (float)a/255.0f; 93 | 94 | return stream; 95 | } 96 | } // namespace SceneGraph 97 | #endif 98 | -------------------------------------------------------------------------------- /include/SceneGraph/GLCube.h: -------------------------------------------------------------------------------- 1 | #ifndef _GLCUBE_H_ 2 | #define _GLCUBE_H_ 3 | 4 | #include 5 | #include 6 | 7 | namespace SceneGraph { 8 | class GLCube : public GLObject { 9 | public: 10 | GLCube(); 11 | GLCube(GLuint texId); 12 | void ClearTexture(); 13 | void SetCheckerboard(); 14 | void SetTexture(GLuint texId); 15 | void DrawCanonicalObject(); 16 | 17 | protected: 18 | const static int TEX_W = 64; 19 | const static int TEX_H = 64; 20 | 21 | bool m_bOwnsTexture; 22 | GLuint m_nTexID; 23 | }; 24 | } // namespace SceneGraph 25 | #endif //_GLCube_H_ 26 | -------------------------------------------------------------------------------- /include/SceneGraph/GLCylinder.h: -------------------------------------------------------------------------------- 1 | // Copyright 2014 ARPG 2 | 3 | #ifndef SCENEGRAPH_GLCYLINDER_H_ 4 | #define SCENEGRAPH_GLCYLINDER_H_ 5 | 6 | #include 7 | #include 8 | 9 | namespace SceneGraph { 10 | 11 | class GLCylinder : public GLObject { 12 | public: 13 | explicit GLCylinder(GLuint texId = 0); 14 | ~GLCylinder(); 15 | void Init( 16 | double base_radius, 17 | double top_radius, 18 | double height, 19 | int slices, 20 | int stacks); 21 | void ClearTexture(); 22 | void SetColor(GLColor color); 23 | void SetCheckerboard(); 24 | void SetTexture(GLuint texId); 25 | void DrawCanonicalObject(); 26 | 27 | protected: 28 | double base_radius_; 29 | double top_radius_; 30 | double height_; 31 | double slices_; 32 | double stacks_; 33 | bool draw_caps_; 34 | bool owns_texture_; 35 | GLuint texture_ID_; 36 | GLColor color_; 37 | static const int TEX_W = 64; 38 | static const int TEX_H = 64; 39 | }; 40 | 41 | inline GLCylinder::GLCylinder(GLuint texId) { 42 | owns_texture_ = false; 43 | texture_ID_ = texId; 44 | draw_caps_ = true; 45 | SetCheckerboard(); 46 | } 47 | 48 | inline GLCylinder::~GLCylinder() { 49 | } 50 | 51 | inline void GLCylinder::Init( 52 | double dBaseRadius, 53 | double dTopRadius, 54 | double dHeight_, 55 | int nSlices_, 56 | int nStacks_) { 57 | base_radius_ = dBaseRadius; 58 | top_radius_ = dTopRadius; 59 | height_ = dHeight_; 60 | slices_ = nSlices_; 61 | stacks_ = nStacks_; 62 | } 63 | 64 | inline void GLCylinder::ClearTexture() { 65 | if (texture_ID_ > 0) { 66 | if (owns_texture_) { 67 | glDeleteTextures(1, &texture_ID_); 68 | } 69 | texture_ID_ = 0; 70 | } 71 | } 72 | 73 | inline void GLCylinder::SetColor(GLColor color) { 74 | color_ = color; 75 | } 76 | 77 | inline void GLCylinder::SetCheckerboard() { 78 | ClearTexture(); 79 | 80 | // Texture Map Init 81 | // after glTexImage2D(), array is no longer needed 82 | GLubyte img[TEX_W][TEX_H][3]; 83 | for (int x = 0; x < TEX_W; x++) { 84 | for (int y = 0; y < TEX_H; y++) { 85 | GLubyte c = ((x & 16) ^ (y & 16)) ? 255 : 0; // checkerboard 86 | img[x][y][0] = c; 87 | img[x][y][1] = c; 88 | img[x][y][2] = c; 89 | } 90 | } 91 | // Generate and bind the texture 92 | owns_texture_ = true; 93 | glGenTextures(1, &texture_ID_); 94 | glBindTexture(GL_TEXTURE_2D, texture_ID_); 95 | glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 96 | glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 97 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, TEX_W, TEX_H, 0, 98 | GL_RGB, GL_UNSIGNED_BYTE, &img[0][0][0]); 99 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 100 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 101 | } 102 | 103 | inline void GLCylinder::SetTexture(GLuint texId) { 104 | ClearTexture(); 105 | owns_texture_ = false; 106 | texture_ID_ = texId; 107 | } 108 | 109 | // adapted from http://math.hws.edu/graphicsnotes/source/glutil/UVCylinder.java 110 | inline void GLCylinder::DrawCanonicalObject() { 111 | color_.Apply(); 112 | for (int j = 0; j < stacks_; j++) { 113 | double z1 = (height_/stacks_) * j; 114 | double z2 = (height_/stacks_) * (j + 1); 115 | glBegin(GL_QUAD_STRIP); 116 | for (int i = 0; i <= slices_; i++) { 117 | double longitude = (2 * 3.14 / slices_) * i; 118 | double sinLong = sin(longitude); 119 | double cosLong = cos(longitude); 120 | double x = cosLong; 121 | double y = sinLong; 122 | glNormal3d(x, y, 0); 123 | if (owns_texture_) { 124 | glTexCoord2d(1.0 / slices_ * i, 1.0 / stacks_ * (j+1)); 125 | } 126 | glVertex3d(base_radius_ * x, base_radius_ * y, z2); 127 | if (owns_texture_) { 128 | glTexCoord2d(1.0 / slices_ * i, 1.0 / stacks_ * j); 129 | } 130 | glVertex3d(top_radius_ * x, top_radius_ * y, z1); 131 | } 132 | glEnd(); 133 | } 134 | if (draw_caps_) { 135 | // top 136 | double rings = 5; 137 | glNormal3d(0, 0, 1); 138 | for (int j = 0; j < rings; j++) { 139 | double d1 = (1.0 / rings) * j; 140 | double d2 = (1.0 / rings) * (j + 1); 141 | glBegin(GL_QUAD_STRIP); 142 | for (int i = 0; i <= slices_; i++) { 143 | double angle = (2 * 3.14 / slices_) * i; 144 | double dsin = sin(angle); 145 | double dcos = cos(angle); 146 | if (owns_texture_) 147 | glTexCoord2d(0.5 * (1 + dcos * d1), 0.5 * (1 + dsin * d1)); 148 | glVertex3d(top_radius_ * dcos * d1, top_radius_ * dsin * d1, height_); 149 | if (owns_texture_) 150 | glTexCoord2d(0.5 * (1 + dcos * d2), 0.5 * (1 + dsin * d2)); 151 | glVertex3d(top_radius_ * dcos * d2, top_radius_ * dsin * d2, height_); 152 | } 153 | glEnd(); 154 | } 155 | // bottom 156 | glNormal3d(0, 0, -1); 157 | for (int j = 0; j < rings; j++) { 158 | double d1 = (1.0 / rings) * j; 159 | double d2 = (1.0 / rings) * (j + 1); 160 | glBegin(GL_QUAD_STRIP); 161 | for (int i = 0; i <= slices_; i++) { 162 | double angle = (2 * 3.14 / slices_) * i; 163 | double dsin = sin(angle); 164 | double dcos = cos(angle); 165 | if (owns_texture_) { 166 | glTexCoord2d(0.5 * (1 + dcos * d2), 0.5 * (1 + dsin * d2)); 167 | } 168 | glVertex3d(base_radius_ * dcos * d2, base_radius_ * dsin * d2, 0); 169 | if (owns_texture_) { 170 | glTexCoord2d(0.5 * (1 + dcos * d1), 0.5 * (1 + dsin * d1)); 171 | } 172 | glVertex3d(base_radius_ * dcos * d1, base_radius_ * dsin * d1, 0); 173 | } 174 | glEnd(); 175 | } 176 | } 177 | } 178 | 179 | } // namespace SceneGraph 180 | 181 | #endif // SCENEGRAPH_GLCYLINDER_H_ 182 | -------------------------------------------------------------------------------- /include/SceneGraph/GLDynamicGrid.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace SceneGraph { 7 | class GLDynamicGrid : public GLObject { 8 | public: 9 | GLDynamicGrid(); 10 | virtual ~GLDynamicGrid() {} 11 | 12 | virtual void DrawCanonicalObject(); 13 | 14 | /** The spacing between major lines */ 15 | void set_line_spacing(float spacing); 16 | float line_spacing(); 17 | 18 | /** Number of minor lines between major lines */ 19 | void set_num_minor_lines(int num); 20 | int num_minor_lines(); 21 | 22 | void set_major_color(GLColor color); 23 | GLColor major_color(); 24 | 25 | void set_minor_color(GLColor color); 26 | GLColor minor_color(); 27 | 28 | /** nd_o = (n_o / d_o) 29 | * 30 | * n_o : Normal of plane with respect to object frame of ref 31 | * d_o : Distance of closest approach with origin of object frame 32 | */ 33 | void set_normal(const Eigen::Vector3d& nd_o); 34 | 35 | void set_bounds(const AxisAlignedBoundingBox& bbox) { 36 | m_aabb = bbox; 37 | ComputeGridProperties(); 38 | } 39 | 40 | protected: 41 | void ComputeGridProperties(); 42 | 43 | private: 44 | float spacing_; 45 | int num_minor_lines_; 46 | GLColor major_color_, minor_color_; 47 | 48 | // Plane to object transform (represents canonical basis for plane) 49 | Eigen::Matrix4d t_op_; 50 | 51 | // Grid properties 52 | int num_neg_x_, num_pos_x_, num_neg_y_, num_pos_y_; 53 | }; 54 | } // namespace SceneGraph 55 | -------------------------------------------------------------------------------- /include/SceneGraph/GLES_compat.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #ifdef HAVE_GLUES 7 | #include 8 | #endif 9 | 10 | #define GL_ENABLE_BIT 0 11 | #define GL_LUMINANCE8 GL_LUMINANCE 12 | 13 | #ifndef GL_DEPTH_COMPONENT 14 | # define GL_DEPTH_COMPONENT GL_DEPTH_COMPONENT24 15 | #endif 16 | 17 | #define glActiveTextureARB glActiveTexture 18 | #define GL_TEXTURE1_ARB GL_TEXTURE1 19 | #define GL_TEXTURE0_ARB GL_TEXTURE0 20 | 21 | inline void glMultMatrixd(const double *m ) 22 | { 23 | glMultMatrixf(static_cast( 24 | Eigen::Map(m).cast()).data()); 25 | } 26 | 27 | inline void glScaled( double x, double y, double z) 28 | { 29 | glScalef( (GLfloat)x, (GLfloat)y, (GLfloat)z); 30 | } 31 | -------------------------------------------------------------------------------- /include/SceneGraph/GLGrid.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL_GRID_H_ 2 | #define _GL_GRID_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace SceneGraph { 9 | 10 | class GLGrid : public GLObject { 11 | public: 12 | GLGrid(int num_lines = 50, 13 | float line_spacing = 2.0, 14 | bool perceptable = false); 15 | 16 | /** Draw a grid centered at (0, 0, 0) with a specified number of 17 | * lines in each direction. 18 | * 19 | * @param filled Should the grid squares be filled in 20 | * @param num_lines_neg_x # of lines to draw in the -x direction 21 | * @param num_lines_x # of lines to draw in the +x direction 22 | * @param num_lines_neg_y # of lines to draw in the -y direction 23 | * @param num_lines_y # of lines to draw in the +y direction 24 | * @param line_spacing The space between major grid lines 25 | * @param color_plane Color of filled grid squares. Ignored if filled == false 26 | * @param major_color Color of major grid lines 27 | * @param num_minor_lines Number of minor grid lines between each major line 28 | * @param minor_color Color for minor grid lines 29 | */ 30 | static void DrawGridZ0( 31 | bool filled, 32 | int num_lines_neg_x, int num_lines_x, 33 | int num_lines_neg_y, int num_lines_y, 34 | float line_spacing, GLColor color_plane, GLColor major_color, 35 | int num_minor_lines, GLColor minor_color); 36 | 37 | void DrawCanonicalObject(); 38 | 39 | void SetNumLines(int nNumLines) { 40 | num_lines_ = nNumLines; 41 | ComputeBounds(); 42 | } 43 | 44 | void SetLineSpacing(float fLineSpacing) { 45 | line_spacing_ = fLineSpacing; 46 | ComputeBounds(); 47 | } 48 | 49 | void SetColors(const GLColor& planeColor, const GLColor& lineColor) { 50 | color_plane_ = planeColor; 51 | major_color_lines_ = lineColor; 52 | } 53 | 54 | void SetPlaneColor(const GLColor& color) { 55 | color_plane_ = color; 56 | } 57 | 58 | void SetLineColor(const GLColor& color) { 59 | major_color_lines_ = color; 60 | } 61 | 62 | void set_has_minor_lines(bool minor) { 63 | has_minor_lines_ = minor; 64 | } 65 | 66 | bool has_minor_lines() { 67 | return has_minor_lines_; 68 | } 69 | 70 | /** Set the number of minor lines between major lines */ 71 | void set_num_minor_lines(int num) { 72 | num_minor_ = num; 73 | } 74 | 75 | /** Number of minor lines between major lines */ 76 | int num_minor_lines() { 77 | return num_minor_; 78 | } 79 | 80 | /** nd_o = (n_o / d_o) 81 | * 82 | * n_o : Normal of plane with respect to object frame of ref 83 | * d_o : Distance of closest approach with origin of object frame 84 | */ 85 | void SetPlane(const Eigen::Vector3d& nd_o); 86 | 87 | protected: 88 | void ComputeBounds(); 89 | 90 | private: 91 | int num_lines_; 92 | float line_spacing_; 93 | 94 | GLColor color_plane_; 95 | GLColor major_color_lines_; 96 | GLColor minor_color_lines_; 97 | 98 | // Plane to object transform (represents canonical basis for plane) 99 | Eigen::Matrix4d t_op_; 100 | 101 | bool has_minor_lines_; 102 | 103 | // Number of minor grid lines between major lines 104 | int num_minor_; 105 | }; 106 | } // namespace SceneGraph 107 | 108 | #endif 109 | -------------------------------------------------------------------------------- /include/SceneGraph/GLGroup.h: -------------------------------------------------------------------------------- 1 | #ifndef GLGROUP_H 2 | #define GLGROUP_H 3 | 4 | #include 5 | 6 | namespace SceneGraph 7 | { 8 | 9 | /////////////////////////////////////////////////////////////////////////////// 10 | class GLGroup : public GLObject 11 | { 12 | public: 13 | 14 | GLGroup() 15 | : GLObject("Group") 16 | { 17 | m_bPerceptable = false; 18 | } 19 | 20 | void DrawCanonicalObject() 21 | { 22 | // Do nothing 23 | } 24 | 25 | /// Include children in calllist (since the group itself does nothing) 26 | virtual void CompileAsGlCallList() 27 | { 28 | #ifndef HAVE_GLES 29 | if( m_nDisplayList == -1 ){ 30 | m_nDisplayList = glGenLists(1); 31 | glNewList( m_nDisplayList, GL_COMPILE ); 32 | DrawChildren(); 33 | glEndList(); 34 | } 35 | #endif 36 | } 37 | 38 | /// Override GLObject::DrawObjectAndChildren since children are included 39 | /// in call list. 40 | virtual void DrawObjectAndChildren(RenderMode renderMode) 41 | { 42 | if( IsVisible() && ( 43 | (renderMode == eRenderVisible) || (renderMode == eRenderNoPrePostHooks) || 44 | (renderMode == eRenderSelectable && (IsSelectable() || m_vpChildren.size() > 0) ) || 45 | (renderMode == eRenderPerceptable && IsPerceptable()) 46 | ) 47 | ) { 48 | glMatrixMode(GL_MODELVIEW); 49 | glPushMatrix(); 50 | 51 | #ifdef HAVE_GLES 52 | Eigen::Matrix4f T_po = m_T_po.cast(); 53 | glMultMatrixf(T_po.data()); 54 | glScalef(m_dScale[0],m_dScale[1],m_dScale[2]); 55 | DrawCanonicalObject(); 56 | #else 57 | glMultMatrixd(m_T_po.data()); 58 | glScaled(m_dScale[0],m_dScale[1],m_dScale[2]); 59 | if(m_nDisplayList >= 0) { 60 | glCallList( m_nDisplayList ); 61 | }else{ 62 | DrawChildren(); 63 | } 64 | #endif //HAVE_GLES 65 | 66 | glPopMatrix(); 67 | } 68 | } 69 | 70 | }; 71 | 72 | } // SceneGraph 73 | 74 | #endif // GLGROUP_H 75 | -------------------------------------------------------------------------------- /include/SceneGraph/GLHeightmap.h: -------------------------------------------------------------------------------- 1 | #ifndef SCENEGRAPH_GLHEIGHTMAP_H_ 2 | #define SCENEGRAPH_GLHEIGHTMAP_H_ 3 | 4 | #include "SceneGraph/GLObject.h" 5 | 6 | namespace SceneGraph { 7 | /// The SceneGraph heightmap 8 | class GLHeightmap : public GLObject { 9 | public: 10 | 11 | GLHeightmap(std::vector x_array, std::vector y_array, 12 | std::vector z_array, 13 | double row_count, double col_count) { 14 | X_ = x_array; 15 | Y_ = y_array; 16 | Z_ = z_array; 17 | row_count_ = row_count; 18 | col_count_ = col_count; 19 | render_ = false; 20 | } 21 | 22 | ///////////////////////////////////////////////////////////////////////////// 23 | void DrawCanonicalObject() { 24 | if (render_) { 25 | glBegin(GL_TRIANGLES); // Render Polygons 26 | } else { 27 | glBegin(GL_LINES); // Render Lines Instead 28 | } 29 | int index = 0; 30 | for (int i = 0; i X_; 60 | std::vector Y_; 61 | std::vector Z_; 62 | double row_count_; 63 | double col_count_; 64 | bool render_; 65 | }; 66 | 67 | } 68 | 69 | #endif // SCENEGRAPH_GLHEIGHTMAP_H_ 70 | -------------------------------------------------------------------------------- /include/SceneGraph/GLHelpersDevil.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | //////////////////////////////////////////////////////////////////////////// 7 | // Interface 8 | //////////////////////////////////////////////////////////////////////////// 9 | namespace SceneGraph 10 | { 11 | 12 | GLuint LoadGLTextureFromDevIL(ILuint ilTexId); 13 | 14 | GLuint LoadGLTextureFromDevIL(const std::string filename); 15 | 16 | GLuint LoadGLTextureFromDevIL(const unsigned char* data, size_t bytes, const char* extensionHint = 0 ); 17 | 18 | } 19 | 20 | //////////////////////////////////////////////////////////////////////////// 21 | // Implementation 22 | //////////////////////////////////////////////////////////////////////////// 23 | 24 | namespace SceneGraph 25 | { 26 | 27 | //////////////////////////////////////////////////////////////////////////// 28 | inline GLuint LoadGLTextureFromDevIL(ILuint ilTexId) 29 | { 30 | ilBindImage(ilTexId); 31 | 32 | ILinfo ilImageInfo; 33 | iluGetImageInfo(&ilImageInfo); 34 | 35 | if (ilImageInfo.Origin == IL_ORIGIN_UPPER_LEFT) { 36 | iluFlipImage(); 37 | } 38 | 39 | if ( !ilConvertImage(IL_RGB, IL_UNSIGNED_BYTE) ) { 40 | ILenum ilError = ilGetError(); 41 | std::cerr << "Unable to decode image, DevIL: " << ilError << " - " << iluErrorString(ilError) << std::endl; 42 | return 0; 43 | } 44 | 45 | GLuint glTexId = 0; 46 | glGenTextures(1, &glTexId); 47 | glBindTexture(GL_TEXTURE_2D, glTexId); 48 | // load Mipmaps instead of single texture 49 | glTexImage2D(GL_TEXTURE_2D, 0, ilGetInteger(IL_IMAGE_BPP), ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT), 50 | 0, ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE, ilGetData() ); 51 | // glGenerateMipmap( GL_TEXTURE_2D ); 52 | gluBuild2DMipmaps(GL_TEXTURE_2D, 3, ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT), 53 | ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE, ilGetData() ); 54 | return glTexId; 55 | } 56 | 57 | //////////////////////////////////////////////////////////////////////////// 58 | inline GLuint LoadGLTextureFromDevIL(const std::string filename) 59 | { 60 | GLuint glTexId = 0; 61 | 62 | ILuint ilTexId; 63 | ilGenImages(1, &ilTexId); 64 | ilBindImage(ilTexId); 65 | 66 | if( ilLoadImage(filename.c_str() ) ) { 67 | glTexId = LoadGLTextureFromDevIL(ilTexId); 68 | }else{ 69 | std::cerr << "Failed to load texture file '" << filename << "'" << std::endl; 70 | } 71 | 72 | ilDeleteImages(1, &ilTexId); 73 | return glTexId; 74 | } 75 | 76 | //////////////////////////////////////////////////////////////////////////// 77 | inline GLuint LoadGLTextureFromDevIL(const unsigned char* data, size_t bytes, const char* extensionHint ) 78 | { 79 | GLuint glTexId = 0; 80 | 81 | ILuint ilTexId; 82 | ilGenImages(1, &ilTexId); 83 | ilBindImage(ilTexId); 84 | 85 | ILenum filetype = IL_TYPE_UNKNOWN; 86 | 87 | // Guess filetype by data 88 | if (filetype == IL_TYPE_UNKNOWN) { 89 | filetype = ilDetermineTypeL(data, bytes); 90 | } 91 | 92 | // Guess filetype by extension 93 | if( filetype == IL_TYPE_UNKNOWN && extensionHint != 0 ) { 94 | const std::string sExt(extensionHint); 95 | const std::string sDummy = std::string("dummy.") + sExt; 96 | filetype = ilDetermineType(sDummy.c_str()); 97 | } 98 | 99 | // Some extra guesses that seem to be missed in devIL 100 | if( filetype == IL_TYPE_UNKNOWN ) { 101 | if( !strcmp(extensionHint, "bmp") ) { 102 | filetype = IL_TGA; 103 | } 104 | } 105 | 106 | // Load image to ilTexId us devIL 107 | if( ilLoadL(filetype, data, bytes) ) { 108 | glTexId = LoadGLTextureFromDevIL(ilTexId); 109 | }else{ 110 | ILenum ilError = ilGetError(); 111 | std::cerr << "Failed to Load embedded texture, DevIL: " << ilError << " - " << iluErrorString(ilError) << std::endl; 112 | } 113 | 114 | ilDeleteImages(1, &ilTexId); 115 | 116 | return glTexId; 117 | } 118 | 119 | } // namespace SceneGraph 120 | -------------------------------------------------------------------------------- /include/SceneGraph/GLHelpersLoadTextures.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "GLHelpersDevil.h" 4 | 5 | //////////////////////////////////////////////////////////////////////////// 6 | // Interface 7 | //////////////////////////////////////////////////////////////////////////// 8 | 9 | namespace SceneGraph 10 | { 11 | 12 | GLuint LoadGLTextureFromFile(const char* path, size_t length); 13 | GLuint LoadGLTextureFromArray(const unsigned char* data, size_t bytes, const char* extensionHint = 0 ); 14 | 15 | } 16 | 17 | //////////////////////////////////////////////////////////////////////////// 18 | // Implementation 19 | //////////////////////////////////////////////////////////////////////////// 20 | 21 | namespace SceneGraph 22 | { 23 | 24 | //////////////////////////////////////////////////////////////////////////// 25 | inline GLuint LoadGLTextureFromFile(const char* path, size_t length) 26 | { 27 | std::string filename(path); 28 | if(length >= 2 && filename[0] == '/' && filename[1] == '/' ) { 29 | filename[0] = '.'; 30 | } 31 | 32 | GLuint glTexId = 0; 33 | 34 | std::string extension; 35 | extension = filename.substr( filename.rfind( "." ) + 1 ); 36 | 37 | 38 | glTexId = LoadGLTextureFromDevIL(filename); 39 | 40 | return glTexId; 41 | } 42 | 43 | //////////////////////////////////////////////////////////////////////////// 44 | inline GLuint LoadGLTextureFromArray(const unsigned char* data, size_t bytes, const char* extensionHint ) 45 | { 46 | GLuint glTexId = 0; 47 | 48 | glTexId = LoadGLTextureFromDevIL(data,bytes,extensionHint); 49 | 50 | return glTexId; 51 | } 52 | 53 | } // namespace SceneGraph 54 | -------------------------------------------------------------------------------- /include/SceneGraph/GLLight.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL_LIGHT_H_ 2 | #define _GL_LIGHT_H_ 3 | 4 | #include 5 | #include 6 | 7 | namespace SceneGraph 8 | { 9 | 10 | class SCENEGRAPH_EXPORT GLLight : public GLObjectPrePostRender 11 | { 12 | public: 13 | GLLight(double x = 0, double y = 0, double z = 0) 14 | : GLObjectPrePostRender("Light"), 15 | m_ambient(0.2, 0.2, 0.2, 1.0), 16 | m_diffuse(0.8, 0.8, 0.8, 1.0) 17 | { 18 | m_nLigthId = (s_nNextLightId++); 19 | SetPerceptable(false); 20 | SetVisible(false); 21 | SetPosition(x,y,z); 22 | } 23 | 24 | ~GLLight() 25 | { 26 | } 27 | 28 | virtual void DrawCanonicalObject() 29 | { 30 | // TODO: Draw something that better resembles a light 31 | pangolin::GlState gl; 32 | gl.glDisable( GL_LIGHTING ); 33 | GLAxis::DrawAxis(1.0); 34 | } 35 | 36 | void EnableLight() 37 | { 38 | glEnable( m_nLigthId ); 39 | const Eigen::Matrix pose = this->GetPose(); 40 | const float pos[4] = {(float)pose(0),(float)pose(1),(float)pose(2), 1}; 41 | glLightfv(m_nLigthId, GL_POSITION, pos ); 42 | 43 | glLightfv(m_nLigthId, GL_AMBIENT, m_ambient.data()); 44 | glLightfv(m_nLigthId, GL_DIFFUSE, m_diffuse.data()); 45 | } 46 | 47 | void DisableLight() 48 | { 49 | glDisable(m_nLigthId); 50 | } 51 | 52 | virtual void PreRender(GLSceneGraph& /*scene*/) { 53 | EnableLight(); 54 | } 55 | 56 | virtual void PostRender(GLSceneGraph& /*scene*/) { 57 | DisableLight(); 58 | } 59 | 60 | virtual void SetAmbient(const Eigen::Vector4f& fAmbient){ 61 | m_ambient = fAmbient; 62 | } 63 | 64 | virtual void SetDiffuse(const Eigen::Vector4f& fDiffuse){ 65 | m_diffuse = fDiffuse; 66 | } 67 | 68 | protected: 69 | Eigen::Vector4f m_ambient; 70 | Eigen::Vector4f m_diffuse; 71 | 72 | int m_nLigthId; 73 | static int s_nNextLightId; 74 | }; 75 | 76 | } 77 | 78 | #endif // _GL_LIGHT_H_ 79 | -------------------------------------------------------------------------------- /include/SceneGraph/GLLineStrip.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL_LINESTRIP_H_ 2 | #define _GL_LINESTRIP_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace SceneGraph { 9 | 10 | class GLLineStrip : public GLObject { 11 | public: 12 | GLLineStrip() 13 | : GLObject("LineStrip"), 14 | m_buffer(pangolin::GlArrayBuffer, 100, GL_FLOAT, 3, GL_DYNAMIC_DRAW) { 15 | m_bPerceptable = false; 16 | m_line_width = 1; 17 | } 18 | 19 | void InitReset() { m_Color = GLColor(); } 20 | 21 | void DrawCanonicalObject() { 22 | m_Color.Apply(); 23 | m_buffer.Bind(); 24 | glVertexPointer(m_buffer.count_per_element, m_buffer.datatype, 0, 0); 25 | glLineWidth(m_line_width); 26 | glEnableClientState(GL_VERTEX_ARRAY); 27 | glDrawArrays(GL_LINE_STRIP, m_buffer.start(), m_buffer.size()); 28 | glDisableClientState(GL_VERTEX_ARRAY); 29 | m_buffer.Unbind(); 30 | } 31 | 32 | void SetPoint(Eigen::Vector3d Point) { m_buffer.Add(Point.cast()); } 33 | 34 | void SetPoint(double P[3]) { 35 | m_buffer.Add(Eigen::Vector3f(P[0], P[1], P[2])); 36 | } 37 | 38 | void SetPoint(double X = 0, double Y = 0, double Z = 0) { 39 | m_buffer.Add(Eigen::Vector3f(X, Y, Z)); 40 | } 41 | 42 | void SetPoints(const std::vector& vPts) { 43 | m_buffer.Clear(); 44 | for (size_t i = 0; i < vPts.size(); i += 3) { 45 | SetPoint(vPts[i], vPts[i + 1], vPts[i + 2]); 46 | } 47 | } 48 | 49 | void SetPointsFromTrajectory(const Eigen::Vector6dAlignedVec& vPts) { 50 | m_buffer.Clear(); 51 | for (size_t i = 0; i < vPts.size(); ++i) { 52 | SetPoint(vPts[i][0], vPts[i][1], vPts[i][2]); 53 | } 54 | } 55 | 56 | void SetPointsFromTrajectory(const Eigen::Vector3dAlignedVec& vPts) { 57 | m_buffer.Clear(); 58 | for (size_t i = 0; i < vPts.size(); ++i) { 59 | SetPoint(vPts[i][0], vPts[i][1], vPts[i][2]); 60 | } 61 | } 62 | 63 | // deprecated: set GLLineStrip pose instead. 64 | void SetReference(unsigned int Xref, unsigned int Yref, unsigned int Zref) { 65 | m_T_po(0, 3) = Xref; 66 | m_T_po(1, 3) = Yref; 67 | m_T_po(2, 3) = Zref; 68 | } 69 | 70 | void ClearLines() { m_buffer.Clear(); } 71 | 72 | void SetColor(const GLColor& c) { m_Color = c; } 73 | 74 | void SetLineWidth(double width) { m_line_width = width; } 75 | 76 | void SetColor(double r, double g, double b, double a) { 77 | m_Color.r = r; 78 | m_Color.g = g; 79 | m_Color.b = b; 80 | m_Color.a = a; 81 | } 82 | 83 | private: 84 | GlCachedSizeableBuffer m_buffer; 85 | GLColor m_Color; 86 | double m_line_width; 87 | }; 88 | } 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /include/SceneGraph/GLMesh.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL_MESH_H_ 2 | #define _GL_MESH_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace SceneGraph 9 | { 10 | 11 | struct GLMeshException : std::exception 12 | { 13 | GLMeshException(const std::string& description ) throw() 14 | : m_sWhat(description) 15 | { 16 | } 17 | 18 | ~GLMeshException() throw() {} 19 | 20 | const char* what() const throw() { 21 | return m_sWhat.c_str(); 22 | } 23 | 24 | protected: 25 | std::string m_sWhat; 26 | }; 27 | 28 | class GLMesh : public GLObject 29 | { 30 | public: 31 | GLMesh(); 32 | GLMesh(const std::string& sMeshFile); 33 | ~GLMesh(); 34 | 35 | bool Init( const std::string& sMeshFile, 36 | bool bFlipUVs = false ); 37 | bool Init( const struct aiScene* pScene ); 38 | 39 | bool Mouse(int /*button*/, const Eigen::Vector3d& /*win*/, 40 | const Eigen::Vector3d& /*obj*/, 41 | const Eigen::Vector3d& /*normal*/, 42 | bool /*pressed*/, int /*button_state*/, int /*pickId*/) { 43 | return false; 44 | } 45 | 46 | bool MouseMotion(const Eigen::Vector3d& /*win*/, 47 | const Eigen::Vector3d& /*obj*/, 48 | const Eigen::Vector3d& /*normal*/, 49 | int /*button_state*/, int /*pickId*/) { 50 | return false; 51 | } 52 | 53 | virtual void ComputeDimensions(); 54 | virtual void DrawCanonicalObject(); 55 | 56 | void ShowNormals(bool showNormals = true); 57 | 58 | void ComputeNodeBounds( const struct aiScene *pAIScene, const struct aiNode *pAINode, AxisAlignedBoundingBox& aabb, aiMatrix4x4 dParentTransform ); 59 | 60 | void SetScale(Eigen::Vector3d s); 61 | 62 | void SetScale(double s); 63 | 64 | void SetAlpha(const double a) { m_fAlpha = a; } 65 | 66 | void SetMeshColor(SceneGraph::GLColor& mesh_color); 67 | 68 | bool IsSelectable(); 69 | // TODO: Ideally we would deprecate this and not make 70 | // ASSIMP structures public. 71 | const struct aiScene *GetScene( void ); 72 | 73 | Eigen::Vector3d GetDimensions(); 74 | 75 | struct Vertex 76 | { 77 | float m_posX; 78 | float m_posY; 79 | float m_posZ; 80 | 81 | float m_normalX; 82 | float m_normalY; 83 | float m_normalZ; 84 | 85 | float m_texU; 86 | float m_texV; 87 | 88 | Vertex() {} 89 | 90 | Vertex(const float posX, const float posY, const float posZ, 91 | const float texU, const float texV, 92 | const float normX,const float normY,const float normZ) 93 | { 94 | m_posX = posX; 95 | m_posY = posY; 96 | m_posZ = posZ; 97 | 98 | m_texU = texU; 99 | m_texV = texV; 100 | 101 | m_normalX = normX; 102 | m_normalY = normY; 103 | m_normalZ = normZ; 104 | } 105 | }; 106 | 107 | struct Mesh { 108 | Mesh(); 109 | 110 | ~Mesh(); 111 | 112 | bool Init(const std::vector& vVertices, 113 | const std::vector& vIndices, 114 | const aiMatrix4x4& m_Transformation); 115 | 116 | GLuint m_uVB; 117 | GLuint m_uIB; 118 | aiMatrix4x4 m_Transformation; 119 | unsigned int m_uNumIndices; 120 | unsigned int m_uMaterialIndex; 121 | }; 122 | 123 | void InitMesh(unsigned int Index, const aiMesh *paiMesh, const aiMatrix4x4 &mTransformation); 124 | void InitNode(const aiScene *sc, const aiNode *nd, const aiMatrix4x4 &mTransformation); 125 | protected: 126 | void LoadMeshTextures(); 127 | void LoadMaterialTextures(aiMaterial* pMaterial); 128 | GLuint LoadGLTextureResource(aiString& path); 129 | void ApplyMaterial(const struct aiMaterial *mtl ); 130 | 131 | // void RecursiveRender( const struct aiScene *sc, const struct aiNode* nd ); 132 | // void RenderMesh( const struct aiMesh* mesh, const struct aiMaterial* mtl ); 133 | // void RenderFace( GLenum face_mode, GLenum fill_mode, float fAlpha, const struct aiFace* face, const struct aiMesh* mesh ); 134 | 135 | 136 | const struct aiScene* m_pScene; 137 | std::string m_sMeshPath; 138 | SceneGraph::GLColor m_meshcolor; 139 | float m_fAlpha; // render translucent meshes? 140 | unsigned int m_iMeshID; 141 | bool m_bShowMeshNormals; 142 | unsigned int m_uMeshCount; 143 | std::map m_mapPathToGLTex; 144 | std::vector m_Meshes; 145 | }; 146 | 147 | } // SceneGraph 148 | 149 | #endif 150 | 151 | -------------------------------------------------------------------------------- /include/SceneGraph/GLMovableAxis.h: -------------------------------------------------------------------------------- 1 | #ifndef GLMOVABLEAXIS_H 2 | #define GLMOVABLEAXIS_H 3 | 4 | #include 5 | 6 | namespace SceneGraph 7 | { 8 | 9 | /////////////////////////////////////////////////////////////////////////////// 10 | class GLMovableAxis : public GLObject 11 | { 12 | public: 13 | 14 | GLMovableAxis(float axisSize = 1.0f, bool rotatable = true, bool translatable = true) 15 | : GLObject("Axis"), m_axisSize(axisSize), m_rotatable(rotatable), m_translatable(translatable) 16 | { 17 | m_bIsSelectable = translatable | rotatable; 18 | m_bPerceptable = false; 19 | x_label = AllocSelectionId(); 20 | y_label = AllocSelectionId(); 21 | z_label = AllocSelectionId(); 22 | } 23 | 24 | bool Mouse(int button, const Eigen::Vector3d& /*win*/, const Eigen::Vector3d& /*obj*/, const Eigen::Vector3d& /*normal*/, bool /*pressed*/, int button_state, int pickId) 25 | { 26 | if((button == MouseWheelUp || button == MouseWheelDown) ) { 27 | float scale = (button == MouseWheelUp) ? 0.01 : -0.01; 28 | if(button_state & KeyModifierShift) scale /= 10; 29 | 30 | Eigen::Matrix T_po = GetPose(); 31 | Eigen::Matrix T_on = Eigen::Matrix::Zero(); 32 | 33 | if(button_state & KeyModifierCtrl) { 34 | if(m_rotatable) { 35 | // rotate 36 | if(pickId == x_label) { 37 | T_on(3) += scale; 38 | }else if(pickId == y_label) { 39 | T_on(4) += scale; 40 | }else if(pickId == z_label) { 41 | T_on(5) += scale; 42 | }else{ 43 | return false; 44 | } 45 | } 46 | }else{ 47 | if(m_translatable) { 48 | // translate 49 | if(pickId == x_label) { 50 | T_on(0) += m_axisSize*scale; 51 | }else if(pickId == y_label) { 52 | T_on(1) += m_axisSize*scale; 53 | }else if(pickId == z_label) { 54 | T_on(2) += m_axisSize*scale; 55 | }else{ 56 | return false; 57 | } 58 | } 59 | } 60 | Eigen::Matrix4d T_pn = (GLCart2T(T_po) * GLCart2T(T_on)); 61 | SetPose(T_pn); 62 | return true; 63 | } 64 | 65 | return false; 66 | } 67 | 68 | void DrawCanonicalObject() 69 | { 70 | // draw axis 71 | glPushName(x_label); 72 | glColor4f(1, 0, 0, 1); 73 | glBegin(GL_LINES); 74 | glVertex3d(0, 0, 0); 75 | glVertex3d(m_axisSize, 0, 0); 76 | glEnd(); 77 | glPopName(); 78 | 79 | glPushName(y_label); 80 | glColor4f(0, 1, 0, 1); 81 | glBegin(GL_LINES); 82 | glVertex3d(0, 0, 0); 83 | glVertex3d(0, m_axisSize, 0); 84 | glEnd(); 85 | glPopName(); 86 | 87 | glPushName(z_label); 88 | glColor4f(0, 0, 1, 1); 89 | glBegin(GL_LINES); 90 | glVertex3d(0, 0, 0); 91 | glVertex3d(0, 0, m_axisSize); 92 | glEnd(); 93 | glPopName(); 94 | } 95 | 96 | protected: 97 | float m_axisSize; 98 | bool m_rotatable, m_translatable; 99 | int x_label, y_label, z_label; 100 | }; 101 | 102 | } // SceneGraph 103 | 104 | #endif // GLMOVABLEAXIS_H 105 | -------------------------------------------------------------------------------- /include/SceneGraph/GLOpenBox.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL_OPENBOX_H_ 2 | #define _GL_OPENBOX_H_ 3 | 4 | #include 5 | #include 6 | 7 | namespace SceneGraph 8 | { 9 | 10 | ///////////////////////////////////////////////////////////////////////////// 11 | class GLOpenBox : public GLObject 12 | { 13 | public: 14 | GLOpenBox(double interval = 1.0, int sub_ticks_per_interval = 10) 15 | : GLObject("GLBox"), 16 | m_box_grow_factor(1,1,1), 17 | m_interval(interval), 18 | m_ticks_per_interval(sub_ticks_per_interval), 19 | m_ambient(1.4, 1.4, 1.4, 1.0 ), 20 | m_diffuse(0.63, 0.65, 0.67, 1.0), 21 | m_linemod(0.686, 0.874, 0.929, 1.0), 22 | m_specular(0,0,0,1) 23 | { 24 | m_lambient = m_ambient.array() * m_linemod; 25 | m_ldiffuse = m_diffuse.array() * m_linemod; 26 | } 27 | 28 | inline void DrawFace(const Eigen::Vector3d& bmin, const Eigen::Vector3d& bmax, int axis, double nmag) 29 | { 30 | Eigen::Vector3f n(0,0,0); 31 | Eigen::Vector3f v; 32 | 33 | n(axis) = nmag; 34 | v(axis) = (nmag > 0) ? bmin(axis) : bmax(axis); 35 | 36 | glNormal3fv(n.data()); 37 | 38 | int o1 = (axis+1)%3; 39 | int o2 = (axis+2)%3; 40 | 41 | if(nmag > 0) std::swap(o1,o2); 42 | 43 | glBegin(GL_QUADS); 44 | v(o1) = bmin(o1); v(o2) = bmax(o2); glVertex3fv(v.data()); 45 | v(o1) = bmax(o1); v(o2) = bmax(o2); glVertex3fv(v.data()); 46 | v(o1) = bmax(o1); v(o2) = bmin(o2); glVertex3fv(v.data()); 47 | v(o1) = bmin(o1); v(o2) = bmin(o2); glVertex3fv(v.data()); 48 | glEnd(); 49 | } 50 | 51 | inline void DrawFaceLines(const Eigen::Vector3d& bmin, const Eigen::Vector3d& bmax, int axis, double nmag) 52 | { 53 | Eigen::Vector3f n(0,0,0); 54 | Eigen::Vector3f v; 55 | 56 | n(axis) = nmag; 57 | v(axis) = (nmag > 0) ? bmin(axis) : bmax(axis); 58 | 59 | int o1 = (axis+1)%3; 60 | int o2 = (axis+2)%3; 61 | 62 | if(nmag > 0) std::swap(o1,o2); 63 | 64 | glNormal3fv(n.data()); 65 | 66 | float origLineWidth; 67 | glGetFloatv(GL_LINE_WIDTH, &origLineWidth); 68 | 69 | for(float intrvl=m_interval, ls=1.0; intrvl >= 0.1; intrvl /= m_ticks_per_interval, ls /= 2) 70 | { 71 | glLineWidth(origLineWidth*ls); 72 | glBegin(GL_LINES); 73 | for(float xv= intrvl*ceil(bmin(o1) / intrvl); xv < bmax(o1); xv += intrvl) 74 | { 75 | v(o1) = xv; 76 | v(o2) = bmin(o2); glVertex3fv(v.data()); 77 | v(o2) = bmax(o2); glVertex3fv(v.data()); 78 | } 79 | for(float xv= intrvl*ceil(bmin(o2) / intrvl); xv < bmax(o2); xv += intrvl) 80 | { 81 | v(o2) = xv; 82 | v(o1) = bmin(o1); glVertex3fv(v.data()); 83 | v(o1) = bmax(o1); glVertex3fv(v.data()); 84 | } 85 | glEnd(); 86 | } 87 | glLineWidth(origLineWidth); 88 | } 89 | 90 | inline void DrawOpenBox(const AxisAlignedBoundingBox& bbox) 91 | { 92 | pangolin::GlState gl; 93 | 94 | // Prevent Z-Fighting between plane and lines 95 | glPolygonOffset( 1.0, 1.0 ); 96 | gl.glEnable(GL_POLYGON_OFFSET_FILL); 97 | 98 | gl.glEnable(GL_CULL_FACE); 99 | gl.glCullFace(GL_BACK); 100 | 101 | const Eigen::Vector3d bmin = bbox.Min(); 102 | const Eigen::Vector3d bmax = bbox.Max(); 103 | 104 | // TODO: use projectmatrix too to cope with different cameras 105 | Eigen::Matrix4f T_co; 106 | glGetFloatv( GL_MODELVIEW_MATRIX, T_co.data() ); 107 | 108 | gl.glDisable(GL_COLOR_MATERIAL); 109 | glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT, m_ambient.data() ); 110 | glMaterialfv( GL_FRONT_AND_BACK, GL_DIFFUSE, m_diffuse.data() ); 111 | glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, m_specular.data() ); 112 | 113 | for(int ax=0; ax<3; ++ax) { 114 | Eigen::Vector3f n(0,0,0); n(ax) = 1; 115 | Eigen::Vector3f nc = T_co.topLeftCorner<3,3>() * n; 116 | DrawFace(bmin,bmax,ax,nc(2)>0 ? 1 : -1); 117 | } 118 | 119 | gl.glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE); 120 | glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT, m_lambient.data() ); 121 | glMaterialfv( GL_FRONT_AND_BACK, GL_DIFFUSE, m_ldiffuse.data() ); 122 | 123 | for(int ax=0; ax<3; ++ax) { 124 | Eigen::Vector3f n(0,0,0); n(ax) = 1; 125 | Eigen::Vector3f nc = T_co.topLeftCorner<3,3>() * n; 126 | DrawFaceLines(bmin,bmax,ax,nc(2)>0 ? 1 : -1); 127 | } 128 | } 129 | 130 | Eigen::Vector3d& SizeFactor() 131 | { 132 | return m_box_grow_factor; 133 | } 134 | 135 | void DrawCanonicalObject(void) 136 | { 137 | AxisAlignedBoundingBox bbox = ChildrenBounds(); 138 | if(!bbox.Empty()) { 139 | bbox.ScaleFromCenter(m_box_grow_factor); 140 | GLObject::m_aabb = bbox; 141 | }else{ 142 | GLObject::m_aabb = AxisAlignedBoundingBox(Eigen::Vector3d(-1,-1,-1), Eigen::Vector3d(1,1,1) ); 143 | } 144 | DrawOpenBox(GLObject::m_aabb); 145 | } 146 | 147 | protected: 148 | Eigen::Vector3d m_box_grow_factor; 149 | double m_interval; 150 | int m_ticks_per_interval; 151 | 152 | Eigen::Vector4f m_ambient; 153 | Eigen::Vector4f m_diffuse; 154 | Eigen::Array4f m_linemod; 155 | Eigen::Vector4f m_lambient; 156 | Eigen::Vector4f m_ldiffuse; 157 | Eigen::Vector4f m_specular; 158 | }; 159 | 160 | } // SceneGraph 161 | 162 | #endif 163 | 164 | -------------------------------------------------------------------------------- /include/SceneGraph/GLPointCloud.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL_POINT_CLOUD_H_ 2 | #define _GL_POINT_CLOUD_H_ 3 | 4 | class GLPointCloud : public GLObject 5 | { 6 | 7 | public: 8 | 9 | GLPointCloud() 10 | { 11 | m_nDisplayList = -1; 12 | m_nOldRangeDataSize = 0; 13 | m_dPose = Eigen::Matrix4d::Identity(); 14 | } 15 | 16 | /// will recompile list if users add more data 17 | void draw() 18 | { 19 | if( m_nDisplayList == -1 ){ 20 | m_nDisplayList = glGenLists(1); 21 | CompileDisplyList(); 22 | } 23 | if( m_vRangeData.size() != m_nOldRangeDataSize ){ 24 | m_nOldRangeDataSize = m_vRangeData.size(); 25 | CompileDisplyList(); 26 | } 27 | 28 | // TODO re-compile only when data changes 29 | CompileDisplyList(); 30 | 31 | glPushMatrix(); 32 | glMultMatrixd( m_dPose.data() ); 33 | glCallList(m_nDisplayList); 34 | glPopMatrix(); 35 | } 36 | 37 | // change the "pose" of the point cloud 38 | void SetPose( const Eigen::Matrix4d& dPose ) 39 | { 40 | m_dPose = dPose; 41 | } 42 | 43 | // will compile new drawlist 44 | void CompileDisplyList() 45 | { 46 | glNewList( m_nDisplayList, GL_COMPILE ); 47 | glPointSize( 2 ); 48 | glEnable( GL_COLOR_MATERIAL ); 49 | glColor3f( 1,0,1 ); 50 | glBegin( GL_POINTS ); 51 | for( size_t ii = 0; ii < m_vRangeData.size(); ii+=3 ){ 52 | glVertex3fv( &m_vRangeData[ii] ); 53 | } 54 | glEnd(); 55 | glPointSize( 1 ); 56 | glEndList(); 57 | } 58 | 59 | // return ref to our range data 60 | std::vector& RangeDataRef() 61 | { 62 | return m_vRangeData; 63 | } 64 | 65 | void Clear() { 66 | m_vRangeData.clear(); 67 | } 68 | 69 | private: 70 | GLint m_nDisplayList; 71 | std::vector m_vRangeData; 72 | unsigned int m_nOldRangeDataSize; 73 | Eigen::Matrix4d m_dPose; 74 | }; 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /include/SceneGraph/GLPrimitives.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace SceneGraph 8 | { 9 | 10 | typedef Eigen::Matrix Vector6d; 11 | 12 | typedef std::vector > 13 | Vector6dAlignedVec; 14 | 15 | typedef std::vector > 16 | Vector3dAlignedVec; 17 | 18 | template 19 | class GLPrimitives 20 | : public GLObject 21 | { 22 | public: 23 | GLPrimitives(GLenum mode = GL_LINE_STRIP, SceneGraph::GLColor color = SceneGraph::GLColor(), int initial_vert_buffer_elements = 1024) 24 | : GLObject("GLPrimitives"), m_mode(mode), m_color(color), 25 | m_vbo(pangolin::GlArrayBuffer, initial_vert_buffer_elements, GL_FLOAT, 3, GL_DYNAMIC_DRAW) 26 | { 27 | 28 | } 29 | 30 | GLPrimitives(const std::vector >& vArray, GLenum mode = GL_LINE_STRIP, SceneGraph::GLColor color = SceneGraph::GLColor()) 31 | : m_mode(mode), m_color(color), 32 | m_vbo(pangolin::GlArrayBuffer, vArray.size()*3, GL_FLOAT, 3, GL_DYNAMIC_DRAW) 33 | { 34 | for( int ii = 0; ii < vArray.size() ; ++ii ){ 35 | AddVertex(vArray[ii]); 36 | } 37 | } 38 | 39 | void DrawCanonicalObject() 40 | { 41 | m_color.Apply(); 42 | 43 | m_vbo.Bind(); 44 | glVertexPointer(m_vbo.count_per_element, m_vbo.datatype, 0, 0); 45 | glEnableClientState(GL_VERTEX_ARRAY); 46 | glDrawArrays(m_mode, m_vbo.start(), m_vbo.size() ); 47 | glDisableClientState(GL_VERTEX_ARRAY); 48 | m_vbo.Unbind(); 49 | } 50 | 51 | template inline 52 | void AddVertex( const Eigen::DenseBase& vec) 53 | { 54 | GLObject::m_aabb.Insert(vec); 55 | m_vbo.Add(vec.template cast() ); 56 | } 57 | 58 | void AddVertex(const Eigen::Vector3d& p) 59 | { 60 | GLObject::m_aabb.Insert(p); 61 | m_vbo.Add(p.cast() ); 62 | } 63 | 64 | void AddVertex(const Eigen::Vector3f& p) 65 | { 66 | Eigen::Vector3d temp; 67 | temp = p.cast(); 68 | GLObject::m_aabb.Insert(temp); 69 | m_vbo.Add( p ); 70 | } 71 | 72 | void AddVerticesFromTrajectory(const Vector6dAlignedVec& vPts) { 73 | m_vbo.Clear(); 74 | for (size_t i = 0; i < vPts.size(); ++i ) { 75 | AddVertex(vPts[i][0], vPts[i][1], vPts[i][2]); 76 | } 77 | } 78 | 79 | void AddVerticesFromTrajectory(const Vector3dAlignedVec& vPts) { 80 | m_vbo.Clear(); 81 | for (size_t i = 0; i < vPts.size(); ++i ) { 82 | Eigen::Vector3f vPt; 83 | vPt << vPts[i][0], vPts[i][1], vPts[i][2]; 84 | AddVertex(vPt); 85 | } 86 | } 87 | 88 | void Clear() 89 | { 90 | GLObject::m_aabb.Clear(); 91 | m_vbo.Clear(); 92 | } 93 | 94 | void SetColor( const GLColor& c ) 95 | { 96 | m_color = c; 97 | } 98 | 99 | protected: 100 | GLenum m_mode; 101 | SceneGraph::GLColor m_color; 102 | GlBufferType m_vbo; 103 | }; 104 | 105 | typedef GLPrimitives GLCachedPrimitives; 106 | 107 | } 108 | -------------------------------------------------------------------------------- /include/SceneGraph/GLSceneGraph.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL_SCENE_GRAPH_H_ 2 | #define _GL_SCENE_GRAPH_H_ 3 | 4 | #include 5 | #include 6 | 7 | namespace SceneGraph 8 | { 9 | 10 | class GLObjectPrePostRender; 11 | 12 | class SCENEGRAPH_EXPORT GLSceneGraph : public GLObject 13 | { 14 | public: 15 | GLSceneGraph(); 16 | 17 | GLObject* Root(); 18 | GLObject* GetObject( unsigned int nId ); 19 | 20 | // Remove everything 21 | void Clear(); 22 | 23 | // Reset to default state 24 | void Reset(); 25 | 26 | // Add GLObject to scenegraph 27 | void AddChild( GLObject* pChild ); 28 | bool RemoveChild( GLObject* pChild ); 29 | 30 | void DrawCanonicalObject(); 31 | 32 | void DrawObjectAndChildren(RenderMode renderMode = eRenderVisible); 33 | 34 | static void ApplyPreferredGlSettings(); 35 | 36 | 37 | 38 | private: 39 | void PreDraw(); 40 | void PostDraw(); 41 | 42 | // These lights are owned by the SceneGraph (it takes care of destruction) 43 | std::vector m_vpPrePostRender; 44 | 45 | bool m_bEnableLighting; 46 | 47 | }; 48 | 49 | class SCENEGRAPH_EXPORT GLObjectPrePostRender : public GLObject 50 | { 51 | public: 52 | GLObjectPrePostRender() {} 53 | 54 | GLObjectPrePostRender(std::string name) 55 | : GLObject(name) 56 | { 57 | } 58 | 59 | virtual void PreRender(GLSceneGraph& scene) = 0; 60 | 61 | virtual void PostRender(GLSceneGraph& scene) = 0; 62 | }; 63 | 64 | } 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /include/SceneGraph/GLSphereGrid.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL_SPHERE_GRID_H_ 2 | #define _GL_SPHERE_GRID_H_ 3 | 4 | #include 5 | #include 6 | 7 | extern GLWindowConfig gConfig; 8 | 9 | class GLSphereGrid : public GLObject 10 | { 11 | 12 | public: 13 | GLSphereGrid() 14 | { 15 | m_nDisplayList = -1; 16 | } 17 | 18 | void draw() 19 | { 20 | glEnable( GL_COLOR_MATERIAL ); 21 | if( m_nDisplayList == -1 ) { 22 | m_nDisplayList = glGenLists(1); 23 | glNewList( m_nDisplayList, GL_COMPILE ); 24 | 25 | // to check lighting 26 | glColor4f( 1, 1, 1, 1 ); 27 | for( int y = -100; y < 100; y+=10 ){ 28 | for( int x = -100; x < 100; x+=10 ){ 29 | glPushMatrix(); 30 | glTranslatef( x, y, 0 ); 31 | glutSolidSphere( 2, 32, 32 ); 32 | glPopMatrix(); 33 | } 34 | } 35 | glEndList(); 36 | } 37 | else { 38 | if( gConfig.m_bDebugLighting ){ 39 | glCallList( m_nDisplayList ); 40 | } 41 | } 42 | } 43 | 44 | private: 45 | GLint m_nDisplayList; 46 | }; 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /include/SceneGraph/GLTeapot.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef ANDROID 4 | #ifdef __APPLE_CC__ 5 | #include 6 | #else 7 | #include 8 | #endif // __APPLE_CC__ 9 | #endif // ANDROID 10 | 11 | #include 12 | #include 13 | 14 | namespace SceneGraph { 15 | 16 | /** Draws a glutSolidTeapot with scale == scale[0] of GLObject */ 17 | class GLTeapot : public GLObject { 18 | public: 19 | GLTeapot() {} 20 | 21 | void DrawCanonicalObject() { 22 | #ifndef ANDROID 23 | glutSolidTeapot(1); 24 | #endif // ANDROID 25 | } 26 | }; 27 | } // namespace SceneGraph 28 | -------------------------------------------------------------------------------- /include/SceneGraph/GLText.h: -------------------------------------------------------------------------------- 1 | #ifndef _GL_TEXT_H_ 2 | #define _GL_TEXT_H_ 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | namespace SceneGraph { 13 | 14 | class GLText : public GLObject { 15 | public: 16 | static pangolin::GlFont& GetFont() { 17 | static pangolin::GlFont s_font; 18 | return s_font; 19 | } 20 | 21 | ///////////////////////////////// 22 | // Static Utilities for drawing text 23 | ///////////////////////////////// 24 | 25 | /// Render text at current glRasterPos 26 | static void Draw(const std::string& text) { 27 | pangolin::GlText txt = GetFont().Text(text.c_str()); 28 | txt.Draw(); 29 | } 30 | 31 | /// Render text at (x,y,z) 32 | static void Draw(const std::string& text, float x, float y, float z = 0) { 33 | pangolin::GlText txt = GetFont().Text(text.c_str()); 34 | txt.Draw(x,y,z); 35 | } 36 | 37 | /// Return width (in pixels) of text 38 | static int Width(const std::string& text) { 39 | pangolin::GlText txt = GetFont().Text(text.c_str()); 40 | return txt.Width(); 41 | } 42 | 43 | ///////////////////////////////// 44 | // GLText constructors 45 | ///////////////////////////////// 46 | 47 | GLText(std::string text = "", double x = 0, double y = 0, double z = 0) 48 | : GLObject("Text: " + text), m_sText(text), viewpoint_invariant_(true) { 49 | m_bPerceptable = false; 50 | SetPosition(x,y,z); 51 | } 52 | 53 | ///////////////////////////////// 54 | // GLText member functions 55 | ///////////////////////////////// 56 | 57 | void DrawCanonicalObject() { 58 | if(m_gltext.Text() != m_sText) { 59 | // Reinitialise text 60 | m_gltext = GetFont().Text(m_sText.c_str()); 61 | } 62 | 63 | m_Color.Apply(); 64 | pangolin::GlState gl; 65 | gl.glDisable(GL_DEPTH_TEST); 66 | gl.glDisable(GL_LIGHTING); 67 | if (viewpoint_invariant_) { 68 | Draw(m_sText, 0, 0, 0); 69 | } else { 70 | Draw(m_sText); 71 | } 72 | } 73 | 74 | void SetText(const std::string& sText) { 75 | m_sText = sText; 76 | } 77 | 78 | void ClearText() { 79 | m_sText.clear(); 80 | } 81 | 82 | void set_color(const GLColor& color) { 83 | m_Color = color; 84 | } 85 | 86 | /** Configure if the GLText is 3D or attach to the window as a 2D object */ 87 | void set_viewpoint_invariant(bool is) { 88 | viewpoint_invariant_ = is; 89 | } 90 | 91 | private: 92 | std::string m_sText; 93 | pangolin::GlText m_gltext; 94 | GLColor m_Color; 95 | bool viewpoint_invariant_; 96 | }; 97 | } // SceneGraph 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /include/SceneGraph/GLVbo.h: -------------------------------------------------------------------------------- 1 | #ifndef GLVBO_H 2 | #define GLVBO_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace SceneGraph 9 | { 10 | 11 | /////////////////////////////////////////////////////////////////////////////// 12 | class GLVbo : public GLObject 13 | { 14 | public: 15 | 16 | GLVbo(pangolin::GlBuffer* vbo, pangolin::GlBuffer* ibo=0, 17 | pangolin::GlBuffer* cbo=0, pangolin::GlBuffer* nbo=0) 18 | : GLObject("Vbo"), m_vbo(vbo), m_ibo(ibo), m_cbo(cbo), m_nbo(nbo) 19 | { 20 | } 21 | 22 | void DrawCanonicalObject() 23 | { 24 | pangolin::GlState gl; 25 | 26 | if(!m_nbo) { 27 | gl.glDisable(GL_LIGHTING); 28 | } 29 | 30 | pangolin::RenderVboIboCboNbo( 31 | *m_vbo,*m_ibo,*m_cbo,*m_nbo, 32 | m_ibo, m_cbo, m_nbo 33 | ); 34 | } 35 | 36 | protected: 37 | pangolin::GlBuffer* m_vbo; 38 | pangolin::GlBuffer* m_ibo; 39 | pangolin::GlBuffer* m_cbo; 40 | pangolin::GlBuffer* m_nbo; 41 | }; 42 | 43 | } // SceneGraph 44 | 45 | #endif // GLVBO_H 46 | -------------------------------------------------------------------------------- /include/SceneGraph/GLWireSphere.h: -------------------------------------------------------------------------------- 1 | #ifndef GLWIRESPHERE_H 2 | #define GLWIRESPHERE_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #define rads 180/M_PI 9 | 10 | namespace SceneGraph 11 | { 12 | 13 | class GLWireSphere : public GLObject 14 | { 15 | 16 | public: 17 | 18 | GLWireSphere( 19 | float Radius, 20 | int Lines = 10, 21 | int ElemsPerDiv = 10, 22 | GLColor color = GLColor() 23 | ) 24 | : GLObject("Wire Sphere"), 25 | m_nLines(Lines), 26 | m_nElemsPerDiv(ElemsPerDiv), 27 | m_fRadius(Radius), 28 | m_Color(color) 29 | { 30 | initSphere(); 31 | } 32 | 33 | void initSphere( void ) 34 | { 35 | float step = M_PI / (m_nLines*m_nElemsPerDiv); 36 | 37 | m_vVerts.clear(); 38 | m_vVerts.push_back(0); 39 | m_vVerts.push_back(0); 40 | m_vVerts.push_back(m_fRadius); 41 | 42 | for (float theta = step; theta < M_PI; theta += step) { 43 | float z = m_fRadius*cos(theta); 44 | float r = m_fRadius*sin(theta); 45 | m_vVerts.push_back(r); 46 | m_vVerts.push_back(0); 47 | m_vVerts.push_back(z); 48 | 49 | if (((int) ((theta + step) / step)) % m_nElemsPerDiv == 0) { 50 | for (float phi = 0; phi <= 2*M_PI + step; phi += step) { 51 | m_vVerts.push_back(r*cos(phi)); 52 | m_vVerts.push_back(r*sin(phi)); 53 | m_vVerts.push_back(z); 54 | } 55 | } 56 | } 57 | 58 | m_vVerts.push_back(0); 59 | m_vVerts.push_back(0); 60 | m_vVerts.push_back(-m_fRadius); 61 | 62 | for (float phi = 0; phi <=M_PI; phi += m_nElemsPerDiv*step) { 63 | for (float theta = -M_PI; theta <= M_PI; theta += step) { 64 | m_vVerts.push_back(m_fRadius*sin(theta)*cos(phi)); 65 | m_vVerts.push_back(m_fRadius*sin(theta)*sin(phi)); 66 | m_vVerts.push_back(m_fRadius*cos(theta)); 67 | } 68 | } 69 | 70 | for (float theta = -M_PI; theta <= 0; theta += step) { 71 | m_vVerts.push_back(m_fRadius*sin(theta)); 72 | m_vVerts.push_back(0); 73 | m_vVerts.push_back(m_fRadius*cos(theta)); 74 | } 75 | } 76 | 77 | void drawSphere( void ) 78 | { 79 | m_Color.Apply(); 80 | glEnableClientState(GL_VERTEX_ARRAY); 81 | glVertexPointer(3, GL_FLOAT, 0, m_vVerts.data()); 82 | glDrawArrays(GL_LINE_LOOP, 0, m_vVerts.size() / 3); 83 | glDisableClientState(GL_VERTEX_ARRAY); 84 | } 85 | 86 | void SetColor(GLColor color) 87 | { 88 | m_Color = color; 89 | } 90 | 91 | GLColor GetColor( void ) 92 | { 93 | return m_Color; 94 | } 95 | 96 | void DrawCanonicalObject() 97 | { 98 | drawSphere(); 99 | } 100 | 101 | private: 102 | int m_nLines; 103 | int m_nElemsPerDiv; 104 | float m_fRadius; 105 | std::vector< float > m_vVerts; 106 | GLColor m_Color; 107 | }; 108 | 109 | } 110 | #endif // GLWIRESPHERE_H 111 | -------------------------------------------------------------------------------- /include/SceneGraph/GLinclude.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #ifdef _ANDROID_ 6 | #include 7 | #endif 8 | 9 | #ifdef _MSVC_ 10 | // MSVC doesn't define C99's snprintf directly. _snprintf_s is equivelent. 11 | #define snprintf _snprintf_s 12 | #endif 13 | 14 | #ifdef _MSVC_ 15 | // MSVC requires export annotations in order to generate DLL's 16 | # include 17 | #else 18 | # define SCENEGRAPH_EXPORT 19 | #endif 20 | -------------------------------------------------------------------------------- /include/SceneGraph/Gui.h: -------------------------------------------------------------------------------- 1 | #ifndef _SIMPLE_GUI_H_ 2 | #define _SIMPLE_GUI_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include // for friendy command line parsing 13 | #include 14 | #include 15 | 16 | #endif 17 | 18 | -------------------------------------------------------------------------------- /include/SceneGraph/LineSegment.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace SceneGraph { 6 | 7 | template 8 | class LineSegment 9 | { 10 | public: 11 | // Uninitialised 12 | LineSegment() 13 | { 14 | } 15 | 16 | template 17 | LineSegment(const Eigen::MatrixBase& Pa, 18 | const Eigen::MatrixBase& Pb) 19 | : mPa(Pa), mPbmPa(Pb - mPa) 20 | { 21 | } 22 | 23 | Eigen::Matrix operator()(T lambda) 24 | { 25 | return mPa + lambda * mPbmPa; 26 | } 27 | 28 | bool InSegment(T lambda) 29 | { 30 | return 0 <= lambda && lambda <= 1.0; 31 | } 32 | 33 | Eigen::Matrix& P() { return mPa; } 34 | const Eigen::Matrix& P() const { return mPa; } 35 | 36 | Eigen::Matrix& Dir() { return mPbmPa; } 37 | const Eigen::Matrix& Dir() const { return mPbmPa; } 38 | 39 | Eigen::Matrix Pb() const { 40 | return mPa + mPbmPa; 41 | } 42 | 43 | protected: 44 | Eigen::Matrix mPa; 45 | Eigen::Matrix mPbmPa; 46 | }; 47 | 48 | template 49 | LineSegment operator*(const Eigen::MatrixBase& T_ba, const LineSegment& ls_a) 50 | { 51 | LineSegment ls_b; 52 | ls_b.P() = T_ba.template block<3,3>(0,0) * ls_a.P() + T_ba.template block<3,1>(0,3); 53 | ls_b.Dir() = T_ba.template block<3,3>(0,0) * ls_a.Dir(); 54 | return ls_b; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /include/SceneGraph/PangolinDrawGLObject.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace SceneGraph 7 | { 8 | 9 | struct ActivateDrawFunctor 10 | { 11 | ActivateDrawFunctor(SceneGraph::GLObject& glObject, pangolin::OpenGlRenderState& renderState) 12 | :glObject(glObject), renderState(renderState) 13 | { 14 | } 15 | 16 | void operator()(pangolin::View& view) { 17 | view.Activate(renderState); 18 | glObject.DrawObjectAndChildren( eRenderVisible ); 19 | } 20 | 21 | SceneGraph::GLObject& glObject; 22 | pangolin::OpenGlRenderState& renderState; 23 | }; 24 | 25 | struct ActivateScissorClearDrawFunctor 26 | { 27 | ActivateScissorClearDrawFunctor(SceneGraph::GLObject& glObject, const pangolin::OpenGlRenderState& renderState) 28 | :glObject(glObject), renderState(renderState) 29 | { 30 | } 31 | 32 | void operator()(pangolin::View& view) { 33 | view.ActivateScissorAndClear(renderState); 34 | glObject.DrawObjectAndChildren(eRenderVisible); 35 | } 36 | 37 | SceneGraph::GLObject& glObject; 38 | const pangolin::OpenGlRenderState& renderState; 39 | }; 40 | 41 | struct ActivateDrawFunctor3d2d 42 | { 43 | ActivateDrawFunctor3d2d(SceneGraph::GLObject& glObject3d, pangolin::OpenGlRenderState& renderState3d, 44 | SceneGraph::GLObject& glObject2d, pangolin::OpenGlRenderState& renderState2d) 45 | :glObject3d(glObject3d), renderState3d(renderState3d), 46 | glObject2d(glObject2d), renderState2d(renderState2d) 47 | { 48 | } 49 | 50 | void operator()(pangolin::View& view) { 51 | view.Activate(renderState3d); 52 | glObject3d.DrawObjectAndChildren(eRenderVisible); 53 | renderState2d.Apply(); 54 | glObject2d.DrawObjectAndChildren(eRenderVisible); 55 | } 56 | 57 | SceneGraph::GLObject& glObject3d; 58 | pangolin::OpenGlRenderState& renderState3d; 59 | SceneGraph::GLObject& glObject2d; 60 | pangolin::OpenGlRenderState& renderState2d; 61 | }; 62 | 63 | struct ActivateScissorClearDrawFunctor3d2d 64 | { 65 | ActivateScissorClearDrawFunctor3d2d(SceneGraph::GLObject& glObject3d, pangolin::OpenGlRenderState& renderState3d, 66 | SceneGraph::GLObject& glObject2d, pangolin::OpenGlRenderState& renderState2d) 67 | :glObject3d(glObject3d), renderState3d(renderState3d), 68 | glObject2d(glObject2d), renderState2d(renderState2d) 69 | { 70 | } 71 | 72 | void operator()(pangolin::View& view) { 73 | view.ActivateScissorAndClear(renderState3d); 74 | glObject3d.DrawObjectAndChildren(eRenderVisible); 75 | renderState2d.Apply(); 76 | glObject2d.DrawObjectAndChildren(eRenderVisible); 77 | } 78 | 79 | SceneGraph::GLObject& glObject3d; 80 | pangolin::OpenGlRenderState& renderState3d; 81 | SceneGraph::GLObject& glObject2d; 82 | pangolin::OpenGlRenderState& renderState2d; 83 | }; 84 | 85 | } 86 | -------------------------------------------------------------------------------- /include/SceneGraph/PangolinGlCachedSizeableBuffer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace SceneGraph 7 | { 8 | 9 | /// Public interface mirroring pangolin::GlSizeableBuffer 10 | /// but with cpu cache for delayed batch upload. 11 | class GlCachedSizeableBuffer 12 | : public pangolin::GlSizeableBuffer 13 | { 14 | public: 15 | GlCachedSizeableBuffer(pangolin::GlBufferType buffer_type, GLuint initial_num_elements, GLenum datatype, GLuint count_per_element, GLenum gluse = GL_DYNAMIC_DRAW ) 16 | : pangolin::GlSizeableBuffer(buffer_type, initial_num_elements, datatype, count_per_element, gluse), 17 | m_dirty(false), 18 | m_num_verts(0), 19 | m_vs(count_per_element, initial_num_elements) 20 | 21 | { 22 | 23 | } 24 | 25 | /// Clear cache 26 | inline void Clear() { 27 | m_num_verts = 0; 28 | pangolin::GlSizeableBuffer::Clear(); 29 | } 30 | 31 | /// Add vertices to cpu cache 32 | template inline 33 | void Add(const Eigen::DenseBase& vec) 34 | { 35 | assert(vec.rows() == (int)pangolin::GlSizeableBuffer::count_per_element); 36 | CheckResize(m_num_verts + vec.cols() ); 37 | m_vs.block(0,m_num_verts,vec.rows(),vec.cols()) = vec; 38 | m_num_verts += vec.cols(); 39 | m_dirty = true; 40 | } 41 | 42 | template 43 | void Update(const Eigen::DenseBase& vec, size_t position = 0) 44 | { 45 | assert(vec.rows() == pangolin::GlSizeableBuffer::count_per_element); 46 | CheckResize(position + vec.cols()); 47 | m_vs.block(0,position, vec.rows(), vec.cols()) = vec; 48 | m_num_verts = std::max(position+vec.cols(), m_num_verts); 49 | m_dirty = true; 50 | } 51 | 52 | /// Force sync of cpu cache to gpu buffer 53 | inline void Sync() 54 | { 55 | if(m_dirty) { 56 | pangolin::GlSizeableBuffer::Update( m_vs.leftCols(m_num_verts) ); 57 | m_dirty = false; 58 | } 59 | } 60 | 61 | /// Sync cache with gpu buffer and bind 62 | inline void Bind() 63 | { 64 | Sync(); 65 | pangolin::GlSizeableBuffer::Bind(); 66 | } 67 | 68 | size_t start() const 69 | { 70 | return 0; 71 | } 72 | 73 | size_t size() const 74 | { 75 | return m_num_verts; 76 | } 77 | 78 | protected: 79 | inline void CheckResize(int num_verts) 80 | { 81 | if( num_verts > m_vs.cols()) { 82 | const size_t new_size = NextSize(num_verts); 83 | Eigen::MatrixXf tmp(pangolin::GlSizeableBuffer::count_per_element, new_size); 84 | tmp.leftCols(m_num_verts) = m_vs.leftCols(m_num_verts); 85 | std::swap(m_vs, tmp); 86 | } 87 | } 88 | 89 | inline size_t NextSize(size_t min_size) const 90 | { 91 | size_t new_size = m_vs.cols(); 92 | while(new_size < min_size) { 93 | new_size *= 2; 94 | } 95 | return new_size; 96 | } 97 | 98 | bool m_dirty; 99 | int m_num_verts; 100 | Eigen::MatrixXf m_vs; 101 | }; 102 | 103 | } 104 | 105 | -------------------------------------------------------------------------------- /include/SceneGraph/SceneGraph.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | // OpenGL defines are in here 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | // GLObjects that use pangolin 23 | #include 24 | #include 25 | 26 | // Objects that could be refactored into pangolin 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #ifndef HAVE_GLES 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | #ifdef HAVE_ASSIMP 46 | #include 47 | #endif // HAVE_ASSIMP 48 | 49 | #endif // HAVE_GLES 50 | -------------------------------------------------------------------------------- /include/SceneGraph/Widgets/GLWidgetView.h: -------------------------------------------------------------------------------- 1 | #ifndef GLWIDGETPANEL_H 2 | #define GLWIDGETPANEL_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include "nvGlutWidgets.h" 8 | 9 | using namespace SceneGraph; 10 | using namespace pangolin; 11 | 12 | 13 | class GLWidgetView : public pangolin::View, public pangolin::Handler 14 | { 15 | public: 16 | 17 | GLWidgetView() : 18 | m_RenderState2d(pangolin::ProjectionMatrixOrthographic(0,1,0,1,0.0,100)) 19 | { 20 | SetHandler(this); 21 | } 22 | 23 | void Init(const Attach bottom,const Attach top,const Attach left, const Attach right, 24 | std::function func) { 25 | SetBounds(bottom,top,left,right); 26 | m_DrawFunc = func; 27 | } 28 | 29 | int DoNumericLineEdit(nv::Rect& rect, const char *label, int* nNumber) 30 | { 31 | m_Ui.doLabel(rect,label); 32 | int charsReturned; 33 | char sNumber[10]; 34 | sprintf(sNumber,"%d",*nNumber); 35 | m_Ui.doLineEdit(rect,sNumber,10,&charsReturned); 36 | *nNumber = atoi(sNumber); 37 | return charsReturned; 38 | } 39 | 40 | void Render(){ 41 | ActivateAndScissor(m_RenderState2d); 42 | 43 | glColor4f(0.0,0.0,0.0,0.5); 44 | pangolin::glDrawRect(-1.0f,-1.0f,1.0f,1.0f); 45 | 46 | m_Rect = nv::Rect(0,0,m_nWidth,0); 47 | m_Ui.begin(); 48 | m_DrawFunc(m_Ui,m_Rect); 49 | m_Ui.end(); 50 | } 51 | 52 | void Resize(const Viewport &parent) 53 | { 54 | View::Resize(parent); 55 | m_nWidth = v.w; 56 | m_nHeight = v.h; 57 | m_Ui.init(m_nWidth, m_nHeight); 58 | } 59 | 60 | template 61 | T GetVar(std::string name){ 62 | return (T)m_mVars[name]; 63 | } 64 | 65 | GLWidgetView& SetVar(std::string name, void *ptr) 66 | { 67 | m_mVars[name] = ptr; 68 | return *this; 69 | } 70 | 71 | nv::GlutUIContext* GetUIContext(){ return &m_Ui; } 72 | 73 | void Mouse(pangolin::View& view, pangolin::MouseButton button, int x, int y, bool pressed, int button_state) 74 | { 75 | //convert pangolin button to GLUT button 76 | int glutButton = (int)button; 77 | int log2 = 0; 78 | while (glutButton >>= 1) ++log2; 79 | m_Ui.mouse(log2,(int)!pressed,x,view.v.h - y); 80 | } 81 | 82 | void MouseMotion(pangolin::View& view, int x, int y, int button_state) 83 | { 84 | m_Ui.mouseMotion(x,view.v.h - y); 85 | } 86 | 87 | void Keyboard(View& view, unsigned char key, int x, int y, bool pressed) 88 | { 89 | m_Ui.keyboard(key,x,y); 90 | } 91 | 92 | // void Resize(const Viewport &parent) 93 | // { 94 | // m_Ui.reshape(parent.w, parent.h); 95 | // } 96 | 97 | protected: 98 | int m_nWidth; 99 | int m_nHeight; 100 | nv::Rect m_Rect; 101 | nv::GlutUIContext m_Ui; 102 | std::map m_mVars; 103 | std::function m_DrawFunc; 104 | pangolin::OpenGlRenderState m_RenderState2d; 105 | 106 | }; 107 | 108 | #endif // GLWIDGETPANEL_H 109 | -------------------------------------------------------------------------------- /include/SceneGraph/Widgets/nvGlutWidgets.h: -------------------------------------------------------------------------------- 1 | // 2 | // nvGlutWidgets 3 | // 4 | // Adaptor classes to integrate the nvWidgets UI library with the GLUT windowing 5 | // toolkit. The adaptors convert native GLUT UI data to native nvWidgets data. All 6 | // adaptor classes are implemented as in-line code in this header. The adaptor 7 | // defaults to using the standard OpenGL painter implementation. 8 | // 9 | // Author: Ignacio Castano, Samuel Gateau, Evan Hart 10 | // Email: sdkfeedback@nvidia.com 11 | // 12 | // Copyright (c) NVIDIA Corporation. All rights reserved. 13 | //////////////////////////////////////////////////////////////////////////////////////////////////// 14 | 15 | #ifndef NV_GLUT_WIDGETS_H 16 | #define NV_GLUT_WIDGETS_H 17 | 18 | #include "nvGLWidgets.h" 19 | 20 | namespace nv 21 | { 22 | 23 | class NVSDKENTRY GlutUIContext : public UIContext 24 | { 25 | public: 26 | 27 | // 28 | // Default UI constructor 29 | // 30 | // Creates private OpenGL painter 31 | ////////////////////////////////////////////////////////////////// 32 | GlutUIContext() : 33 | UIContext( *(new GLUIPainter()) ), 34 | m_ownPainter(true) 35 | { 36 | } 37 | 38 | // 39 | // Alternate UI constructor 40 | // 41 | // Allows for overriding the standard painter 42 | ////////////////////////////////////////////////////////////////// 43 | GlutUIContext(UIPainter& painter) : 44 | UIContext( painter ), 45 | m_ownPainter(false) 46 | { 47 | } 48 | 49 | // 50 | // UI destructor 51 | // 52 | // Destroy painter if it is private 53 | ////////////////////////////////////////////////////////////////// 54 | ~GlutUIContext() 55 | { 56 | if (m_ownPainter){ 57 | delete getPainter(); 58 | } 59 | } 60 | 61 | // 62 | // One time initialization 63 | // 64 | ////////////////////////////////////////////////////////////////// 65 | bool init(int w, int h); 66 | 67 | // 68 | // UI method for processing GLUT mouse button events 69 | // 70 | // Call this method from the glutMouseFunc callback, the 71 | // modifier parameter maps to glutGetModifiers. 72 | ////////////////////////////////////////////////////////////////// 73 | virtual void mouse(int button, int state, int modifier, int x, int y); 74 | 75 | void mouse(int button, int state, int x, int y); 76 | 77 | // 78 | // UI method for processing key events 79 | // 80 | // Call this method from the glutReshapeFunc callback 81 | ////////////////////////////////////////////////////////////////// 82 | void specialKeyboard(int k, int x, int y); 83 | 84 | private: 85 | 86 | // 87 | // Translate non-ascii keys from GLUT to nvWidgets 88 | ////////////////////////////////////////////////////////////////// 89 | unsigned char translateKey( int k ); 90 | 91 | bool m_ownPainter; 92 | }; 93 | 94 | }; 95 | 96 | 97 | 98 | #endif 99 | -------------------------------------------------------------------------------- /include/SceneGraph/Widgets/nvShaderUtils.h: -------------------------------------------------------------------------------- 1 | // 2 | // Utility functions for compiling shaders and programs 3 | // 4 | // Author: Evan Hart 5 | // Copyright (c) NVIDIA Corporation. All rights reserved. 6 | //////////////////////////////////////////////////////////////////////////////// 7 | 8 | 9 | #ifndef NV_SHADER_UTILS_H 10 | #define NV_SHADER_UTILS_H 11 | 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | namespace nv 18 | { 19 | 20 | // 21 | // 22 | //////////////////////////////////////////////////////////// 23 | inline GLuint CompileGLSLShader( GLenum target, const char* shader) 24 | { 25 | GLuint object; 26 | 27 | object = glCreateShader( target); 28 | 29 | if (!object) 30 | return object; 31 | 32 | glShaderSource( object, 1, &shader, NULL); 33 | 34 | glCompileShader(object); 35 | 36 | // check if shader compiled 37 | GLint compiled = 0; 38 | glGetShaderiv(object, GL_COMPILE_STATUS, &compiled); 39 | glGetError(); 40 | 41 | if (!compiled) 42 | { 43 | #ifdef NV_REPORT_COMPILE_ERRORS 44 | char temp[256] = ""; 45 | glGetShaderInfoLog( object, 256, NULL, temp); 46 | fprintf( stderr, "Compile failed:\n%s\n", temp); 47 | #endif 48 | glDeleteShader( object); 49 | glGetError(); 50 | return 0; 51 | } 52 | 53 | 54 | 55 | return object; 56 | } 57 | 58 | // 59 | // 60 | //////////////////////////////////////////////////////////// 61 | inline GLuint CompileGLSLShaderFromFile( GLenum target, const char* filename) 62 | { 63 | FILE *shaderFile; 64 | char *text; 65 | long size; 66 | 67 | //must read files as binary to prevent problems from newline translation 68 | shaderFile = fopen( filename, "rb"); 69 | 70 | if ( shaderFile == NULL) 71 | return 0; 72 | 73 | fseek( shaderFile, 0, SEEK_END); 74 | 75 | size = ftell(shaderFile); 76 | 77 | fseek( shaderFile, 0, SEEK_SET); 78 | 79 | text = new char[size+1]; 80 | 81 | fread( text, size, 1, shaderFile); 82 | 83 | fclose( shaderFile); 84 | 85 | text[size] = '\0'; 86 | 87 | GLuint object = CompileGLSLShader( target, text); 88 | 89 | delete []text; 90 | 91 | return object; 92 | } 93 | 94 | 95 | // Create a program composed of vertex and fragment shaders. 96 | inline GLuint LinkGLSLProgram( GLuint vertexShader, GLuint fragmentShader) 97 | { 98 | GLuint program = glCreateProgram(); 99 | glAttachShader(program, vertexShader); 100 | glAttachShader(program, fragmentShader); 101 | glLinkProgram(program); 102 | 103 | #ifdef NV_REPORT_COMPILE_ERRORS 104 | // Get error log. 105 | GLint charsWritten, infoLogLength; 106 | glGetProgramiv(program, GL_INFO_LOG_LENGTH, &infoLogLength); 107 | 108 | char * infoLog = new char[infoLogLength]; 109 | glGetProgramInfoLog(program, infoLogLength, &charsWritten, infoLog); 110 | fputs(infoLog, stdout); 111 | delete [] infoLog; 112 | #endif 113 | 114 | // Test linker result. 115 | GLint linkSucceed = GL_FALSE; 116 | glGetProgramiv(program, GL_LINK_STATUS, &linkSucceed); 117 | 118 | if (linkSucceed == GL_FALSE) 119 | { 120 | glDeleteProgram(program); 121 | return 0; 122 | } 123 | 124 | return program; 125 | } 126 | 127 | 128 | // Create a program composed of vertex, geometry and fragment shaders. 129 | inline GLuint LinkGLSLProgram( GLuint vertexShader, GLuint geometryShader, GLint inputType, GLint vertexOut, GLint outputType, GLuint fragmentShader) 130 | { 131 | GLuint program = glCreateProgram(); 132 | glAttachShader(program, vertexShader); 133 | glAttachShader(program, geometryShader); 134 | glProgramParameteriEXT(program, GL_GEOMETRY_INPUT_TYPE_EXT, inputType); 135 | glProgramParameteriEXT(program, GL_GEOMETRY_VERTICES_OUT_EXT, vertexOut); 136 | glProgramParameteriEXT(program, GL_GEOMETRY_OUTPUT_TYPE_EXT, outputType); 137 | glAttachShader(program, fragmentShader); 138 | glLinkProgram(program); 139 | 140 | #ifdef NV_REPORT_COMPILE_ERRORS 141 | // Get error log. 142 | GLint charsWritten, infoLogLength; 143 | glGetProgramiv(program, GL_INFO_LOG_LENGTH, &infoLogLength); 144 | 145 | char * infoLog = new char[infoLogLength]; 146 | glGetProgramInfoLog(program, infoLogLength, &charsWritten, infoLog); 147 | fputs(infoLog, stdout); 148 | delete [] infoLog; 149 | #endif 150 | 151 | // Test linker result. 152 | GLint linkSucceed = GL_FALSE; 153 | glGetProgramiv(program, GL_LINK_STATUS, &linkSucceed); 154 | 155 | if (linkSucceed == GL_FALSE) 156 | { 157 | glDeleteProgram(program); 158 | return 0; 159 | } 160 | 161 | return program; 162 | } 163 | 164 | 165 | // 166 | // 167 | //////////////////////////////////////////////////////////// 168 | inline GLuint CompileASMShader(GLenum program_type, const char *code) 169 | { 170 | GLuint program_id; 171 | glGenProgramsARB(1, &program_id); 172 | glBindProgramARB(program_type, program_id); 173 | glProgramStringARB(program_type, GL_PROGRAM_FORMAT_ASCII_ARB, (GLsizei) strlen(code), (GLubyte *) code); 174 | 175 | GLint error_pos; 176 | glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &error_pos); 177 | if (error_pos != -1) { 178 | #ifdef NV_REPORT_COMPILE_ERRORS 179 | const GLubyte *error_string; 180 | error_string = glGetString(GL_PROGRAM_ERROR_STRING_ARB); 181 | fprintf(stderr, "Program error at position: %d\n%s\n", (int)error_pos, error_string); 182 | #endif 183 | return 0; 184 | } 185 | return program_id; 186 | } 187 | 188 | // 189 | // 190 | //////////////////////////////////////////////////////////// 191 | inline GLuint CompileASMShaderFromFile( GLenum target, const char* filename) 192 | { 193 | FILE *shaderFile; 194 | char *text; 195 | long size; 196 | 197 | //must read files as binary to prevent problems from newline translation 198 | shaderFile = fopen( filename, "rb"); 199 | 200 | if ( shaderFile == NULL) 201 | return 0; 202 | 203 | fseek( shaderFile, 0, SEEK_END); 204 | 205 | size = ftell(shaderFile); 206 | 207 | fseek( shaderFile, 0, SEEK_SET); 208 | 209 | text = new char[size+1]; 210 | 211 | fread( text, size, 1, shaderFile); 212 | 213 | fclose( shaderFile); 214 | 215 | text[size] = '\0'; 216 | 217 | GLuint program_id = CompileASMShader( target, text); 218 | 219 | delete []text; 220 | 221 | return program_id; 222 | } 223 | 224 | } // nv namespace 225 | 226 | #endif // NV_SHADER_UTILS_H 227 | -------------------------------------------------------------------------------- /include/SceneGraph/config.h.in: -------------------------------------------------------------------------------- 1 | #ifndef SCENEGRAPH_CONFIG_H 2 | #define SCENEGRAPH_CONFIG_H 3 | 4 | /// Platform 5 | #cmakedefine _UNIX_ 6 | #cmakedefine _WIN_ 7 | #cmakedefine _OSX_ 8 | #cmakedefine _LINUX_ 9 | #cmakedefine _ANDROID_ 10 | 11 | /// Configured libraries 12 | #cmakedefine HAVE_GLES 13 | #cmakedefine HAVE_GLUES 14 | #cmakedefine HAVE_PANGOLIN 15 | #cmakedefine HAVE_ASSIMP 16 | #cmakedefine HAVE_DEVIL 17 | #cmakedefine HAVE_PNG 18 | #cmakedefine HAVE_JPEG 19 | #cmakedefine HAVE_TIFF 20 | 21 | #endif //SCENEGRAPH_CONFIG_H 22 | -------------------------------------------------------------------------------- /models/2floor.mtl: -------------------------------------------------------------------------------- 1 | # Max2Mtl Version 4.0 Mar 10th, 2001 2 | # 3 | newmtl Material__29 4 | Ka 1.0 0.6 0.1 5 | Kd 1.0 0.6 0.1 6 | Ks 0.9 0.9 0.9 7 | d 1.0 8 | Ns 0.0 9 | illum 2 10 | # 11 | newmtl Material__39 12 | Ka 0.6 0.6 0.6 13 | Kd 0.6 0.6 0.6 14 | Ks 0.9 0.9 0.9 15 | d 1.0 16 | Ns 0.0 17 | illum 2 18 | # 19 | newmtl 2_-_Default 20 | Ka 1.0 1.0 1.0 21 | Kd 1.0 1.0 1.0 22 | Ks 0.9 0.9 0.9 23 | d 1.0 24 | Ns 0.0 25 | illum 2 26 | # 27 | newmtl Material__30 28 | Ka 0.6 0.6 0.6 29 | Kd 0.6 0.6 0.6 30 | Ks 0.9 0.9 0.9 31 | d 1.0 32 | Ns 0.0 33 | illum 2 34 | # 35 | newmtl Material__31 36 | Ka 1.0 1.0 0.9 37 | Kd 1.0 1.0 0.9 38 | Ks 0.9 0.9 0.9 39 | d 1.0 40 | Ns 0.0 41 | illum 2 42 | # 43 | newmtl Material__26 44 | Ka 1.0 1.0 1.0 45 | Kd 1.0 1.0 1.0 46 | Ks 0.9 0.9 0.9 47 | d 1.0 48 | Ns 0.0 49 | illum 2 50 | # 51 | newmtl Material__25 52 | Ka 1.0 0.9 0.0 53 | Kd 1.0 0.9 0.0 54 | Ks 0.9 0.9 0.9 55 | d 1.0 56 | Ns 0.0 57 | illum 2 58 | # 59 | newmtl elevator1 60 | Ka 0.8 0.8 0.8 61 | Kd 0.8 0.8 0.8 62 | Ks 0.9 0.9 0.9 63 | d 1.0 64 | Ns 5.5 65 | illum 2 66 | # 67 | newmtl Material__37 68 | Ka 1.0 1.0 1.0 69 | Kd 1.0 1.0 1.0 70 | Ks 0.9 0.9 0.9 71 | d 1.0 72 | Ns 0.0 73 | illum 2 74 | # 75 | newmtl Material__32 76 | Ka 1.0 1.0 0.9 77 | Kd 1.0 1.0 0.9 78 | Ks 0.9 0.9 0.9 79 | d 1.0 80 | Ns 0.0 81 | illum 2 82 | # 83 | newmtl Material__38 84 | Ka 0.9 1.0 1.0 85 | Kd 0.9 1.0 1.0 86 | Ks 0.9 0.9 0.9 87 | d 1.0 88 | Ns 0.0 89 | illum 2 90 | # 91 | newmtl Material__34 92 | Ka 0.6 0.6 0.6 93 | Kd 0.6 0.6 0.6 94 | Ks 0.9 0.9 0.9 95 | d 0.3 96 | Ns 0.0 97 | illum 2 98 | # 99 | newmtl door 100 | Ka 1.0 1.0 0.9 101 | Kd 1.0 1.0 0.9 102 | Ks 0.9 0.9 0.9 103 | d 1.0 104 | Ns 0.0 105 | illum 2 106 | # 107 | newmtl 1_-_Default 108 | Ka 0.9 0.9 0.9 109 | Kd 0.9 0.9 0.9 110 | Ks 0.9 0.9 0.9 111 | d 1.0 112 | Ns 0.0 113 | illum 2 114 | # 115 | newmtl Material__43 116 | Ka 0.6 0.6 0.6 117 | Kd 0.6 0.6 0.6 118 | Ks 0.9 0.9 0.9 119 | d 1.0 120 | Ns 0.0 121 | illum 2 122 | # 123 | newmtl Material__29 124 | Ka 0.8 0.2 0.1 125 | Kd 0.8 0.2 0.1 126 | Ks 0.9 0.9 0.9 127 | d 1.0 128 | Ns 0.0 129 | illum 2 130 | # 131 | newmtl Material__39 132 | Ka 0.6 0.6 0.6 133 | Kd 0.6 0.6 0.6 134 | Ks 0.9 0.9 0.9 135 | d 1.0 136 | Ns 0.0 137 | illum 2 138 | # 139 | newmtl Material__441 140 | Ka 0.6 0.6 0.6 141 | Kd 0.6 0.6 0.6 142 | Ks 0.9 0.9 0.9 143 | d 1.0 144 | Ns 0.0 145 | illum 2 146 | # 147 | newmtl Material__35 148 | Ka 0.3 0.2 0.2 149 | Kd 0.3 0.2 0.2 150 | Ks 0.9 0.9 0.9 151 | d 1.0 152 | Ns 5.5 153 | illum 2 154 | # 155 | newmtl Material__40 156 | Ka 0.6 0.6 0.6 157 | Kd 0.6 0.6 0.6 158 | Ks 0.9 0.9 0.9 159 | d 1.0 160 | Ns 0.0 161 | illum 2 162 | # 163 | newmtl Material__31 164 | Ka 1.0 1.0 0.9 165 | Kd 1.0 1.0 0.9 166 | Ks 0.9 0.9 0.9 167 | d 1.0 168 | Ns 0.0 169 | illum 2 170 | # 171 | newmtl Material__41 172 | Ka 0.6 0.6 0.6 173 | Kd 0.6 0.6 0.6 174 | Ks 0.9 0.9 0.9 175 | d 1.0 176 | Ns 0.0 177 | illum 2 178 | # 179 | newmtl Material__36 180 | Ka 0.6 0.6 0.6 181 | Kd 0.6 0.6 0.6 182 | Ks 0.9 0.9 0.9 183 | d 1.0 184 | Ns 0.0 185 | illum 2 186 | # 187 | # EOF 188 | -------------------------------------------------------------------------------- /models/allrooms4.3DS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arpg/SceneGraph/1ae7142615bb2c15883ed928a5ed69b0cd281665/models/allrooms4.3DS -------------------------------------------------------------------------------- /models/bench.mtl: -------------------------------------------------------------------------------- 1 | newmtl pasted__bancoMadeiraSG 2 | illum 4 3 | Kd 0.66 0.08 0.04 4 | Ka 0.33 0.04 0.02 5 | 6 | 7 | newmtl pasted__bancoPernasSG 8 | illum 4 9 | Kd 0.08 0.46 0.46 10 | Ka 0.04 0.23 0.23 11 | 12 | -------------------------------------------------------------------------------- /models/chair.3DS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arpg/SceneGraph/1ae7142615bb2c15883ed928a5ed69b0cd281665/models/chair.3DS -------------------------------------------------------------------------------- /models/chair.mtl: -------------------------------------------------------------------------------- 1 | # Max2Mtl Version 4.0 Mar 10th, 2001 2 | # 3 | newmtl Material__39 4 | Ka 0.6 0.6 0.6 5 | Kd 0.6 0.6 0.6 6 | Ks 0.9 0.9 0.9 7 | d 1.0 8 | Ns 0.0 9 | illum 2 10 | # 11 | newmtl Material__29 12 | Ka 0.8 0.2 0.1 13 | Kd 0.8 0.2 0.1 14 | Ks 0.9 0.9 0.9 15 | d 1.0 16 | Ns 0.0 17 | illum 2 18 | # 19 | # EOF 20 | -------------------------------------------------------------------------------- /src/FBO.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace SceneGraph 4 | { 5 | 6 | FBO* FBO::m_pInstance = NULL; 7 | 8 | FBO* FBO::Instance() 9 | { 10 | if (!m_pInstance) { 11 | m_pInstance = new FBO; 12 | } 13 | 14 | return m_pInstance; 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/GLAxis.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2014 ARPG 2 | 3 | #include 4 | 5 | namespace SceneGraph { 6 | 7 | GLAxis::GLAxis(const float axisSize, const bool bPretty) 8 | : GLObject("Axis"), m_fAxisScale(axisSize), m_bPretty(bPretty) { 9 | m_iAxisID = AllocSelectionId(); 10 | m_bPerceptable = false; 11 | m_aabb.SetZero(); 12 | } 13 | 14 | GLAxis::~GLAxis() { 15 | } 16 | 17 | bool GLAxis::IsSelectable() { 18 | return m_bIsSelectable; 19 | } 20 | 21 | void GLAxis::DrawAxis(float fScale) { 22 | // Draw axis 23 | glEnableClientState(GL_VERTEX_ARRAY); 24 | 25 | GLfloat axis[] = { 26 | 0.0, 0.0, 0.0, 27 | fScale , 0, 0 }; 28 | glColor4f(1, 0, 0, 1); 29 | glVertexPointer(3, GL_FLOAT, 0, axis); 30 | glDrawArrays(GL_LINE_STRIP, 0, 2); 31 | 32 | axis[3] = 0.0; 33 | axis[4] = fScale; 34 | glColor4f(0, 1, 0, 1); 35 | glVertexPointer(3, GL_FLOAT, 0, axis); 36 | glDrawArrays(GL_LINE_STRIP, 0, 2); 37 | 38 | axis[4] = 0.0; 39 | axis[5] = fScale; 40 | glColor4f(0, 0, 1, 1); 41 | glVertexPointer(3, GL_FLOAT, 0, axis); 42 | glDrawArrays(GL_LINE_STRIP, 0, 2); 43 | 44 | glDisableClientState(GL_VERTEX_ARRAY); 45 | } 46 | 47 | void GLAxis::DrawCanonicalObject() { 48 | glPushName( m_iAxisID ); 49 | DrawAxis(m_fAxisScale); 50 | glPopName(); 51 | } 52 | 53 | } // namespace SceneGraph 54 | -------------------------------------------------------------------------------- /src/GLCube.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace SceneGraph { 4 | void GLCube::ClearTexture() 5 | { 6 | if(m_nTexID > 0) { 7 | if(m_bOwnsTexture) { 8 | glDeleteTextures(1,&m_nTexID); 9 | } 10 | m_nTexID = 0; 11 | } 12 | } 13 | 14 | /////////////////////////////////////////////////////////////////////////////// 15 | 16 | void GLCube::SetCheckerboard() 17 | { 18 | ClearTexture(); 19 | 20 | // Texture Map Init 21 | GLubyte img[TEX_W][TEX_H][3]; // after glTexImage2D(), array is no longer needed 22 | for (int x=0; x 2 | #include 3 | 4 | namespace SceneGraph { 5 | 6 | GLDynamicGrid::GLDynamicGrid() : spacing_(10.0), 7 | num_minor_lines_(5), 8 | major_color_(0.5f, 0.5f, 0.5f, 1.0f), 9 | minor_color_(0.5f, 0.5f, 0.5f, 0.5f) { 10 | t_op_.setIdentity(); 11 | set_bounds({{-20., -20., 0.}, {20., 20., 0.}}); 12 | } 13 | 14 | void GLDynamicGrid::ComputeGridProperties() { 15 | Eigen::Vector3d bmax = m_aabb.Max(); 16 | Eigen::Vector3d bmin = m_aabb.Min(); 17 | 18 | double minx = std::min(bmin[0], bmax[0]); 19 | double miny = std::min(bmin[1], bmax[1]); 20 | 21 | double maxx = std::max(bmin[0], bmax[0]); 22 | double maxy = std::max(bmin[1], bmax[1]); 23 | 24 | num_neg_x_ = minx < 0 ? std::ceil(std::abs(minx / spacing_)) : 1; 25 | num_pos_x_ = maxx > 0 ? std::ceil(std::abs(maxx / spacing_)) : 1; 26 | 27 | num_neg_y_ = miny < 0 ? std::ceil(std::abs(miny / spacing_)) : 1; 28 | num_pos_y_ = maxy > 0 ? std::ceil(std::abs(maxy / spacing_)) : 1; 29 | } 30 | 31 | void GLDynamicGrid::DrawCanonicalObject() { 32 | glPushMatrix(); 33 | glMultMatrixd(t_op_.data()); 34 | GLGrid::DrawGridZ0(false, 35 | num_neg_x_, num_pos_x_, 36 | num_neg_y_, num_pos_y_, 37 | spacing_, GLColor(), major_color_, 38 | num_minor_lines_, minor_color_); 39 | glPopMatrix(); 40 | } 41 | 42 | void GLDynamicGrid::set_normal(const Eigen::Vector3d& nd_o) { 43 | const double d = 1.0 / nd_o.norm(); 44 | const Eigen::Vector3d n = d * nd_o; 45 | t_op_.block<3,3>(0,0) = Rotation_a2b(Eigen::Vector3d(0,0,-1),n); 46 | t_op_.block<3,1>(0,3) = -d*n; 47 | } 48 | 49 | /** The spacing between major lines */ 50 | void GLDynamicGrid::set_line_spacing(float spacing) { 51 | spacing_ = spacing; 52 | ComputeGridProperties(); 53 | } 54 | 55 | float GLDynamicGrid::line_spacing() { 56 | return spacing_; 57 | } 58 | 59 | /** Number of minor lines between major lines */ 60 | void GLDynamicGrid::set_num_minor_lines(int num) { 61 | num_minor_lines_ = num; 62 | } 63 | 64 | int GLDynamicGrid::num_minor_lines() { 65 | return num_minor_lines_; 66 | } 67 | 68 | 69 | void GLDynamicGrid::set_major_color(GLColor color) { 70 | major_color_ = color; 71 | } 72 | 73 | GLColor GLDynamicGrid::major_color() { 74 | return major_color_; 75 | } 76 | 77 | 78 | void GLDynamicGrid::set_minor_color(GLColor color) { 79 | minor_color_ = color; 80 | } 81 | 82 | GLColor GLDynamicGrid::minor_color() { 83 | return minor_color_; 84 | } 85 | } // namespace SceneGraph 86 | -------------------------------------------------------------------------------- /src/GLGrid.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace SceneGraph { 4 | GLGrid::GLGrid(int num_lines, float line_spacing, bool perceptable) 5 | : GLObject("Grid"), 6 | num_lines_(num_lines), 7 | line_spacing_(line_spacing), 8 | color_plane_(0.4f, 0.4f, 0.4f, 1.0f), 9 | major_color_lines_(0.5f, 0.5f, 0.5f, 1.0f), 10 | minor_color_lines_(0.5f, 0.5f, 0.5f, 0.5f), 11 | has_minor_lines_(false), 12 | num_minor_(5) { 13 | m_bPerceptable = perceptable; 14 | t_op_ = Eigen::Matrix4d::Identity(); 15 | ComputeBounds(); 16 | } 17 | 18 | 19 | // along_x or along Y axis 20 | inline void DrawMajorGridLines( 21 | int num_neg, int num_pos, float spacing, 22 | float min, float max, bool along_x) { 23 | for (int i = -num_neg; i <= num_pos; i++) { 24 | if (!i) continue; 25 | float major_pos = i * spacing; 26 | if (along_x) { 27 | pangolin::glDrawLine(max, major_pos, 0.0, 28 | min, major_pos, 0.0); 29 | } else { 30 | pangolin::glDrawLine(major_pos, max, 0.0, 31 | major_pos, min, 0.0); 32 | } 33 | } 34 | } 35 | 36 | inline void DrawMinorGridLines(int num_major_neg, 37 | int num_major_pos, 38 | int num_minor_lines, 39 | float major_spacing, 40 | float min, float max, 41 | bool along_x) { 42 | float minor_spacing = major_spacing / (num_minor_lines + 1); 43 | 44 | for (int i = -num_major_neg; i < num_major_pos; i++) { 45 | float minor_pos = i * major_spacing; 46 | for (int j = 0; j < num_minor_lines; ++j) { 47 | minor_pos += minor_spacing; 48 | if (along_x) { 49 | pangolin::glDrawLine(max, minor_pos, 0.0, 50 | min, minor_pos, 0.0); 51 | } else { 52 | pangolin::glDrawLine(minor_pos, max, 0.0, 53 | minor_pos, min, 0.0); 54 | } 55 | } 56 | } 57 | } 58 | 59 | // from mvl dispview 60 | void GLGrid::DrawGridZ0( 61 | bool filled, 62 | int num_lines_neg_x, int num_lines_x, 63 | int num_lines_neg_y, int num_lines_y, 64 | float line_spacing, 65 | GLColor color_plane, GLColor major_color, 66 | int num_minor_lines, GLColor minor_color) { 67 | pangolin::GlState gl; 68 | #ifdef ANDROID 69 | gl.glDisable(GL_LINE_SMOOTH); 70 | #endif 71 | 72 | // Prevent Z-Fighting between plane and lines 73 | glPolygonOffset(1.0, 1.0); 74 | gl.glEnable(GL_POLYGON_OFFSET_FILL); 75 | gl.glDisable(GL_CULL_FACE); 76 | 77 | // glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT); 78 | GLfloat ambient[4] = {1,1,1,1}; 79 | GLfloat diffuse[4] = {0,0,0,1}; 80 | GLfloat specular[4] = {0,0,0,1}; 81 | glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient); 82 | glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse); 83 | glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular); 84 | 85 | glNormal3f(0,0,-1); 86 | 87 | float minx = -(num_lines_neg_x * line_spacing); 88 | float maxx = num_lines_x * line_spacing; 89 | float miny = -(num_lines_neg_y * line_spacing); 90 | float maxy = num_lines_y * line_spacing; 91 | 92 | if (filled) { 93 | color_plane.Apply(); 94 | glRectf(minx, miny, maxx, maxy); 95 | 96 | // Don't overwrite this depth when drawing lines: 97 | gl.glDepthMask(GL_FALSE); 98 | } 99 | 100 | major_color.Apply(); 101 | DrawMajorGridLines(num_lines_neg_x, num_lines_x, 102 | line_spacing, maxy, miny, false); 103 | DrawMajorGridLines(num_lines_neg_y, num_lines_y, 104 | line_spacing, maxx, minx, true); 105 | 106 | minor_color.Apply(); 107 | DrawMinorGridLines(num_lines_neg_x, num_lines_x, num_minor_lines, 108 | line_spacing, maxy, miny, false); 109 | DrawMinorGridLines(num_lines_neg_y, num_lines_y, num_minor_lines, 110 | line_spacing, maxx, minx, true); 111 | 112 | glColor4ub(255, 0, 0, 128); 113 | pangolin::glDrawLine(minx, 0.0, 0.0, maxx , 0.0, 0.0); 114 | 115 | glColor4ub(0, 255, 0, 128); 116 | pangolin::glDrawLine(0.0, miny, 0.0, 0.0, maxy, 0.0); 117 | } 118 | 119 | void GLGrid::DrawCanonicalObject(void) { 120 | glPushMatrix(); 121 | glMultMatrixd(t_op_.data()); 122 | DrawGridZ0(m_bPerceptable, 123 | num_lines_ / 2, num_lines_ / 2, num_lines_ / 2, num_lines_ / 2, 124 | line_spacing_, 125 | color_plane_, major_color_lines_, 126 | has_minor_lines_ ? num_minor_ : 0, 127 | minor_color_lines_); 128 | glPopMatrix(); 129 | } 130 | 131 | void GLGrid::SetPlane(const Eigen::Vector3d& nd_o) { 132 | const double d = 1.0 / nd_o.norm(); 133 | const Eigen::Vector3d n = d * nd_o; 134 | t_op_.block<3,3>(0,0) = Rotation_a2b(Eigen::Vector3d(0,0,-1),n); 135 | t_op_.block<3,1>(0,3) = -d*n; 136 | ComputeBounds(); 137 | } 138 | 139 | void GLGrid::ComputeBounds() { 140 | const float halfsize_x = line_spacing_*num_lines_; 141 | m_aabb.Clear(); 142 | m_aabb.Insert(t_op_, Eigen::Vector3d(-halfsize_x, -halfsize_x, 0)); 143 | m_aabb.Insert(t_op_, Eigen::Vector3d(-halfsize_x, halfsize_x, 0)); 144 | m_aabb.Insert(t_op_, Eigen::Vector3d(halfsize_x, -halfsize_x, 0)); 145 | m_aabb.Insert(t_op_, Eigen::Vector3d(halfsize_x, halfsize_x, 0)); 146 | } 147 | } // namespace SceneGraph 148 | -------------------------------------------------------------------------------- /src/GLLight.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace SceneGraph { 4 | 5 | int GLLight::s_nNextLightId = GL_LIGHT0; 6 | 7 | 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/GLSceneGraph.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | namespace SceneGraph 6 | { 7 | 8 | extern std::map g_mObjects; // map of id to objects 9 | 10 | ///////////////////////////////////////////////////////////////////////////////// 11 | GLSceneGraph::GLSceneGraph() 12 | : GLObject("SceneGraph"), m_bEnableLighting(false) 13 | { 14 | Reset(); 15 | } 16 | 17 | ///////////////////////////////////////////////////////////////////////////////// 18 | GLObject* GLSceneGraph::Root() 19 | { 20 | return this; 21 | } 22 | 23 | ///////////////////////////////////////////////////////////////////////////////// 24 | void GLSceneGraph::Clear() 25 | { 26 | // Remove children 27 | m_vpChildren.clear(); 28 | 29 | m_vpPrePostRender.clear(); 30 | 31 | // This object and children can be selected 32 | m_bIsSelectable = true; 33 | } 34 | 35 | ///////////////////////////////////////////////////////////////////////////////// 36 | void GLSceneGraph::Reset() 37 | { 38 | Clear(); 39 | } 40 | 41 | ///////////////////////////////////////////////////////////////////////////////// 42 | void GLSceneGraph::AddChild( GLObject* pChild ) 43 | { 44 | GLObjectPrePostRender* prepost = dynamic_cast(pChild); 45 | GLLight* light = dynamic_cast(pChild); 46 | 47 | if(light) { 48 | m_bEnableLighting = true; 49 | } 50 | 51 | if(prepost) { 52 | m_vpPrePostRender.push_back(prepost); 53 | } 54 | 55 | GLObject::AddChild(pChild); 56 | } 57 | 58 | ///////////////////////////////////////////////////////////////////////////////// 59 | bool GLSceneGraph::RemoveChild( GLObject* pChild ) 60 | { 61 | GLObjectPrePostRender* prepost = dynamic_cast(pChild); 62 | if(prepost) { 63 | for(size_t ii = 0 ; ii < m_vpPrePostRender.size() ;ii++ ) { 64 | if(m_vpPrePostRender[ii] == prepost){ 65 | m_vpPrePostRender.erase(m_vpPrePostRender.begin()+ii); 66 | break; 67 | } 68 | } 69 | } 70 | 71 | return GLObject::RemoveChild(pChild); 72 | } 73 | 74 | 75 | 76 | ///////////////////////////////////////////////////////////////////////////////// 77 | void GLSceneGraph::DrawCanonicalObject() 78 | { 79 | // Nothing to do here 80 | } 81 | 82 | void GLSceneGraph::DrawObjectAndChildren(RenderMode renderMode) 83 | { 84 | pangolin::GlState gl; 85 | 86 | glPushMatrix(); 87 | glMultMatrixd(m_T_po.data()); 88 | glScaled(m_dScale[0],m_dScale[1],m_dScale[2]); 89 | 90 | if(m_bEnableLighting) { 91 | gl.glEnable( GL_LIGHTING ); 92 | gl.glEnable( GL_COLOR_MATERIAL ); 93 | #ifndef HAVE_GLES 94 | glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE ); 95 | #endif 96 | glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); 97 | }else{ 98 | gl.glDisable( GL_LIGHTING ); 99 | gl.glDisable( GL_COLOR_MATERIAL ); 100 | glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE ); 101 | } 102 | 103 | if(renderMode == eRenderNoPrePostHooks || renderMode == eRenderSelectable) { 104 | DrawChildren(renderMode); 105 | }else{ 106 | for(unsigned int l=0; l < m_vpPrePostRender.size(); ++l) { 107 | m_vpPrePostRender[l]->PreRender(*this); 108 | } 109 | DrawChildren(renderMode); 110 | for(unsigned int l=0; l < m_vpPrePostRender.size(); ++l) { 111 | m_vpPrePostRender[l]->PostRender(*this); 112 | } 113 | } 114 | 115 | glPopMatrix(); 116 | } 117 | 118 | void GLSceneGraph::ApplyPreferredGlSettings() 119 | { 120 | // Default to transparent white background for better screenshots 121 | glClearColor(1.0f, 1.0f, 1.0f, 0.0f); 122 | 123 | // Disable multisample for general use (it messes up antialiased lines) 124 | // Enable individually for particular GLObjects 125 | glDisable(GL_MULTISAMPLE); 126 | 127 | // // GL_POLYGON_SMOOTH is known to be really bad. 128 | // glEnable(GL_POLYGON_SMOOTH); 129 | // glHint( GL_POLYGON_SMOOTH_HINT, GL_NICEST ); 130 | 131 | glEnable(GL_NORMALIZE); 132 | 133 | // Antialiased lines work great, but should be disabled if multisampling is enabled 134 | glEnable(GL_LINE_SMOOTH); 135 | glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ); 136 | glHint( GL_LINE_SMOOTH_HINT, GL_NICEST ); 137 | 138 | // Enable alpha blending 139 | glEnable (GL_BLEND); 140 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 141 | 142 | // Enable back face culling by default. Rendering quality and speed is improved 143 | // glEnable(GL_CULL_FACE); 144 | 145 | // Shading model to use when lighing is enabled 146 | glShadeModel(GL_SMOOTH); 147 | 148 | glDepthFunc( GL_LEQUAL ); 149 | glEnable( GL_DEPTH_TEST ); 150 | 151 | glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 152 | glPixelStorei(GL_PACK_ALIGNMENT, 1); 153 | 154 | glLineWidth(1.5); 155 | } 156 | 157 | 158 | ///////////////////////////////////////////////////////////////////////////////// 159 | GLObject* GLSceneGraph::GetObject( unsigned int nId ) 160 | { 161 | std::map::iterator it = g_mObjects.find( nId ); 162 | if( it == g_mObjects.end() ){ 163 | return NULL; 164 | } 165 | return it->second; 166 | } 167 | 168 | ///////////////////////////////////////////////////////////////////////////////// 169 | 170 | 171 | 172 | } // SceneGraph 173 | -------------------------------------------------------------------------------- /src/Widgets/nvGlutWidgets.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // nvGlutWidgets 3 | // 4 | // Adaptor classes to integrate the nvWidgets UI library with the GLUT windowing 5 | // toolkit. The adaptors convert native GLUT UI data to native nvWidgets data. All 6 | // adaptor classes are implemented as in-line code in this header. The adaptor 7 | // defaults to using the standard OpenGL painter implementation. 8 | // 9 | // Author: Ignacio Castano, Samuel Gateau, Evan Hart 10 | // Email: sdkfeedback@nvidia.com 11 | // 12 | // Copyright (c) NVIDIA Corporation. All rights reserved. 13 | //////////////////////////////////////////////////////////////////////////////////////////////////// 14 | 15 | #include 16 | 17 | #include // exit, needed by GL/glut.h 18 | #include 19 | #ifdef __APPLE_CC__ 20 | #include 21 | #else 22 | #include 23 | #endif 24 | 25 | using namespace nv; 26 | 27 | 28 | bool GlutUIContext::init(int w, int h) 29 | { 30 | // @@ Remove glew dependency. Load extensions explicitely and pass pointers to painter. 31 | 32 | if (glewInit() != GLEW_OK) 33 | { 34 | return false; 35 | } 36 | 37 | if (!glewIsSupported( 38 | "GL_VERSION_2_0 " 39 | "GL_ARB_vertex_program " 40 | "GL_ARB_fragment_program " 41 | )) 42 | { 43 | return false; 44 | } 45 | 46 | reshape(w, h); 47 | 48 | return true; 49 | } 50 | 51 | void GlutUIContext::mouse(int button, int state, int modifier, int x, int y) 52 | { 53 | int modifierMask = 0; 54 | 55 | if ( button == GLUT_LEFT_BUTTON) button = MouseButton_Left; 56 | else if ( button == GLUT_MIDDLE_BUTTON) button = MouseButton_Middle; 57 | else if ( button == GLUT_RIGHT_BUTTON) button = MouseButton_Right; 58 | 59 | if ( modifier & GLUT_ACTIVE_ALT) modifierMask |= ButtonFlags_Alt; 60 | if ( modifier & GLUT_ACTIVE_SHIFT) modifierMask |= ButtonFlags_Shift; 61 | if ( modifier & GLUT_ACTIVE_CTRL) modifierMask |= ButtonFlags_Ctrl; 62 | 63 | if ( state == GLUT_DOWN) state = 1; else state = 0; 64 | 65 | UIContext::mouse( button, state, modifierMask, x, y); 66 | } 67 | 68 | void GlutUIContext::mouse(int button, int state, int x, int y) 69 | { 70 | mouse(button, state, glutGetModifiers(), x, y); 71 | } 72 | 73 | void GlutUIContext::specialKeyboard(int k, int x, int y) 74 | { 75 | UIContext::keyboard( translateKey(k), x, y); 76 | } 77 | 78 | unsigned char GlutUIContext::translateKey( int k ) 79 | { 80 | switch (k) 81 | { 82 | case GLUT_KEY_F1 : 83 | return Key_F1; 84 | case GLUT_KEY_F2 : 85 | return Key_F2; 86 | case GLUT_KEY_F3 : 87 | return Key_F3; 88 | case GLUT_KEY_F4 : 89 | return Key_F4; 90 | case GLUT_KEY_F5 : 91 | return Key_F5; 92 | case GLUT_KEY_F6 : 93 | return Key_F6; 94 | case GLUT_KEY_F7 : 95 | return Key_F7; 96 | case GLUT_KEY_F8 : 97 | return Key_F8; 98 | case GLUT_KEY_F9 : 99 | return Key_F9; 100 | case GLUT_KEY_F10 : 101 | return Key_F10; 102 | case GLUT_KEY_F11 : 103 | return Key_F11; 104 | case GLUT_KEY_F12 : 105 | return Key_F12; 106 | case GLUT_KEY_LEFT : 107 | return Key_Left; 108 | case GLUT_KEY_UP : 109 | return Key_Up; 110 | case GLUT_KEY_RIGHT : 111 | return Key_Right; 112 | case GLUT_KEY_DOWN : 113 | return Key_Down; 114 | case GLUT_KEY_PAGE_UP : 115 | return Key_PageUp; 116 | case GLUT_KEY_PAGE_DOWN : 117 | return Key_PageDown; 118 | case GLUT_KEY_HOME : 119 | return Key_Home; 120 | case GLUT_KEY_END : 121 | return Key_End; 122 | case GLUT_KEY_INSERT : 123 | return Key_Insert; 124 | default: 125 | return 0; 126 | } 127 | } 128 | 129 | --------------------------------------------------------------------------------