Skip to content

Commit

Permalink
Merge pull request #5 from stevenlovegrove/master
Browse files Browse the repository at this point in the history
pull steve's latest
  • Loading branch information
Juan Falquez committed Oct 13, 2014
2 parents a99e22a + e849e3b commit e6a3d3f
Show file tree
Hide file tree
Showing 40 changed files with 817 additions and 344 deletions.
43 changes: 27 additions & 16 deletions CMakeModules/FindOculus.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ FIND_PATH(
NAMES OVR.h
PATHS
${CMAKE_SOURCE_DIR}/../LibOVR/Include
${CMAKE_SOURCE_DIR}/../OculusSDK/LibOVR/Include
/usr/include/LibOVR/Include
/usr/local/include/LibOVR/Include
/opt/local/include/LibOVR/Include
Expand All @@ -22,6 +23,7 @@ FIND_LIBRARY(
NAMES ovr
PATHS
${CMAKE_SOURCE_DIR}/../LibOVR/Lib/MacOS/Release
${CMAKE_SOURCE_DIR}/../OculusSDK/LibOVR/Lib/Linux/Release/x86_64
/usr/include/LibOVR/Lib
/usr/local/include/LibOVR/Lib
/opt/local/include/LibOVR/Lib
Expand All @@ -30,23 +32,32 @@ FIND_LIBRARY(
/opt/local/lib
)

IF (Oculus_INCLUDE_DIRS AND Oculus_LIBRARIES)
SET(Oculus_FOUND TRUE)
ENDIF (Oculus_INCLUDE_DIRS AND Oculus_LIBRARIES)
IF(Oculus_INCLUDE_DIRS AND Oculus_LIBRARIES)
IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
find_library(CARBON_LIBRARIES NAMES Carbon)
find_library(IOKIT_LIBRARIES NAMES IOKit)
list(APPEND Oculus_LIBRARIES ${CARBON_LIBRARIES})
list(APPEND Oculus_LIBRARIES ${IOKIT_LIBRARIES})
SET(Oculus_FOUND TRUE)
ELSEIF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
FIND_PACKAGE(Xrandr)
IF( Xrandr_FOUND )
list(APPEND Oculus_LIBRARIES ${Xrandr_LIBRARIES} -ludev -lXrandr )
SET(Oculus_FOUND TRUE)
ENDIF()
ENDIF()
ENDIF(Oculus_INCLUDE_DIRS AND Oculus_LIBRARIES)

IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
find_library(CARBON_LIBRARIES NAMES Carbon)
find_library(IOKIT_LIBRARIES NAMES IOKit)
list(APPEND Oculus_LIBRARIES ${CARBON_LIBRARIES})
list(APPEND Oculus_LIBRARIES ${IOKIT_LIBRARIES})
endif()

IF (Oculus_FOUND)
IF (NOT Oculus_FIND_QUIETLY)

IF(Oculus_FOUND)
IF(NOT Oculus_FIND_QUIETLY)
MESSAGE(STATUS "Found Oculus: ${Oculus_LIBRARIES}")
ENDIF (NOT Oculus_FIND_QUIETLY)
ELSE (Oculus_FOUND)
IF (Oculus_FIND_REQUIRED)
MESSAGE(STATUS "Found Oculus: ${Oculus_INCLUDE_DIRS}")
ENDIF(NOT Oculus_FIND_QUIETLY)
ELSE(Oculus_FOUND)
message(STATUS "Oculus NOT found")
IF(Oculus_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find Oculus")
ENDIF (Oculus_FIND_REQUIRED)
ENDIF (Oculus_FOUND)
ENDIF(Oculus_FIND_REQUIRED)
ENDIF(Oculus_FOUND)
6 changes: 3 additions & 3 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ if(BUILD_PANGOLIN_GUI AND (FREEGLUT_FOUND OR GLUT_FOUND OR ANDROID) )
add_subdirectory(SimpleRepeatVideo)
endif()

if(Oculus_FOUND)
add_subdirectory(SimpleOculus)
endif()
# if(Oculus_FOUND)
# add_subdirectory(SimpleOculus)
# endif()

# This sample fails on many platforms, so exclude it for now,
# until we can create a better cmake test for support.
Expand Down
78 changes: 40 additions & 38 deletions examples/SimpleDisplay/main.cpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
#include <iostream>

#include <pangolin/pangolin.h>

using namespace pangolin;
using namespace std;

struct CustomType
{
CustomType()
: x(0), y(0.0f) {}

CustomType(int x, float y, string z)
CustomType(int x, float y, std::string z)
: x(x), y(y), z(z) {}

int x;
float y;
string z;
std::string z;
};

std::ostream& operator<< (std::ostream& os, const CustomType& o){
Expand All @@ -30,17 +26,17 @@ std::istream& operator>> (std::istream& is, CustomType& o){
return is;
}

void GlobalKeyHook()
void SampleMethod()
{
cout << "You pushed ctrl-r" << endl;
std::cout << "You typed ctrl-r or pushed reset" << std::endl;
}

int main( int /*argc*/, char* argv[] )
{
// Load configuration data
pangolin::ParseVarsFile("app.cfg");

// Create OpenGL window in single line thanks to GLUT
// Create OpenGL window in single line
pangolin::CreateWindowAndBind("Main",640,480);

// 3D Mouse handler requires depth testing to be enabled
Expand All @@ -52,52 +48,58 @@ int main( int /*argc*/, char* argv[] )

// Define Camera Render Object (for view / scene browsing)
pangolin::OpenGlRenderState s_cam(
ProjectionMatrix(640,480,420,420,320,240,0.1,1000),
ModelViewLookAt(-0,0.5,-3, 0,0,0, AxisY)
pangolin::ProjectionMatrix(640,480,420,420,320,240,0.1,1000),
pangolin::ModelViewLookAt(-0,0.5,-3, 0,0,0, pangolin::AxisY)
);

const int UI_WIDTH = 180;

// Add named OpenGL viewport to window and provide 3D Handler
View& d_cam = pangolin::CreateDisplay()
.SetBounds(0.0, 1.0, Attach::Pix(UI_WIDTH), 1.0, -640.0f/480.0f)
.SetHandler(new Handler3D(s_cam));
pangolin::View& d_cam = pangolin::CreateDisplay()
.SetBounds(0.0, 1.0, pangolin::Attach::Pix(UI_WIDTH), 1.0, -640.0f/480.0f)
.SetHandler(new pangolin::Handler3D(s_cam));

// Add named Panel and bind to variables beginning 'ui'
// A Panel is just a View with a default layout and input handling
pangolin::CreatePanel("ui")
.SetBounds(0.0, 1.0, 0.0, Attach::Pix(UI_WIDTH));

// Demonstration of how we can register a keyboard hook to alter a Var
pangolin::RegisterKeyPressCallback( PANGO_CTRL + 'b', SetVarFunctor<double>("ui.A Double", 3.5) );

// Demonstration of how we can register a keyboard hook to trigger a method
pangolin::RegisterKeyPressCallback( PANGO_CTRL + 'r', GlobalKeyHook );
.SetBounds(0.0, 1.0, 0.0, pangolin::Attach::Pix(UI_WIDTH));

// Safe and efficient binding of named variables.
// Specialisations mean no conversions take place for exact types
// and conversions between scalar types are cheap.
Var<bool> a_button("ui.A Button",false,false);
Var<double> a_double("ui.A Double",3,0,5);
Var<int> an_int("ui.An Int",2,0,5);
Var<double> a_double_log("ui.Log scale var",3,1,1E4, true);
Var<bool> a_checkbox("ui.A Checkbox",false,true);
Var<int> an_int_no_input("ui.An Int No Input",2);
Var<CustomType> any_type("ui.Some Type", CustomType(0,1.2,"Hello") );
pangolin::Var<bool> a_button("ui.A Button",false,false);
pangolin::Var<double> a_double("ui.A Double",3,0,5);
pangolin::Var<int> an_int("ui.An Int",2,0,5);
pangolin::Var<double> a_double_log("ui.Log scale var",3,1,1E4, true);
pangolin::Var<bool> a_checkbox("ui.A Checkbox",false,true);
pangolin::Var<int> an_int_no_input("ui.An Int No Input",2);
pangolin::Var<CustomType> any_type("ui.Some Type", CustomType(0,1.2,"Hello") );

Var<bool> save_window("ui.Save Window",false,false);
Var<bool> save_teapot("ui.Save Teapot",false,false);
pangolin::Var<bool> save_window("ui.Save Window",false,false);
pangolin::Var<bool> save_teapot("ui.Save Teapot",false,false);

Var<bool> record_teapot("ui.Record Teapot",false,false);
pangolin::Var<bool> record_teapot("ui.Record Teapot",false,false);

#ifdef CPP11_NO_BOOST
// boost::function / std::function objects can be used for Var's too.
// In C++11, these work great with closures.
pangolin::Var<std::function<void(void)> > reset("ui.Reset", SampleMethod);
#endif

// Demonstration of how we can register a keyboard hook to alter a Var
pangolin::RegisterKeyPressCallback(pangolin::PANGO_CTRL + 'b', pangolin::SetVarFunctor<double>("ui.A Double", 3.5));

// Demonstration of how we can register a keyboard hook to trigger a method
pangolin::RegisterKeyPressCallback(pangolin::PANGO_CTRL + 'r', SampleMethod);

// Default hooks for exiting (Esc) and fullscreen (tab).
while( !pangolin::ShouldQuit() )
{
// Clear entire screen
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

if( Pushed(a_button) )
cout << "You Pushed a button!" << endl;
if( pangolin::Pushed(a_button) )
std::cout << "You Pushed a button!" << std::endl;

// Overloading of Var<T> operators allows us to treat them like
// their wrapped types, eg:
Expand All @@ -109,21 +111,21 @@ int main( int /*argc*/, char* argv[] )

an_int_no_input = an_int;

if( Pushed(save_window) )
if( pangolin::Pushed(save_window) )
pangolin::SaveWindowOnRender("window");

if( Pushed(save_teapot) )
if( pangolin::Pushed(save_teapot) )
d_cam.SaveOnRender("teapot");

if(Pushed(record_teapot))
DisplayBase().RecordOnRender("ffmpeg:[fps=50,bps=8388608,unique_filename]//screencap.avi");
if( pangolin::Pushed(record_teapot) )
pangolin::DisplayBase().RecordOnRender("ffmpeg:[fps=50,bps=8388608,unique_filename]//screencap.avi");

// Activate efficiently by object
d_cam.Activate(s_cam);

// Render some stuff
glColor3f(1.0,1.0,1.0);
glutWireTeapot(1.0);
pangolin::glDrawColouredCube();

// Swap frames and Process Events
pangolin::FinishFrame();
Expand Down
27 changes: 12 additions & 15 deletions examples/SimpleDisplayImage/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
#include <iostream>
#include <pangolin/pangolin.h>

using namespace std;
using namespace pangolin;

void setImageData(unsigned char * imageArray, int size){
for(int i = 0 ; i < size;i++) {
imageArray[i] = (unsigned char)(rand()/(RAND_MAX/255.0));
Expand All @@ -13,39 +10,39 @@ void setImageData(unsigned char * imageArray, int size){

int main( int /*argc*/, char* argv[] )
{
// Create OpenGL window in single line thanks to GLUT
CreateWindowAndBind("Main",640,480);
// Create OpenGL window in single line
pangolin::CreateWindowAndBind("Main",640,480);

// 3D Mouse handler requires depth testing to be enabled
glEnable(GL_DEPTH_TEST);

pangolin::OpenGlRenderState s_cam(
ProjectionMatrix(640,480,420,420,320,240,0.1,1000),
ModelViewLookAt(-1,1,-1, 0,0,0, AxisY)
pangolin::ProjectionMatrix(640,480,420,420,320,240,0.1,1000),
pangolin::ModelViewLookAt(-1,1,-1, 0,0,0, pangolin::AxisY)
);

// Aspect ratio allows us to constrain width and height whilst fitting within specified
// bounds. A positive aspect ratio makes a view 'shrink to fit' (introducing empty bars),
// whilst a negative ratio makes the view 'grow to fit' (cropping the view).
View& d_cam = Display("cam")
pangolin::View& d_cam = pangolin::Display("cam")
.SetBounds(0,1.0f,0,1.0f,-640/480.0)
.SetHandler(new Handler3D(s_cam));
.SetHandler(new pangolin::Handler3D(s_cam));

// This view will take up no more than a third of the windows width or height, and it
// will have a fixed aspect ratio to match the image that it will display. When fitting
// within the specified bounds, push to the top-left (as specified by SetLock).
View& d_image = Display("image")
pangolin::View& d_image = pangolin::Display("image")
.SetBounds(2/3.0f,1.0f,0,1/3.0f,640.0/480)
.SetLock(LockLeft,LockTop);
.SetLock(pangolin::LockLeft, pangolin::LockTop);

cout << "Resize the window to experiment with SetBounds, SetLock and SetAspect." << endl;
cout << "Notice that the teapots aspect is maintained even though it covers the whole screen." << endl;
std::cout << "Resize the window to experiment with SetBounds, SetLock and SetAspect." << std::endl;
std::cout << "Notice that the teapots aspect is maintained even though it covers the whole screen." << std::endl;

const int width = 64;
const int height = 48;

unsigned char* imageArray = new unsigned char[3*width*height];
GlTexture imageTexture(width,height,GL_RGB,false,0,GL_RGB,GL_UNSIGNED_BYTE);
pangolin::GlTexture imageTexture(width,height,GL_RGB,false,0,GL_RGB,GL_UNSIGNED_BYTE);

// Default hooks for exiting (Esc) and fullscreen (tab).
while(!pangolin::ShouldQuit())
Expand All @@ -55,7 +52,7 @@ int main( int /*argc*/, char* argv[] )
d_cam.Activate(s_cam);

glColor3f(1.0,1.0,1.0);
glDrawColouredCube();
pangolin::glDrawColouredCube();

//Set some random image data and upload to GPU
setImageData(imageArray,3*width*height);
Expand Down
Loading

0 comments on commit e6a3d3f

Please sign in to comment.