diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..1adb795 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,42 @@ +#Specify the version being used aswell as the language +cmake_minimum_required(VERSION 2.8.11) + +#Name your project here +project(shview) + +#set the module directory +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}") + +#find the STIM library +find_package(STIM REQUIRED) + +find_package(OpenGL REQUIRED) +find_package(GLUT REQUIRED) + +#find the pthreads package +find_package(Threads) + +include_directories( + ${STIM_INCLUDE_DIRS} + ${GLUT_INCLUDE_DIR} + ${OpenGL_INCLUDE_DIRS} + ) + +#Assign source files to the appropriate variables +file(GLOB SRC_CPP "*.cpp") +file(GLOB SRC_H "*.h") + +#create an executable file +add_executable(shview + ${SRC_H} + ${SRC_CPP} + ) + +#set the link libraries +target_link_libraries(shview + ${CMAKE_THREAD_LIBS_INIT} + ${OPENGL_LIBRARIES} + ${GLUT_LIBRARY} + ) + + diff --git a/FindSTIM.cmake b/FindSTIM.cmake new file mode 100644 index 0000000..700157d --- /dev/null +++ b/FindSTIM.cmake @@ -0,0 +1,9 @@ +include(FindPackageHandleStandardArgs) + +set(STIM_INCLUDE_DIR $ENV{STIMLIB_PATH}) + +find_package_handle_standard_args(STIM DEFAULT_MSG STIM_INCLUDE_DIR) + +if(STIM_FOUND) + set(STIM_INCLUDE_DIRS ${STIM_INCLUDE_DIR}) +endif() \ No newline at end of file diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..0e366ac --- /dev/null +++ b/main.cpp @@ -0,0 +1,179 @@ +#include + +#include + +#include +#include +#include + +#define theta_scale 0.01 +#define phi_scale 0.01 + +//create a global camera that will specify the viewport +stim::camera cam; +int mx, my; //mouse coordinates in the window space + +stim::sph_harmonics S; + +float d = 1.5; //initial distance between the camera and the sphere + +bool rotate_zoom = true; //sets the current camera mode (rotation = true, zoom = false) + +stim::arglist args; //class for processing command line arguments + +#ifdef _WIN32 + args.set_ansi(false); +#endif + +bool init(){ + + //set the clear color to white + glClearColor(1.0f, 1.0f, 1.0f, 1.0f); + + //initialize the camera + cam.setPosition(d, d, d); + cam.LookAt(0, 0, 0, 0, 1, 1); + cam.setFOV(40); + + //initialize the texture map stuff + + srand(time(NULL)); + unsigned int T = 40; + double c; + for(unsigned int t = 0; t < T; t++){ + + c = (double)rand() / RAND_MAX - 0.5; + S.push(c); + } + + S.glInit(256); + + return true; +} + +//code that is run every time the user changes something +void display(){ + //clear the screen + glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); + + //set the projection matrix + glMatrixMode(GL_PROJECTION); //put the projection matrix on the stack + glLoadIdentity(); //set it to the identity matrix + gluPerspective(cam.getFOV(), 1, 0.001, 1000000); //set up a perspective projection + + + //set the model view matrix + glMatrixMode(GL_MODELVIEW); //load the model view matrix to the stack + glLoadIdentity(); //set it to the identity matrix + + //get the camera parameters + stim::vec p = cam.getPosition(); + stim::vec u = cam.getUp(); + stim::vec d = cam.getDirection(); + + //specify the camera parameters to OpenGL + gluLookAt(p[0], p[1], p[2], d[0], d[1], d[2], u[0], u[1], u[2]); + + //draw the sphere + S.glRender(); + + //flush commands on the GPU + glutSwapBuffers(); +} + +void mouse_press(int button, int state, int x, int y){ + + //set the camera motion mode based on the mouse button pressed + if(button == GLUT_LEFT_BUTTON) + rotate_zoom = true; + else if(button == GLUT_MIDDLE_BUTTON) + rotate_zoom = false; + + //if the mouse is pressed + if(state == GLUT_DOWN){ + //set the current mouse position + mx = x; my = y; + } +} + +void mouse_drag(int x, int y){ + + //if the camera is in rotation mode, rotate + if(rotate_zoom == true){ + float theta = theta_scale * (mx - x); + float phi = -phi_scale * (my - y); + + //if the mouse is dragged + cam.OrbitFocus(theta, phi); + } + //otherwize zoom + else{ + cam.Push(my - y); + } + + //update the mouse position + mx = x; my = y; + + glutPostRedisplay(); +} + +void process_arguments(int argc, char* argv[]){ + + args.add("help", "prints this help"); + + //process the command line arguments + args.parse(argc, argv); + + + //push all of the arguments to the spherical harmonics class as coefficients + for(unsigned int a = 0; a < args.nargs(); a++) + S.push(atof(args.arg(a).c_str())); + + //if the user asks for help, give it and exit + if(args["help"].is_set()){ + std::cout<<"usage: shview c0 c1 c2 c3 ... --option [A B C]"<