├── .gitignore ├── CMakeLists.txt ├── Common.cmake ├── Executables ├── VRIntro-osx.zip └── VRIntro-windows.zip ├── README.md ├── VRIntroConfig.cmake.in ├── cmake-module ├── AddPCH.cmake ├── ConditionalSources.cmake ├── CreateImportTargetHelpers.cmake ├── DefinePostBuildResourceCopyRules.cmake ├── FindAntTweakBar.cmake ├── FindAssimp.cmake ├── FindBreakpad.cmake ├── FindBullet.cmake ├── FindCURL.cmake ├── FindCinder.cmake ├── FindEigen.cmake ├── FindFbxSdk.cmake ├── FindFreeImage.cmake ├── FindGlew.cmake ├── FindInf2Cat.cmake ├── FindIrrklang.cmake ├── FindLeap.cmake ├── FindNanoSVG.cmake ├── FindOculusSDK.cmake ├── FindOpenGL.cmake ├── FindOpenSSL.cmake ├── FindPackageHandleStandardArgs.cmake ├── FindPolyPartition.cmake ├── FindSDL.cmake ├── FindSFML.cmake ├── FindThreads.cmake ├── FindWDK.cmake ├── LeapCMakeTemplates.cmake ├── PrintTargetProperties.cmake ├── README.md ├── SelectConfigurations.cmake ├── TargetImportedLibraries.cmake ├── TargetStrip.cmake └── VerboseMessage.cmake └── source ├── CMakeLists.txt ├── VRIntro ├── APIFrameSupplier.cpp ├── APIFrameSupplier.h ├── CMakeLists.txt ├── LeapListener.cpp ├── LeapListener.h ├── RunMirrored.bat ├── images │ ├── help.png │ ├── level3_popup.png │ ├── level4_popup.png │ ├── lowfps.png │ ├── no_images.png │ ├── no_oculus.png │ └── random.png ├── main.cpp ├── shaders │ ├── fractal-frag.glsl │ ├── fractal-vert.glsl │ ├── passthrough-frag.glsl │ ├── passthrough-vert.glsl │ ├── solid-frag.glsl │ ├── solid-vert.glsl │ ├── transparent-frag.glsl │ └── transparent-vert.glsl ├── stdafx.cpp └── stdafx.h └── VRIntroLib ├── CMakeLists.txt ├── Config.h.in ├── FlyingLayer.cpp ├── FlyingLayer.h ├── FractalLayer.cpp ├── FractalLayer.h ├── GridLayer.cpp ├── GridLayer.h ├── HandLayer.cpp ├── HandLayer.h ├── IFrameSupplier.h ├── InteractionLayer.cpp ├── Interactionlayer.h ├── LifeLayer.cpp ├── LifeLayer.h ├── MathUtility.cpp ├── MathUtility.h ├── MessageLayer.cpp ├── MessageLayer.h ├── Mirror.cpp ├── Mirror.h ├── PassthroughLayer.cpp ├── PassthroughLayer.h ├── PhysicsLayer.cpp ├── PhysicsLayer.h ├── PlatformInitializer.h ├── PlatformInitializerMac.h ├── PlatformInitializerMac.mm ├── PlatformInitializerWin.cpp ├── PlatformInitializerWin.h ├── PrecisionTimer.h ├── QuadsLayer.cpp ├── QuadsLayer.h ├── SpaceLayer.cpp ├── SpaceLayer.h ├── SpheresLayer.cpp ├── SpheresLayer.h ├── VRIntroApp.cpp ├── VRIntroApp.h ├── stdafx.cpp └── stdafx.h /.gitignore: -------------------------------------------------------------------------------- 1 | CMakeFiles 2 | *.vcxproj 3 | *.filters 4 | *.user 5 | *.dir 6 | VRIntro.sdf 7 | VRIntro.opensdf 8 | VRIntro.sln 9 | cmake_install.cmake 10 | CMakeCache.txt 11 | ipch 12 | VRIntro.v12.suo 13 | Debug 14 | Release 15 | bin 16 | lib 17 | install_manifest.txt 18 | VRIntroConfig.cmake 19 | VRIntroVersion.cmake 20 | VRIntroTargets.cmake 21 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | 3 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}) 4 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake-module") 5 | 6 | project(VRIntro) 7 | 8 | # External module includes 9 | include(ConditionalSources) 10 | 11 | # Set up our output directories to be in our root 12 | set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) 13 | set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) 14 | 15 | # Run all of our project configuration steps 16 | add_subdirectory(source) 17 | 18 | # Include directory setup 19 | set(INCLUDE_INSTALL_DIR "${CMAKE_SOURCE_DIR}/source" CACHE PATH "Path to include files for VRIntro") 20 | 21 | # Let everyone know we're here 22 | include(CMakePackageConfigHelpers) 23 | configure_package_config_file( 24 | VRIntroConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/VRIntroConfig.cmake 25 | INSTALL_DESTINATION ${LIB_INSTALL_DIR}/VRIntro/cmake 26 | PATH_VARS INCLUDE_INSTALL_DIR 27 | ) 28 | 29 | write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/VRIntroVersion.cmake 30 | VERSION 1.0.0 31 | COMPATIBILITY SameMajorVersion ) 32 | 33 | # Add all targets to the build-tree export set 34 | export(TARGETS VRIntroLib 35 | FILE "${PROJECT_BINARY_DIR}/VRIntroTargets.cmake") -------------------------------------------------------------------------------- /Common.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_CONFIGURATION_TYPES "Release;Debug" CACHE STRING "" FORCE) 2 | 3 | include(TargetImportedLibraries) # for Walter's target_package command 4 | 5 | ################################################################################################### 6 | # We use an EXTERNAL_LIBRARY_DIR variable as a hint to where all the libraries can be found. 7 | # This is an optional means to not have to specify each library's root dir directly. 8 | ################################################################################################### 9 | 10 | find_path(EXTERNAL_LIBRARY_DIR "glew-1.9.0" HINTS /opt/local/Libraries PATHS $ENV{PATH} $ENV{EXTERNAL_LIBRARY_DIR} NO_DEFAULT_PATH) 11 | 12 | # TODO: Make EXTERNAL_LIBRARY_DIR detection optional, since users may not have their libraries 13 | # installed the same way we (Leap) do. 14 | if(EXTERNAL_LIBRARY_DIR STREQUAL "EXTERNAL_LIBRARY_DIR-NOTFOUND") 15 | message( FATAL_ERROR "EXTERNAL_LIBRARY_DIR not found, please specify a folder to look for external libraries") 16 | endif() 17 | 18 | # CMAKE_PREFIX_PATH is the path used for searching by FIND_XXX(), with appropriate suffixes added. 19 | # EXTERNAL_LIBRARY_DIR is a hint for all the find_library calls. 20 | list(INSERT CMAKE_PREFIX_PATH 0 ${EXTERNAL_LIBRARY_DIR}) 21 | 22 | 23 | # Adds a precompiled header 24 | MACRO(ADD_MSVC_PRECOMPILED_HEADER PrecompiledHeader PrecompiledSource SourcesVar) 25 | if(MSVC) 26 | set_source_files_properties(${PrecompiledSource} 27 | PROPERTIES 28 | COMPILE_FLAGS "/Yc${PrecompiledHeader}" 29 | ) 30 | foreach( src_file ${${SourcesVar}} ) 31 | set_source_files_properties( 32 | ${src_file} 33 | PROPERTIES 34 | COMPILE_FLAGS "/Yu${PrecompiledHeader}" 35 | ) 36 | endforeach( src_file ${${SourcesVar}} ) 37 | list(APPEND ${SourcesVar} ${PrecompiledHeader} ${PrecompiledSource}) 38 | endif(MSVC) 39 | ENDMACRO(ADD_MSVC_PRECOMPILED_HEADER) -------------------------------------------------------------------------------- /Executables/VRIntro-osx.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leapmotion/VRIntro/b2eb1e349e46ee2231cf8162ff6cf3e06e5ff222/Executables/VRIntro-osx.zip -------------------------------------------------------------------------------- /Executables/VRIntro-windows.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leapmotion/VRIntro/b2eb1e349e46ee2231cf8162ff6cf3e06e5ff222/Executables/VRIntro-windows.zip -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | VRIntro 2 | ======= 3 | 4 | Leap Motion's intro to VR 5 | 6 | ##### Usage 7 | 8 | In VR you can do anything. You can fly through space, manipulate the stars and swim through bubbles. 9 | 10 | Press 1 for Grid, 2 for Spheres, 3 for Magical Stars and 4 for Aerobatics. 11 | 12 | Be sure to select "Allow Images" and "Optimize for top-down tracking" in the Leap Motion Control Panel before launching this example. 13 | 14 | * This demo supports both the Oculus DK1 and DK2. 15 | * Includes exectuables for both Windows and OSX. 16 | * Please use the 0.4.4+ runtime and set the Rift Display Mode to "Extend Desktop to the HMD" 17 | * Designed to be used with [Leap Motion VR Developer Mount](https://developer.leapmotion.com/vr). 18 | * Requires Leap SDK Version 2.1.3 or newer 19 | * Source code available now! 20 | * Works best with discrete graphics cards (NVIDIA, AMD) 21 | 22 | ##### How to build (Win32) 23 | 24 | 1. Get CMake 3.1+ and Microsoft Visual Studio 2013 Update 3 25 | 2. Download libraries here https://leapmotion.box.com/s/4ea6vdx2h1hidxz7vmhm 26 | 3. Extract the zip file into a local folder 27 | 4. Obtain Oculus Rift SDK 0.4.4+, and the latest LeapSDK, and copy "OculusSDK" and "LeapSDK" into the folder mentioned in step 3 28 | 5. Run CMake and set the source directory to this repository 29 | 6. Set EXTERNAL_LIBRARY_DIR to the folder mentioned in step 3 30 | 7. Open the generated VRIntro.sln file, and build 31 | 8. Copy any needed DLLs (SDL, SFML) from within the libraries folder to your binary folder. (We are planning to automate this soon!) 32 | 33 | ##### How to build (OSX) 34 | 35 | 1. Get CMake 3.1+ and Xcode 6.0+ 36 | 2. Download libraries here https://leapmotion.box.com/s/ujxqevpwdr06ccybwq2m 37 | 3. Extract the zip file into a local folder 38 | 4. Obtain Oculus Rift SDK 0.4.4+, and the latest LeapSDK, and copy "OculusSDK" and "LeapSDK" into the folder mentioned in step 3 39 | 5. cd into the VRintro repository and run ccmake. Set the source directory to ./VRIntro 40 | 6. Set EXTERNAL_LIBRARY_DIR to the folder mentioned in step 3 41 | 7. Open the generated VRIntro.xcodeproj file, and build 42 | -------------------------------------------------------------------------------- /VRIntroConfig.cmake.in: -------------------------------------------------------------------------------- 1 | # - Config file for the websocketpp package 2 | # It defines the following variables 3 | # vrintro_FOUND - indicates that the module was found 4 | # vrintro_INCLUDE_DIR - include directories 5 | 6 | include(${CMAKE_CURRENT_LIST_DIR}/VRIntroTargets.cmake) 7 | 8 | set(vrintro_FOUND TRUE) 9 | set(vrintro_INCLUDE_DIR "@INCLUDE_INSTALL_DIR@") 10 | set(vrintro_LIBRARIES VRIntroLib) -------------------------------------------------------------------------------- /cmake-module/AddPCH.cmake: -------------------------------------------------------------------------------- 1 | #MSVC pch helper. Copied from http://pastebin.com/84dm5rXZ and modified by Walter Gray. 2 | #Files already in SourcesVar will be marked as using a PCH, then the pch files will be 3 | #appended to the list. 4 | 5 | function(add_pch SourcesVar PrecompiledHeader PrecompiledSource) 6 | if(MSVC) 7 | set_source_files_properties(${PrecompiledSource} 8 | PROPERTIES 9 | COMPILE_FLAGS "/Yc${PrecompiledHeader}" 10 | ) 11 | foreach( src_file ${${SourcesVar}} ) 12 | set_source_files_properties( 13 | ${src_file} 14 | PROPERTIES 15 | COMPILE_FLAGS "/Yu${PrecompiledHeader}" 16 | ) 17 | endforeach( src_file ${${SourcesVar}} ) 18 | list(APPEND ${SourcesVar} ${PrecompiledHeader} ${PrecompiledSource}) 19 | set(${SourcesVar} ${${SourcesVar}} PARENT_SCOPE) 20 | endif(MSVC) 21 | endfunction(add_pch) -------------------------------------------------------------------------------- /cmake-module/ConditionalSources.cmake: -------------------------------------------------------------------------------- 1 | #.rst 2 | #ConditionalSources 3 | #--------------- 4 | # Created by Walter Gray 5 | # 6 | # This module defines a set of functions for specifying conditionally compiled source files, 7 | # generally platform specific ones. Files that are listed but whose condition is not met will 8 | # still be visible in any IDE generated projects, but will not be compiled and will be isolated in 9 | # a named filter group. This is particularly useful for find and replace operations in multi-platform 10 | # codebases. 11 | # 12 | # There are two groups of functions 13 | # conditional_sources is sufficient for setting all the flags on a list of files so that they will be grouped 14 | # and only compiled under the given conditions. 15 | # add_conditional_sources will first call conditional_sources, and will then append the list of sources to the given 16 | # variable. 17 | # 18 | # add_named_conditional_functions is used for defining shorthand functions. Examples are at the bottom, and cover the most common 19 | # platform-specific use cases. 20 | # 21 | # It is also worth noting that this is the only example I'm aware of showing cmake macro for defining functions. 22 | # The trick was realising that referencing ${ARGV} in a macro references the ARGV of the *macro*, but you can 23 | # access the defined function's ARGV by putting "ARGV" in a variable, then double-dereferincing it - this prevents 24 | # the ${ARGV} from being parsed by cmake's macro preprocessor. 25 | include(VerboseMessage) 26 | 27 | macro(_conditional_sources_parse_arguments) 28 | include(CMakeParseArguments) 29 | cmake_parse_arguments(conditional_sources "" "GROUP_NAME" "FILES" ${ARGN}) 30 | 31 | if(NOT DEFINED conditional_sources_FILES) 32 | set(conditional_sources_FILES ${conditional_sources_UNPARSED_ARGUMENTS}) 33 | endif() 34 | endmacro() 35 | 36 | function(conditional_sources condition_var) 37 | _conditional_sources_parse_arguments(${ARGN}) 38 | 39 | source_group(${conditional_sources_GROUP_NAME} FILES ${conditional_sources_FILES}) 40 | 41 | separate_arguments(condition_var) 42 | verbose_message("Evaluating conditional as: ${condition_var}") 43 | if(NOT (${condition_var})) 44 | set_source_files_properties( ${conditional_sources_FILES} PROPERTIES HEADER_FILE_ONLY TRUE) 45 | verbose_message("Setting INACTIVE source group \"${conditional_sources_GROUP_NAME}\" with files ${conditional_sources_FILES}") 46 | else() 47 | verbose_message("Setting source group \"${conditional_sources_GROUP_NAME}\" with files ${conditional_sources_FILES}") 48 | endif() 49 | endfunction() 50 | 51 | #as conditional_sources, but also appends the soruces to the source_list_var 52 | function(add_conditional_sources source_list_var condition_var) 53 | list(REMOVE_AT ARGV 0) 54 | conditional_sources(${ARGV}) 55 | 56 | _conditional_sources_parse_arguments(${ARGN}) 57 | 58 | set(${source_list_var} ${${source_list_var}} ${conditional_sources_FILES} PARENT_SCOPE) 59 | verbose_message("Adding ${conditional_sources_FILES} to ${source_list_var}") 60 | endfunction() 61 | 62 | #defines 'func_name' and add_'func_name' shorthands for add_conditional_sources with pre-set conditions. 63 | macro(add_named_conditional_functions func_name group_name condition) 64 | function(${func_name} ...) 65 | set(my_argv ARGV) 66 | conditional_sources("${condition}" GROUP_NAME "${group_name}" FILES ${${my_argv}}) 67 | endfunction() 68 | 69 | function(add_${func_name} source_list_var ...) 70 | set(my_argv ARGV) 71 | 72 | list(REMOVE_AT ARGV 0) 73 | add_conditional_sources(${source_list_var} "${condition}" GROUP_NAME "${group_name}" FILES ${${my_argv}}) 74 | set(${source_list_var} ${${source_list_var}} PARENT_SCOPE) 75 | endfunction() 76 | endmacro() 77 | 78 | #Some good defaults 79 | add_named_conditional_functions("windows_sources" "Windows Source" WIN32) 80 | add_named_conditional_functions("mac_sources" "Mac Source" APPLE) 81 | add_named_conditional_functions("unix_sources" "Unix Source" "UNIX AND NOT APPLE AND NOT WIN32") 82 | add_named_conditional_functions("resource_files" "Resource Files" FALSE) 83 | -------------------------------------------------------------------------------- /cmake-module/CreateImportTargetHelpers.cmake: -------------------------------------------------------------------------------- 1 | #.rst 2 | # CreateImportTargetHelpers 3 | # ------------------------- 4 | # 5 | # Created by Walter Gray 6 | # A suite of functions helpful for writing Find modules that make use of the 7 | # INTERFACE targets and Usage Requirements concepts introduced in cmake 3.0.0. 8 | # 9 | # The following functions are provided by this module: 10 | # :: 11 | # map_var_to_prop 12 | # generate_import_target 13 | # 14 | # :: 15 | # GENERATE_IMPORT_TARGET( []) 16 | # 17 | # namespace - The namespace of the library 18 | # type - The type of target. Allowed values are SHARED, STATIC, INTERFACE and UNKNOWN 19 | # target - Optional parameter allowing you to specify the generated target name 20 | # 21 | # Generates an import target of the specified type with the default name 22 | # ::. 23 | # 24 | # The values for the resulting library are read from the standard variables below. 25 | # Any variable which is found is marked as advanced. 26 | # _LIBRARY<_DEBUG/_RELEASE> 27 | # The file to use as the IMPORTED_LOCATION. If is SHARED, this should 28 | # be a .dll, .dylib, or .so. If is STATIC or UNKNOWN, this should be 29 | # a .lib, or .a file. This is unused for INTERFACE libraries 30 | # _SHARED_LIB<_DEBUG/_RELEASE> 31 | # The file to use as the IMPORTED_LOCATION if is SHARED. This is helpful 32 | # for backwards compatilbility where projects expect _LIBRARY to be the import_lib. 33 | # _IMPORT_LIB<_DEBUG/_RELEASE> 34 | # The import library corresponding to the .dll. Only used on Windows. 35 | # This may not use generator expressions. 36 | # _INTERFACE_LIBS<_DEBUG/_RELEASE> 37 | # Additional link libraries, *excluding* the _LIBRARY and 38 | # _IMPORT_LIB values, if any. Generator expressions OK. 39 | # _INCLUDE_DIR 40 | # Interface include directories. Generator expressions OK. 41 | # 42 | # :: 43 | # MAP_VAR_TO_PROP(target property variable [REQUIRED]) 44 | # 45 | # target - The name of the target we're changing. 46 | # property - The property to append to. 47 | # variable - The root name of the variable we're appending to target::property 48 | # REQUIRED - Optional arg, if specified will throw a fatal error if no matching variable is found 49 | # 50 | # Primarily used by GENERATE_IMPORT_TARGET, but perhaps helpful externally when dealing 51 | # with tricky libraries. Searches for as well as _ values, 52 | # and appends any value found to the matching property (_DEBUG goes to _DEBUG) 53 | 54 | include(CMakeParseArguments) 55 | include(VerboseMessage) 56 | 57 | function(map_var_to_prop target property var ) 58 | set(options REQUIRED) 59 | cmake_parse_arguments(map_var_to_prop ${options} "" "" ${ARGN}) 60 | # message("Searching for ${var}") 61 | foreach(_config _DEBUG _RELEASE "") 62 | if(${var}${_config}) 63 | verbose_message("Appending to ${target} ${property}${_config}: ${${var}${_config}}") 64 | set(_found TRUE) 65 | #mark_as_advanced(${property}${_config}) #anything that gets passed in here is an advanced variable 66 | set_property(TARGET ${target} APPEND 67 | PROPERTY ${property}${_config} "${${var}${_config}}") 68 | endif() 69 | endforeach() 70 | 71 | #set the default to a nice generator expression if it is not in the blacklist 72 | set(_genexpr_unsupported_properties "IMPORTED_LOCATION") 73 | list(FIND _genexpr_unsupported_properties _find_result ${property}) 74 | if(NOT ${var} AND (_find_result EQUAL -1)) 75 | set(_defaultprop) 76 | foreach(_config DEBUG RELEASE) 77 | if(${var}_${_config}) 78 | set(_defaultprop ${_defaultprop}$<$:${${var}_${_config}}>) 79 | endif() 80 | endforeach() 81 | set_property(TARGET ${target} PROPERTY ${property} ${_defaultprop}) 82 | endif() 83 | 84 | if(map_var_to_prop_REQUIRED AND NOT _found) 85 | message(FATAL_ERROR "${target}: required variable ${var}${var_suffix} is undefined.") 86 | endif() 87 | 88 | get_target_property(_fullprop ${target} ${property}) 89 | verbose_message("${target}:${property} = ${_fullprop}") 90 | endfunction() 91 | 92 | #acceptable libtypes are SHARED, STATIC, INTERFACE, and UNKNOWN 93 | function(generate_import_target namespace libtype) 94 | set(_target ${namespace}::${namespace}) 95 | cmake_parse_arguments(generate_import_target "LOCAL" "TARGET" "" ${ARGN}) 96 | 97 | if(generate_import_target_TARGET) 98 | set(_target ${generate_import_target_TARGET}) 99 | endif() 100 | 101 | if(${namespace}_FOUND) 102 | verbose_message("Generating ${libtype} lib: ${_target} with namespace ${namespace}") 103 | 104 | set(_global GLOBAL) 105 | if(generate_import_target_LOCAL) 106 | unset(_global) 107 | endif() 108 | 109 | add_library(${_target} ${libtype} IMPORTED ${_global}) 110 | 111 | if(MSVC AND ${libtype} STREQUAL SHARED) 112 | map_var_to_prop(${_target} IMPORTED_IMPLIB ${namespace}_IMPORT_LIB REQUIRED) 113 | endif() 114 | 115 | if(NOT ${libtype} STREQUAL INTERFACE) 116 | if(${libtype} STREQUAL SHARED AND (${namespace}_SHARED_LIB OR (${namespace}_SHARED_LIB_DEBUG AND ${namespace}_SHARED_LIB_RELEASE))) 117 | map_var_to_prop(${_target} IMPORTED_LOCATION ${namespace}_SHARED_LIB REQUIRED) 118 | else() 119 | map_var_to_prop(${_target} IMPORTED_LOCATION ${namespace}_LIBRARY REQUIRED) 120 | endif() 121 | endif() 122 | 123 | map_var_to_prop(${_target} INTERFACE_LINK_LIBRARIES ${namespace}_INTERFACE_LIBS) 124 | map_var_to_prop(${_target} INTERFACE_INCLUDE_DIRECTORIES ${namespace}_INCLUDE_DIR) 125 | endif() 126 | endfunction() -------------------------------------------------------------------------------- /cmake-module/DefinePostBuildResourceCopyRules.cmake: -------------------------------------------------------------------------------- 1 | #.rst 2 | # 3 | # DefinePostBuildResourceCopyRules 4 | # -------------- 5 | # 6 | # Created by Victor Dods. 7 | # Hides the nastiness of defining platform-specific rules for installing 8 | # resource files post-build. 9 | 10 | # The RELATIVE_PATH_BASE option can be used to specify an (absolute) path which 11 | # will be used as the base path for determining where the resource directory is 12 | # located. The resource directory will depend on the platform and other options, 13 | # such as if the target has MACOSX_BUNDLE specified. 14 | function(define_post_build_resource_copy_rules) 15 | # Do the fancy map-style parsing of the arguments 16 | set(_options "") 17 | set(_one_value_args 18 | TARGET 19 | RELATIVE_PATH_BASE 20 | ) 21 | set(_multi_value_args 22 | RELATIVE_PATH_RESOURCES 23 | ABSOLUTE_PATH_RESOURCES 24 | TARGETS 25 | ) 26 | cmake_parse_arguments(_arg "${_options}" "${_one_value_args}" "${_multi_value_args}" ${ARGN}) 27 | 28 | if(NOT _arg_TARGET) 29 | message(SEND_ERROR "must specify a value for TARGET in define_post_build_resource_copy_rules") 30 | return() 31 | endif() 32 | 33 | # The "base" resources dir which may be appended to, depending on the platform and other conditions. 34 | set(_resources_dir "${PROJECT_BINARY_DIR}") 35 | # Override it with the RELATIVE_PATH_BASE value if specified. 36 | if(_arg_RELATIVE_PATH_BASE) 37 | set(_resources_dir "${_arg_RELATIVE_PATH_BASE}") 38 | endif() 39 | # Decide where the resources directory is on each platform. 40 | if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") # This is the correct way to detect Mac OS X operating system -- see http://www.openguru.com/2009/04/cmake-detecting-platformoperating.html 41 | # TODO: apparently there is a different "correct" way to install files on Mac; 42 | # see: http://www.cmake.org/cmake/help/v3.0/prop_sf/MACOSX_PACKAGE_LOCATION.html 43 | # Though this seems unnecessary. Maybe we'll do this later. 44 | if(${CMAKE_GENERATOR} MATCHES "Xcode") 45 | # CMAKE_BUILD_TYPE will be one of Release, Debug, etc. 46 | set(_resources_dir "${_resources_dir}/${CMAKE_BUILD_TYPE}") 47 | endif() 48 | 49 | 50 | # Check to see if the target is a Mac OS X bundle. If so, set the resources dir to the appropriate 51 | # directory in the bundle 52 | get_property(_mac_bundle TARGET ${_arg_TARGET} PROPERTY MACOSX_BUNDLE SET) 53 | if (_mac_bundle) 54 | set(_resources_dir "${_resources_dir}/${_arg_TARGET}.app/Contents/Resources") 55 | endif() 56 | elseif(${CMAKE_SYSTEM_NAME} MATCHES "Windows") 57 | # CMAKE_CFG_INTDIR will be one of Release, Debug, etc. 58 | set(_resources_dir "${_resources_dir}/${CMAKE_CFG_INTDIR}") 59 | endif() 60 | 61 | # Add post-build rules for copying the resources into the correct place. 62 | # This should happen at the end of the build. 63 | foreach(_resource ${_arg_RELATIVE_PATH_RESOURCES}) 64 | # Add the post-build command for copying files (if different) 65 | add_custom_command( 66 | TARGET ${_arg_TARGET} 67 | POST_BUILD 68 | COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/${_resource}" "${_resources_dir}/${_resource}" 69 | ) 70 | endforeach() 71 | foreach(_resource ${_arg_ABSOLUTE_PATH_RESOURCES}) 72 | # Add the post-build command for copying files (if different) 73 | get_filename_component(_resource_filename_component "${_resource}" NAME) 74 | add_custom_command( 75 | TARGET ${_arg_TARGET} 76 | POST_BUILD 77 | COMMAND ${CMAKE_COMMAND} -E copy_if_different "${_resource}" "${_resources_dir}/${_resource_filename_component}" 78 | ) 79 | endforeach() 80 | 81 | # Also add install rules for Linux 82 | if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") 83 | install(FILES ${_arg_RESOURCES} DESTINATION ${CMAKE_INSTALL_PREFIX}) 84 | endif() 85 | endfunction() 86 | -------------------------------------------------------------------------------- /cmake-module/FindAntTweakBar.cmake: -------------------------------------------------------------------------------- 1 | #.rst 2 | # FindAntTweakBar 3 | # ------------ 4 | # 5 | # Created by Chen Zheng. 6 | # Locate and configure AntTweakBar 7 | # 8 | # Interface Targets 9 | # ^^^^^^^^^^^^^^^^^ 10 | # FindAntTweakBar::FindAntTweakBar 11 | # 12 | # Variables 13 | # ^^^^^^^^^ 14 | # AntTweakBar_DIR 15 | # AntTweakBar_FOUND 16 | # AntTweakBar_INCLUDE_DIR 17 | # AntTweakBar_LIBRARIES 18 | # AntTweakBar_64_BIT - can be overridden 19 | # 20 | find_path(AntTweakBar_DIR 21 | NAMES include/AntTweakBar.h 22 | PATH_SUFFIXES AntTweakBar) 23 | 24 | find_path( 25 | AntTweakBar_INCLUDE_DIR 26 | NAMES include/AntTweakBar.h 27 | HINTS ${AntTweakBar_ROOT_DIR} 28 | PATH_SUFFIXES include 29 | NO_DEFAULT_PATH 30 | ) 31 | 32 | if(DEFINED BUILD_64_BIT) 33 | set(AntTweakBar_64_BIT ON) 34 | endif() 35 | 36 | if(NOT DEFINED AntTweakBar_64_BIT) 37 | if (CMAKE_SIZEOF_VOID_P EQUAL 8) # 64bit 38 | set(AntTweakBar_64_BIT ON) 39 | else() # 32bit 40 | set(AntTweakBar_64_BIT OFF) 41 | endif() 42 | endif() 43 | 44 | if(MSVC) 45 | if(AntTweakBar_64_BIT) 46 | find_library(AntTweakBar_LIBRARY_RELEASE "AntTweakBar64.lib" HINTS "${AntTweakBar_DIR}" PATH_SUFFIXES lib) 47 | find_library(AntTweakBar_LIBRARY_DEBUG "AntTweakBar64.lib" HINTS "${AntTweakBar_DIR}" PATH_SUFFIXES lib/debug) 48 | else() 49 | find_library(AntTweakBar_LIBRARY_RELEASE "AntTweakBar.lib" HINTS "${AntTweakBar_DIR}" PATH_SUFFIXES lib) 50 | find_library(AntTweakBar_LIBRARY_DEBUG "AntTweakBar.lib" HINTS "${AntTweakBar_DIR}" PATH_SUFFIXES lib/debug) 51 | endif() 52 | else() 53 | # TODO: Need more logic on Mac/Linux 54 | find_library(AntTweakBar_LIBRARY_RELEASE "libAntTweakBar.a" HINTS "${AntTweakBar_DIR}" PATH_SUFFIXES lib) 55 | find_library(AntTweakBar_LIBRARY_DEBUG "libAntTweakBar.a" HINTS "${AntTweakBar_DIR}" PATH_SUFFIXES lib/debug) 56 | endif() 57 | 58 | include(SelectConfigurations) 59 | select_configurations(AntTweakBar LIBRARY LIBRARIES) 60 | 61 | include(FindPackageHandleStandardArgs) 62 | find_package_handle_standard_args( AntTweakBar DEFAULT_MSG 63 | AntTweakBar_DIR AntTweakBar_INCLUDE_DIR 64 | AntTweakBar_LIBRARY_RELEASE AntTweakBar_LIBRARY_DEBUG) 65 | 66 | include(CreateImportTargetHelpers) 67 | 68 | generate_import_target(AntTweakBar STATIC) 69 | -------------------------------------------------------------------------------- /cmake-module/FindAssimp.cmake: -------------------------------------------------------------------------------- 1 | #.rst 2 | # FindAssimp 3 | # ------------ 4 | # 5 | # Created by Raffi Bedikian. 6 | # Locate and configure Assimp 7 | # 8 | # Interface Targets 9 | # ^^^^^^^^^^^^^^^^^ 10 | # Assimp::Assimp 11 | # 12 | # Variables 13 | # ^^^^^^^^^ 14 | # Assimp_ROOT_DIR 15 | # Assimp_FOUND 16 | # Assimp_INCLUDE_DIR 17 | # Assimp_LIBRARIES 18 | # 19 | 20 | find_path(Assimp_ROOT_DIR 21 | NAMES include/assimp/scene.h 22 | PATH_SUFFIXES assimp-${Assimp_FIND_VERSION} 23 | assimp) 24 | 25 | set(Assimp_INCLUDE_DIR ${Assimp_ROOT_DIR}/include) 26 | 27 | if(MSVC) 28 | find_library(Assimp_LIBRARY_RELEASE "assimp.lib" HINTS "${Assimp_ROOT_DIR}" PATH_SUFFIXES lib) 29 | find_library(Assimp_LIBRARY_DEBUG "assimpd.lib" HINTS "${Assimp_ROOT_DIR}" PATH_SUFFIXES lib) 30 | else(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") 31 | find_library(Assimp_LIBRARY_RELEASE "libassimp.a" HINTS "${Assimp_ROOT_DIR}" PATH_SUFFIXES lib) 32 | find_library(Assimp_LIBRARY_DEBUG "libassimp.a" HINTS "${Assimp_ROOT_DIR}" PATH_SUFFIXES lib) 33 | endif() 34 | include(SelectConfigurations) 35 | select_configurations(Assimp LIBRARY LIBRARIES) 36 | 37 | include(FindPackageHandleStandardArgs) 38 | find_package_handle_standard_args(Assimp DEFAULT_MSG Assimp_ROOT_DIR Assimp_INCLUDE_DIR Assimp_LIBRARY_RELEASE Assimp_LIBRARY_DEBUG) 39 | 40 | include(CreateImportTargetHelpers) 41 | 42 | generate_import_target(Assimp STATIC) 43 | 44 | -------------------------------------------------------------------------------- /cmake-module/FindBreakpad.cmake: -------------------------------------------------------------------------------- 1 | #.rst 2 | # FindBreakpad 3 | # ------------ 4 | # 5 | # Created by Walter Gray. 6 | # Locate and configure Breakpad 7 | # 8 | # Interface Targets 9 | # ^^^^^^^^^^^^^^^^^ 10 | # Breakpad::Breakpad 11 | # 12 | # Variables 13 | # ^^^^^^^^^ 14 | # Breakpad_FOUND 15 | # Breakpad_INCLUDE_DIR 16 | # Breakpad_LIBRARY_DIR 17 | # Breakpad_ROOT_DIR 18 | 19 | find_path(Breakpad_ROOT_DIR 20 | NAMES include/google_breakpad/common/breakpad_types.h 21 | PATH_SUFFIXES breakpad-${Breakpad_FIND_VERSION} 22 | breakpad) 23 | 24 | set(Breakpad_INCLUDE_DIR "${Breakpad_ROOT_DIR}/include") 25 | set(Breakpad_LIBRARY_DIR "${Breakpad_ROOT_DIR}/lib") 26 | foreach(_lib IN ITEMS common.lib exception_handler.lib crash_generation_client.lib) 27 | list(APPEND Breakpad_LIBRARIES "${Breakpad_LIBRARY_DIR}/${_lib}") 28 | endforeach() 29 | 30 | set(Breakpad_LIBRARY ${Breakpad_LIBRARIES}) 31 | 32 | include(FindPackageHandleStandardArgs) 33 | find_package_handle_standard_args(Breakpad DEFAULT_MSG Breakpad_ROOT_DIR Breakpad_INCLUDE_DIR Breakpad_LIBRARY_DIR Breakpad_LIBRARIES) 34 | 35 | include(CreateImportTargetHelpers) 36 | generate_import_target(Breakpad STATIC) 37 | -------------------------------------------------------------------------------- /cmake-module/FindBullet.cmake: -------------------------------------------------------------------------------- 1 | #.rst 2 | # FindBullet 3 | # ------------ 4 | # 5 | # Locate and configure Bullet Physics 6 | # 7 | # Interface Targets 8 | # ^^^^^^^^^^^^^^^^^ 9 | # FindBullet::FindBullet 10 | # 11 | # Variables 12 | # ^^^^^^^^^ 13 | # Bullet_ROOT_DIR 14 | # Bullet_FOUND 15 | # Bullet_INCLUDE_DIR 16 | # Bullet_LIBRARIES 17 | # 18 | 19 | 20 | find_path(Bullet_ROOT_DIR NAMES "src/btBulletDynamicsCommon.h" PATH_SUFFIXES bullet-2.82-r2704) 21 | 22 | set(Bullet_INCLUDE_DIR ${Bullet_ROOT_DIR}/src) 23 | 24 | if(MSVC) 25 | find_library(Bullet_COLLISION_LIBRARY_RELEASE NAMES "BulletCollision.lib" HINTS "${Bullet_ROOT_DIR}/lib/Win32/VS2013/Release" PATH_SUFFIXES lib) 26 | find_library(Bullet_DYNAMICS_LIBRARY_RELEASE NAMES "BulletDynamics.lib" HINTS "${Bullet_ROOT_DIR}/lib/Win32/VS2013/Release" PATH_SUFFIXES lib) 27 | find_library(Bullet_LINEAR_MATH_LIBRARY_RELEASE NAMES "LinearMath.lib" HINTS "${Bullet_ROOT_DIR}/lib/Win32/VS2013/Release" PATH_SUFFIXES lib) 28 | 29 | find_library(Bullet_COLLISION_LIBRARY_DEBUG NAMES "BulletCollision_Debug.lib" HINTS "${Bullet_ROOT_DIR}/lib/Win32/VS2013/Debug" PATH_SUFFIXES lib) 30 | find_library(Bullet_DYNAMICS_LIBRARY_DEBUG NAMES "BulletDynamics_Debug.lib" HINTS "${Bullet_ROOT_DIR}/lib/Win32/VS2013/Debug" PATH_SUFFIXES lib) 31 | find_library(Bullet_LINEAR_MATH_LIBRARY_DEBUG NAMES "LinearMath_Debug.lib" HINTS "${Bullet_ROOT_DIR}/lib/Win32/VS2013/Debug" PATH_SUFFIXES lib) 32 | 33 | add_library(Bullet::Collision STATIC IMPORTED) 34 | set_target_properties(Bullet::Collision PROPERTIES IMPORTED_LOCATION_DEBUG ${Bullet_COLLISION_LIBRARY_DEBUG}) 35 | set_target_properties(Bullet::Collision PROPERTIES IMPORTED_LOCATION_RELEASE ${Bullet_COLLISION_LIBRARY_RELEASE}) 36 | 37 | add_library(Bullet::Dynamics STATIC IMPORTED) 38 | set_target_properties(Bullet::Dynamics PROPERTIES IMPORTED_LOCATION_DEBUG ${Bullet_DYNAMICS_LIBRARY_DEBUG}) 39 | set_target_properties(Bullet::Dynamics PROPERTIES IMPORTED_LOCATION_RELEASE ${Bullet_DYNAMICS_LIBRARY_RELEASE}) 40 | 41 | add_library(Bullet::LinearMath STATIC IMPORTED) 42 | set_target_properties(Bullet::LinearMath PROPERTIES IMPORTED_LOCATION_DEBUG ${Bullet_LINEAR_MATH_LIBRARY_DEBUG}) 43 | set_target_properties(Bullet::LinearMath PROPERTIES IMPORTED_LOCATION_RELEASE ${Bullet_LINEAR_MATH_LIBRARY_RELEASE}) 44 | 45 | add_library(Bullet::Bullet INTERFACE IMPORTED GLOBAL) 46 | target_link_libraries(Bullet::Bullet INTERFACE Bullet::Collision Bullet::Dynamics Bullet::LinearMath) 47 | set_target_properties(Bullet::Bullet PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${Bullet_INCLUDE_DIR}) 48 | elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") # Mac 49 | find_library(Bullet_COLLISION_LIBRARY_RELEASE NAMES "BulletCollision.a" HINTS "${Bullet_ROOT_DIR}/lib/Mac/Release" PATH_SUFFIXES lib) 50 | find_library(Bullet_DYNAMICS_LIBRARY_RELEASE NAMES "BulletDynamics.a" HINTS "${Bullet_ROOT_DIR}/lib/Mac/Release" PATH_SUFFIXES lib) 51 | find_library(Bullet_LINEAR_MATH_LIBRARY_RELEASE NAMES "LinearMath.a" HINTS "${Bullet_ROOT_DIR}/lib/Mac/Release" PATH_SUFFIXES lib) 52 | 53 | find_library(Bullet_COLLISION_LIBRARY_DEBUG NAMES "BulletCollision_Debug.a" HINTS "${Bullet_ROOT_DIR}/lib/Mac/Debug" PATH_SUFFIXES lib) 54 | find_library(Bullet_DYNAMICS_LIBRARY_DEBUG NAMES "BulletDynamics_Debug.a" HINTS "${Bullet_ROOT_DIR}/lib/Mac/Debug" PATH_SUFFIXES lib) 55 | find_library(Bullet_LINEAR_MATH_LIBRARY_DEBUG NAMES "LinearMath_Debug.a" HINTS "${Bullet_ROOT_DIR}/lib/Mac/Debug" PATH_SUFFIXES lib) 56 | 57 | set(Bullet_LIBRARY_RELEASE "${Bullet_COLLISION_LIBRARY_RELEASE}" "${Bullet_DYNAMICS_LIBRARY_RELEASE}" "${Bullet_LINEAR_MATH_LIBRARY_RELEASE}") 58 | set(Bullet_LIBRARY_DEBUG "${Bullet_COLLISION_LIBRARY_DEBUG}" "${Bullet_DYNAMICS_LIBRARY_DEBUG}" "${Bullet_LINEAR_MATH_LIBRARY_DEBUG}") 59 | 60 | include(FindPackageHandleStandardArgs) 61 | find_package_handle_standard_args(Bullet DEFAULT_MSG Bullet_ROOT_DIR Bullet_INCLUDE_DIR Bullet_LIBRARY_RELEASE Bullet_LIBRARY_DEBUG) 62 | else() 63 | # No linux support from Bullet! 64 | endif() 65 | mark_as_advanced(Bullet_COLLISION_LIBRARY_RELEASE) 66 | mark_as_advanced(Bullet_DYNAMICS_LIBRARY_RELEASE) 67 | mark_as_advanced(Bullet_LINEAR_MATH_LIBRARY_RELEASE) 68 | mark_as_advanced(Bullet_COLLISION_LIBRARY_DEBUG) 69 | mark_as_advanced(Bullet_DYNAMICS_LIBRARY_DEBUG) 70 | mark_as_advanced(Bullet_LINEAR_MATH_LIBRARY_DEBUG) 71 | 72 | include(SelectConfigurations) 73 | select_configurations(Bullet LIBRARY LIBRARIES) 74 | 75 | include(CreateImportTargetHelpers) 76 | 77 | generate_import_target(Bullet STATIC) 78 | -------------------------------------------------------------------------------- /cmake-module/FindCURL.cmake: -------------------------------------------------------------------------------- 1 | #.rst 2 | # FindCURL 3 | # ------------ 4 | # 5 | # Created by Walter Gray. 6 | # Locate and configure CURL 7 | # 8 | # Interface Targets 9 | # ^^^^^^^^^^^^^^^^^ 10 | # CURL::CURL 11 | # 12 | # Variables 13 | # ^^^^^^^^^ 14 | # CURL_ROOT_DIR 15 | # CURL_FOUND 16 | # CURL_INCLUDE_DIR 17 | # CURL_LIBRARIES 18 | # CURL_LIBRARY_RELEASE 19 | # CURL_LIBRARY_DEBUG 20 | 21 | find_path(CURL_ROOT_DIR 22 | NAMES include/curl/curl.h 23 | PATH_SUFFIXES curl-${CURL_FIND_VERSION} 24 | curl) 25 | 26 | set(CURL_INCLUDE_DIR ${CURL_ROOT_DIR}/include) 27 | 28 | if(MSVC) 29 | find_library(CURL_LIBRARY_RELEASE "libcurl.lib" HINTS "${CURL_ROOT_DIR}/lib/release") 30 | find_library(CURL_LIBRARY_DEBUG "libcurl.lib" HINTS "${CURL_ROOT_DIR}/lib/debug") 31 | else() 32 | find_library(CURL_LIBRARY_RELEASE "libcurl.a" HINTS "${CURL_ROOT_DIR}/lib") 33 | find_library(CURL_LIBRARY_DEBUG "libcurl.a" HINTS "${CURL_ROOT_DIR}/lib") 34 | endif() 35 | include(SelectConfigurations) 36 | select_configurations(CURL LIBRARY LIBRARIES) 37 | 38 | include(FindPackageHandleStandardArgs) 39 | find_package_handle_standard_args(CURL DEFAULT_MSG CURL_INCLUDE_DIR CURL_LIBRARIES) 40 | 41 | include(CreateImportTargetHelpers) 42 | generate_import_target(CURL STATIC) -------------------------------------------------------------------------------- /cmake-module/FindCinder.cmake: -------------------------------------------------------------------------------- 1 | #.rst 2 | # FindCinder 3 | # ---------- 4 | # 5 | # Created by Walter Gray 6 | # Locate and configure cinder 0.8.5 for vc2010. Untested with other versions. 7 | # 8 | # Interface Targets 9 | # ^^^^^^^^^^^^^^^^^ 10 | # Cinder::Cinder 11 | # Interface target. references Cinder::Core and all 12 | # required boost libraries with the required ordering. 13 | # 14 | # Cinder::Core 15 | # Static import target. Does not include cinder's dependencies. 16 | # Typically not referenced outside of Cinder::Cinder 17 | # 18 | # Variables 19 | # ^^^^^^^^^ 20 | # Cinder_ROOT_DIR 21 | # Root of the cinder package 22 | # Cinder_FOUND 23 | # If false, do not link to Cinder 24 | # Cinder_LIBRARIES 25 | # The names of the libraries to feed into target_link_libraries 26 | # Cinder_INCLUDE_DIR 27 | # Where to find the root of the cinder includes 28 | # Cinder_LIBRARY_ 29 | # The location of the main cinder library 30 | # 31 | # This module will also find and add the Boost package which is included with Cinder, 32 | # create a master Boost::Boost interface library which links to a series of 33 | # Boost:: static import libraries. 34 | 35 | if(MSVC10) 36 | set(_compiler_SUFFIX "vc2010") 37 | endif() 38 | 39 | find_path(Cinder_ROOT_DIR 40 | NAMES include/cinder/Cinder.h 41 | PATH_SUFFIXES cinder_${Cinder_FIND_VERSION}_${_compiler_SUFFIX} 42 | cinder_${Cinder_FIND_VERSION} 43 | cinder) 44 | 45 | 46 | find_path(Cinder_INCLUDE_DIR 47 | NAMES "cinder/Cinder.h" 48 | HINTS "${Cinder_ROOT_DIR}" 49 | PATH_SUFFIXES "include") 50 | 51 | find_library(Cinder_LIBRARY_RELEASE "cinder.lib" HINTS "${Cinder_ROOT_DIR}/lib") 52 | find_library(Cinder_LIBRARY_DEBUG "cinder_d.lib" HINTS "${Cinder_ROOT_DIR}/lib") 53 | 54 | include(SelectConfigurations) 55 | select_configurations(Cinder LIBRARY LIBRARIES) 56 | 57 | #Find Boost 58 | if(MSVC) 59 | set(BOOST_LIBRARYDIR "${Cinder_ROOT_DIR}/lib/msw") 60 | set(_boost_components chrono date_time filesystem regex system thread) 61 | else() 62 | set(BOOST_LIBRARYDIR "${Cinder_ROOT_DIR}/lib/macosx") 63 | set(_boost_components date_time filesystem system) 64 | endif() 65 | 66 | 67 | set(BOOST_ROOT ${Cinder_ROOT_DIR}/boost) 68 | set(Boost_USE_STATIC_RUNTIME ON) 69 | set(Boost_USE_MULTITHREADED ON) 70 | set(Boost_USE_STATIC_LIBS ON) 71 | 72 | find_package(Boost REQUIRED QUIET COMPONENTS ${_boost_components} ) 73 | 74 | include(FindPackageHandleStandardArgs) 75 | find_package_handle_standard_args(Cinder DEFAULT_MSG Cinder_ROOT_DIR Cinder_LIBRARIES Cinder_INCLUDE_DIR) 76 | 77 | #Setup the interface targets 78 | 79 | #Thanks to cinder's custom boost layout, we have to first create import targets 80 | #for all of the boost components, then link them with the Cinder master interface library 81 | #BEFORE linking in the actual cinder import target 82 | include(CreateImportTargetHelpers) 83 | 84 | if(Cinder_FOUND AND NOT TARGET Cinder::Cinder) 85 | generate_import_target(Boost INTERFACE) 86 | foreach(_component ${_boost_components}) 87 | string(TOUPPER ${_component} _componentUPPER) 88 | generate_import_target(Boost_${_componentUPPER} STATIC TARGET Boost::${_component}) 89 | target_link_libraries(Boost::Boost INTERFACE Boost::${_component}) 90 | endforeach() 91 | 92 | generate_import_target(Cinder STATIC TARGET Cinder::Core) 93 | add_library(Cinder::Cinder INTERFACE IMPORTED GLOBAL) 94 | target_link_libraries(Cinder::Cinder INTERFACE Boost::Boost Cinder::Core) 95 | endif() -------------------------------------------------------------------------------- /cmake-module/FindEigen.cmake: -------------------------------------------------------------------------------- 1 | #.rst 2 | # FindEigen 3 | # ---------- 4 | # 5 | # Created by Walter Gray 6 | # Locate and configure Eigen 7 | # 8 | # Interface Targets 9 | # ^^^^^^^^^^^^^^^^^ 10 | # Eigen::Eigen 11 | # 12 | # Variables 13 | # ^^^^^^^^^ 14 | # Eigen_ROOT_DIR 15 | # Eigen_FOUND 16 | # Eigen_INCLUDE_DIR 17 | 18 | find_path(Eigen_ROOT_DIR 19 | NAMES Eigen/Eigen 20 | PATH_SUFFIXES eigen-${Eigen_FIND_VERSION} 21 | eigen) 22 | 23 | set(Eigen_INCLUDE_DIR "${Eigen_ROOT_DIR}") 24 | if(EXISTS ${Eigen_INCLUDE_DIR}) 25 | set(Eigen_FOUND) 26 | endif() 27 | 28 | include(FindPackageHandleStandardArgs) 29 | find_package_handle_standard_args(Eigen DEFAULT_MSG Eigen_INCLUDE_DIR) 30 | 31 | include(CreateImportTargetHelpers) 32 | generate_import_target(Eigen INTERFACE) -------------------------------------------------------------------------------- /cmake-module/FindFbxSdk.cmake: -------------------------------------------------------------------------------- 1 | #.rst 2 | # FindFbxSdk 3 | # ------------ 4 | # 5 | # Created by Walter Gray. 6 | # Locate and configure FbxSdk 7 | # 8 | # Interface Targets 9 | # ^^^^^^^^^^^^^^^^^ 10 | # FbxSdk::FbxSdk 11 | # 12 | # Variables 13 | # ^^^^^^^^^ 14 | # FbxSdk_ROOT_DIR 15 | # FbxSdk_FOUND 16 | # FbxSdk_INCLUDE_DIR 17 | # FbxSdk_LIBRARIES 18 | 19 | find_path(FbxSdk_ROOT_DIR 20 | NAMES include/fbxsdk.h 21 | HINTS ${EXTERNAL_LIBRARY_DIR} 22 | PATH_SUFFIXES fbx-sdk-${FbxSdk_FIND_VERSION} 23 | fbx-sdk 24 | # NOTE: 2014.2 does not compile with VS2012 25 | # fbx-sdk/2014.2 26 | # TODO: we should make this folder structure more consistent, most likely fbx-sdk/2015.1 27 | fbx-sdk/2015.1 28 | fbx2015/2015.1) 29 | 30 | set(FbxSdk_INCLUDE_DIR "${FbxSdk_ROOT_DIR}/include") 31 | 32 | if (CMAKE_SIZEOF_VOID_P EQUAL 8) # 64bit 33 | set(BUILD_BIT_TYPE "x64") 34 | else() # 32bit 35 | set(BUILD_BIT_TYPE "x86") 36 | endif() 37 | 38 | if(MSVC) 39 | find_library(FbxSdk_LIBRARY_RELEASE "libfbxsdk-md.lib" HINTS "${FbxSdk_ROOT_DIR}/lib/vs2013/${BUILD_BIT_TYPE}/release") 40 | find_library(FbxSdk_LIBRARY_DEBUG "libfbxsdk-md.lib" HINTS "${FbxSdk_ROOT_DIR}/lib/vs2013/${BUILD_BIT_TYPE}/debug") 41 | elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux") # This is the correct way to detect Linux operating system -- see http://www.openguru.com/2009/04/cmake-detecting-platformoperating.html 42 | find_library(FbxSdk_LIBRARY_RELEASE "libfbxsdk.a" HINTS "${FbxSdk_ROOT_DIR}/lib/gcc4/${BUILD_BIT_TYPE}/release") 43 | find_library(FbxSdk_LIBRARY_DEBUG "libfbxsdk.a" HINTS "${FbxSdk_ROOT_DIR}/lib/gcc4/${BUILD_BIT_TYPE}/debug") 44 | else() 45 | find_library(FbxSdk_LIBRARY_RELEASE "libfbxsdk.a" HINTS "${FbxSdk_ROOT_DIR}/lib/clang/ub/release") 46 | find_library(FbxSdk_LIBRARY_DEBUG "libfbxsdk.a" HINTS "${FbxSdk_ROOT_DIR}/lib/clang/ub/debug") 47 | endif() 48 | include(SelectConfigurations) 49 | select_configurations(FbxSdk LIBRARY LIBRARIES) 50 | 51 | include(FindPackageHandleStandardArgs) 52 | find_package_handle_standard_args(FbxSdk DEFAULT_MSG FbxSdk_INCLUDE_DIR FbxSdk_LIBRARIES) 53 | 54 | include(CreateImportTargetHelpers) 55 | generate_import_target(FbxSdk STATIC) 56 | 57 | -------------------------------------------------------------------------------- /cmake-module/FindFreeImage.cmake: -------------------------------------------------------------------------------- 1 | #.rst 2 | # FindFreeImage 3 | # ------------ 4 | # 5 | # Created by Walter Gray. 6 | # Locate and configure FreeImage 7 | # 8 | # Interface Targets 9 | # ^^^^^^^^^^^^^^^^^ 10 | # FreeImage::FreeImage 11 | # 12 | # Variables 13 | # ^^^^^^^^^ 14 | # FreeImage_ROOT_DIR 15 | # FreeImage_FOUND 16 | # FreeImage_INCLUDE_DIR 17 | # FreeImage_LIBRARIES 18 | # 19 | find_path(FreeImage_ROOT_DIR 20 | NAMES Dist/FreeImage.h 21 | include/FreeImage.h 22 | PATH_SUFFIXES FreeImage-${FreeImage_FIND_VERSION} 23 | FreeImage) 24 | 25 | find_path(FreeImage_INCLUDE_DIR "FreeImage.h" 26 | HINTS "${FreeImage_ROOT_DIR}" 27 | PATH_SUFFIXES Dist include) 28 | 29 | 30 | #Todo: add the ability to select between shared and dynamic versions 31 | if(MSVC) 32 | find_library(FreeImage_LIBRARY_RELEASE "FreeImage.lib" HINTS "${FreeImage_ROOT_DIR}" PATH_SUFFIXES lib Dist) 33 | find_library(FreeImage_LIBRARY_DEBUG "FreeImaged.lib" HINTS "${FreeImage_ROOT_DIR}" PATH_SUFFIXES lib Dist) 34 | else() 35 | find_library(FreeImage_LIBRARY_RELEASE "libfreeimage.a" HINTS "${FreeImage_ROOT_DIR}" PATH_SUFFIXES lib Dist) 36 | find_library(FreeImage_LIBRARY_DEBUG "libfreeimage.a" HINTS "${FreeImage_ROOT_DIR}" PATH_SUFFIXES lib Dist) 37 | endif() 38 | 39 | include(SelectConfigurations) 40 | select_configurations(FreeImage LIBRARY LIBRARIES) 41 | 42 | include(FindPackageHandleStandardArgs) 43 | find_package_handle_standard_args(FreeImage DEFAULT_MSG FreeImage_ROOT_DIR FreeImage_INCLUDE_DIR FreeImage_LIBRARY_RELEASE FreeImage_LIBRARY_DEBUG) 44 | 45 | include(CreateImportTargetHelpers) 46 | 47 | generate_import_target(FreeImage STATIC) 48 | -------------------------------------------------------------------------------- /cmake-module/FindGlew.cmake: -------------------------------------------------------------------------------- 1 | #.rst 2 | # FindGlew 3 | # ------------ 4 | # 5 | # Created by Raffi Bedikian. 6 | # Locate and configure Glew 7 | # 8 | # Interface Targets 9 | # ^^^^^^^^^^^^^^^^^ 10 | # FindGlew::FindGlew 11 | # 12 | # Variables 13 | # ^^^^^^^^^ 14 | # Glew_ROOT_DIR 15 | # Glew_FOUND 16 | # Glew_INCLUDE_DIR 17 | # Glew_LIBRARIES 18 | # 19 | find_path(Glew_ROOT_DIR 20 | NAMES include/GL/glew.h 21 | PATH_SUFFIXES glew-${Glew_FIND_VERSION} 22 | Glew) 23 | find_path( 24 | Glew_INCLUDE_DIR 25 | NAMES GL/glew.h 26 | HINTS ${Glew_ROOT_DIR} 27 | PATH_SUFFIXES include 28 | NO_DEFAULT_PATH 29 | ) 30 | 31 | if(MSVC) 32 | find_library(Glew_LIBRARY_RELEASE "glew32s.lib" HINTS "${Glew_ROOT_DIR}" PATH_SUFFIXES lib) 33 | find_library(Glew_LIBRARY_DEBUG "glew32s.lib" HINTS "${Glew_ROOT_DIR}" PATH_SUFFIXES lib) 34 | else() 35 | # Linux's glew-1.9.0 package's libs are in lib64 36 | find_library(Glew_LIBRARY_RELEASE "libGLEW.a" HINTS "${Glew_ROOT_DIR}" PATH_SUFFIXES lib lib64) 37 | find_library(Glew_LIBRARY_DEBUG "libGLEW.a" HINTS "${Glew_ROOT_DIR}" PATH_SUFFIXES lib lib64) 38 | endif() 39 | include(SelectConfigurations) 40 | select_configurations(Glew LIBRARY LIBRARIES) 41 | 42 | include(FindPackageHandleStandardArgs) 43 | find_package_handle_standard_args(Glew DEFAULT_MSG Glew_ROOT_DIR Glew_INCLUDE_DIR Glew_LIBRARY_RELEASE Glew_LIBRARY_DEBUG) 44 | 45 | include(CreateImportTargetHelpers) 46 | 47 | generate_import_target(Glew STATIC) 48 | -------------------------------------------------------------------------------- /cmake-module/FindInf2Cat.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find Inf2Cat 2 | # Once done this will define 3 | # Inf2Cat_FOUND - System has Inf2Cat 4 | # Inf2Cat_BIN - The path to Inf2Cat 5 | 6 | set(wdkregpath80 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots;KitsRoot]") 7 | get_filename_component(wdkpath80 ${wdkregpath80} ABSOLUTE) 8 | 9 | set(wdkregpath81 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots;KitsRoot81]") 10 | get_filename_component(wdkpath81 ${wdkregpath81} ABSOLUTE) 11 | 12 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) 13 | set(WDK_ARCH "x64") 14 | else() 15 | set(WDK_ARCH "x86") 16 | endif() 17 | 18 | # Directly locate inf2cat: 19 | find_program( 20 | Inf2Cat_BIN Inf2Cat 21 | PATHS ${wdkpath81} ${wdkpath80} ${WDK_ROOT_ALTERNATE} 22 | PATH_SUFFIXES bin/${WDK_ARCH} 23 | ) 24 | 25 | include(FindPackageHandleStandardArgs) 26 | find_package_handle_standard_args(Inf2Cat DEFAULT_MSG Inf2Cat_BIN) 27 | 28 | 29 | -------------------------------------------------------------------------------- /cmake-module/FindIrrklang.cmake: -------------------------------------------------------------------------------- 1 | #.rst 2 | # FindIrrklang 3 | # ------------ 4 | # 5 | # Created by Walter Gray. 6 | # Locate and configure Irrklang 7 | # 8 | # Interface Targets 9 | # ^^^^^^^^^^^^^^^^^ 10 | # Irrklang::Irrklang 11 | # 12 | # Variables 13 | # ^^^^^^^^^ 14 | # Irrklang_ROOT_DIR 15 | # Irrklang_FOUND 16 | # Irrklang_INCLUDE_DIR 17 | # Irrklang_LIBRARY 18 | # Irrklang_IMPORT_LIB 19 | 20 | find_path(Irrklang_ROOT_DIR 21 | NAMES include/irrKlang.h 22 | HINTS ${EXTERNAL_LIBRARY_DIR} 23 | PATH_SUFFIXES irrKlang-${Irrklang_FIND_VERSION} 24 | irrKlang) 25 | 26 | find_path(Irrklang_INCLUDE_DIR 27 | NAMES irrKlang.h 28 | HINTS "${Irrklang_ROOT_DIR}/include") 29 | 30 | if(MSVC) 31 | find_file(Irrklang_LIBRARY 32 | NAMES irrKlang.dll 33 | HINTS "${Irrklang_ROOT_DIR}/bin/win32-visualStudio/") 34 | find_library(Irrklang_IMPORT_LIB 35 | NAMES irrKlang.lib 36 | HINTS "${Irrklang_ROOT_DIR}/lib/win32-visualStudio/") 37 | mark_as_advanced(Irrklang_IMPORT_LIB) 38 | else() 39 | find_library(Irrklang_LIBRARY 40 | NAMES libirrklang.dylib 41 | HINTS "${Irrklang_ROOT_DIR}/bin/macosx-gcc/") 42 | endif() 43 | 44 | include(FindPackageHandleStandardArgs) 45 | find_package_handle_standard_args(Irrklang DEFAULT_MSG Irrklang_INCLUDE_DIR Irrklang_LIBRARY) 46 | 47 | include(CreateImportTargetHelpers) 48 | generate_import_target(Irrklang SHARED) -------------------------------------------------------------------------------- /cmake-module/FindLeap.cmake: -------------------------------------------------------------------------------- 1 | #.rst 2 | # FindLeap 3 | # ------------ 4 | # 5 | # Created by Walter Gray. 6 | # Locate and configure Leap 7 | # 8 | # Interface Targets 9 | # ^^^^^^^^^^^^^^^^^ 10 | # Leap::Leap 11 | # 12 | # Variables 13 | # ^^^^^^^^^ 14 | # Leap_ROOT_DIR 15 | # Leap_FOUND 16 | # Leap_INCLUDE_DIR 17 | # Leap_LIBRARY 18 | # Leap_IMPORT_LIB 19 | 20 | find_path(Leap_ROOT_DIR 21 | NAMES include/Leap.h 22 | HINTS ${EXTERNAL_LIBRARY_DIR} 23 | PATH_SUFFIXES LeapSDK-${Leap_FIND_VERSION} 24 | LeapSDK) 25 | #we should check the version.txt file here... 26 | 27 | set(Leap_INCLUDE_DIR "${Leap_ROOT_DIR}/include") 28 | if(MSVC) 29 | find_library(Leap_IMPORT_LIB_RELEASE "Leap.lib" HINTS "${Leap_ROOT_DIR}/lib/x86") 30 | find_library(Leap_IMPORT_LIB_DEBUG "Leapd.lib" HINTS "${Leap_ROOT_DIR}/lib/x86") 31 | 32 | find_file(Leap_LIBRARY_RELEASE 33 | NAMES Leap.dll 34 | HINTS "${Leap_ROOT_DIR}/lib/x86") 35 | find_file(Leap_LIBRARY_DEBUG 36 | NAMES Leapd.dll 37 | Leap.dll #fallback on the release library if we must 38 | HINTS "${Leap_ROOT_DIR}/lib/x86") 39 | mark_as_advanced(Leap_IMPORT_LIB_RELEASE Leap_IMPORT_LIB_DEBUG) 40 | else() 41 | string(FIND "${CMAKE_CXX_FLAGS}" "-stdlib=libc++" found_lib) 42 | 43 | if(${found_lib} GREATER -1) 44 | set(_libdir ${Leap_ROOT_DIR}/lib) 45 | else() 46 | set(_libdir ${Leap_ROOT_DIR}/lib/libstdc++) 47 | endif() 48 | 49 | find_library(Leap_LIBRARY_RELEASE 50 | NAMES libLeap.dylib 51 | HINTS "${_libdir}") 52 | find_library(Leap_LIBRARY_DEBUG 53 | NAMES libLeapd.dylib 54 | libLeap.dylib #fallback on the release library 55 | HINTS "${_libdir}") 56 | endif() 57 | 58 | 59 | include(FindPackageHandleStandardArgs) 60 | find_package_handle_standard_args(Leap DEFAULT_MSG Leap_ROOT_DIR Leap_INCLUDE_DIR Leap_LIBRARY_RELEASE Leap_LIBRARY_DEBUG) 61 | 62 | include(CreateImportTargetHelpers) 63 | generate_import_target(Leap SHARED) 64 | -------------------------------------------------------------------------------- /cmake-module/FindNanoSVG.cmake: -------------------------------------------------------------------------------- 1 | #.rst 2 | # FindNanoSVG 3 | # ---------- 4 | # 5 | # Created by Jonathan Marsden 6 | # Locate and configure nanosvg 7 | # 8 | # Interface Targets 9 | # ^^^^^^^^^^^^^^^^^ 10 | # NanoSVG::NanoSVG 11 | # 12 | # Variables 13 | # ^^^^^^^^^ 14 | # NanoSVG_ROOT_DIR 15 | # NanoSVG_FOUND 16 | # NanoSVG_INCLUDE_DIR 17 | 18 | find_path(NanoSVG_ROOT_DIR 19 | NAMES include/nanosvg.h 20 | PATH_SUFFIXES nanosvg) 21 | 22 | set(NanoSVG_INCLUDE_DIR "${NanoSVG_ROOT_DIR}/include") 23 | if(EXISTS ${NanoSVG_INCLUDE_DIR}) 24 | set(NanoSVG_FOUND) 25 | endif() 26 | 27 | include(FindPackageHandleStandardArgs) 28 | find_package_handle_standard_args(NanoSVG DEFAULT_MSG NanoSVG_INCLUDE_DIR) 29 | 30 | include(CreateImportTargetHelpers) 31 | generate_import_target(NanoSVG INTERFACE) 32 | -------------------------------------------------------------------------------- /cmake-module/FindOculusSDK.cmake: -------------------------------------------------------------------------------- 1 | #.rst 2 | # FindOculusSDK 3 | # ------------ 4 | # 5 | # Locate and configure Oculus 6 | # 7 | # Interface Targets 8 | # ^^^^^^^^^^^^^^^^^ 9 | # FindOculusSDK::FindOculusSDK 10 | # 11 | # Variables 12 | # ^^^^^^^^^ 13 | # OculusSDK_ROOT_DIR 14 | # OculusSDK_INCLUDE_DIR 15 | # OculusSDK_LIBRARIES_RELEASE 16 | # OculusSDK_LIBRARIES_DEBUG 17 | # 18 | 19 | 20 | find_path(OculusSDK_ROOT_DIR NAMES "LibOVR/Include/OVR.h" PATH_SUFFIXES OculusSDK) 21 | 22 | #We include the src directory as well since we need OVR_CAPI_GL/D3D 23 | set(OculusSDK_INCLUDE_DIR "${OculusSDK_ROOT_DIR}/LibOVR/Include" "${OculusSDK_ROOT_DIR}/LibOVR/Src") 24 | 25 | if(MSVC) 26 | find_library(OculusSDK_LIBRARY_RELEASE "libovr.lib" HINTS "${OculusSDK_ROOT_DIR}/LibOVR/Lib/Win32/VS2013" PATH_SUFFIXES lib) 27 | find_library(OculusSDK_LIBRARY_DEBUG "libovrd.lib" HINTS "${OculusSDK_ROOT_DIR}/LibOVR/Lib/Win32/VS2013" PATH_SUFFIXES lib) 28 | elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") # Mac 29 | find_library(OculusSDK_LIBRARY_RELEASE "libovr.a" HINTS "${OculusSDK_ROOT_DIR}/LibOVR/Lib/Mac/Release" PATH_SUFFIXES lib) 30 | find_library(OculusSDK_LIBRARY_DEBUG "libovr.a" HINTS "${OculusSDK_ROOT_DIR}/LibOVR/Lib/Mac/Debug" PATH_SUFFIXES lib) 31 | else() 32 | # No linux support from Oculus Rift! 33 | endif() 34 | include(SelectConfigurations) 35 | select_configurations(OculusSDK LIBRARY LIBRARIES) 36 | 37 | include(FindPackageHandleStandardArgs) 38 | find_package_handle_standard_args(OculusSDK DEFAULT_MSG OculusSDK_ROOT_DIR OculusSDK_INCLUDE_DIR OculusSDK_LIBRARY_RELEASE OculusSDK_LIBRARY_DEBUG) 39 | 40 | include(CreateImportTargetHelpers) 41 | 42 | generate_import_target(OculusSDK STATIC) 43 | 44 | if(WIN32) 45 | #Oculus dev kit relies on winmm and winsock2 46 | target_link_libraries(OculusSDK::OculusSDK INTERFACE winmm Ws2_32) 47 | endif() -------------------------------------------------------------------------------- /cmake-module/FindOpenGL.cmake: -------------------------------------------------------------------------------- 1 | #.rst: 2 | # FindOpenGL 3 | # ---------- 4 | # 5 | # Total refactor of the cmake-supplied FindOpenGL.cmake module to be 6 | # more in-line with the generate_import_target command. 7 | 8 | set(_OpenGL_REQUIRED_VARS "") 9 | 10 | if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") 11 | list(APPEND _OpenGL_REQUIRED_VARS OpenGL_LIBRARY) 12 | 13 | #opengl32.lib lives in the windows sdk, which means we can't use find_library since windows 14 | #doesn't add the wdk directory to any path variable that I could find. 15 | set(OpenGL_LIBRARY opengl32.lib CACHE STRING "OpenGL library for win32") 16 | set(OpenGL_INTERFACE_LIBS glu32.lib CACHE STRING "GLU library for win32") 17 | elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") # Mac 18 | list(APPEND _OpenGL_REQUIRED_VARS OpenGL_INCLUDE_DIR) 19 | find_path(OpenGL_INCLUDE_DIR OpenGL/gl.h DOC "Include for OpenGL on OSX") 20 | set(OpenGL_INTERFACE_LIBS "-framework OpenGL;-framework AGL") 21 | else() 22 | # The first line below is to make sure that the proper headers 23 | # are used on a Linux machine with the NVidia drivers installed. 24 | # They replace Mesa with NVidia's own library but normally do not 25 | # install headers and that causes the linking to 26 | # fail since the compiler finds the Mesa headers but NVidia's library. 27 | # Make sure the NVIDIA directory comes BEFORE the others. 28 | # - Atanas Georgiev 29 | 30 | list(APPEND _OpenGL_REQUIRED_VARS OpenGL_INCLUDE_DIR) 31 | list(APPEND _OpenGL_REQUIRED_VARS OpenGL_LIBRARY) 32 | find_path( 33 | OpenGL_INCLUDE_DIR 34 | NAMES 35 | GL/gl.h 36 | PATHS 37 | /usr/share/doc/NVIDIA_GLX-1.0/include 38 | /usr/openwin/share/include 39 | /opt/graphics/OpenGL/include 40 | /usr/X11R6/include 41 | ) 42 | 43 | find_library( 44 | OpenGL_LIBRARY 45 | NAMES 46 | GL 47 | MesaGL 48 | PATHS 49 | /opt/graphics/OpenGL/lib 50 | /usr/openwin/lib 51 | /usr/shlib /usr/X11R6/lib 52 | ) 53 | find_library( 54 | OpenGL_INTERFACE_LIBS 55 | NAMES 56 | GLU 57 | MesaGLU 58 | PATHS 59 | ${OpenGL_gl_LIBRARY} 60 | /opt/graphics/OpenGL/lib 61 | /usr/openwin/lib 62 | /usr/shlib /usr/X11R6/lib 63 | ) 64 | 65 | # # On Unix OpenGL most certainly always requires X11. 66 | # # Feel free to tighten up these conditions if you don't 67 | # # think this is always true. 68 | 69 | # if (OpenGL_gl_LIBRARY) 70 | # if(NOT X11_FOUND) 71 | # include(${CMAKE_CURRENT_LIST_DIR}/FindX11.cmake) 72 | # endif() 73 | # if (X11_FOUND) 74 | # set (OPENGL_LIBRARIES ${X11_LIBRARIES}) 75 | # endif () 76 | # endif () 77 | endif () 78 | 79 | include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) 80 | find_package_handle_standard_args(OpenGL REQUIRED_VARS ${_OpenGL_REQUIRED_VARS}) 81 | unset(_OpenGL_REQUIRED_VARS) 82 | 83 | mark_as_advanced( 84 | OpenGL_LIBRARY 85 | OpenGL_INCLUDE_DIR 86 | ) 87 | 88 | include(CreateImportTargetHelpers) 89 | if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") 90 | generate_import_target(OpenGL INTERFACE) 91 | elseif(${CMAKE_SYSTEM_NAME} MATCHES "Windows") 92 | #technically not true, but we don't have to do anything with the dll so... 93 | generate_import_target(OpenGL STATIC) 94 | else() 95 | generate_import_target(OpenGL SHARED) 96 | endif() 97 | -------------------------------------------------------------------------------- /cmake-module/FindOpenSSL.cmake: -------------------------------------------------------------------------------- 1 | #Our OpenSSL setup is non-standard, so set these variables up beforehand 2 | 3 | find_path(OPENSSL_ROOT_DIR 4 | NAMES include/openssl/opensslconf.h 5 | PATH_SUFFIXES openssl 6 | ) 7 | 8 | include(CreateImportTargetHelpers) 9 | 10 | if(MSVC) 11 | find_library(LIB_EAY_DEBUG NAMES libeay32.lib HINTS ${OPENSSL_ROOT_DIR}/lib/debug) 12 | find_library(LIB_EAY_RELEASE NAMES libeay32.lib HINTS ${OPENSSL_ROOT_DIR}/lib/release) 13 | find_library(SSL_EAY_DEBUG NAMES ssleay32.lib HINTS ${OPENSSL_ROOT_DIR}/lib/debug) 14 | find_library(SSL_EAY_RELEASE NAMES ssleay32.lib HINTS ${OPENSSL_ROOT_DIR}/lib/release) 15 | mark_as_advanced(LIB_EAY_DEBUG LIB_EAY_RELEASE SSL_EAY_DEBUG SSL_EAY_RELEASE) 16 | 17 | include(${CMAKE_ROOT}/Modules/FindOpenSSL.cmake) 18 | 19 | #override the bad OPENSSL_LIBRARIES value 20 | include(SelectConfigurations) 21 | select_configurations(LIB_EAY LIBRARY) 22 | select_configurations(SSL_EAY LIBRARY) 23 | 24 | set(OPENSSL_LIBRARIES "${SSL_EAY_LIBRARY} ${LIB_EAY_LIBRARY}") 25 | set(OPENSSL_LIBRARY_DEBUG "${LIB_EAY_DEBUG};${SSL_EAY_DEBUG}") 26 | set(OPENSSL_LIBRARY_RELEASE "${LIB_EAY_RELEASE};${SSL_EAY_RELEASE}") 27 | generate_import_target(OPENSSL STATIC) 28 | 29 | else() 30 | include(${CMAKE_ROOT}/Modules/FindOpenSSL.cmake) 31 | if(EXISTS "${OPENSSL_CRYPTO_LIBRARY}") 32 | set(OPENSSL_CRYPTO_FOUND TRUE) 33 | endif() 34 | if(EXISTS "${OPENSSL_SSL_LIBRARY}") 35 | set(OPENSSL_SSL_FOUND TRUE) 36 | endif() 37 | generate_import_target(OPENSSL_CRYPTO STATIC TARGET OPENSSL::Crypto) 38 | generate_import_target(OPENSSL_SSL STATIC TARGET OPENSSL::SSL) 39 | generate_import_target(OPENSSL INTERFACE) 40 | target_link_libraries(OPENSSL::OPENSSL INTERFACE OPENSSL::Crypto OPENSSL::SSL) 41 | endif() 42 | 43 | 44 | -------------------------------------------------------------------------------- /cmake-module/FindPolyPartition.cmake: -------------------------------------------------------------------------------- 1 | #.rst 2 | # FindPolyPartition 3 | # ------------ 4 | # 5 | # Created by Jonathan Marsden 6 | # Locate and configure PolyPartition 7 | # 8 | # Interface Targets 9 | # ^^^^^^^^^^^^^^^^^ 10 | # PolyPartition::PolyPartition 11 | # 12 | # Variables 13 | # ^^^^^^^^^ 14 | # PolyPartition_ROOT_DIR 15 | # PolyPartition_FOUND 16 | # PolyPartition_INCLUDE_DIR 17 | # PolyPartition_LIBRARY 18 | # PolyPartition_IMPORT_LIB 19 | 20 | find_path(PolyPartition_ROOT_DIR 21 | NAMES include/polypartition.h 22 | HINTS ${EXTERNAL_LIBRARY_DIR} 23 | PATH_SUFFIXES polypartition) 24 | 25 | set(PolyPartition_INCLUDE_DIR "${PolyPartition_ROOT_DIR}/include") 26 | if(MSVC) 27 | find_library(PolyPartition_LIBRARY_RELEASE "polypartition.lib" HINTS "${PolyPartition_ROOT_DIR}/lib/release") 28 | find_library(PolyPartition_LIBRARY_DEBUG "polypartition.lib" HINTS "${PolyPartition_ROOT_DIR}/lib/debug") 29 | else() 30 | find_library(PolyPartition_LIBRARY_RELEASE "libpolypartition.a" HINTS "${PolyPartition_ROOT_DIR}/lib") 31 | find_library(PolyPartition_LIBRARY_DEBUG "libpolypartition.a" HINTS "${PolyPartition_ROOT_DIR}/lib") 32 | endif() 33 | 34 | include(FindPackageHandleStandardArgs) 35 | find_package_handle_standard_args(PolyPartition DEFAULT_MSG PolyPartition_ROOT_DIR PolyPartition_INCLUDE_DIR PolyPartition_LIBRARY_RELEASE PolyPartition_LIBRARY_DEBUG) 36 | 37 | include(CreateImportTargetHelpers) 38 | generate_import_target(PolyPartition STATIC) 39 | -------------------------------------------------------------------------------- /cmake-module/FindThreads.cmake: -------------------------------------------------------------------------------- 1 | #.rst: 2 | # FindThreads 3 | # ----------- 4 | # 5 | # Modified by Victor Dods to use the generate_import_target function to define 6 | # the library correctly as a target under the new cmake usage requirements rules. 7 | # 8 | # This module determines the thread library of the system. 9 | # 10 | # The following variables are set 11 | # 12 | # :: 13 | # 14 | # CMAKE_THREAD_LIBS_INIT - the thread library 15 | # CMAKE_USE_SPROC_INIT - are we using sproc? 16 | # CMAKE_USE_WIN32_THREADS_INIT - using WIN32 threads? 17 | # CMAKE_USE_PTHREADS_INIT - are we using pthreads 18 | # CMAKE_HP_PTHREADS_INIT - are we using hp pthreads 19 | # 20 | # For systems with multiple thread libraries, caller can set 21 | # 22 | # :: 23 | # 24 | # CMAKE_THREAD_PREFER_PTHREAD 25 | 26 | #============================================================================= 27 | # Copyright 2002-2009 Kitware, Inc. 28 | # 29 | # Distributed under the OSI-approved BSD License (the "License"); 30 | # see accompanying file Copyright.txt for details. 31 | # 32 | # This software is distributed WITHOUT ANY WARRANTY; without even the 33 | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 34 | # See the License for more information. 35 | #============================================================================= 36 | # (To distribute this file outside of CMake, substitute the full 37 | # License text for the above reference.) 38 | 39 | include (CheckIncludeFiles) 40 | include (CheckLibraryExists) 41 | include (CheckSymbolExists) 42 | set(Threads_FOUND FALSE) 43 | 44 | # Do we have sproc? 45 | if(CMAKE_SYSTEM MATCHES IRIX AND NOT CMAKE_THREAD_PREFER_PTHREAD) 46 | CHECK_INCLUDE_FILES("sys/types.h;sys/prctl.h" CMAKE_HAVE_SPROC_H) 47 | endif() 48 | 49 | if(CMAKE_HAVE_SPROC_H AND NOT CMAKE_THREAD_PREFER_PTHREAD) 50 | # We have sproc 51 | set(CMAKE_USE_SPROC_INIT 1) 52 | else() 53 | # Do we have pthreads? 54 | CHECK_INCLUDE_FILES("pthread.h" CMAKE_HAVE_PTHREAD_H) 55 | if(CMAKE_HAVE_PTHREAD_H) 56 | # 57 | # We have pthread.h 58 | # Let's check for the library now. 59 | # 60 | set(CMAKE_HAVE_THREADS_LIBRARY) 61 | if(NOT THREADS_HAVE_PTHREAD_ARG) 62 | # Check if pthread functions are in normal C library 63 | CHECK_SYMBOL_EXISTS(pthread_create pthread.h CMAKE_HAVE_LIBC_CREATE) 64 | if(CMAKE_HAVE_LIBC_CREATE) 65 | set(CMAKE_THREAD_LIBS_INIT "") 66 | set(CMAKE_HAVE_THREADS_LIBRARY 1) 67 | set(Threads_FOUND TRUE) 68 | endif() 69 | 70 | if(NOT CMAKE_HAVE_THREADS_LIBRARY) 71 | # Do we have -lpthreads 72 | CHECK_LIBRARY_EXISTS(pthreads pthread_create "" CMAKE_HAVE_PTHREADS_CREATE) 73 | if(CMAKE_HAVE_PTHREADS_CREATE) 74 | set(CMAKE_THREAD_LIBS_INIT "-lpthreads") 75 | set(CMAKE_HAVE_THREADS_LIBRARY 1) 76 | set(Threads_FOUND TRUE) 77 | endif() 78 | 79 | # Ok, how about -lpthread 80 | CHECK_LIBRARY_EXISTS(pthread pthread_create "" CMAKE_HAVE_PTHREAD_CREATE) 81 | if(CMAKE_HAVE_PTHREAD_CREATE) 82 | set(CMAKE_THREAD_LIBS_INIT "-lpthread") 83 | set(CMAKE_HAVE_THREADS_LIBRARY 1) 84 | set(Threads_FOUND TRUE) 85 | endif() 86 | 87 | if(CMAKE_SYSTEM MATCHES "SunOS.*") 88 | # On sun also check for -lthread 89 | CHECK_LIBRARY_EXISTS(thread thr_create "" CMAKE_HAVE_THR_CREATE) 90 | if(CMAKE_HAVE_THR_CREATE) 91 | set(CMAKE_THREAD_LIBS_INIT "-lthread") 92 | set(CMAKE_HAVE_THREADS_LIBRARY 1) 93 | set(Threads_FOUND TRUE) 94 | endif() 95 | endif() 96 | endif() 97 | endif() 98 | 99 | if(NOT CMAKE_HAVE_THREADS_LIBRARY) 100 | # If we did not found -lpthread, -lpthread, or -lthread, look for -pthread 101 | if("THREADS_HAVE_PTHREAD_ARG" MATCHES "^THREADS_HAVE_PTHREAD_ARG") 102 | message(STATUS "Check if compiler accepts -pthread") 103 | try_run(THREADS_PTHREAD_ARG THREADS_HAVE_PTHREAD_ARG 104 | ${CMAKE_BINARY_DIR} 105 | ${CMAKE_ROOT}/Modules/CheckForPthreads.c 106 | CMAKE_FLAGS -DLINK_LIBRARIES:STRING=-pthread 107 | COMPILE_OUTPUT_VARIABLE OUTPUT) 108 | 109 | if(THREADS_HAVE_PTHREAD_ARG) 110 | if(THREADS_PTHREAD_ARG STREQUAL "2") 111 | set(Threads_FOUND TRUE) 112 | message(STATUS "Check if compiler accepts -pthread - yes") 113 | else() 114 | message(STATUS "Check if compiler accepts -pthread - no") 115 | file(APPEND 116 | ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log 117 | "Determining if compiler accepts -pthread returned ${THREADS_PTHREAD_ARG} instead of 2. The compiler had the following output:\n${OUTPUT}\n\n") 118 | endif() 119 | else() 120 | message(STATUS "Check if compiler accepts -pthread - no") 121 | file(APPEND 122 | ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log 123 | "Determining if compiler accepts -pthread failed with the following output:\n${OUTPUT}\n\n") 124 | endif() 125 | 126 | endif() 127 | 128 | if(THREADS_HAVE_PTHREAD_ARG) 129 | set(Threads_FOUND TRUE) 130 | set(CMAKE_THREAD_LIBS_INIT "-pthread") 131 | endif() 132 | 133 | endif() 134 | endif() 135 | endif() 136 | 137 | if(CMAKE_THREAD_LIBS_INIT OR CMAKE_HAVE_LIBC_CREATE) 138 | set(CMAKE_USE_PTHREADS_INIT 1) 139 | set(Threads_FOUND TRUE) 140 | endif() 141 | 142 | if(CMAKE_SYSTEM MATCHES "Windows") 143 | set(CMAKE_USE_WIN32_THREADS_INIT 1) 144 | set(Threads_FOUND TRUE) 145 | endif() 146 | 147 | if(CMAKE_USE_PTHREADS_INIT) 148 | if(CMAKE_SYSTEM MATCHES "HP-UX-*") 149 | # Use libcma if it exists and can be used. It provides more 150 | # symbols than the plain pthread library. CMA threads 151 | # have actually been deprecated: 152 | # http://docs.hp.com/en/B3920-90091/ch12s03.html#d0e11395 153 | # http://docs.hp.com/en/947/d8.html 154 | # but we need to maintain compatibility here. 155 | # The CMAKE_HP_PTHREADS setting actually indicates whether CMA threads 156 | # are available. 157 | CHECK_LIBRARY_EXISTS(cma pthread_attr_create "" CMAKE_HAVE_HP_CMA) 158 | if(CMAKE_HAVE_HP_CMA) 159 | set(CMAKE_THREAD_LIBS_INIT "-lcma") 160 | set(CMAKE_HP_PTHREADS_INIT 1) 161 | set(Threads_FOUND TRUE) 162 | endif() 163 | set(CMAKE_USE_PTHREADS_INIT 1) 164 | endif() 165 | 166 | if(CMAKE_SYSTEM MATCHES "OSF1-V*") 167 | set(CMAKE_USE_PTHREADS_INIT 0) 168 | set(CMAKE_THREAD_LIBS_INIT ) 169 | endif() 170 | 171 | if(CMAKE_SYSTEM MATCHES "CYGWIN_NT*") 172 | set(CMAKE_USE_PTHREADS_INIT 1) 173 | set(Threads_FOUND TRUE) 174 | set(CMAKE_THREAD_LIBS_INIT ) 175 | set(CMAKE_USE_WIN32_THREADS_INIT 0) 176 | endif() 177 | endif() 178 | 179 | include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake) 180 | find_package_handle_standard_args(Threads DEFAULT_MSG Threads_FOUND) 181 | 182 | if(${CMAKE_THREAD_LIBS_INIT}) 183 | include(CreateImportTargetHelpers) 184 | set(Threads_LIBRARY ${CMAKE_THREAD_LIBS_INIT}) 185 | generate_import_target(Threads STATIC) 186 | else() 187 | add_library(Threads::Threads INTERFACE IMPORTED) 188 | endif() 189 | -------------------------------------------------------------------------------- /cmake-module/FindWDK.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find WDK 2 | # This module takes as inputs 3 | # WDK_ROOT_ALTERNATE - An alternate possible location for the wdk 4 | # 5 | # Once done this will define 6 | # WDK_FOUND - System has WDK 7 | # WDK_INCLUDE_DIRS - The WDK include directory 8 | # WDK_LIBRARIES - The libraries needed to use WDK 9 | # WDK_BIN - The path to the WDK binaries folder 10 | 11 | set(wdkregpath80 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots;KitsRoot]") 12 | get_filename_component(wdkpath80 ${wdkregpath80} ABSOLUTE) 13 | 14 | set(wdkregpath81 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots;KitsRoot81]") 15 | get_filename_component(wdkpath81 ${wdkregpath81} ABSOLUTE) 16 | 17 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) 18 | set(WDK_ARCH "x64") 19 | else() 20 | set(WDK_ARCH "x86") 21 | endif() 22 | 23 | # Select a root path first: 24 | find_path( 25 | WDK_ROOT_DIR Include/um/UPnP.h 26 | HINTS ${wdkpath81} ${wdkpath80} ${WDK_ROOT_ALTERNATE} 27 | ) 28 | 29 | # Generate include directories variable from the root path 30 | set(WDK_INCLUDE_DIRS ${WDK_ROOT_DIR}/Include/um ${WDK_ROOT_DIR}/Include/Shared) 31 | 32 | # Also generate the binaries directory: 33 | find_path( 34 | WDK_BIN_DIR makecat.exe 35 | HINTS ${WDK_ROOT_DIR}/bin/${WDK_ARCH} 36 | ) 37 | 38 | # Now we scan for all components: 39 | foreach(COMPONENT ${WDK_FIND_COMPONENTS}) 40 | string(TOUPPER ${COMPONENT} UPPERCOMPONENT) 41 | 42 | find_library( 43 | WDK_${UPPERCOMPONENT} ${COMPONENT} 44 | PATHS ${WDK_ROOT_DIR} 45 | PATH_SUFFIXES /Lib/win8/um/${WDK_ARCH} /Lib/winv6.3/um/${WDK_ARCH} 46 | ) 47 | mark_as_advanced(CLEAR WDK_${UPPERCOMPONENT}) 48 | list(APPEND WDK_LIBRARIES ${WDK_${UPPERCOMPONENT}}) 49 | endforeach() 50 | 51 | include(FindPackageHandleStandardArgs) 52 | if(WDK_FIND_COMPONENTS) 53 | find_package_handle_standard_args(WDK DEFAULT_MSG WDK_LIBRARIES WDK_INCLUDE_DIRS) 54 | else() 55 | find_package_handle_standard_args(WDK DEFAULT_MSG WDK_INCLUDE_DIRS) 56 | endif() 57 | 58 | 59 | -------------------------------------------------------------------------------- /cmake-module/LeapCMakeTemplates.cmake: -------------------------------------------------------------------------------- 1 | #.rst 2 | #LeapTemplates 3 | #------------- 4 | # Created by Walter Gray 5 | # 6 | # Some Leap Motion specific boilderplate code. 7 | # Not reccomended for use outside of the Leap Motion engineering group, 8 | # though you're welcome to define your own. 9 | 10 | macro(leap_find_external_libraries pc_variant) 11 | find_path(EXTERNAL_LIBRARY_DIR "eigen-3.2.1/Eigen/CmakeLists.txt" 12 | PATHS 13 | "$ENV{EXTERNAL_LIBRARY_DIR}" 14 | "$ENV{LIBRARIES_PATH}" 15 | "$ENV{PATH}" 16 | "/opt/local/Libraries" 17 | ) 18 | 19 | list(INSERT CMAKE_PREFIX_PATH 0 "${EXTERNAL_LIBRARY_DIR}") 20 | endmacro() 21 | 22 | macro(leap_use_standard_platform_settings) 23 | 24 | if(NOT (MSVC OR CMAKE_BUILD_TYPE)) 25 | set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release." FORCE) 26 | endif() 27 | 28 | # Disable MinSizeRel & MaxSpeedRel 29 | set(CMAKE_CONFIGURATION_TYPES "Release;Debug" CACHE STRING "" FORCE) 30 | set_property(GLOBAL PROPERTY USE_FOLDERS ON) 31 | 32 | if(APPLE) 33 | if(NOT CMAKE_OSX_ARCHITECTURES) 34 | set(CMAKE_OSX_ARCHITECTURES "x86_64" CACHE STRING "Mac OS X build architectures" FORCE) 35 | endif() 36 | if(NOT CMAKE_OSX_SYSROOT) 37 | set(CMAKE_OSX_SYSROOT "macosx10.9" CACHE STRING "Mac OS X build environment" FORCE) 38 | endif() 39 | 40 | set(CMAKE_OSX_DEPLOYMENT_TARGET "10.7" CACHE STRING "Mac OS X deployment target" FORCE) 41 | mark_as_advanced(CMAKE_OSX_DEPLOYMENT_TARGET) 42 | set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++11") 43 | set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++") 44 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++") 45 | set(USE_LIBCXX ON) 46 | endif() 47 | 48 | endmacro() 49 | -------------------------------------------------------------------------------- /cmake-module/PrintTargetProperties.cmake: -------------------------------------------------------------------------------- 1 | # This useful script was taken from http://www.kitware.com/blog/home/post/390 and slightly modified. 2 | function(echo_target_property tgt prop) 3 | # message("echo_target_property -- tgt = ${tgt}, prop = ${prop}") 4 | # v for value, d for defined, s for set 5 | get_property(v TARGET ${tgt} PROPERTY ${prop}) 6 | get_property(d TARGET ${tgt} PROPERTY ${prop} DEFINED) 7 | get_property(s TARGET ${tgt} PROPERTY ${prop} SET) 8 | 9 | # only produce output for values that are set 10 | if(s) 11 | message("tgt='${tgt}' prop='${prop}'") 12 | message(" value='${v}'") 13 | message(" defined='${d}'") 14 | message(" set='${s}'") 15 | message("") 16 | endif() 17 | endfunction() 18 | 19 | function(echo_target tgt) 20 | if(NOT TARGET ${tgt}) 21 | message("There is no target named '${tgt}'") 22 | return() 23 | endif() 24 | 25 | set(props 26 | DEBUG_OUTPUT_NAME 27 | DEBUG_POSTFIX 28 | RELEASE_OUTPUT_NAME 29 | RELEASE_POSTFIX 30 | ARCHIVE_OUTPUT_DIRECTORY 31 | ARCHIVE_OUTPUT_DIRECTORY_DEBUG 32 | ARCHIVE_OUTPUT_DIRECTORY_RELEASE 33 | ARCHIVE_OUTPUT_NAME 34 | ARCHIVE_OUTPUT_NAME_DEBUG 35 | ARCHIVE_OUTPUT_NAME_RELEASE 36 | AUTOMOC 37 | AUTOMOC_MOC_OPTIONS 38 | BUILD_WITH_INSTALL_RPATH 39 | BUNDLE 40 | BUNDLE_EXTENSION 41 | COMPILE_DEFINITIONS 42 | COMPILE_DEFINITIONS_DEBUG 43 | COMPILE_DEFINITIONS_RELEASE 44 | COMPILE_FLAGS 45 | COMPILE_OPTIONS 46 | DEBUG_POSTFIX 47 | RELEASE_POSTFIX 48 | DEFINE_SYMBOL 49 | ENABLE_EXPORTS 50 | EXCLUDE_FROM_ALL 51 | EchoString 52 | FOLDER 53 | FRAMEWORK 54 | Fortran_FORMAT 55 | Fortran_MODULE_DIRECTORY 56 | GENERATOR_FILE_NAME 57 | GNUtoMS 58 | HAS_CXX 59 | IMPLICIT_DEPENDS_INCLUDE_TRANSFORM 60 | IMPORTED 61 | IMPORTED_CONFIGURATIONS 62 | IMPORTED_IMPLIB 63 | IMPORTED_IMPLIB_DEBUG 64 | IMPORTED_IMPLIB_RELEASE 65 | IMPORTED_LINK_DEPENDENT_LIBRARIES 66 | IMPORTED_LINK_DEPENDENT_LIBRARIES_DEBUG 67 | IMPORTED_LINK_DEPENDENT_LIBRARIES_RELEASE 68 | IMPORTED_LINK_INTERFACE_LANGUAGES 69 | IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG 70 | IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE 71 | IMPORTED_LINK_INTERFACE_LIBRARIES 72 | IMPORTED_LINK_INTERFACE_LIBRARIES_DEBUG 73 | IMPORTED_LINK_INTERFACE_LIBRARIES_RELEASE 74 | IMPORTED_LINK_INTERFACE_MULTIPLICITY 75 | IMPORTED_LINK_INTERFACE_MULTIPLICITY_DEBUG 76 | IMPORTED_LINK_INTERFACE_MULTIPLICITY_RELEASE 77 | IMPORTED_LOCATION 78 | IMPORTED_LOCATION_DEBUG 79 | IMPORTED_LOCATION_RELEASE 80 | IMPORTED_NO_SONAME 81 | IMPORTED_NO_SONAME_DEBUG 82 | IMPORTED_NO_SONAME_RELEASE 83 | IMPORTED_SONAME 84 | IMPORTED_SONAME_DEBUG 85 | IMPORTED_SONAME_RELEASE 86 | IMPORT_PREFIX 87 | IMPORT_SUFFIX 88 | INCLUDE_DIRECTORIES 89 | INSTALL_NAME_DIR 90 | INSTALL_RPATH 91 | INSTALL_RPATH_USE_LINK_PATH 92 | INTERFACE_COMPILE_DEFINITIONS 93 | INTERFACE_COMPILE_OPTIONS 94 | INTERFACE_INCLUDE_DIRECTORIES 95 | INTERFACE_LINK_LIBRARIES 96 | INTERPROCEDURAL_OPTIMIZATION 97 | INTERPROCEDURAL_OPTIMIZATION_DEBUG 98 | INTERPROCEDURAL_OPTIMIZATION_RELEASE 99 | LABELS 100 | LIBRARY_OUTPUT_DIRECTORY 101 | LIBRARY_OUTPUT_DIRECTORY_DEBUG 102 | LIBRARY_OUTPUT_DIRECTORY_RELEASE 103 | LIBRARY_OUTPUT_NAME 104 | LIBRARY_OUTPUT_NAME_DEBUG 105 | LIBRARY_OUTPUT_NAME_RELEASE 106 | LINKER_LANGUAGE 107 | LINK_DEPENDS 108 | LINK_FLAGS 109 | LINK_FLAGS_DEBUG 110 | LINK_FLAGS_RELEASE 111 | LINK_INTERFACE_LIBRARIES 112 | LINK_INTERFACE_LIBRARIES_DEBUG 113 | LINK_INTERFACE_LIBRARIES_RELEASE 114 | LINK_INTERFACE_MULTIPLICITY 115 | LINK_INTERFACE_MULTIPLICITY_DEBUG 116 | LINK_INTERFACE_MULTIPLICITY_RELEASE 117 | LINK_LIBRARIES 118 | LINK_SEARCH_END_STATIC 119 | LINK_SEARCH_START_STATIC 120 | # LOCATION 121 | # LOCATION_DEBUG 122 | # LOCATION_RELEASE 123 | MACOSX_BUNDLE 124 | MACOSX_BUNDLE_INFO_PLIST 125 | MACOSX_FRAMEWORK_INFO_PLIST 126 | MAP_IMPORTED_CONFIG_DEBUG 127 | MAP_IMPORTED_CONFIG_RELEASE 128 | OSX_ARCHITECTURES 129 | OSX_ARCHITECTURES_DEBUG 130 | OSX_ARCHITECTURES_RELEASE 131 | OUTPUT_NAME 132 | OUTPUT_NAME_DEBUG 133 | OUTPUT_NAME_RELEASE 134 | POST_INSTALL_SCRIPT 135 | PREFIX 136 | PRE_INSTALL_SCRIPT 137 | PRIVATE_HEADER 138 | PROJECT_LABEL 139 | PUBLIC_HEADER 140 | RESOURCE 141 | RULE_LAUNCH_COMPILE 142 | RULE_LAUNCH_CUSTOM 143 | RULE_LAUNCH_LINK 144 | RUNTIME_OUTPUT_DIRECTORY 145 | RUNTIME_OUTPUT_DIRECTORY_DEBUG 146 | RUNTIME_OUTPUT_DIRECTORY_RELEASE 147 | RUNTIME_OUTPUT_NAME 148 | RUNTIME_OUTPUT_NAME_DEBUG 149 | RUNTIME_OUTPUT_NAME_RELEASE 150 | SKIP_BUILD_RPATH 151 | SOURCES 152 | SOVERSION 153 | STATIC_LIBRARY_FLAGS 154 | STATIC_LIBRARY_FLAGS_DEBUG 155 | STATIC_LIBRARY_FLAGS_RELEASE 156 | SUFFIX 157 | TYPE 158 | VERSION 159 | VS_DOTNET_REFERENCES 160 | VS_GLOBAL_WHATEVER 161 | VS_GLOBAL_KEYWORD 162 | VS_GLOBAL_PROJECT_TYPES 163 | VS_KEYWORD 164 | VS_SCC_AUXPATH 165 | VS_SCC_LOCALPATH 166 | VS_SCC_PROJECTNAME 167 | VS_SCC_PROVIDER 168 | VS_WINRT_EXTENSIONS 169 | VS_WINRT_REFERENCES 170 | WIN32_EXECUTABLE 171 | XCODE_ATTRIBUTE_WHATEVER 172 | ) 173 | 174 | message("======================== ${tgt} ========================") 175 | foreach(p ${props}) 176 | echo_target_property("${tgt}" "${p}") 177 | endforeach() 178 | message("") 179 | endfunction() 180 | 181 | 182 | function(echo_targets) 183 | set(tgts ${ARGV}) 184 | foreach(t ${tgts}) 185 | echo_target("${t}") 186 | endforeach() 187 | endfunction() 188 | 189 | 190 | # set(targets 191 | # CMakeLib 192 | # cmake-gui 193 | # MathFunctions 194 | # Tutorial 195 | # vtkCommonCore 196 | # ) 197 | 198 | # echo_targets(${targets}) 199 | -------------------------------------------------------------------------------- /cmake-module/README.md: -------------------------------------------------------------------------------- 1 | #### CMake-Modules 2 | This repo is a common place to store useful cmake modules, including customized 3 | Find files and utility modules. It is intended to be incorporated into projects 4 | as a subtree. 5 | 6 | ##### Usage 7 | First add the cmake-module repo as a remote, so you can more easily reference it 8 | ``` 9 | git remote add -f cmake-modules-repo git@sf-github.leap.corp:leapmotion/cmake-module.git 10 | ``` 11 | 12 | To setup cmake-modules in your repository (only run once as a setup step): 13 | ``` 14 | git subtree add --prefix cmake-modules cmake-modules-repo develop 15 | ``` 16 | 17 | To update the copy of cmake-modules in your repository from the latest code in the cmake-modules repo: 18 | ``` 19 | git fetch cmake-modules-repo develop 20 | git subtree pull --prefix cmake-modules cmake-modules-repo develop 21 | ``` 22 | 23 | To push changes from your repository upstream into the cmake-module repo: 24 | ``` 25 | git subtree push --prefix cmake-modules cmake-modules-repo 26 | Open a pull request to merge to develop 27 | ``` 28 | 29 | 30 | For more information on subtrees see Atlassian's [Git Subtree Tutorial](http://blogs.atlassian.com/2013/05/alternatives-to-git-submodule-git-subtree/) 31 | 32 | #### Best Practices 33 | ##### Rule 1: Always check the docs & existing modules for examples 34 | Documentation for CMake is rapidly improving. See if you can find answers in the links below. 35 | 36 | * [CMake 3.0.0 Documentation](http://www.cmake.org/cmake/help/v3.0/index.html) 37 | * [CMake git-master Documentation](http://www.cmake.org/cmake/help/git-master/) 38 | 39 | ##### Naming conventions 40 | * UPPER_CASE identifiers are public 41 | * Mixed_CASE identifiers are also public assuming the first word is a namespace, as with package find modules 42 | * _lower_idents with preceding underscores should be used for private, temporary variables 43 | * lower_idents should also be used for function calls 44 | * UPPER_CASE should be used for naming arguments to functions (see [CMakeParseArguments](http://www.cmake.org/cmake/help/git-master/module/CMakeParseArguments.html)) 45 | 46 | ##### General Guidelines 47 | 1. Prefer setting target properties over global or directory properties, eg. use target_include_directories over include_directories. 48 | 2. Prefer Generator expressions over PROPERTY_ variants wherever allowed. see [Generator Expressions Manual](http://www.cmake.org/cmake/help/v3.0/manual/cmake-generator-expressions.7.html) 49 | 3. install() is meant to define a step to package the build products of a library, and install them on the host system for use by cmake by adding it to the [Package Registry](http://www.cmake.org/cmake/help/v3.0/manual/cmake-packages.7.html#package-registry). For steps such as copying .DLLs or resource files to the appropriate location so a build can be run and debugged at all, use add_custom_command( POST_BUILD ...) 50 | 4. Never manually add a library directly in a CMakeLists.txt file (eg, via find_library or find_path). Instead, write a Find.cmake module that does that instead. See the guidelines for writing find modules further down, as well as the official [Module Developer Docs](http://www.cmake.org/cmake/help/v3.0/manual/cmake-developer.7.html#modules) 51 | 5. Avoid the target_link_libraries signatures which use[debug|optimized|general]. Use Generator Expressions instead. 52 | 6. Make use of INTERFACE targets and other pseudo targets to specify usage requirements. See 53 | 54 | * [Pseudo Targets](http://www.cmake.org/cmake/help/v3.0/manual/cmake-buildsystem.7.html#pseudo-targets) for information on what Pseudo Targets and Usage Requirements in general are. 55 | * [Packages](http://www.cmake.org/cmake/help/v3.0/manual/cmake-packages.7.html) for information on what packages are and how to write Config.cmake files that provide IMPORT targets. 56 | 57 | ##### Creating New Projects 58 | This assumes that you have added cmake-modules as a subtree in a folder at the root of your project. 59 | 60 | ##### Directory Structure 61 | Root: A global CMakeLists.txt file containing global settings for all sub-projects. 62 | If you have only one sub project, you may add and configure it at the end of the root cmakelists file. 63 | Don't call find_package at the global level - use target_package (Defined in TargetImportedLibraries) instead. 64 | This has the additional benifit of setting up the appropriate post-build steps to handle copying shared libraries 65 | 66 | ##### Handling Resources in OS X Bundles 67 | See [CMake: Bundles and Frameworks](http://www.cmake.org/Wiki/CMake:Bundles_And_Frameworks) 68 | as well as documentation for the [MACOSX_PACKAGE_LOCATION](http://www.cmake.org/cmake/help/v3.0/prop_sf/MACOSX_PACKAGE_LOCATION.html) 69 | 70 | ##### Root CMakeLists.txt 71 | ``` 72 | cmake_minimum_required(VERSION 3.0) 73 | project() 74 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules") 75 | set(CMAKE_CONFIGURATION_TYPES "Release;Debug" CACHE STRING "" FORCE) #Disables MinSizeRel & MaxSpeedRel 76 | set(CMAKE_INCLUDE_CURRENT_DIR ON) #essentially the same as include_directories(.) in every subdir 77 | set_property(GLOBAL PROPERTY USE_FOLDERS ON) 78 | 79 | #Leap-Specific: We package any external libraries we're using in a single place, so add it to the default 80 | #Search path. SDL-2.0.1 is used as a marker of something to look for. 81 | find_path(EXTERNAL_LIBRARY_DIR "SDL-2.0.1" 82 | PATHS 83 | "$ENV{EXTERNAL_LIBRARY_DIR}" 84 | "$ENV{LIBRARIES_PATH}" 85 | "$ENV{PATH}" 86 | "/opt/local/Libraries" 87 | NO_DEFAULT_PATH) 88 | list(INSERT CMAKE_PREFIX_PATH 0 "${EXTERNAL_LIBRARY_DIR}") 89 | 90 | #Set any global flags for the project here, such as compiler settings you want used universally 91 | #if(MSVC) #Uncomment this if you want to use use /MT instead of /MD on Windows 92 | # add_compile_options($<$:/MTd> $<$:/MT>) 93 | #endif() 94 | 95 | #Call add_subdirectory on relevant sub-directories 96 | 97 | ``` 98 | 99 | ##### Project's CMakeLists.txt 100 | ``` 101 | set(_SRC ) 102 | set(_HEADERS ) 103 | 104 | add_( ${_SRC} ${_HEADERS}) 105 | target_include_directories( PUBLIC .) 106 | target_package( REQUIRED) #Repeat as nessecary 107 | 108 | #set target's custom build settings here 109 | 110 | #define install steps here 111 | 112 | ``` 113 | 114 | ##### Writing Find Modules 115 | For packages which do not provide Package.cmake commands, or ones that do not yet support import targets, 116 | you will have to author your own find module. This may be as simple as 117 | ``` 118 | include(${CMAKE_ROOT}/Modules/Find.cmake) 119 | include(CreateImportTargetHelpers) 120 | generate_import_target( ) 121 | ``` 122 | but may also be much more complicated. See the existing Find modules in this repo for examples, and 123 | CreateImportTargetHelpers.cmake's documentation on how it works. 124 | 125 | All Import targets generated by a Find module should use the 126 | :: naming convention where :: is an import target which will include 127 | all components specified as arguments to find_package. Private import targets should use 128 | ::_ 129 | 130 | #### Notes & TODOs 131 | 132 | - Better helpers and handling for modules which may be either SHARED or STATIC. 133 | 134 | - Proposed solution is to define SHARED_LIBRARY and STATIC_LIBRARY separately, then set 135 | LIBRARY to whichever one exists, and if both are defined then create an option so the 136 | user can choose. Alternatively, we could detect which are available, default to SHARED 137 | if both are, and expose an Xxx_IMPORT_TYPE cache variable that the user could override. 138 | This would also let us throw errors if the files for the desired type are unavailable. 139 | 140 | - Make a cmake module for installing executables/resources in a platform-agnostic way 141 | (e.g. Mac has a particular "bundle" format it follows). 142 | 143 | - The organization of the Components (with its component and library dependencies) should 144 | be implemented using a cmake module, so little redundant boilerplate is necessary. 145 | 146 | - Write variants of find_file and find_path which actually return ALL matches, instead of 147 | an ill-defined single match. This functionality is distinctly lacking in cmake, and 148 | causes nontrivial problems when trying to find files/paths. 149 | 150 | -------------------------------------------------------------------------------- /cmake-module/SelectConfigurations.cmake: -------------------------------------------------------------------------------- 1 | #.rst: 2 | # SelectConfigurations 3 | # --------------------------- 4 | # 5 | # Originally SelectConfigurations 6 | # Modified by Walter gray to create generator expressions instead of 7 | # using the optimized and debug keywords. This makes the output 8 | # suitable for use with the INTERFACE_LINK_LIBRARIES property. 9 | # 10 | # select_configurations( basename ) 11 | # 12 | # This macro takes a library base name as an argument, and will choose 13 | # good values for basename_LIBRARY, basename_LIBRARIES, 14 | # basename_LIBRARY_DEBUG, and basename_LIBRARY_RELEASE depending on what 15 | # has been found and set. If only basename_LIBRARY_RELEASE is defined, 16 | # basename_LIBRARY will be set to the release value, and 17 | # basename_LIBRARY_DEBUG will be set to basename_LIBRARY_DEBUG-NOTFOUND. 18 | # If only basename_LIBRARY_DEBUG is defined, then basename_LIBRARY will 19 | # take the debug value, and basename_LIBRARY_RELEASE will be set to 20 | # basename_LIBRARY_RELEASE-NOTFOUND. 21 | # 22 | # If the generator supports configuration types, then basename_LIBRARY 23 | # and basename_LIBRARIES will be set with debug and optimized flags 24 | # specifying the library to be used for the given configuration. If no 25 | # build type has been set or the generator in use does not support 26 | # configuration types, then basename_LIBRARY and basename_LIBRARIES will 27 | # take only the release value, or the debug value if the release one is 28 | # not set. 29 | 30 | #============================================================================= 31 | # Copyright 2009 Will Dicharry 32 | # Copyright 2005-2009 Kitware, Inc. 33 | # 34 | # Distributed under the OSI-approved BSD License (the "License"); 35 | # see accompanying file Copyright.txt for details. 36 | # 37 | # This software is distributed WITHOUT ANY WARRANTY; without even the 38 | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 39 | # See the License for more information. 40 | #============================================================================= 41 | # (To distribute this file outside of CMake, substitute the full 42 | # License text for the above reference.) 43 | 44 | # This macro was adapted from the FindQt4 CMake module and is maintained by Will 45 | # Dicharry . 46 | 47 | function(select_configurations basename suffix) 48 | if(ARGC GREATER 2) #checking argv2 directly is bad, since the argvX variables are not reset between function calls 49 | set(_outvar ${ARGV2}) 50 | else() 51 | set(_outvar ${suffix}) 52 | endif() 53 | 54 | if(NOT ${basename}_${suffix}_RELEASE) 55 | set(${basename}_${suffix}_RELEASE "${basename}_${suffix}_RELEASE-NOTFOUND" CACHE FILEPATH "Path to a library.") 56 | endif() 57 | if(NOT ${basename}_${suffix}_DEBUG) 58 | set(${basename}_${suffix}_DEBUG "${basename}_${suffix}_DEBUG-NOTFOUND" CACHE FILEPATH "Path to a library.") 59 | endif() 60 | 61 | if( ${basename}_${suffix}_DEBUG AND ${basename}_${suffix}_RELEASE AND 62 | NOT ${basename}_${suffix}_DEBUG STREQUAL ${basename}_${suffix}_RELEASE AND 63 | ( CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE ) ) 64 | # if the generator supports configuration types or CMAKE_BUILD_TYPE 65 | # is set, then set optimized and debug options. 66 | set( ${basename}_${_outvar} "" ) 67 | foreach( _libname IN LISTS ${basename}_${suffix}_RELEASE ) 68 | list( APPEND ${basename}_${_outvar} $<$:"${_libname}"> ) 69 | endforeach() 70 | foreach( _libname IN LISTS ${basename}_${suffix}_DEBUG ) 71 | list( APPEND ${basename}_${_outvar} $<$:"${_libname}"> ) 72 | endforeach() 73 | elseif( ${basename}_${suffix}_RELEASE ) 74 | set( ${basename}_${_outvar} ${${basename}_${suffix}_RELEASE} ) 75 | elseif( ${basename}_${suffix}_DEBUG ) 76 | set( ${basename}_${_outvar} ${${basename}_${suffix}_DEBUG} ) 77 | else() 78 | set( ${basename}_${_outvar} "${basename}_${suffix}-NOTFOUND") 79 | endif() 80 | 81 | #break out of local scope 82 | set(${basename}_${_outvar} ${${basename}_${_outvar}} PARENT_SCOPE) 83 | 84 | mark_as_advanced( ${basename}_${suffix}_RELEASE ${basename}_${suffix}_DEBUG ) 85 | endfunction() -------------------------------------------------------------------------------- /cmake-module/TargetImportedLibraries.cmake: -------------------------------------------------------------------------------- 1 | #.rst: 2 | # ImportTargetLibraries 3 | # --------------------- 4 | # 5 | # Created by Walter Gray 6 | # See CreateImportTargetHelpers.cmake for a suite of functions suitable for writing Find 7 | # modules compatible with this approach. 8 | # 9 | # ======================== 10 | # TARGET_IMPORTED_LIBRARIES( ) 11 | # Takes the same arguments as target_link_libraries, but for any listed library where 12 | # is a valid target with a TYPE property of SHARED_LIBRARY, it will 13 | # read from the IMPORTED_LOCATION and IMPORTED_LOCATION_ parameters and generate 14 | # a custom post-build step to copy the shared library files to the appropriate location. 15 | # On windows, this is the TARGET_FILE_DIR of . link_type should be one of 16 | # PUBLIC, PRIVATE, or INTERFACE 17 | # 18 | # TARGET_PACKAGE( ...) 19 | # Takes the same arguments as find_package, with the addition of the target you're 20 | # linking to as the first parameter. Upon successfully finding the package, it 21 | # attempts to call TARGET_IMPORTED_LIBRARIES( ::) 22 | 23 | include(CMakeParseArguments) 24 | function(target_imported_libraries target) 25 | list(REMOVE_AT ARGV 0) #pop the target 26 | cmake_parse_arguments(target_imported_libraries "" "LINK_TYPE" "" ${ARGV}) 27 | 28 | set(_library_list ${target_imported_libraries_UNPARSED_ARGUMENTS}) 29 | target_link_libraries(${target} ${target_imported_libraries_LINK_TYPE} ${_library_list}) 30 | 31 | #early out if the target isn't an EXECUTABLE 32 | get_target_property(_target_type ${target} TYPE) 33 | if(NOT ${_target_type} STREQUAL EXECUTABLE) 34 | return() 35 | endif() 36 | 37 | #setup custom commands to copy .dll/dylib files for all dependencies 38 | set(_lib_index 0 ) 39 | list(LENGTH _library_list _lib_length) 40 | 41 | #foreach doesn't allow you to append to the list from within the loop. 42 | while(_lib_index LESS _lib_length) 43 | list(GET _library_list ${_lib_index} _import_lib) 44 | 45 | if(TARGET ${_import_lib}) 46 | get_target_property(_depends ${_import_lib} INTERFACE_LINK_LIBRARIES) 47 | foreach(_depend ${_depends}) 48 | if(TARGET ${_depend}) 49 | list(FIND _library_list ${_depend} _found_lib) 50 | if(_found_lib EQUAL -1) #make sure we don't do duplicate adds. 51 | verbose_message("${target}:Adding nested dependency ${_depend}") 52 | list(APPEND _library_list ${_depend}) 53 | else() 54 | verbose_message("${target}:skipping duplicate nested dependency ${_depend}") 55 | endif() 56 | 57 | endif() 58 | endforeach() 59 | 60 | get_target_property(_type ${_import_lib} TYPE) 61 | get_target_property(_imported ${_import_lib} IMPORTED) 62 | if(${_type} STREQUAL SHARED_LIBRARY AND ${_imported}) 63 | 64 | set(_found_configs_expr) 65 | set(_imported_location) 66 | 67 | #if only the _ variants are set, create a generator expression. 68 | get_target_property(_imported_location ${_import_lib} IMPORTED_LOCATION) 69 | if(NOT _imported_location) 70 | get_target_property(_imported_location_debug ${_import_lib} IMPORTED_LOCATION_DEBUG) 71 | get_target_property(_imported_location_release ${_import_lib} IMPORTED_LOCATION_RELEASE) 72 | if(NOT _imported_location_debug AND NOT _imported_location_release) 73 | message(FATAL_ERROR "No IMPORTED_LOCATION specified for SHARED import target ${_import_lib}") 74 | endif() 75 | set(_imported_location "$<$:${_imported_location_debug}>$<$:${_imported_location_release}>") 76 | endif() 77 | 78 | verbose_message("Adding copy command for ${_import_lib}: ${_imported_location}") 79 | 80 | if(MSVC) 81 | add_custom_command(TARGET ${target} POST_BUILD 82 | COMMAND ${CMAKE_COMMAND} -E copy_if_different \"${_imported_location}\" \"$\") 83 | elseif(APPLE) 84 | get_target_property(_is_bundle ${target} MACOSX_BUNDLE) 85 | if(_is_bundle) 86 | add_custom_command(TARGET ${target} POST_BUILD 87 | COMMAND ${CMAKE_COMMAND} -E make_directory "$/../Frameworks/" 88 | COMMAND ${CMAKE_COMMAND} -E copy_if_different "${_imported_location}" "$/../Frameworks/" 89 | COMMAND install_name_tool -change @loader_path/libLeap.dylib @loader_path/../Frameworks/libLeap.dylib "$") 90 | #call install_name_tool and fixup the dylib paths here: 91 | endif() 92 | else() 93 | message(WARNING "Automatic handling of shared libraries is unimplemented on this platform") 94 | endif() 95 | endif() 96 | endif() 97 | 98 | math(EXPR _lib_index "${_lib_index} + 1") #an extremely verbose i++... 99 | #if this is expensive, simply increment it when adding to the list. 100 | list(LENGTH _library_list _lib_length) #this is likely to have changed 101 | endwhile() 102 | endfunction() 103 | 104 | #This function wraps find_package, then calls target_imported_libraries on the generated package) 105 | function(target_package target package ) 106 | list(REMOVE_AT ARGV 0) # pop the target 107 | cmake_parse_arguments(target_package "" "LINK_TYPE" "" ${ARGV}) 108 | 109 | if(TARGET ${package}::${package}) 110 | verbose_message("${package}::${package} already exists, skipping find op") 111 | else() 112 | find_package(${target_package_UNPARSED_ARGUMENTS}) 113 | endif() 114 | 115 | if(target_package_LINK_TYPE) 116 | target_imported_libraries(${target} ${package}::${package} LINK_TYPE ${target_package_LINK_TYPE}) 117 | else() 118 | target_imported_libraries(${target} ${package}::${package}) 119 | endif() 120 | endfunction() 121 | -------------------------------------------------------------------------------- /cmake-module/TargetStrip.cmake: -------------------------------------------------------------------------------- 1 | # primary function of this macro: strip symbols at link time on Mac and Linux 2 | # secondary function: avoid MSVC warnings in Debug by specifying /nodefaultlib 3 | # tertiary function: avoid MSVC warnings about combining /incremental with /ltcg 4 | function(target_strip Target) 5 | if(MSVC) 6 | if(CMAKE_CXX_FLAGS_RELEASE) 7 | set_target_properties(${Target} PROPERTIES LINK_FLAGS_DEBUG "/INCREMENTAL:NO /NODEFAULTLIB:MSVCRT") 8 | else() 9 | set_target_properties(${Target} PROPERTIES LINK_FLAGS_DEBUG "/NODEFAULTLIB:MSVCRT") 10 | endif() 11 | else() 12 | set_target_properties(${Target} PROPERTIES LINK_FLAGS_RELEASE 13 | "-Xlinker -unexported_symbol -Xlinker \"*\" -Xlinker -dead_strip -Xlinker -dead_strip_dylibs") 14 | endif() 15 | endfunction() 16 | -------------------------------------------------------------------------------- /cmake-module/VerboseMessage.cmake: -------------------------------------------------------------------------------- 1 | #.rst 2 | # 3 | # VerboseMessage 4 | # -------------- 5 | # 6 | # Handy function for printing debug info 7 | function(verbose_message ...) 8 | if(CMAKE_VERBOSE_MAKEFILE OR VERBOSE) 9 | message(STATUS "${ARGV}") 10 | endif() 11 | endfunction() 12 | 13 | # Prints a list of vars in the format 14 | # varname1 = "${varname1}", varname2 = "${varname2}", etc. 15 | function(verbose_message_print_vars ...) 16 | set(_output_string "") 17 | foreach(_var_name ${ARGV}) 18 | set(_output_string "${_output_string}${_var_name} = \"${${_var_name}}\", ") 19 | endforeach() 20 | verbose_message("${_output_string}") 21 | endfunction() 22 | -------------------------------------------------------------------------------- /source/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include(Common) 2 | 3 | # Root dependency 4 | find_package(Components REQUIRED) 5 | 6 | # This directory is a basis for all other includes 7 | include_directories(.) 8 | 9 | # All libraries for this app 10 | add_subdirectory(VRIntro) 11 | add_subdirectory(VRIntroLib) -------------------------------------------------------------------------------- /source/VRIntro/APIFrameSupplier.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "VRIntroLib/PassthroughLayer.h" 4 | #include "APIFrameSupplier.h" 5 | 6 | #include "Leap.h" 7 | 8 | APIFrameSupplier::APIFrameSupplier() { 9 | m_LeapController.addListener(m_LeapListener); 10 | m_LeapController.setPolicyFlags(static_cast(Leap::Controller::POLICY_BACKGROUND_FRAMES | Leap::Controller::POLICY_IMAGES | Leap::Controller::POLICY_OPTIMIZE_HMD)); 11 | } 12 | 13 | APIFrameSupplier::~APIFrameSupplier() { 14 | m_LeapController.removeListener(m_LeapListener); 15 | } 16 | 17 | void APIFrameSupplier::PopulateInteractionLayer(InteractionLayer& target, const float* worldTransformRaw) const { 18 | const Leap::Frame& frame = m_LeapController.frame(); 19 | 20 | target.m_Tips.clear(); 21 | target.m_TipsLeftRight.clear(); 22 | target.m_TipsExtended.clear(); 23 | target.m_TipsIndex.clear(); 24 | target.m_Palms.clear(); 25 | target.m_PalmOrientations.clear(); 26 | target.m_SkeletonHands.clear(); 27 | EigenTypes::Matrix4x4f worldTransform = EigenTypes::Matrix4x4f(worldTransformRaw); 28 | EigenTypes::Matrix3x3f rotation = worldTransform.block<3, 3>(0, 0); 29 | EigenTypes::Vector3f translation = worldTransform.block<3, 1>(0, 3); 30 | 31 | for (int i = 0; i < frame.hands().count(); i++) { 32 | const Leap::Hand& hand = frame.hands()[i]; 33 | SkeletonHand outHand; 34 | outHand.id = hand.id(); 35 | outHand.confidence = hand.confidence(); 36 | outHand.grabStrength = hand.grabStrength(); 37 | 38 | const EigenTypes::Vector3f palm = rotation*hand.palmPosition().toVector3() + translation; 39 | const EigenTypes::Vector3f palmDir = (rotation*hand.direction().toVector3()).normalized(); 40 | const EigenTypes::Vector3f palmNormal = (rotation*hand.palmNormal().toVector3()).normalized(); 41 | const EigenTypes::Vector3f palmSide = palmDir.cross(palmNormal).normalized(); 42 | 43 | const EigenTypes::Matrix3x3f palmRotation = rotation*(EigenTypes::Matrix3x3f(hand.basis().toArray3x3()))*rotation.inverse(); 44 | EigenTypes::Matrix3x3f palmBasis = rotation*(EigenTypes::Matrix3x3f(hand.basis().toArray3x3())); 45 | 46 | // Remove scale from palmBasis 47 | const float basisScale = (palmBasis * EigenTypes::Vector3f::UnitX()).norm(); 48 | palmBasis *= 1.0f / basisScale; 49 | 50 | outHand.center = palm; 51 | outHand.rotationButNotReally = palmBasis; 52 | target.m_Palms.push_back(palm); 53 | target.m_PalmOrientations.push_back(palmRotation); 54 | EigenTypes::Vector3f sumExtended = EigenTypes::Vector3f::Zero(); 55 | int numExtended = 0; 56 | 57 | for (int j = 0; j < 5; j++) { 58 | const Leap::Finger& finger = hand.fingers()[j]; 59 | target.m_Tips.push_back(rotation*finger.tipPosition().toVector3() + translation); 60 | target.m_TipsExtended.push_back(hand.grabStrength() > 0.9f || finger.isExtended()); 61 | if (target.m_TipsExtended.back()) { 62 | sumExtended += target.m_Tips.back(); 63 | numExtended++; 64 | } 65 | target.m_TipsLeftRight.push_back(hand.isRight()); 66 | target.m_TipsIndex.push_back(j); 67 | 68 | for (int k = 0; k < 3; k++) { 69 | Leap::Bone bone = finger.bone(static_cast(k + 1)); 70 | outHand.joints[j*3 + k] = rotation*bone.nextJoint().toVector3() + translation; 71 | outHand.jointConnections[j*3 + k] = rotation*bone.prevJoint().toVector3() + translation; 72 | } 73 | } 74 | outHand.avgExtended = numExtended == 0 ? palm : (const EigenTypes::Vector3f)(sumExtended/static_cast(numExtended)); 75 | 76 | const float thumbDist = (outHand.jointConnections[0] - palm).norm(); 77 | const EigenTypes::Vector3f wrist = palm - thumbDist*(palmDir*0.8f + static_cast(hand.isLeft() ? -1 : 1)*palmSide*0.5f); 78 | 79 | for (int j = 0; j < 4; j++) { 80 | outHand.joints[15 + j] = outHand.jointConnections[3 * j]; 81 | outHand.jointConnections[15 + j] = outHand.jointConnections[3 * (j + 1)]; 82 | } 83 | outHand.joints[19] = outHand.jointConnections[12]; 84 | outHand.jointConnections[19] = wrist; 85 | outHand.joints[20] = wrist; 86 | outHand.jointConnections[20] = outHand.jointConnections[0]; 87 | 88 | // Arm 89 | const EigenTypes::Vector3f elbow = rotation*hand.arm().elbowPosition().toVector3() + translation; 90 | outHand.joints[21] = elbow - thumbDist*(hand.isLeft() ? -1 : 1)*palmSide*0.5; 91 | outHand.jointConnections[21] = wrist; 92 | outHand.joints[22] = elbow + thumbDist*(hand.isLeft() ? -1 : 1)*palmSide*0.5; 93 | outHand.jointConnections[22] = outHand.jointConnections[0]; 94 | 95 | target.m_SkeletonHands.push_back(outHand); 96 | } 97 | } 98 | 99 | void APIFrameSupplier::PopulatePassthroughLayer(PassthroughLayer& target, int i, bool useLatestImage) const { 100 | // Set passthrough images 101 | const Leap::ImageList& images = useLatestImage ? m_LeapController.images() : m_LeapController.frame().images(); 102 | if (images.count() == 2) { 103 | if (images[i].width() == 640) { 104 | target.SetImage(images[i].data(), images[i].width(), images[i].height()); 105 | } else { 106 | target.SetColorImage(images[i].data()); 107 | } 108 | target.SetDistortion(images[i].distortion()); 109 | } 110 | } 111 | 112 | bool APIFrameSupplier::IsDragonfly() const { 113 | const Leap::ImageList& images = m_LeapController.images(); 114 | 115 | return images.count() == 2 && images[0].width() != 640; 116 | } 117 | 118 | double APIFrameSupplier::GetFPSEstimate() const { 119 | return m_LeapController.frame().currentFramesPerSecond(); 120 | } 121 | -------------------------------------------------------------------------------- /source/VRIntro/APIFrameSupplier.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "VRIntroLib/IFrameSupplier.h" 4 | #include "LeapListener.h" 5 | #include "Leap.h" 6 | 7 | class APIFrameSupplier : public virtual IFrameSupplier { 8 | public: 9 | APIFrameSupplier(); 10 | ~APIFrameSupplier(); 11 | virtual void PopulateInteractionLayer(InteractionLayer& target, const float* worldTransformRaw) const override; 12 | virtual void PopulatePassthroughLayer(PassthroughLayer& target, int i, bool useLatestImage = true) const override; 13 | virtual bool IsDragonfly() const override; 14 | virtual double GetFPSEstimate() const override; 15 | 16 | virtual void Lock() override {} 17 | virtual void Unlock() override {} 18 | 19 | private: 20 | LeapListener m_LeapListener; 21 | Leap::Controller m_LeapController; 22 | }; 23 | -------------------------------------------------------------------------------- /source/VRIntro/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(VRIntro_SOURCES 2 | main.cpp 3 | APIFrameSupplier.h 4 | APIFrameSupplier.cpp 5 | LeapListener.cpp 6 | LeapListener.h 7 | ) 8 | 9 | option(SHOW_CONSOLE "Display console window for debugging" OFF) 10 | 11 | if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") # This is the correct way to detect Mac OS X operating system -- see http://www.openguru.com/2009/04/cmake-detecting-platformoperating.html 12 | set(_add_executable_options "MACOSX_BUNDLE") 13 | set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++") 14 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -Wall -Werror -Wno-reorder -Wno-unused-variable -Wno-unused-private-field") 15 | 16 | # Locate all recourses 17 | 18 | set(VRINTRO_SOURCE_DIR ${PROJECT_SOURCE_DIR}/source/VRIntro) 19 | 20 | file(GLOB COPY_IMG_RESOURCES ${VRINTRO_SOURCE_DIR}/images/*) 21 | set_source_files_properties( 22 | ${COPY_IMG_RESOURCES} 23 | PROPERTIES 24 | MACOSX_PACKAGE_LOCATION Resources/images 25 | ) 26 | 27 | file(GLOB COPY_COMPONENTS_GLSL_RESOURCES ${Components_DIR}/resources/*) 28 | file(GLOB COPY_VRINTRO_GLSL_RESOURCES ${VRINTRO_SOURCE_DIR}/shaders/*) 29 | set_source_files_properties( 30 | ${COPY_VRINTRO_GLSL_RESOURCES} 31 | PROPERTIES 32 | MACOSX_PACKAGE_LOCATION Resources/shaders 33 | ) 34 | set_source_files_properties( 35 | ${COPY_COMPONENTS_GLSL_RESOURCES} 36 | PROPERTIES 37 | MACOSX_PACKAGE_LOCATION Resources 38 | ) 39 | endif() 40 | 41 | if(NOT SHOW_CONSOLE AND ${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC") 42 | set(_add_executable_options WIN32) 43 | endif() 44 | 45 | if(${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC") 46 | set(CMAKE_CXX_DEBUG_FLAGS "${CMAKE_CXX_DEBUG_FLAGS} /Zi /fp:fast /MP") 47 | set(CMAKE_CXX_RELEASE_FLAGS "${CMAKE_CXX_RELEASE_FLAGS} /fp:except /MP") 48 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /NODEFAULTLIB:LIBCMT /ignore:4099") 49 | endif() 50 | 51 | ADD_MSVC_PRECOMPILED_HEADER("stdafx.h" "stdafx.cpp" VRIntro_SOURCES) 52 | add_executable(VRIntro 53 | ${_add_executable_options} 54 | ${VRIntro_SOURCES} 55 | ${COPY_IMG_RESOURCES} 56 | ${COPY_VRINTRO_GLSL_RESOURCES} 57 | ${COPY_COMPONENTS_GLSL_RESOURCES} 58 | ) 59 | target_link_libraries(VRIntro VRIntroLib) 60 | target_package(VRIntro Leap) 61 | 62 | ################################################################################################### 63 | # Resource rules 64 | ################################################################################################### 65 | if(${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC") 66 | include(DefinePostBuildResourceCopyRules) 67 | define_post_build_resource_copy_rules( 68 | TARGET 69 | VRIntro 70 | RELATIVE_PATH_BASE 71 | $/.. 72 | RELATIVE_PATH_RESOURCES 73 | shaders/fractal-frag.glsl 74 | shaders/fractal-vert.glsl 75 | shaders/passthrough-frag.glsl 76 | shaders/passthrough-vert.glsl 77 | shaders/solid-frag.glsl 78 | shaders/solid-vert.glsl 79 | shaders/transparent-frag.glsl 80 | shaders/transparent-vert.glsl 81 | images/help.png 82 | images/lowfps.png 83 | images/no_oculus.png 84 | images/level3_popup.png 85 | images/level4_popup.png 86 | images/no_images.png 87 | images/random.png 88 | RunMirrored.bat 89 | ABSOLUTE_PATH_RESOURCES 90 | ${Components_DIR}/resources/material-frag.glsl 91 | ${Components_DIR}/resources/matrix-transformed-vert.glsl 92 | "${SDL_SHARED_LIB}" 93 | ) 94 | endif() 95 | -------------------------------------------------------------------------------- /source/VRIntro/LeapListener.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "LeapListener.h" 3 | 4 | //#include "PrecisionTimer.h" 5 | 6 | #include 7 | #include 8 | #include "Leap.h" 9 | 10 | const double LeapListener::FPS_SMOOTHING = 0.1; 11 | 12 | using namespace Leap; 13 | 14 | LeapListener::LeapListener() : 15 | m_LastTimestamp(DBL_MAX), 16 | m_FPSIntegral(1/(std::exp(FPS_SMOOTHING/100) - 1)) { 17 | } 18 | 19 | void LeapListener::onInit(const Controller& controller) { 20 | std::cout << "Initialized" << std::endl; 21 | } 22 | 23 | void LeapListener::onConnect(const Controller& controller) { 24 | std::cout << "Connected" << std::endl; 25 | } 26 | 27 | void LeapListener::onDisconnect(const Controller& controller) { 28 | std::cout << "Disconnected" << std::endl; 29 | } 30 | 31 | void LeapListener::onExit(const Controller& controller) { 32 | std::cout << "Exited" << std::endl; 33 | } 34 | 35 | void LeapListener::onFrame(const Controller& controller) { 36 | std::lock_guard lock(m_Mutex); 37 | m_Cond.notify_all(); 38 | 39 | double t = static_cast(controller.frame().timestamp()) * 1e-6; 40 | //double t = PrecisionTimer::GetTime(); 41 | 42 | m_LastTimestamp = std::min(m_LastTimestamp, t); 43 | EstimateFPS(t - m_LastTimestamp); 44 | m_LastTimestamp = t; 45 | //std::cout << __LINE__ << ":\t m_FPSEstimate = " << (m_FPSEstimate) << std::endl; 46 | } 47 | 48 | void LeapListener::onFocusGained(const Controller& controller) { 49 | std::cout << "Focus Gained" << std::endl; 50 | m_LastTimestamp = DBL_MAX; 51 | } 52 | 53 | void LeapListener::onFocusLost(const Controller& controller) { 54 | std::cout << "Focus Lost" << std::endl; 55 | } 56 | 57 | void LeapListener::onDeviceChange(const Controller& controller) { 58 | std::cout << "Device Changed" << std::endl; 59 | const DeviceList devices = controller.devices(); 60 | 61 | for (int i = 0; i < devices.count(); ++i) { 62 | std::cout << "id: " << devices[i].toString() << std::endl; 63 | std::cout << " isStreaming: " << (devices[i].isStreaming() ? "true" : "false") << std::endl; 64 | } 65 | } 66 | 67 | void LeapListener::onServiceConnect(const Controller& controller) { 68 | std::cout << "Service Connected" << std::endl; 69 | } 70 | 71 | void LeapListener::onServiceDisconnect(const Controller& controller) { 72 | std::cout << "Service Disconnected" << std::endl; 73 | } 74 | 75 | void LeapListener::WaitForFrame() { 76 | std::unique_lock lock(m_Mutex); 77 | m_Cond.wait(lock); 78 | } 79 | 80 | void LeapListener::EstimateFPS(double dt) { 81 | m_FPSIntegral = (m_FPSIntegral + 1)*std::exp(-FPS_SMOOTHING*dt); 82 | m_FPSEstimate = m_FPSIntegral == 0 ? 0 : FPS_SMOOTHING/std::log(1 + 1/m_FPSIntegral); 83 | } 84 | -------------------------------------------------------------------------------- /source/VRIntro/LeapListener.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Leap.h" 4 | #include "EigenTypes.h" 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace Leap; 10 | 11 | class LeapListener : public Listener { 12 | public: 13 | LeapListener(); 14 | virtual void onInit(const Controller&); 15 | virtual void onConnect(const Controller&); 16 | virtual void onDisconnect(const Controller&); 17 | virtual void onExit(const Controller&); 18 | virtual void onFrame(const Controller&); 19 | virtual void onFocusGained(const Controller&); 20 | virtual void onFocusLost(const Controller&); 21 | virtual void onDeviceChange(const Controller&); 22 | virtual void onServiceConnect(const Controller&); 23 | virtual void onServiceDisconnect(const Controller&); 24 | //std::mutex& getMutex() { return m_Mutex; } 25 | //const std::mutex& getMutex() const { return m_Mutex; } 26 | void WaitForFrame(); 27 | double GetFPSEstimate() { return m_FPSEstimate; } 28 | 29 | private: 30 | static const double FPS_SMOOTHING; 31 | 32 | void EstimateFPS(double dt); 33 | 34 | std::mutex m_Mutex; 35 | std::condition_variable m_Cond; 36 | 37 | double m_FPSEstimate; 38 | double m_FPSIntegral; 39 | double m_LastTimestamp; 40 | }; 41 | -------------------------------------------------------------------------------- /source/VRIntro/RunMirrored.bat: -------------------------------------------------------------------------------- 1 | VRIntro.exe mirror -------------------------------------------------------------------------------- /source/VRIntro/images/help.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leapmotion/VRIntro/b2eb1e349e46ee2231cf8162ff6cf3e06e5ff222/source/VRIntro/images/help.png -------------------------------------------------------------------------------- /source/VRIntro/images/level3_popup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leapmotion/VRIntro/b2eb1e349e46ee2231cf8162ff6cf3e06e5ff222/source/VRIntro/images/level3_popup.png -------------------------------------------------------------------------------- /source/VRIntro/images/level4_popup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leapmotion/VRIntro/b2eb1e349e46ee2231cf8162ff6cf3e06e5ff222/source/VRIntro/images/level4_popup.png -------------------------------------------------------------------------------- /source/VRIntro/images/lowfps.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leapmotion/VRIntro/b2eb1e349e46ee2231cf8162ff6cf3e06e5ff222/source/VRIntro/images/lowfps.png -------------------------------------------------------------------------------- /source/VRIntro/images/no_images.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leapmotion/VRIntro/b2eb1e349e46ee2231cf8162ff6cf3e06e5ff222/source/VRIntro/images/no_images.png -------------------------------------------------------------------------------- /source/VRIntro/images/no_oculus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leapmotion/VRIntro/b2eb1e349e46ee2231cf8162ff6cf3e06e5ff222/source/VRIntro/images/no_oculus.png -------------------------------------------------------------------------------- /source/VRIntro/images/random.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leapmotion/VRIntro/b2eb1e349e46ee2231cf8162ff6cf3e06e5ff222/source/VRIntro/images/random.png -------------------------------------------------------------------------------- /source/VRIntro/main.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "APIFrameSupplier.h" 3 | #include "VRIntroLib/VRIntroApp.h" 4 | 5 | Uint32 SDL_Window_ID; 6 | 7 | int main(int argc, char **argv) { 8 | bool showMirror = argc >= 2 && strcmp(argv[1], "mirror") == 0; 9 | 10 | APIFrameSupplier supplier; 11 | 12 | VRIntroApp app(showMirror); 13 | app.SetFrameSupplier(&supplier); 14 | app.Run(); 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /source/VRIntro/shaders/fractal-frag.glsl: -------------------------------------------------------------------------------- 1 | #version 120 2 | uniform sampler2D texture; 3 | varying vec2 oTexcoord; 4 | 5 | vec2 iResolution = vec2(1.0, 1.0); 6 | uniform float time; 7 | uniform vec2 c_in; 8 | 9 | float LIMIT = 100; 10 | int MAXITER = 200; 11 | 12 | int count(vec2 z, vec2 c) { 13 | int iter = 0; 14 | while (iter++ < MAXITER && dot(z, z) < LIMIT) { 15 | z = vec2(z.x*z.x - z.y*z.y, 2.0*z.x*z.y) + c; 16 | } 17 | return iter; 18 | } 19 | 20 | void main(void) 21 | { 22 | vec2 q = oTexcoord; 23 | vec2 p = -2.0 + 4.0*q; 24 | 25 | float cnt = float(count(p, c_in))/float(MAXITER); 26 | float alpha = cnt > 0.99 ? 0.0 : cnt; 27 | 28 | gl_FragColor = vec4(alpha, 0.5 + alpha*0.4, 1.0-alpha*0.4, alpha); 29 | } 30 | -------------------------------------------------------------------------------- /source/VRIntro/shaders/fractal-vert.glsl: -------------------------------------------------------------------------------- 1 | #version 120 2 | attribute vec3 position; 3 | attribute vec2 texcoord; 4 | uniform mat4 projection_times_model_view_matrix; 5 | varying vec2 oTexcoord; 6 | 7 | void main(void) { 8 | gl_Position = projection_times_model_view_matrix * vec4(position, 1.0); 9 | oTexcoord = texcoord; 10 | } 11 | -------------------------------------------------------------------------------- /source/VRIntro/shaders/passthrough-frag.glsl: -------------------------------------------------------------------------------- 1 | #version 120 2 | 3 | //ray. This is specialized for overlays 4 | varying vec2 frag_ray; 5 | 6 | // original texture 7 | uniform sampler2D texture; 8 | 9 | // distortion maps 10 | uniform sampler2D distortion; 11 | 12 | // controls 13 | uniform float gamma; 14 | uniform float brightness; 15 | uniform float use_color; 16 | uniform float ir_mode; 17 | uniform float cripple_mode; 18 | uniform float stencil_mode; 19 | 20 | // debayer 21 | float width = 672.0; 22 | float height = 600.0; 23 | float rscale = 1.5; 24 | float gscale = 1.0; 25 | float bscale = 0.5; 26 | float irscale = 1.2; 27 | 28 | float corr_ir_g = 0.2; 29 | float corr_ir_rb = 0.2; 30 | float corr_r_b = 0.1; 31 | float corr_g_rb = 0.1; 32 | 33 | vec2 r_offset = vec2(0, -0.5); 34 | vec2 g_offset = vec2(0.5, -0.5); 35 | vec2 b_offset = vec2(0.5, 0); 36 | 37 | void main(void) { 38 | vec2 texCoord = texture2D(distortion, frag_ray).xy; 39 | 40 | // 60 degree FOV 16:9 aspect ratio single camera setup 41 | if (cripple_mode > 0.5 && (frag_ray.x < 0.4335 || frag_ray.x > 0.5665 || frag_ray.y < 0.4508 || frag_ray.y > 0.5492)) { 42 | gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0); 43 | return; 44 | } 45 | 46 | if (use_color > 0.5) { 47 | // Unwarp the point. Correct oculus distortion, if applicable 48 | 49 | float dx = 1.0/width; 50 | float dy = 1.0/height; 51 | 52 | vec2 redOffset = vec2(dx, dy)*r_offset; 53 | vec2 greenOffset = vec2(dx, dy)*g_offset; 54 | vec2 blueOffset = vec2(dx, dy)*b_offset; 55 | 56 | float ir_lf = texture2D(texture, texCoord).r; 57 | float ir_l = texture2D(texture, texCoord + vec2(-dx, 0)).r; 58 | float ir_t = texture2D(texture, texCoord + vec2(0, -dy)).r; 59 | float ir_r = texture2D(texture, texCoord + vec2(dx, 0)).r; 60 | float ir_b = texture2D(texture, texCoord + vec2(0, dy)).r; 61 | float ir_hf = ir_lf - 0.25*(ir_l + ir_t + ir_r + ir_b); 62 | 63 | float r_lf = texture2D(texture, texCoord + redOffset).b; 64 | float r_l = texture2D(texture, texCoord + redOffset + vec2(-dx, 0)).b; 65 | float r_t = texture2D(texture, texCoord + redOffset + vec2(0, -dy)).b; 66 | float r_r = texture2D(texture, texCoord + redOffset + vec2(dx, 0)).b; 67 | float r_b = texture2D(texture, texCoord + redOffset + vec2(0, dy)).b; 68 | float r_hf = r_lf - 0.25*(r_l + r_t + r_r + r_b); 69 | 70 | float g_lf = texture2D(texture, texCoord + greenOffset).a; 71 | float g_l = texture2D(texture, texCoord + greenOffset + vec2(-dx, 0)).a; 72 | float g_t = texture2D(texture, texCoord + greenOffset + vec2(0, -dy)).a; 73 | float g_r = texture2D(texture, texCoord + greenOffset + vec2(dx, 0)).a; 74 | float g_b = texture2D(texture, texCoord + greenOffset + vec2(0, dy)).a; 75 | float g_hf = g_lf - 0.25*(g_l + g_t + g_r + g_b); 76 | 77 | float b_lf = texture2D(texture, texCoord + blueOffset).g; 78 | float b_l = texture2D(texture, texCoord + blueOffset + vec2(-dx, 0)).g; 79 | float b_t = texture2D(texture, texCoord + blueOffset + vec2(0, -dy)).g; 80 | float b_r = texture2D(texture, texCoord + blueOffset + vec2(dx, 0)).g; 81 | float b_b = texture2D(texture, texCoord + blueOffset + vec2(0, dy)).g; 82 | float b_hf = b_lf - 0.25*(b_l + b_t + b_r + b_b); 83 | 84 | const mat4 transformation = mat4(5.6220, -1.5456, 0.3634, -0.1106, -1.6410, 3.1944, -1.7204, 0.0189, 0.1410, 0.4896, 10.8399, -0.1053, -3.7440, -1.9080, -8.6066, 1.0000); 85 | const mat4 conservative = mat4(5.6220, 0.0000, 0.3634, 0.0000, 0.0000, 3.1944, 0.0000, 0.0189, 0.1410, 0.4896, 10.8399, 0.0000, 0.0000, 0.0000, 0.0000, 1.0000); 86 | 87 | const mat4 transformation_filtered = mat4(5.0670, -1.2312, 0.8625, -0.0507, -1.5210, 3.1104, -2.0194, 0.0017, -0.8310, -0.3000, 13.1744, -0.1052, -2.4540, -1.3848, -10.9618, 1.0000); 88 | const mat4 conservative_filtered = mat4(5.0670, 0.0000, 0.8625, 0.0000, 0.0000, 3.1104, 0.0000, 0.0017, 0.0000, 0.0000, 13.1744, 0.0000, 0.0000, 0.0000, 0.0000, 1.0000); 89 | 90 | vec4 input_lf = vec4(r_lf, g_lf, b_lf, ir_lf); 91 | 92 | // input_lf = bilateral_a*bilateral(texCoord, input_lf) + (1-bilateral_a)*input_lf; 93 | input_lf.r += ir_hf*corr_ir_rb + g_hf*corr_g_rb + b_hf*corr_r_b; 94 | input_lf.g += ir_hf*corr_ir_g + r_hf*corr_g_rb + b_hf*corr_g_rb; 95 | input_lf.b += ir_hf*corr_ir_rb + r_hf*corr_r_b + g_hf*corr_g_rb; 96 | 97 | vec4 output_lf = transformation_filtered*input_lf; 98 | vec4 output_lf_fudge = conservative_filtered*input_lf; 99 | //vec4 output_lf_gray = gray*input_lf; 100 | 101 | float fudge_threshold = 0.5; 102 | float ir_fudge_threshold = 0.95; 103 | float ir_fudge_factor = 0.333*(r_lf + g_lf + b_lf); 104 | 105 | float rfudge = r_lf > fudge_threshold ? (r_lf - fudge_threshold)/(1.0 - fudge_threshold) : 0; 106 | float gfudge = g_lf > fudge_threshold ? (g_lf - fudge_threshold)/(1.0 - fudge_threshold) : 0; 107 | float bfudge = b_lf > fudge_threshold ? (b_lf - fudge_threshold)/(1.0 - fudge_threshold) : 0; 108 | float irfudge = ir_fudge_factor > ir_fudge_threshold ? (ir_fudge_factor - ir_fudge_threshold)/(1.0 - ir_fudge_threshold) : 0; 109 | rfudge *= rfudge; 110 | gfudge *= gfudge; 111 | bfudge *= bfudge; 112 | irfudge *= irfudge; 113 | 114 | gl_FragColor.r = rfudge*output_lf_fudge.r + (1-rfudge)*output_lf.r; 115 | gl_FragColor.g = gfudge*output_lf_fudge.g + (1-gfudge)*output_lf.g; 116 | gl_FragColor.b = bfudge*output_lf_fudge.b + (1-bfudge)*output_lf.b; 117 | float ir_out = irfudge*output_lf_fudge.a + (1-irfudge)*output_lf.a; 118 | 119 | gl_FragColor.r *= rscale; 120 | gl_FragColor.g *= gscale; 121 | gl_FragColor.b *= bscale; 122 | ir_out *= irscale; 123 | 124 | //float avgrgb = 0.33333*(input_lf.r + input_lf.g + input_lf.b) - 0.9*input_lf.a; 125 | //float threshold = min(1, avgrgb*100); 126 | //threshold *= threshold; 127 | //gl_FragColor.rgb = output_lf_gray.rgb*(1 - threshold) + gl_FragColor.rgb*(threshold); 128 | 129 | gl_FragColor.rgb = ir_mode > 0.5 ? vec3(ir_out) : gl_FragColor.rgb; 130 | gl_FragColor.rgb = 1.05*brightness*pow(gl_FragColor.rgb, vec3(gamma)); 131 | vec3 dist = normalize(output_lf.rgb) - vec3(0.6968, 0.4856, 0.5279); 132 | gl_FragColor.a = stencil_mode > 0.5 ? ir_out*6.0 + 0.08/(1 + 25*dot(dist, dist)) : 1.0; 133 | 134 | } else { 135 | gl_FragColor.rgb = brightness*vec3(pow(texture2D(texture, texCoord).r, gamma)); 136 | gl_FragColor.a = stencil_mode > 0.5 ? gl_FragColor.r : 1.0; 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /source/VRIntro/shaders/passthrough-vert.glsl: -------------------------------------------------------------------------------- 1 | #version 120 2 | attribute vec3 position; 3 | uniform mat4 projection_times_model_view_matrix; 4 | uniform vec2 ray_scale; 5 | uniform vec2 ray_offset; 6 | varying vec2 frag_ray; 7 | 8 | void main(void) { 9 | gl_Position = projection_times_model_view_matrix * vec4(position, 1.0); 10 | vec2 ray = vec2(-position.x/position.z, -position.y/position.z); 11 | frag_ray = ray*ray_scale + ray_offset; 12 | } 13 | -------------------------------------------------------------------------------- /source/VRIntro/shaders/solid-frag.glsl: -------------------------------------------------------------------------------- 1 | #version 120 2 | #if 1 3 | varying vec4 out_position; 4 | varying vec4 out_positionProj; 5 | varying vec4 out_velocityProj; 6 | varying vec3 oColor; 7 | #else 8 | varying vec4 oColor; 9 | #endif 10 | 11 | void main() { 12 | #if 1 13 | vec2 velProj = out_velocityProj.xy*out_positionProj.w - out_positionProj.xy*out_velocityProj.w; 14 | float scale = out_positionProj.w/(sqrt((sqrt(dot(velProj, velProj)) + 1.15e-3))*-out_position.z); 15 | gl_FragColor = vec4(oColor, 0.005*scale); 16 | #else 17 | gl_FragColor = oColor; 18 | #endif 19 | } 20 | -------------------------------------------------------------------------------- /source/VRIntro/shaders/solid-vert.glsl: -------------------------------------------------------------------------------- 1 | #version 120 2 | uniform mat4 projection_times_model_view_matrix; 3 | uniform mat4 model_view_matrix; 4 | attribute vec3 position; 5 | attribute vec3 velocity; 6 | #if 1 7 | varying vec4 out_position; 8 | varying vec4 out_positionProj; 9 | varying vec4 out_velocityProj; 10 | varying vec3 oColor; 11 | #else 12 | varying vec4 oColor; 13 | #endif 14 | 15 | void main(void) { 16 | gl_Position = projection_times_model_view_matrix * vec4(position, 1.0); 17 | #if 1 18 | out_position = model_view_matrix * vec4(position, 1.0); 19 | out_positionProj = gl_Position; 20 | out_velocityProj = projection_times_model_view_matrix * vec4(velocity, 0.0); 21 | if (dot(velocity, velocity) < 1e-10){ 22 | out_velocityProj.x = 10; 23 | } 24 | float colorFactor = 0.02/(0.02 + length(velocity)); 25 | oColor = vec3(colorFactor, 0.6 - 0.2*colorFactor, 1 - 0.8*colorFactor); 26 | #else 27 | vec4 out_position = model_view_matrix * vec4(position, 1.0); 28 | oColor = vec4(1.0, 1.0, 1.0, 0.1/length(out_position.xyz)); 29 | #endif 30 | } 31 | -------------------------------------------------------------------------------- /source/VRIntro/shaders/transparent-frag.glsl: -------------------------------------------------------------------------------- 1 | #version 120 2 | 3 | uniform sampler2D texture; 4 | varying vec2 oTexcoord; 5 | uniform float alpha; 6 | 7 | void main(void) { 8 | gl_FragColor = texture2D(texture, oTexcoord).bgra; 9 | gl_FragColor.a *= alpha; 10 | } 11 | -------------------------------------------------------------------------------- /source/VRIntro/shaders/transparent-vert.glsl: -------------------------------------------------------------------------------- 1 | #version 120 2 | attribute vec3 position; 3 | attribute vec2 texcoord; 4 | uniform mat4 projection_times_model_view_matrix; 5 | varying vec2 oTexcoord; 6 | 7 | void main(void) { 8 | gl_Position = projection_times_model_view_matrix * vec4(position, 1.0); 9 | oTexcoord = texcoord; 10 | } 11 | -------------------------------------------------------------------------------- /source/VRIntro/stdafx.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | -------------------------------------------------------------------------------- /source/VRIntro/stdafx.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "VRIntroLib/InteractionLayer.h" -------------------------------------------------------------------------------- /source/VRIntroLib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | option(USE_BULLET "Use Bullet physics engine to build block simulation level" OFF) 2 | 3 | CONFIGURE_FILE(Config.h.in ${PROJECT_BINARY_DIR}/Config.h @ONLY IMMEDIATE) 4 | include_directories(${PROJECT_BINARY_DIR}) 5 | 6 | set(VRIntroLib_SOURCES 7 | VRIntroApp.cpp 8 | VRIntroApp.h 9 | InteractionLayer.cpp 10 | InteractionLayer.h 11 | PassthroughLayer.cpp 12 | PassthroughLayer.h 13 | HandLayer.cpp 14 | HandLayer.h 15 | MessageLayer.cpp 16 | MessageLayer.h 17 | GridLayer.cpp 18 | GridLayer.h 19 | SpheresLayer.cpp 20 | SpheresLayer.h 21 | SpaceLayer.cpp 22 | SpaceLayer.h 23 | FlyingLayer.cpp 24 | FlyingLayer.h 25 | LifeLayer.cpp 26 | LifeLayer.h 27 | FractalLayer.cpp 28 | FractalLayer.h 29 | QuadsLayer.cpp 30 | QuadsLayer.h 31 | PlatformInitializer.h 32 | PrecisionTimer.h 33 | IFrameSupplier.h 34 | MathUtility.h 35 | MathUtility.cpp 36 | PhysicsLayer.h 37 | ) 38 | 39 | add_windows_sources( 40 | VRIntroLib_SOURCES 41 | PlatformInitializerWin.cpp 42 | PlatformInitializerWin.h 43 | Mirror.h 44 | Mirror.cpp 45 | ) 46 | 47 | if(USE_BULLET) 48 | set(VRIntroLib_SOURCES ${VRIntroLib_SOURCES} PhysicsLayer.cpp) 49 | endif() 50 | 51 | add_mac_sources( 52 | VRIntroLib_SOURCES 53 | PlatformInitializerMac.mm 54 | PlatformInitializerMac.h 55 | ) 56 | 57 | ADD_MSVC_PRECOMPILED_HEADER("stdafx.h" "stdafx.cpp" VRIntroLib_SOURCES) 58 | 59 | option(SHOW_CONSOLE "Display console window for debugging" OFF) 60 | 61 | set(_add_executable_options "") 62 | if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") # This is the correct way to detect Mac OS X operating system -- see http://www.openguru.com/2009/04/cmake-detecting-platformoperating.html 63 | set(_add_executable_options "MACOSX_BUNDLE") 64 | set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++") 65 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -Wall -Werror -Wno-reorder -Wno-unused-variable -Wno-unused-private-field") 66 | endif() 67 | 68 | if(NOT SHOW_CONSOLE AND ${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC") 69 | set(_add_executable_options WIN32) 70 | endif() 71 | 72 | add_library(VRIntroLib STATIC ${VRIntroLib_SOURCES}) 73 | 74 | target_link_components(VRIntroLib Application GLController GLShaderLoader GLTexture2Loader Primitives SDLController OculusVR) 75 | target_package(VRIntroLib Eigen) 76 | if(USE_BULLET) 77 | target_package(VRIntroLib Bullet) 78 | endif() 79 | 80 | if(WIN32) 81 | target_link_libraries(VRIntroLib comctl32.lib Dwmapi.lib Shlwapi.lib) 82 | endif() 83 | -------------------------------------------------------------------------------- /source/VRIntroLib/Config.h.in: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #cmakedefine01 USE_BULLET 4 | -------------------------------------------------------------------------------- /source/VRIntroLib/FlyingLayer.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "FlyingLayer.h" 3 | #include "PrecisionTimer.h" 4 | #include "MathUtility.h" 5 | 6 | #include "Primitives.h" 7 | #include "GLController.h" 8 | 9 | #include "GLTexture2.h" 10 | #include "GLTexture2Loader.h" 11 | #include "GLShaderLoader.h" 12 | 13 | FlyingLayer::FlyingLayer(const EigenTypes::Vector3f& initialEyePos) : 14 | InteractionLayer(initialEyePos), 15 | m_PopupShader(Resource("shaders/transparent")), 16 | m_PopupTexture(Resource("images/level4_popup.png")), 17 | m_GridCenter(initialEyePos), 18 | m_Velocity(EigenTypes::Vector3f::Zero()), 19 | m_RotationAA(EigenTypes::Vector3f::Zero()), 20 | m_GridOrientation(EigenTypes::Matrix4x4f::Identity()), 21 | m_LineThickness(3.0f), 22 | m_GridBrightness(80) { 23 | 24 | // Define popup text coordinates 25 | static const float edges[] = { 26 | -0.4f, -0.174f, -0.312f, 0, 0, 27 | -0.4f, +0.210f, -0.6f, 0, 1, 28 | +0.4f, -0.174f, -0.312f, 1, 0, 29 | +0.4f, +0.210f, -0.6f, 1, 1, 30 | }; 31 | 32 | m_PopupBuffer.Create(GL_ARRAY_BUFFER); 33 | m_PopupBuffer.Bind(); 34 | m_PopupBuffer.Allocate(edges, sizeof(edges), GL_STATIC_DRAW); 35 | m_PopupBuffer.Unbind(); 36 | } 37 | 38 | void FlyingLayer::Update(TimeDelta real_time_delta) { 39 | static const float PERIOD_TRANS = 0.0045f; 40 | static const float PERIOD_ROT = 1.0f; 41 | static const float FILTER = 0.2f; 42 | 43 | if (m_Palms.size() > 0) { 44 | 45 | EigenTypes::Vector3f positionSum = EigenTypes::Vector3f::Zero(); 46 | EigenTypes::Vector3f rotationAASum = EigenTypes::Vector3f::Zero(); 47 | for (size_t i = 0; i < m_Palms.size(); i++) { 48 | positionSum += m_GridOrientation.block<3, 3>(0, 0).transpose()*(m_Palms[i] - m_EyePos - m_EyeView.transpose()*EigenTypes::Vector3f(0, -0.15f, -0.05f)); 49 | //rotationAASum += RotationMatrixToVector(m_EyeView.transpose()*m_PalmOrientations[i]*m_EyeView.transpose()); 50 | EigenTypes::Matrix3x3f rot; 51 | MathUtility::RotationMatrix_VectorToVector(-EigenTypes::Vector3f::UnitZ(), m_EyeView*(m_Palms[i] - m_EyePos) - EigenTypes::Vector3f(0, -0.15f, -0.05f), rot); 52 | //std::cout << __LINE__ << ":\t rot = " << (rot) << std::endl; 53 | rotationAASum += MathUtility::RotationMatrixToVector(rot); 54 | } 55 | if (m_Palms.size() == 2) { 56 | const EigenTypes::Vector3f dir0 = m_EyeView*(m_Palms[0] - m_EyePos) - EigenTypes::Vector3f(0, -0.15f, -0.05f); 57 | const EigenTypes::Vector3f dir1 = m_EyeView*(m_Palms[1] - m_EyePos) - EigenTypes::Vector3f(0, -0.15f, -0.05f); 58 | 59 | EigenTypes::Matrix3x3f rot; 60 | MathUtility::RotationMatrix_VectorToVector((dir0.x() < dir1.x() ? 1.0f : -1.0f) * EigenTypes::Vector3f::UnitX(), dir1 - dir0, rot); 61 | //std::cout << __LINE__ << ":\t positionSum = " << (positionSum) << std::endl; 62 | 63 | rotationAASum += 2.0f*MathUtility::RotationMatrixToVector(rot); 64 | } 65 | m_Velocity = (1 - FILTER)*m_Velocity + FILTER*positionSum/static_cast(m_Palms.size()); 66 | m_RotationAA = (1 - FILTER)*m_RotationAA + FILTER*rotationAASum/static_cast(m_Palms.size()); 67 | } else { 68 | m_Velocity = (1 - 0.3f*FILTER)*m_Velocity; 69 | m_RotationAA = (1 - 0.3f*FILTER)*m_RotationAA; 70 | } 71 | 72 | static const float MAX_VELOCITY_SQNORM = 0.2f; 73 | static const float MAX_ROTATION_SQNORM = 1.0f; 74 | float dt = static_cast(real_time_delta); 75 | m_GridCenter -= m_Velocity*std::min(MAX_VELOCITY_SQNORM, m_Velocity.squaredNorm())*(dt/PERIOD_TRANS); 76 | const EigenTypes::Matrix3x3f rot = MathUtility::RotationVectorToMatrix((dt/PERIOD_ROT)*m_RotationAA*std::min(MAX_ROTATION_SQNORM, m_RotationAA.squaredNorm())); 77 | //std::cout << __LINE__ << ":\t rot = " << (rot) << std::endl; 78 | //EigenTypes::Matrix3x3f foo = ; 79 | m_GridOrientation.block<3, 3>(0, 0) = m_EyeView.transpose()*rot.transpose()*m_EyeView*m_GridOrientation.block<3, 3>(0, 0); 80 | } 81 | 82 | void FlyingLayer::Render(TimeDelta real_time_delta) const { 83 | glDepthMask(GL_FALSE); 84 | // Draw joystick 85 | //PrecisionTimer timer; 86 | //timer.Start(); 87 | m_Shader->Bind(); 88 | const EigenTypes::Vector3f desiredLightPos(0, 1.5, 0.5); 89 | const EigenTypes::Vector3f lightPos = m_EyeView*desiredLightPos; 90 | const int lightPosLoc = m_Shader->LocationOfUniform("lightPosition"); 91 | glUniform3f(lightPosLoc, lightPos[0], lightPos[1], lightPos[2]); 92 | 93 | m_Sphere.SetRadius(0.3f); 94 | m_Sphere.Translation() = (m_EyeView.transpose()*EigenTypes::Vector3f(0, 0, -1.25) + m_EyePos).cast(); 95 | m_Sphere.Material().SetDiffuseLightColor(Color(1.0f, 0.5f, 0.4f, m_Alpha)); 96 | m_Sphere.Material().SetAmbientLightingProportion(0.3f); 97 | //PrimitiveBase::DrawSceneGraph(m_Sphere, m_Renderer); 98 | m_Shader->Unbind(); 99 | 100 | glBegin(GL_LINES); 101 | glVertex3fv(EigenTypes::Vector3f::Zero().eval().data()); 102 | glVertex3fv(m_Velocity.eval().data()); 103 | glEnd(); 104 | 105 | //glMatrixMode(GL_MODELVIEW); 106 | EigenTypes::Vector3f centerpoint = m_EyePos - m_GridCenter; 107 | //glScalef(2.0f, 2.0f, 2.0f); 108 | glMultMatrixf(m_GridOrientation.eval().data()); 109 | glTranslatef(m_GridCenter.x(), m_GridCenter.y(), m_GridCenter.z()); 110 | 111 | int xShift = 2*static_cast(0.5f*centerpoint.x() + 0.5f); 112 | int yShift = 20*static_cast(0.05f*centerpoint.y() + 0.5f); 113 | int zShift = 2*static_cast(0.5f*centerpoint.z() + 0.5f); 114 | glLineWidth(m_LineThickness); 115 | glBegin(GL_LINES); 116 | for (int i = -50 + xShift; i < 50 + xShift; i+=2) { 117 | for (int j = -30 + yShift; j < 50 + yShift; j+=20) { 118 | for (int k = -50 + zShift; k < 50 + zShift; k+=2) { 119 | EigenTypes::Vector3f a(static_cast(i), static_cast(j), static_cast(k)); 120 | EigenTypes::Vector3f b(static_cast(i + 2), static_cast(j), static_cast(k)); 121 | //EigenTypes::Vector3f c(static_cast(i), static_cast(j + 2), static_cast(k)); 122 | EigenTypes::Vector3f d(static_cast(i), static_cast(j), static_cast(k + 2)); 123 | float aColor = std::min(1.0f, static_cast(m_GridBrightness)/(20.0f + (a - centerpoint).squaredNorm())); 124 | float bColor = std::min(1.0f, static_cast(m_GridBrightness)/(20.0f + (b - centerpoint).squaredNorm())); 125 | //float cColor = std::min(1.1f9 100.02/(10.0f + (c - centerpoint).squaredNorm())); 126 | float dColor = std::min(1.0f, static_cast(m_GridBrightness)/(20.0f + (d - centerpoint).squaredNorm())); 127 | 128 | glColor4f(1.0f, 1.0f, 1.0f, m_Alpha*aColor); 129 | glVertex3fv((a).eval().data()); 130 | 131 | glColor4f(1.0f, 1.0f, 1.0f, m_Alpha*bColor); 132 | glVertex3fv((b).eval().data()); 133 | 134 | glColor4f(1.0f, 1.0f, 1.0f, m_Alpha*aColor); 135 | glVertex3fv((a).eval().data()); 136 | 137 | glColor4f(1.0f, 1.0f, 1.0f, m_Alpha*dColor); 138 | glVertex3fv((d).eval().data()); 139 | } 140 | } 141 | } 142 | glEnd(); 143 | //double elapsed = timer.Stop(); 144 | //std::cout << __LINE__ << ":\t elapsed = " << (elapsed) << std::endl; 145 | if (m_Palms.size() == 0) { 146 | RenderPopup(); 147 | } 148 | glDepthMask(GL_TRUE); 149 | } 150 | 151 | void FlyingLayer::RenderPopup() const { 152 | m_PopupShader->Bind(); 153 | EigenTypes::Matrix4x4f modelView = m_ModelView; 154 | modelView.block<3, 1>(0, 3) += modelView.block<3, 3>(0, 0)*m_EyePos; 155 | modelView.block<3, 3>(0, 0) = EigenTypes::Matrix3x3f::Identity(); 156 | GLShaderMatrices::UploadUniforms(*m_PopupShader, modelView.cast(), m_Projection.cast(), BindFlags::NONE); 157 | 158 | glActiveTexture(GL_TEXTURE0 + 0); 159 | glUniform1i(m_PopupShader->LocationOfUniform("texture"), 0); 160 | glUniform1f(m_PopupShader->LocationOfUniform("alpha"), 1.0f); 161 | 162 | m_PopupBuffer.Bind(); 163 | glEnableVertexAttribArray(m_PopupShader->LocationOfAttribute("position")); 164 | glEnableVertexAttribArray(m_PopupShader->LocationOfAttribute("texcoord")); 165 | glVertexAttribPointer(m_PopupShader->LocationOfAttribute("position"), 3, GL_FLOAT, GL_TRUE, 5*sizeof(float), (GLvoid*)0); 166 | glVertexAttribPointer(m_PopupShader->LocationOfAttribute("texcoord"), 2, GL_FLOAT, GL_TRUE, 5*sizeof(float), (GLvoid*)(3*sizeof(float))); 167 | 168 | m_PopupTexture->Bind(); 169 | glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 170 | glBindTexture(GL_TEXTURE_2D, 0); // Unbind 171 | 172 | glDisableVertexAttribArray(m_PopupShader->LocationOfAttribute("position")); 173 | glDisableVertexAttribArray(m_PopupShader->LocationOfAttribute("texcoord")); 174 | m_PopupBuffer.Unbind(); 175 | 176 | m_PopupShader->Unbind(); 177 | } 178 | 179 | EventHandlerAction FlyingLayer::HandleKeyboardEvent(const SDL_KeyboardEvent &ev) { 180 | switch (ev.keysym.sym) { 181 | case 'g': 182 | if (SDL_GetModState() & KMOD_SHIFT) { 183 | m_GridBrightness = std::min(300, m_GridBrightness + 10); 184 | } else { 185 | m_GridBrightness = std::max(10, m_GridBrightness - 10); 186 | } 187 | return EventHandlerAction::CONSUME; 188 | case 'l': 189 | if (SDL_GetModState() & KMOD_SHIFT) { 190 | m_LineThickness = std::min(10.0f, m_LineThickness + 0.5f); 191 | } else { 192 | m_LineThickness = std::max(0.5f, m_LineThickness - 0.5f); 193 | } 194 | return EventHandlerAction::CONSUME; 195 | default: 196 | return EventHandlerAction::PASS_ON; 197 | } 198 | } 199 | -------------------------------------------------------------------------------- /source/VRIntroLib/FlyingLayer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Interactionlayer.h" 4 | 5 | class GLShader; 6 | 7 | class FlyingLayer : public InteractionLayer { 8 | public: 9 | FlyingLayer(const EigenTypes::Vector3f& initialEyePos); 10 | //virtual ~FlyingLayer (); 11 | 12 | 13 | 14 | virtual void Update(TimeDelta real_time_delta) override; 15 | virtual void Render(TimeDelta real_time_delta) const override; 16 | EventHandlerAction HandleKeyboardEvent(const SDL_KeyboardEvent &ev) override; 17 | 18 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW 19 | 20 | private: 21 | mutable GLBuffer m_PopupBuffer; 22 | std::shared_ptr m_PopupTexture; 23 | std::shared_ptr m_PopupShader; 24 | 25 | void RenderPopup() const; 26 | 27 | EigenTypes::Vector3f m_GridCenter; 28 | //EigenTypes::Vector3f m_AveragePalm; 29 | EigenTypes::Vector3f m_Velocity; 30 | EigenTypes::Vector3f m_RotationAA; 31 | EigenTypes::Matrix4x4f m_GridOrientation; 32 | float m_LineThickness; 33 | int m_GridBrightness; 34 | }; 35 | -------------------------------------------------------------------------------- /source/VRIntroLib/FractalLayer.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "FractalLayer.h" 3 | 4 | #include "GLController.h" 5 | #include "Resource.h" 6 | #include "GLTexture2.h" 7 | #include "GLTexture2Loader.h" 8 | 9 | FractalLayer::FractalLayer(const EigenTypes::Vector3f& initialEyePos) : 10 | InteractionLayer(EigenTypes::Vector3f::Zero(), "shaders/fractal"), 11 | m_Texture(Resource("images/random.png")), 12 | m_AvgPalm(EigenTypes::Vector3f::Zero()), 13 | m_Time(0) { 14 | 15 | static const float edges[] = { 16 | // Shader rect 17 | -2, -2, -1.5, 0, 0, 18 | -2, +2, -1.5, 0, 1, 19 | +2, -2, -1.5, 1, 0, 20 | +2, +2, -1.5, 1, 1, 21 | }; 22 | 23 | m_Buffer.Create(GL_ARRAY_BUFFER); 24 | m_Buffer.Bind(); 25 | m_Buffer.Allocate(edges, sizeof(edges), GL_STATIC_DRAW); 26 | m_Buffer.Unbind(); 27 | 28 | m_Texture->Bind(); 29 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 30 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 31 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 32 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 33 | m_Texture->Unbind(); 34 | } 35 | 36 | void FractalLayer::Update(TimeDelta real_time_delta) { 37 | m_Time += real_time_delta; 38 | static const float FILTER = 0.2f; 39 | 40 | if (m_Palms.size() > 0) { 41 | 42 | EigenTypes::Vector3f positionSum = EigenTypes::Vector3f::Zero(); 43 | for (size_t i = 0; i < m_Palms.size(); i++) { 44 | positionSum += m_EyeView*(m_Palms[i] - m_EyePos); 45 | } 46 | m_AvgPalm = (1 - FILTER)*m_AvgPalm + FILTER*(EigenTypes::Vector3f(-0.8f, .156f, 0)+0.2f*positionSum/static_cast(m_Palms.size())); 47 | } 48 | } 49 | 50 | void FractalLayer::Render(TimeDelta real_time_delta) const { 51 | glDepthMask(GL_FALSE); 52 | 53 | m_Shader->Bind(); 54 | EigenTypes::Matrix4x4f modelView = m_ModelView; 55 | modelView.block<3, 1>(0, 3) += modelView.block<3, 3>(0, 0)*m_EyePos; 56 | modelView.block<3, 3>(0, 0) = EigenTypes::Matrix3x3f::Identity(); 57 | GLShaderMatrices::UploadUniforms(*m_Shader, modelView.cast(), m_Projection.cast(), BindFlags::NONE); 58 | 59 | glActiveTexture(GL_TEXTURE0 + 0); 60 | glUniform1i(m_Shader->LocationOfUniform("texture"), 0); 61 | glUniform1f(m_Shader->LocationOfUniform("time"), static_cast(m_Time)); 62 | glUniform2fv(m_Shader->LocationOfUniform("c_in"), 1, m_AvgPalm.data()); 63 | 64 | m_Buffer.Bind(); 65 | glEnableVertexAttribArray(m_Shader->LocationOfAttribute("position")); 66 | glEnableVertexAttribArray(m_Shader->LocationOfAttribute("texcoord")); 67 | glVertexAttribPointer(m_Shader->LocationOfAttribute("position"), 3, GL_FLOAT, GL_TRUE, 5*sizeof(float), (GLvoid*)0); 68 | glVertexAttribPointer(m_Shader->LocationOfAttribute("texcoord"), 2, GL_FLOAT, GL_TRUE, 5*sizeof(float), (GLvoid*)(3*sizeof(float))); 69 | 70 | m_Texture->Bind(); 71 | glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 72 | 73 | glDisableVertexAttribArray(m_Shader->LocationOfAttribute("position")); 74 | glDisableVertexAttribArray(m_Shader->LocationOfAttribute("texcoord")); 75 | m_Buffer.Unbind(); 76 | 77 | m_Shader->Unbind(); 78 | glDepthMask(GL_TRUE); 79 | } 80 | 81 | EventHandlerAction FractalLayer::HandleKeyboardEvent(const SDL_KeyboardEvent &ev) { 82 | //switch (ev.keysym.sym) { 83 | //default: 84 | return EventHandlerAction::PASS_ON; 85 | //} 86 | } 87 | -------------------------------------------------------------------------------- /source/VRIntroLib/FractalLayer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Interactionlayer.h" 4 | 5 | class GLTexture2; 6 | 7 | class FractalLayer : public InteractionLayer 8 | { 9 | public: 10 | FractalLayer(const EigenTypes::Vector3f& initialEyePos); 11 | //virtual ~FractalLayer (); 12 | 13 | virtual void Update(TimeDelta real_time_delta) override; 14 | virtual void Render(TimeDelta real_time_delta) const override; 15 | EventHandlerAction HandleKeyboardEvent(const SDL_KeyboardEvent &ev) override; 16 | 17 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW 18 | 19 | private: 20 | mutable GLBuffer m_Buffer; 21 | 22 | std::shared_ptr m_Texture; 23 | TimePoint m_Time; 24 | 25 | EigenTypes::Vector3f m_AvgPalm; 26 | }; 27 | -------------------------------------------------------------------------------- /source/VRIntroLib/GridLayer.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "GridLayer.h" 3 | 4 | #include "GLController.h" 5 | #include 6 | 7 | GridLayer::GridLayer(const EigenTypes::Vector3f& initialEyePos) : 8 | InteractionLayer(initialEyePos), 9 | m_DivTheta(22), 10 | m_DivPhi(40), 11 | m_Radius(0.7f) { 12 | 13 | } 14 | 15 | void GridLayer::Update(TimeDelta real_time_delta) { 16 | 17 | } 18 | 19 | void GridLayer::Render(TimeDelta real_time_delta) const { 20 | glTranslatef(m_EyePos.x(), m_EyePos.y(), m_EyePos.z()); 21 | glColor4f(0.2f, 0.6f, 1.0f, m_Alpha*0.5f); 22 | glLineWidth(1.0f); 23 | glBegin(GL_LINES); 24 | for (int i = 0; i < m_DivPhi; i++) { 25 | float phi0 = (float)M_PI*(i/static_cast(m_DivPhi) - 0.5f); 26 | float phi1 = (float)M_PI*((i + 1)/static_cast(m_DivPhi) - 0.5f); 27 | for (int j = 0; j < m_DivTheta; j++) { 28 | float theta0 = 2*(float)M_PI*(j/static_cast(m_DivTheta)); 29 | float theta1 = 2*(float)M_PI*((j + 1)/static_cast(m_DivTheta)); 30 | glVertex3f(m_Radius*cos(phi0)*cos(theta0), m_Radius*sin(phi0), m_Radius*cos(phi0)*sin(theta0)); 31 | glVertex3f(m_Radius*cos(phi0)*cos(theta1), m_Radius*sin(phi0), m_Radius*cos(phi0)*sin(theta1)); 32 | glVertex3f(m_Radius*cos(phi0)*cos(theta0), m_Radius*sin(phi0), m_Radius*cos(phi0)*sin(theta0)); 33 | glVertex3f(m_Radius*cos(phi1)*cos(theta0), m_Radius*sin(phi1), m_Radius*cos(phi1)*sin(theta0)); 34 | } 35 | } 36 | glEnd(); 37 | } 38 | 39 | EventHandlerAction GridLayer::HandleKeyboardEvent(const SDL_KeyboardEvent &ev) { 40 | if (ev.type == SDL_KEYDOWN) { 41 | switch (ev.keysym.sym) { 42 | case 'p': 43 | if (SDL_GetModState() & KMOD_SHIFT) { 44 | m_DivPhi = std::min(100, m_DivPhi + 2); 45 | } else { 46 | m_DivPhi = std::max(4, m_DivPhi - 2); 47 | } 48 | return EventHandlerAction::CONSUME; 49 | case 't': 50 | if (SDL_GetModState() & KMOD_SHIFT) { 51 | m_DivTheta = std::min(200, m_DivTheta + 4); 52 | } else { 53 | m_DivTheta = std::max(8, m_DivTheta - 4); 54 | } 55 | return EventHandlerAction::CONSUME; 56 | case 'r': 57 | if (SDL_GetModState() & KMOD_SHIFT) { 58 | m_Radius = std::min(20.0f, m_Radius * 1.03f); 59 | } else { 60 | m_Radius = std::max(0.1f, m_Radius * 0.97087378f); 61 | } 62 | return EventHandlerAction::CONSUME; 63 | default: 64 | return EventHandlerAction::PASS_ON; 65 | } 66 | } 67 | return EventHandlerAction::PASS_ON; 68 | } 69 | -------------------------------------------------------------------------------- /source/VRIntroLib/GridLayer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Interactionlayer.h" 4 | 5 | class GLShader; 6 | 7 | class GridLayer : public InteractionLayer { 8 | public: 9 | GridLayer(const EigenTypes::Vector3f& initialEyePos); 10 | //virtual ~GridLayer (); 11 | 12 | virtual void Update(TimeDelta real_time_delta) override; 13 | virtual void Render(TimeDelta real_time_delta) const override; 14 | EventHandlerAction HandleKeyboardEvent(const SDL_KeyboardEvent &ev) override; 15 | 16 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW 17 | private: 18 | int m_DivTheta; 19 | int m_DivPhi; 20 | float m_Radius; 21 | }; 22 | -------------------------------------------------------------------------------- /source/VRIntroLib/HandLayer.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "HandLayer.h" 3 | 4 | #include "GLController.h" 5 | 6 | HandLayer::HandLayer(const EigenTypes::Vector3f& initialEyePos, bool isGhost) : 7 | InteractionLayer(initialEyePos), 8 | m_IsGhost(isGhost) { 9 | // TODO: switch to non-default shader 10 | } 11 | 12 | void HandLayer::Update(TimeDelta real_time_delta) { 13 | 14 | } 15 | 16 | void HandLayer::Render(TimeDelta real_time_delta) const { 17 | DrawSkeletonHands(m_IsGhost); 18 | } 19 | 20 | EventHandlerAction HandLayer::HandleKeyboardEvent(const SDL_KeyboardEvent &ev) { 21 | //switch (ev.keysym.sym) { 22 | //default: 23 | return EventHandlerAction::PASS_ON; 24 | //} 25 | } 26 | -------------------------------------------------------------------------------- /source/VRIntroLib/HandLayer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Interactionlayer.h" 4 | 5 | class GLShader; 6 | 7 | class HandLayer : public InteractionLayer { 8 | public: 9 | HandLayer(const EigenTypes::Vector3f& initialEyePos, bool isGhost = false); 10 | //virtual ~HandLayer (); 11 | 12 | virtual void Update(TimeDelta real_time_delta) override; 13 | virtual void Render(TimeDelta real_time_delta) const override; 14 | EventHandlerAction HandleKeyboardEvent(const SDL_KeyboardEvent &ev) override; 15 | 16 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW 17 | 18 | private: 19 | bool m_IsGhost; 20 | }; 21 | -------------------------------------------------------------------------------- /source/VRIntroLib/IFrameSupplier.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class InteractionLayer; 4 | class PassthroughLayer; 5 | 6 | class IFrameSupplier { 7 | public: 8 | virtual void PopulateInteractionLayer(InteractionLayer& target, const float* worldTransformRaw) const = 0; 9 | virtual void PopulatePassthroughLayer(PassthroughLayer& target, int i, bool useLatestImage = true) const = 0; 10 | virtual bool IsDragonfly() const = 0; 11 | virtual double GetFPSEstimate() const = 0; 12 | virtual void Lock() = 0; 13 | virtual void Unlock() = 0; 14 | }; 15 | -------------------------------------------------------------------------------- /source/VRIntroLib/InteractionLayer.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "InteractionLayer.h" 3 | 4 | #include "Resource.h" 5 | #include "GLShader.h" 6 | #include "GLShaderLoader.h" 7 | #include "GLController.h" 8 | 9 | 10 | EigenTypes::Matrix3x3f SkeletonHand::arbitraryRelatedRotation() const 11 | { 12 | EigenTypes::Matrix3x3f result = rotationButNotReally; 13 | EigenTypes::Vector3f z = result.col(0).cross(result.col(1)); 14 | result.col(2) = z; 15 | return result; 16 | } 17 | 18 | InteractionLayer::InteractionLayer(const EigenTypes::Vector3f& initialEyePos, const std::string& shaderName) : 19 | m_Shader(Resource(shaderName)), 20 | m_EyePos(initialEyePos), 21 | m_Alpha(0.0f) { 22 | 23 | } 24 | 25 | void InteractionLayer::DrawSkeletonHands(bool capsuleMode) const { 26 | m_Shader->Bind(); 27 | const EigenTypes::Vector3f desiredLightPos(0, 1.5, 0.5); 28 | const EigenTypes::Vector3f lightPos = m_EyeView*desiredLightPos; 29 | const int lightPosLoc = m_Shader->LocationOfUniform("light_position"); 30 | glUniform3f(lightPosLoc, lightPos[0], lightPos[1], lightPos[2]); 31 | 32 | for (size_t i = 0; i < m_SkeletonHands.size(); i++) { 33 | const SkeletonHand hand = m_SkeletonHands[i]; 34 | float distSq = (hand.center - m_EyePos - m_EyeView.transpose()*EigenTypes::Vector3f(0, 0, -0.3f)).squaredNorm(); 35 | float alpha = m_Alpha*std::min(hand.confidence, 0.006f/(distSq*distSq)); 36 | 37 | // Set common properties 38 | m_Sphere.Material().SetDiffuseLightColor(Color(0.4f, 0.6f, 1.0f, alpha)); 39 | m_Sphere.Material().SetAmbientLightColor(Color(0.4f, 0.6f, 1.0f, alpha)); 40 | m_Sphere.Material().SetAmbientLightingProportion(0.3f); 41 | 42 | m_Cylinder.Material().SetDiffuseLightColor(Color(0.85f, 0.85f, 0.85f, alpha)); 43 | m_Cylinder.Material().SetAmbientLightColor(Color(0.85f, 0.85f, 0.85f, alpha)); 44 | m_Cylinder.Material().SetAmbientLightingProportion(0.3f); 45 | 46 | if (capsuleMode) { 47 | glEnable(GL_STENCIL_TEST); 48 | glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 49 | glStencilMask(0); 50 | glStencilFunc(GL_EQUAL, 1, 1); // Pass test if stencil value is 1 51 | for (int i = 0; i < 23; i++) { 52 | DrawSphere(hand.joints[i], 2.5f*m_FingerRadius, 1.0f); 53 | DrawCylinder(hand.joints[i], hand.jointConnections[i], 2.5f*m_FingerRadius, 1.0f); 54 | } 55 | // Fill in palm 56 | DrawSphere(hand.center, 3.0f*m_FingerRadius, 1.0f); 57 | DrawSphere((hand.center + hand.joints[19] + 2.0*hand.joints[20])*0.25f, 2.5f*m_FingerRadius, 1.0f); 58 | DrawSphere((hand.center + hand.joints[0] + 2.0*hand.joints[20])*0.25f, 2.5f*m_FingerRadius, 1.0f); 59 | DrawSphere(hand.center + 12.0*m_FingerRadius*(hand.center - m_EyePos).normalized(), 12.0*m_FingerRadius, 1.0f); 60 | 61 | // Fill in arm 62 | DrawCylinder((hand.joints[20] + hand.joints[21])*0.5f, (hand.jointConnections[20] + hand.jointConnections[21])*0.5f, 3.0f*m_FingerRadius, 1.0f); 63 | 64 | glDisable(GL_STENCIL_TEST); 65 | glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 66 | glStencilMask(1); 67 | } else { 68 | DrawSkeletonHand(hand, alpha); 69 | } 70 | } 71 | m_Shader->Unbind(); 72 | } 73 | 74 | void InteractionLayer::DrawSkeletonHand(const SkeletonHand& hand, float alpha) const { 75 | for (int i = 0; i < 23; i++) { 76 | DrawSphere(hand.joints[i], m_FingerRadius, alpha); 77 | DrawCylinder(hand.joints[i], hand.jointConnections[i], 0.7f*m_FingerRadius, alpha); 78 | } 79 | } 80 | 81 | //std::shared_ptr m_Shader; 82 | //mutable RenderState m_Renderer; 83 | //EigenTypes::Vector3f m_EyePos; 84 | 85 | void InteractionLayer::DrawCylinder(const EigenTypes::Vector3f& p0, const EigenTypes::Vector3f& p1, float radius, float alpha) const { 86 | m_Cylinder.SetRadius(static_cast(radius)); 87 | m_Cylinder.Translation() = 0.5*(p0 + p1).cast(); 88 | 89 | EigenTypes::Vector3f direction = p1 - p0; 90 | const float length = direction.norm(); 91 | m_Cylinder.SetHeight(length); 92 | direction /= length; 93 | 94 | EigenTypes::Vector3f Y = direction; 95 | EigenTypes::Vector3f X = Y.cross(EigenTypes::Vector3f::UnitZ()).normalized(); 96 | EigenTypes::Vector3f Z = Y.cross(X).normalized(); 97 | 98 | EigenTypes::Matrix3x3f basis; 99 | basis << X, Y, Z; 100 | m_Cylinder.LinearTransformation() = basis.cast(); 101 | PrimitiveBase::DrawSceneGraph(m_Cylinder, m_Renderer); 102 | } 103 | 104 | void InteractionLayer::DrawSphere(const EigenTypes::Vector3f& p0, float radius, float alpha) const { 105 | m_Sphere.SetRadius(static_cast(radius)); 106 | m_Sphere.Translation() = p0.cast(); 107 | PrimitiveBase::DrawSceneGraph(m_Sphere, m_Renderer); 108 | } 109 | -------------------------------------------------------------------------------- /source/VRIntroLib/Interactionlayer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "RenderableEventHandler.h" 4 | #include "RenderState.h" 5 | #include "Primitives.h" 6 | 7 | #include "EigenTypes.h" 8 | 9 | #include 10 | 11 | class GLShader; 12 | 13 | struct SkeletonHand { 14 | 15 | // Hand Id from Leap API 16 | int id; 17 | 18 | float confidence; 19 | 20 | // Pinch strength, from API 21 | float grabStrength; 22 | 23 | // Palm's position 24 | EigenTypes::Vector3f center; 25 | 26 | // Palm's rotation/basis -- it's reversed for the left hand 27 | EigenTypes::Matrix3x3f rotationButNotReally; 28 | 29 | //EigenTypes::stdvectorV3f tips[5]; 30 | EigenTypes::Vector3f joints[23]; 31 | EigenTypes::Vector3f jointConnections[23]; 32 | EigenTypes::Vector3f avgExtended; 33 | 34 | EigenTypes::Vector3f getManipulationPoint() const { return 0.5f * (joints[0] + joints[3]); } 35 | 36 | EigenTypes::Matrix3x3f arbitraryRelatedRotation() const; 37 | 38 | 39 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW 40 | }; 41 | 42 | class InteractionLayer : public RenderableEventHandler { 43 | public: 44 | InteractionLayer(const EigenTypes::Vector3f& initialEyePos, const std::string& shaderName = "material"); 45 | void UpdateEyePos(const EigenTypes::Vector3f& eyePos) { m_EyePos = eyePos; } 46 | void UpdateEyeView(const EigenTypes::Matrix3x3f& eyeView) { m_EyeView = eyeView; } 47 | float& Alpha() { return m_Alpha; } 48 | void SetProjection(const EigenTypes::Matrix4x4f& value) { m_Projection = value; m_Renderer.GetProjection().Matrix() = value.cast(); } 49 | void SetModelView(const EigenTypes::Matrix4x4f& value) { m_ModelView = value; m_Renderer.GetModelView().Matrix() = value.cast(); } 50 | void SetFingerRadius(float value) { m_FingerRadius = value; } 51 | 52 | virtual void OnSelected() {} 53 | 54 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW 55 | 56 | // Hack: Making these public for now for easier access 57 | std::vector m_SkeletonHands; 58 | EigenTypes::stdvectorV3f m_Palms; 59 | std::vector> m_PalmOrientations; 60 | EigenTypes::stdvectorV3f m_Tips; 61 | std::vector m_TipsLeftRight; 62 | std::vector m_TipsExtended; 63 | std::vector m_TipsIndex; 64 | 65 | protected: 66 | void DrawSkeletonHands(bool capsuleMode = false) const; 67 | mutable RenderState m_Renderer; 68 | std::shared_ptr m_Shader; 69 | mutable Sphere m_Sphere; 70 | mutable Cylinder m_Cylinder; 71 | mutable Box m_Box; 72 | float m_FingerRadius; 73 | 74 | EigenTypes::Matrix4x4f m_Projection; 75 | EigenTypes::Matrix4x4f m_ModelView; 76 | EigenTypes::Vector3f m_EyePos; 77 | EigenTypes::Matrix3x3f m_EyeView; 78 | 79 | float m_Alpha; 80 | 81 | private: 82 | void DrawSkeletonHand(const SkeletonHand& hand, float alpha) const; 83 | void DrawCylinder(const EigenTypes::Vector3f& p0, const EigenTypes::Vector3f& p1, float radius, float alpha) const; 84 | void DrawSphere(const EigenTypes::Vector3f& p0, float radius, float alpha) const; 85 | }; 86 | -------------------------------------------------------------------------------- /source/VRIntroLib/LifeLayer.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | -------------------------------------------------------------------------------- /source/VRIntroLib/LifeLayer.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leapmotion/VRIntro/b2eb1e349e46ee2231cf8162ff6cf3e06e5ff222/source/VRIntroLib/LifeLayer.h -------------------------------------------------------------------------------- /source/VRIntroLib/MathUtility.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "MathUtility.h" 3 | 4 | EigenTypes::Matrix3x3f MathUtility::CrossProductMatrix(const EigenTypes::Vector3f& vector) { 5 | EigenTypes::Matrix3x3f result; 6 | CrossProductMatrix(vector, result); 7 | return result; 8 | } 9 | 10 | void MathUtility::CrossProductMatrix(const EigenTypes::Vector3f& vector, EigenTypes::Matrix3x3f &retval) { 11 | retval << 0.0, -vector.z(), vector.y(), 12 | vector.z(), 0.0, -vector.x(), 13 | -vector.y(), vector.x(), 0.0; 14 | } 15 | 16 | EigenTypes::Matrix3x3f MathUtility::RotationVectorToMatrix(const EigenTypes::Vector3f& angle_scaled_axis) { 17 | float angle_squared = angle_scaled_axis.squaredNorm(); 18 | if (angle_squared < 1e-10f) { 19 | return EigenTypes::Matrix3x3f::Identity(); 20 | } 21 | const float angle = std::sqrt(angle_squared); 22 | EigenTypes::Matrix3x3f retval; 23 | AngleAxisRotationMatrix(angle, angle_scaled_axis, retval); 24 | return retval; 25 | } 26 | 27 | EigenTypes::Vector3f MathUtility::RotationMatrixToVector(const EigenTypes::Matrix3x3f& rotationMatrix) { 28 | static const float epsilon = 1e-6f; 29 | const float cs = (rotationMatrix.trace() - 1.0f)*0.5f; 30 | if (cs > 1.0f - epsilon) { 31 | return EigenTypes::Vector3f::Zero(); 32 | } else if (cs < epsilon - 1.0f) { 33 | Eigen::SelfAdjointEigenSolver evals(rotationMatrix, Eigen::ComputeEigenvectors); 34 | EigenTypes::Vector3f rotVector = evals.eigenvectors().col(2).transpose(); 35 | return rotVector.normalized()*(float)M_PI; 36 | } else { 37 | const float sn = std::sqrt(1.0f - cs*cs); 38 | const float angle = std::acos(cs); 39 | const float multiplier = angle * 0.5f / sn; 40 | return EigenTypes::Vector3f((rotationMatrix(2, 1) - rotationMatrix(1, 2))*multiplier, 41 | (rotationMatrix(0, 2) - rotationMatrix(2, 0))*multiplier, 42 | (rotationMatrix(1, 0) - rotationMatrix(0, 1))*multiplier); 43 | } 44 | } 45 | 46 | void MathUtility::AngleAxisRotationMatrix(float angle, const EigenTypes::Vector3f& axis, EigenTypes::Matrix3x3f &retval) { 47 | EigenTypes::Vector3f axisVec = axis.normalized(); 48 | 49 | // use Rodrigues' formula to create the EigenTypes::Matrix 50 | float cos_angle = std::cos(angle); 51 | float sin_angle = std::sin(angle); 52 | // start with the cross product term, calculating it in-place 53 | CrossProductMatrix(axisVec*sin_angle, retval); 54 | // add EigenTypes::Matrix3x3f::Identity()*cos_angle to retval 55 | retval(0, 0) += cos_angle; 56 | retval(1, 1) += cos_angle; 57 | retval(2, 2) += cos_angle; 58 | // add the outer product term -- multiply the scalar factor before forming the outer product 59 | retval += ((1.0f - cos_angle)*axisVec) * axisVec.transpose(); 60 | } 61 | 62 | void MathUtility::RotationMatrix_VectorToVector(const EigenTypes::Vector3f& from, const EigenTypes::Vector3f& to, EigenTypes::Matrix3x3f &retval) { 63 | EigenTypes::Vector3f fromVec = from.normalized(); 64 | EigenTypes::Vector3f toVec = to.normalized(); 65 | EigenTypes::Vector3f axis(fromVec.cross(toVec)); 66 | if (axis.squaredNorm() < 1e-10f) { 67 | retval.setIdentity(); 68 | } else { 69 | float angle = std::acos(fromVec.dot(toVec)); 70 | AngleAxisRotationMatrix(angle, axis.normalized(), retval); 71 | } 72 | } 73 | 74 | EigenTypes::Matrix3x3f MathUtility::RotationMatrixLinearInterpolation(const EigenTypes::Matrix3x3f& A0, const EigenTypes::Matrix3x3f& A1, float t) { 75 | EigenTypes::Vector3f dA = RotationMatrixToVector(A0.transpose()*A1); 76 | float angle = std::fmod(t*dA.norm(), (float)M_PI); 77 | EigenTypes::Matrix3x3f At = A0*RotationVectorToMatrix(angle*dA.normalized()); 78 | return At; 79 | } 80 | 81 | void MathUtility::RotationMatrixSuppress(EigenTypes::Matrix3x3f& A0, float t) { 82 | const EigenTypes::Vector3f dA = RotationMatrixToVector(A0); 83 | A0 = RotationVectorToMatrix(dA * t); 84 | } -------------------------------------------------------------------------------- /source/VRIntroLib/MathUtility.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "EigenTypes.h" 4 | 5 | class MathUtility { 6 | public: 7 | static EigenTypes::Matrix3x3f CrossProductMatrix(const EigenTypes::Vector3f& vector); 8 | static void CrossProductMatrix(const EigenTypes::Vector3f& vector, EigenTypes::Matrix3x3f &retval); 9 | static EigenTypes::Matrix3x3f RotationVectorToMatrix(const EigenTypes::Vector3f& angle_scaled_axis); 10 | static EigenTypes::Vector3f RotationMatrixToVector(const EigenTypes::Matrix3x3f& rotationMatrix); 11 | static void AngleAxisRotationMatrix(float angle, const EigenTypes::Vector3f& axis, EigenTypes::Matrix3x3f &retval); 12 | static void RotationMatrix_VectorToVector(const EigenTypes::Vector3f& from, const EigenTypes::Vector3f& to, EigenTypes::Matrix3x3f &retval); 13 | static EigenTypes::Matrix3x3f RotationMatrixLinearInterpolation(const EigenTypes::Matrix3x3f& A0, const EigenTypes::Matrix3x3f& A1, float t); 14 | static void RotationMatrixSuppress(EigenTypes::Matrix3x3f& A0, float t); 15 | }; 16 | -------------------------------------------------------------------------------- /source/VRIntroLib/MessageLayer.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "MessageLayer.h" 3 | 4 | #include "GLController.h" 5 | #include "Resource.h" 6 | #include "GLTexture2.h" 7 | #include "GLTexture2Loader.h" 8 | 9 | MessageLayer::MessageLayer(const EigenTypes::Vector3f& initialEyePos) : 10 | InteractionLayer(EigenTypes::Vector3f::Zero(), "shaders/transparent"), 11 | m_HelpTexture(Resource("images/help.png")), 12 | m_LowFPSTexture(Resource("images/lowfps.png")), 13 | m_NoOculusTexture(Resource("images/no_oculus.png")), 14 | m_NoImagesTexture(Resource("images/no_images.png")) { 15 | 16 | static const float edges[] = { 17 | // No Images warning 18 | -0.4f, -0.3f, -0.6f, 0, 0, 19 | -0.4f, +0.3f, -0.6f, 0, 1, 20 | +0.4f, -0.3f, -0.6f, 1, 0, 21 | +0.4f, +0.3f, -0.6f, 1, 1, 22 | 23 | // Help menu 24 | -0.224f, -0.264f, -0.5f, 0, 0, 25 | -0.224f, +0.264f, -0.5f, 0, 1, 26 | +0.224f, -0.264f, -0.5f, 1, 0, 27 | +0.224f, +0.264f, -0.5f, 1, 1, 28 | 29 | // Low FPS warning 30 | -0.288f, -0.12f, -0.5f, 0, 0, 31 | -0.288f, +0.12f, -0.5f, 0, 1, 32 | +0.288f, -0.12f, -0.5f, 1, 0, 33 | +0.288f, +0.12f, -0.5f, 1, 1, 34 | 35 | // No Oculus warning 36 | -0.288f, -0.184f, -0.3f, 0, 0, 37 | -0.288f, +0.184f, -0.3f, 0, 1, 38 | +0.288f, -0.184f, -0.3f, 1, 0, 39 | +0.288f, +0.184f, -0.3f, 1, 1, 40 | }; 41 | 42 | m_Buffer.Create(GL_ARRAY_BUFFER); 43 | m_Buffer.Bind(); 44 | m_Buffer.Allocate(edges, sizeof(edges), GL_STATIC_DRAW); 45 | m_Buffer.Unbind(); 46 | 47 | m_Visible[0] = false; 48 | m_Visible[1] = true; 49 | for (int i = 2; i < NUM_MESSAGES; i++) { 50 | m_Visible[i] = false; 51 | } 52 | } 53 | 54 | void MessageLayer::Render(TimeDelta real_time_delta) const { 55 | m_Shader->Bind(); 56 | EigenTypes::Matrix4x4f modelView = m_ModelView; 57 | modelView.block<3, 1>(0, 3) += modelView.block<3, 3>(0, 0)*m_EyePos; 58 | modelView.block<3, 3>(0, 0) = EigenTypes::Matrix3x3f::Identity(); 59 | GLShaderMatrices::UploadUniforms(*m_Shader, modelView.cast(), m_Projection.cast(), BindFlags::NONE); 60 | 61 | glActiveTexture(GL_TEXTURE0 + 0); 62 | glUniform1i(m_Shader->LocationOfUniform("texture"), 0); 63 | glUniform1f(m_Shader->LocationOfUniform("alpha"), 1.0f); 64 | 65 | m_Buffer.Bind(); 66 | glEnableVertexAttribArray(m_Shader->LocationOfAttribute("position")); 67 | glEnableVertexAttribArray(m_Shader->LocationOfAttribute("texcoord")); 68 | glVertexAttribPointer(m_Shader->LocationOfAttribute("position"), 3, GL_FLOAT, GL_TRUE, 5*sizeof(float), (GLvoid*)0); 69 | glVertexAttribPointer(m_Shader->LocationOfAttribute("texcoord"), 2, GL_FLOAT, GL_TRUE, 5*sizeof(float), (GLvoid*)(3*sizeof(float))); 70 | 71 | int topMessage = -1; 72 | for (int i = NUM_MESSAGES - 1; i >= 0; i--) { 73 | if (m_Visible[i]) { 74 | topMessage = i; 75 | } 76 | } 77 | if (topMessage >= 0) { 78 | DrawMessage(topMessage); 79 | } 80 | 81 | glDisableVertexAttribArray(m_Shader->LocationOfAttribute("position")); 82 | glDisableVertexAttribArray(m_Shader->LocationOfAttribute("texcoord")); 83 | m_Buffer.Unbind(); 84 | 85 | m_Shader->Unbind(); 86 | } 87 | 88 | void MessageLayer::DrawMessage(int index) const { 89 | switch (index) { 90 | case 0: 91 | m_NoImagesTexture->Bind(); 92 | break; 93 | case 1: 94 | m_HelpTexture->Bind(); 95 | break; 96 | case 2: 97 | m_LowFPSTexture->Bind(); 98 | break; 99 | case 3: 100 | m_NoOculusTexture->Bind(); 101 | break; 102 | default: 103 | return; 104 | } 105 | glDrawArrays(GL_TRIANGLE_STRIP, 4*index, 4); 106 | glBindTexture(GL_TEXTURE_2D, 0); // Unbind 107 | } 108 | 109 | EventHandlerAction MessageLayer::HandleKeyboardEvent(const SDL_KeyboardEvent &ev) { 110 | //switch (ev.keysym.sym) { 111 | //default: 112 | return EventHandlerAction::PASS_ON; 113 | //} 114 | } 115 | -------------------------------------------------------------------------------- /source/VRIntroLib/MessageLayer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Interactionlayer.h" 4 | 5 | class GLTexture2; 6 | 7 | class MessageLayer : public InteractionLayer { 8 | public: 9 | MessageLayer(const EigenTypes::Vector3f& initialEyePos); 10 | //virtual ~MessageLayer (); 11 | 12 | virtual void Update(TimeDelta real_time_delta) override {} 13 | virtual void Render(TimeDelta real_time_delta) const override; 14 | EventHandlerAction HandleKeyboardEvent(const SDL_KeyboardEvent &ev) override; 15 | 16 | void SetVisible(int index, bool value) { m_Visible[index] = value; } 17 | bool GetVisible(int index) const { return m_Visible[index]; } 18 | 19 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW 20 | 21 | private: 22 | static const int NUM_MESSAGES = 4; 23 | void DrawMessage(int index) const; 24 | 25 | mutable GLBuffer m_Buffer; 26 | 27 | std::shared_ptr m_HelpTexture; 28 | std::shared_ptr m_LowFPSTexture; 29 | std::shared_ptr m_NoOculusTexture; 30 | std::shared_ptr m_NoImagesTexture; 31 | 32 | bool m_Visible[NUM_MESSAGES]; 33 | }; 34 | -------------------------------------------------------------------------------- /source/VRIntroLib/Mirror.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Mirror.h" 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | HTHUMBNAIL g_hthumb; 14 | 15 | /* 16 | * OnCreate 17 | * Applications will typically override this and maybe even 18 | * create a child window. 19 | */ 20 | BOOL 21 | OnCreate(HWND hwnd, LPCREATESTRUCT lpcs) { 22 | DWM_THUMBNAIL_PROPERTIES props = {}; 23 | HWND hwndTarget = *reinterpret_cast(lpcs->lpCreateParams); 24 | 25 | props.rcSource.left = 0; 26 | props.rcSource.top = 0; 27 | props.rcSource.right = 1920; 28 | props.rcSource.bottom = 1080; 29 | 30 | // hwndTarget = (HWND)0x00060778; 31 | DwmRegisterThumbnail(hwnd, hwndTarget, &g_hthumb); 32 | props.dwFlags = DWM_TNP_VISIBLE | DWM_TNP_RECTSOURCE | 33 | DWM_TNP_RECTDESTINATION; 34 | props.rcDestination = props.rcSource; 35 | OffsetRect(&props.rcSource, 36 | -props.rcSource.left, -props.rcSource.top); 37 | props.fVisible = TRUE; 38 | DwmUpdateThumbnailProperties(g_hthumb, &props); 39 | return TRUE; 40 | } 41 | 42 | /* 43 | * OnDestroy 44 | * Post a quit message because our application is over when the 45 | * user closes this window. 46 | */ 47 | void 48 | OnDestroy(HWND hwnd) { 49 | if (g_hthumb) { DwmUnregisterThumbnail(g_hthumb); } 50 | PostQuitMessage(0); 51 | } 52 | 53 | /* 54 | * PaintContent 55 | * Interesting things will be painted here eventually. 56 | */ 57 | void 58 | PaintContent(HWND hwnd, PAINTSTRUCT *pps) { 59 | } 60 | 61 | /* 62 | * OnPaint 63 | * Paint the content as part of the paint cycle. 64 | */ 65 | void 66 | OnPaint(HWND hwnd) { 67 | PAINTSTRUCT ps; 68 | BeginPaint(hwnd, &ps); 69 | PaintContent(hwnd, &ps); 70 | EndPaint(hwnd, &ps); 71 | } 72 | 73 | /* 74 | * OnPrintClient 75 | * Paint the content as requested by USER. 76 | */ 77 | void 78 | OnPrintClient(HWND hwnd, HDC hdc) { 79 | PAINTSTRUCT ps; 80 | ps.hdc = hdc; 81 | GetClientRect(hwnd, &ps.rcPaint); 82 | PaintContent(hwnd, &ps); 83 | 84 | } 85 | 86 | /* 87 | * Window procedure 88 | */ 89 | LRESULT CALLBACK 90 | WndProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam) { 91 | switch (uiMsg) { 92 | 93 | HANDLE_MSG(hwnd, WM_CREATE, OnCreate); 94 | HANDLE_MSG(hwnd, WM_DESTROY, OnDestroy); 95 | HANDLE_MSG(hwnd, WM_PAINT, OnPaint); 96 | case WM_PRINTCLIENT: 97 | OnPrintClient(hwnd, (HDC)wParam); 98 | return 0; 99 | } 100 | 101 | return DefWindowProc(hwnd, uiMsg, wParam, lParam); 102 | } 103 | 104 | BOOL 105 | InitApp(void) { 106 | WNDCLASS wc; 107 | 108 | wc.style = 0; 109 | wc.lpfnWndProc = WndProc; 110 | wc.cbClsExtra = 0; 111 | wc.cbWndExtra = 0; 112 | wc.hInstance = (HINSTANCE)GetModuleHandle(NULL); 113 | wc.hIcon = NULL; 114 | wc.hCursor = LoadCursor(NULL, IDC_ARROW); 115 | wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); 116 | wc.lpszMenuName = NULL; 117 | wc.lpszClassName = TEXT("Mirror"); 118 | 119 | if (!RegisterClass(&wc)) { return FALSE; } 120 | 121 | InitCommonControls(); /* In case we use a common control */ 122 | 123 | return TRUE; 124 | } 125 | 126 | void RunMirror(HWND parentHwnd, HWND& outHwnd) { 127 | MSG msg; 128 | 129 | InitApp(); 130 | 131 | if (SUCCEEDED(CoInitialize(NULL))) {/* In case we use COM */ 132 | 133 | outHwnd = CreateWindow( 134 | TEXT("Mirror"), /* Class Name */ 135 | TEXT("Mirror"), /* Title */ 136 | WS_OVERLAPPEDWINDOW, /* Style */ 137 | CW_USEDEFAULT, CW_USEDEFAULT, /* Position */ 138 | CW_USEDEFAULT, CW_USEDEFAULT, /* Size */ 139 | NULL, /* Parent */ 140 | NULL, /* No menu */ 141 | (HINSTANCE)GetModuleHandle(NULL),/* Instance */ 142 | &parentHwnd); 143 | 144 | ShowWindow(outHwnd, SW_MAXIMIZE); 145 | 146 | while (GetMessage(&msg, NULL, 0, 0)) { 147 | TranslateMessage(&msg); 148 | DispatchMessage(&msg); 149 | } 150 | 151 | CoUninitialize(); 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /source/VRIntroLib/Mirror.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void RunMirror(HWND parentHwnd, HWND& outHwnd); 4 | -------------------------------------------------------------------------------- /source/VRIntroLib/PassthroughLayer.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "PassthroughLayer.h" 3 | #include "GLController.h" 4 | #include "GLShader.h" 5 | 6 | #include "GLTexture2.h" 7 | #include "GLTexture2Loader.h" 8 | #include "GLShaderLoader.h" 9 | 10 | PassthroughLayer::PassthroughLayer() : 11 | InteractionLayer(EigenTypes::Vector3f::Zero(), "shaders/passthrough"), 12 | m_RealHeight(240), 13 | m_image(GLTexture2Params(640, 240, GL_LUMINANCE), GLTexture2PixelDataReference(GL_LUMINANCE, GL_UNSIGNED_BYTE, (const void*) NULL, 0)), 14 | m_colorimage(GLTexture2Params(608, 540, GL_RGBA), GLTexture2PixelDataReference(GL_RGBA, GL_UNSIGNED_BYTE, (const void*) NULL, 0)), 15 | m_distortion(GLTexture2Params(64, 64, GL_RG32F), GLTexture2PixelDataReference(GL_RG, GL_FLOAT, (const void*) NULL, 0)), 16 | m_Gamma(0.8f), 17 | m_Brightness(1.0f), 18 | m_IRMode(0), 19 | m_HasData(false) { 20 | 21 | glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 22 | 23 | m_image.Bind(); 24 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); 25 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); 26 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 27 | m_image.Unbind(); 28 | 29 | m_colorimage.Bind(); 30 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); 31 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); 32 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 33 | m_colorimage.Unbind(); 34 | 35 | m_distortion.Bind(); 36 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 37 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 38 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 39 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 40 | m_distortion.Unbind(); 41 | } 42 | 43 | PassthroughLayer::~PassthroughLayer() { 44 | m_Buffer.Destroy(); 45 | } 46 | 47 | void PassthroughLayer::SetImage(const unsigned char* data, int width, int height) { 48 | const GLTexture2Params& params = m_image.Params(); 49 | 50 | // We have to resize our texture when image sizes change 51 | if (height != m_RealHeight) { 52 | m_image.Bind(); 53 | m_RealHeight = height; 54 | glTexImage2D(params.Target(), 55 | 0, 56 | params.InternalFormat(), 57 | params.Width(), 58 | m_RealHeight, 59 | 0, 60 | GL_LUMINANCE, // HACK because we don't have api-level access for glTexImage2D after construction, only glTexSubImage2D 61 | GL_UNSIGNED_BYTE, 62 | data); 63 | m_image.Unbind(); 64 | } else { 65 | m_image.Bind(); 66 | glTexSubImage2D(params.Target(), 67 | 0, 68 | 0, 69 | 0, 70 | params.Width(), 71 | m_RealHeight, 72 | GL_LUMINANCE, // HACK because we don't have api-level access for glTexImage2D after construction, only glTexSubImage2D 73 | GL_UNSIGNED_BYTE, 74 | data); 75 | m_image.Unbind(); 76 | } 77 | m_UseRGBI = false; 78 | m_HasData = true; 79 | } 80 | 81 | void PassthroughLayer::SetColorImage(const unsigned char* data) { 82 | m_colorimage.UpdateTexture(GLTexture2PixelDataReference(GL_RGBA, GL_UNSIGNED_BYTE, data, m_colorimage.Params().Width()*m_colorimage.Params().Height()*4)); 83 | m_UseRGBI = true; 84 | m_HasData = true; 85 | } 86 | 87 | void PassthroughLayer::SetDistortion(const float* data) { 88 | m_distortion.UpdateTexture(GLTexture2PixelDataReference(GL_RG, GL_FLOAT, data, m_distortion.Params().Width()*m_distortion.Params().Height()*8)); 89 | } 90 | 91 | void PassthroughLayer::Render(TimeDelta real_time_delta) const { 92 | if (m_HasData) { 93 | glDepthMask(GL_FALSE); 94 | m_Shader->Bind(); 95 | GLShaderMatrices::UploadUniforms(*m_Shader, EigenTypes::Matrix4x4::Identity(), m_Projection.cast(), BindFlags::NONE); 96 | 97 | glActiveTexture(GL_TEXTURE0 + 0); 98 | if (m_UseRGBI) { 99 | m_colorimage.Bind(); 100 | } else { 101 | m_image.Bind(); 102 | } 103 | glActiveTexture(GL_TEXTURE0 + 1); 104 | m_distortion.Bind(); 105 | 106 | //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 107 | glUniform2f(m_Shader->LocationOfUniform("ray_scale"), 0.125f, 0.125f); 108 | glUniform2f(m_Shader->LocationOfUniform("ray_offset"), 0.5f, 0.5f); 109 | glUniform1i(m_Shader->LocationOfUniform("texture"), 0); 110 | glUniform1i(m_Shader->LocationOfUniform("distortion"), 1); 111 | glUniform1f(m_Shader->LocationOfUniform("gamma"), m_Gamma*(m_UseRGBI ? 0.7f : 1.0f)); 112 | glUniform1f(m_Shader->LocationOfUniform("brightness"), m_Alpha*m_Brightness); 113 | glUniform1f(m_Shader->LocationOfUniform("use_color"), m_UseRGBI ? 1.0f : 0.0f); 114 | 115 | static int i = 0; 116 | glUniform1f(m_Shader->LocationOfUniform("ir_mode"), ((m_IRMode + (++i & 1)) & 2) > 0 ? 1.0f : 0.0f); 117 | glUniform1f(m_Shader->LocationOfUniform("cripple_mode"), m_CrippleMode ? 1.0f : 0.0f); 118 | glUniform1f(m_Shader->LocationOfUniform("stencil_mode"), 0.0f); 119 | 120 | DrawQuad(); 121 | 122 | if (m_GenerateStencil) { 123 | glUniform1f(m_Shader->LocationOfUniform("stencil_mode"), 1.0f); 124 | glEnable(GL_ALPHA_TEST); 125 | glEnable(GL_STENCIL_TEST); 126 | glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 127 | 128 | glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); 129 | glStencilFunc(GL_ALWAYS, 1, 1); 130 | glAlphaFunc(GL_GREATER, 0.2f); 131 | DrawQuad(); 132 | 133 | glDisable(GL_ALPHA_TEST); 134 | glDisable(GL_STENCIL_TEST); 135 | glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 136 | } 137 | 138 | if (m_UseRGBI) { 139 | m_colorimage.Unbind(); 140 | } else { 141 | m_image.Unbind(); 142 | } 143 | m_distortion.Unbind(); 144 | m_Shader->Unbind(); 145 | glDepthMask(GL_TRUE); 146 | } 147 | } 148 | 149 | void PassthroughLayer::DrawQuad() const { 150 | #if 0 151 | const float edges[] = {-4, -4, -1, -4, 4, -1, 4, -4, -1, 4, 4, -1}; 152 | // Why the fuck doesn't this work? 153 | m_Renderer.EnablePositionAttribute(); 154 | m_Buffer.Bind(); 155 | m_Buffer.Allocate(&edges[0], sizeof(edges), GL_DYNAMIC_DRAW); 156 | glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 157 | m_Buffer.Release(); 158 | m_Renderer.DisablePositionAttribute(); 159 | #else 160 | glBegin(GL_TRIANGLE_STRIP); 161 | glVertex3f(-4, -4, -1); 162 | glVertex3f(-4, 4, -1); 163 | glVertex3f(4, -4, -1); 164 | glVertex3f(4, 4, -1); 165 | glEnd(); 166 | #endif 167 | } 168 | 169 | EventHandlerAction PassthroughLayer::HandleKeyboardEvent(const SDL_KeyboardEvent &ev) { 170 | if (ev.type == SDL_KEYDOWN) { 171 | switch (ev.keysym.sym) { 172 | case '[': 173 | m_Gamma = std::max(0.f, m_Gamma - 0.04f); 174 | return EventHandlerAction::CONSUME; 175 | case ']': 176 | m_Gamma = std::min(1.2f, m_Gamma + 0.04f); 177 | return EventHandlerAction::CONSUME; 178 | case SDLK_INSERT: 179 | m_Brightness = std::min(2.f, m_Brightness + 0.02f); 180 | return EventHandlerAction::CONSUME; 181 | case SDLK_DELETE: 182 | m_Brightness = std::max(0.f, m_Brightness - 0.02f); 183 | return EventHandlerAction::CONSUME; 184 | case '.': 185 | m_IRMode++; 186 | return EventHandlerAction::CONSUME; 187 | default: 188 | return EventHandlerAction::PASS_ON; 189 | } 190 | } 191 | return EventHandlerAction::PASS_ON; 192 | } 193 | -------------------------------------------------------------------------------- /source/VRIntroLib/PassthroughLayer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "InteractionLayer.h" 4 | 5 | #include "GLTexture2.h" 6 | #include "GLBuffer.h" 7 | #include "EigenTypes.h" 8 | 9 | #include 10 | 11 | class GLShader; 12 | 13 | class PassthroughLayer : public InteractionLayer { 14 | public: 15 | PassthroughLayer(); 16 | virtual ~PassthroughLayer(); 17 | 18 | void SetImage(const unsigned char* data, int width, int height); 19 | void SetColorImage(const unsigned char* data); 20 | void SetDistortion(const float* data); 21 | void SetCrippleMode(bool value) { m_CrippleMode = value; } 22 | void SetStencil(bool value) { m_GenerateStencil = value; } 23 | 24 | virtual void Update(TimeDelta real_time_delta) override {} 25 | virtual void Render(TimeDelta real_time_delta) const override; 26 | EventHandlerAction HandleKeyboardEvent(const SDL_KeyboardEvent &ev) override; 27 | 28 | 29 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW 30 | bool m_HasData; 31 | 32 | private: 33 | void DrawQuad() const; 34 | 35 | mutable GLTexture2 m_image; 36 | mutable GLTexture2 m_colorimage; 37 | mutable GLTexture2 m_distortion; 38 | mutable GLBuffer m_Buffer; 39 | float m_Gamma; 40 | float m_Brightness; 41 | bool m_UseRGBI; 42 | bool m_GenerateStencil; 43 | int m_IRMode; 44 | bool m_CrippleMode; 45 | 46 | // Hack for robust mode 47 | int m_RealHeight; 48 | }; 49 | -------------------------------------------------------------------------------- /source/VRIntroLib/PhysicsLayer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Interactionlayer.h" 4 | 5 | 6 | class PhysicsLayer : public InteractionLayer 7 | { 8 | public: 9 | PhysicsLayer(const EigenTypes::Vector3f& initialEyePos); 10 | virtual ~PhysicsLayer (); 11 | 12 | virtual void OnSelected(); 13 | virtual void Update(TimeDelta real_time_delta) override; 14 | virtual void Render(TimeDelta real_time_delta) const override; 15 | EventHandlerAction HandleKeyboardEvent(const SDL_KeyboardEvent &ev) override; 16 | 17 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW 18 | 19 | private: 20 | 21 | class BulletWrapper* m_BulletWrapper; 22 | }; 23 | -------------------------------------------------------------------------------- /source/VRIntroLib/PlatformInitializer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #if _WIN32 3 | #include "PlatformInitializerWin.h" 4 | #elif __APPLE__ 5 | #include "PlatformInitializerMac.h" 6 | #endif 7 | -------------------------------------------------------------------------------- /source/VRIntroLib/PlatformInitializerMac.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class PlatformInitializer 4 | { 5 | public: 6 | PlatformInitializer(void); 7 | ~PlatformInitializer(void); 8 | }; 9 | -------------------------------------------------------------------------------- /source/VRIntroLib/PlatformInitializerMac.mm: -------------------------------------------------------------------------------- 1 | //#include "stdafx.h" 2 | #include "PlatformInitializerMac.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | PlatformInitializer::PlatformInitializer(void) 10 | { 11 | // Change the current directory to be that of the either the executable or, 12 | // preferably, the Resources directory if the executable is within an 13 | // application bundle. 14 | char exec_path[PATH_MAX] = {0}; 15 | uint32_t pathSize = sizeof(exec_path); 16 | if (!_NSGetExecutablePath(exec_path, &pathSize)) { 17 | char fullpath[PATH_MAX] = {0}; 18 | if (realpath(exec_path, fullpath)) { 19 | std::string path(fullpath); 20 | size_t pos = path.find_last_of('/'); 21 | 22 | if (pos != std::string::npos) { 23 | path.erase(pos+1); 24 | } 25 | if (!path.empty()) { 26 | chdir(path.c_str()); 27 | } 28 | const char* resources = "../Resources"; 29 | if (!access(resources, R_OK)) { 30 | chdir(resources); 31 | } 32 | } 33 | } 34 | 35 | // 36 | // The isOpaque method in the SFOpenGLView class of SFML always returns YES 37 | // (as it just uses the default implementation of NSOpenGLView). This 38 | // causes us to always get an opaque view. We workaround this problem by 39 | // replacing that method with our own implementation that returns the 40 | // opaqueness based on the enclosing window, all thanks to the power of 41 | // Objective-C. 42 | // 43 | method_setImplementation(class_getInstanceMethod(NSClassFromString(@"SFOpenGLView"), @selector(isOpaque)), 44 | imp_implementationWithBlock(^BOOL(id self, id arg) { return NO; })); 45 | } 46 | 47 | PlatformInitializer::~PlatformInitializer(void) 48 | { 49 | 50 | } 51 | 52 | -------------------------------------------------------------------------------- /source/VRIntroLib/PlatformInitializerWin.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include 4 | #include "PlatformInitializerWin.h" 5 | #include "shlwapi.h" 6 | #include 7 | #include 8 | 9 | PlatformInitializer::PlatformInitializer(void) : 10 | m_hr(CoInitializeEx(nullptr, COINIT_MULTITHREADED)) 11 | { 12 | if(FAILED(m_hr)) 13 | throw std::runtime_error("Failed to initialize COM for multithreading"); 14 | 15 | const size_t MAX_UTF8_BYTES = MAX_PATH * 2; 16 | WCHAR path[MAX_UTF8_BYTES]; 17 | 18 | //Compute the exe path. 19 | const DWORD len = GetModuleFileNameW(nullptr, path, MAX_UTF8_BYTES); 20 | 21 | if (len == 0) { 22 | throw std::runtime_error("Couldn't locate our .exe"); 23 | } 24 | 25 | PathRemoveFileSpecW(path); 26 | SetCurrentDirectoryW(path); 27 | } 28 | 29 | PlatformInitializer::~PlatformInitializer(void) 30 | { 31 | if(SUCCEEDED(m_hr)) 32 | CoUninitialize(); 33 | } -------------------------------------------------------------------------------- /source/VRIntroLib/PlatformInitializerWin.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class PlatformInitializer 4 | { 5 | public: 6 | /// 7 | /// Calls CoInitialize for multithreaded COM, or throws an exception if this could not be done 8 | /// 9 | PlatformInitializer(void); 10 | ~PlatformInitializer(void); 11 | 12 | private: 13 | const HRESULT m_hr; 14 | 15 | public: 16 | operator HRESULT() const { return m_hr; } 17 | }; 18 | -------------------------------------------------------------------------------- /source/VRIntroLib/PrecisionTimer.h: -------------------------------------------------------------------------------- 1 | /*================================================================================================================== 2 | 3 | Copyright (c) 2010 - 2012 Leap Motion. All rights reserved. 4 | 5 | The intellectual and technical concepts contained herein are proprietary and confidential to Leap Motion, and are 6 | protected by trade secret or copyright law. Dissemination of this information or reproduction of this material is 7 | strictly forbidden unless prior written permission is obtained from Leap Motion. 8 | 9 | ===================================================================================================================*/ 10 | 11 | /// 12 | /// Class for accurate timing 13 | /// 14 | /// 15 | /// This is a high-precision timing class. Whereas the resolution of the c++ standard clock() function is about 10ms, 16 | /// this class has a resolution of about one clock cycle (using the PrecisionTimer). 17 | /// 18 | /// 19 | 20 | #ifndef __PrecisionTimer_h__ 21 | #define __PrecisionTimer_h__ 22 | 23 | #include 24 | #include 25 | 26 | #if _WIN32 27 | namespace { 28 | const long long g_Frequency = []() -> long long { 29 | LARGE_INTEGER frequency; 30 | QueryPerformanceFrequency(&frequency); 31 | return frequency.QuadPart; 32 | }(); 33 | } 34 | 35 | struct HighResClock { 36 | typedef long long rep; 37 | typedef std::nano period; 38 | typedef std::chrono::duration duration; 39 | typedef std::chrono::time_point time_point; 40 | static const bool is_steady = true; 41 | 42 | static HighResClock::time_point HighResClock::now() { 43 | LARGE_INTEGER count; 44 | QueryPerformanceCounter(&count); 45 | return time_point(duration(count.QuadPart * static_cast(period::den) / g_Frequency)); 46 | } 47 | }; 48 | #endif 49 | 50 | template 51 | class GeneralTimer { 52 | public: 53 | GeneralTimer(): 54 | m_Start(epoch()) 55 | {} 56 | 57 | void Start() { 58 | m_Start = T::now(); 59 | } 60 | 61 | std::chrono::nanoseconds StopNanoseconds() const { 62 | return T::now() - m_Start; 63 | } 64 | double Stop() const { 65 | return static_cast(std::chrono::duration_cast(StopNanoseconds()).count())*1e-6; 66 | } 67 | 68 | std::chrono::nanoseconds StopAndStartNanoseconds() { 69 | const std::chrono::nanoseconds retVal = StopNanoseconds(); 70 | Start(); 71 | return retVal; 72 | } 73 | double StopAndStart() { 74 | const double retVal = Stop(); 75 | Start(); 76 | return retVal; 77 | } 78 | 79 | static double GetTime() { 80 | const std::chrono::time_point end = T::now(); 81 | return std::chrono::duration_cast(end - epoch()).count() * 1e-9; 82 | } 83 | 84 | /// 85 | /// Returns the current time according to this timer type 86 | /// 87 | static std::chrono::steady_clock::time_point Now() { 88 | return T::now(); 89 | } 90 | 91 | static void Sleep(int milliseconds) { 92 | #if _WIN32 93 | std::this_thread::sleep(std::posix_time::milliseconds(milliseconds)); 94 | #elif __APPLE__ 95 | std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds)); 96 | #endif 97 | } 98 | 99 | private: 100 | static std::chrono::time_point& epoch() { 101 | static std::chrono::time_point s_Epoch = T::now(); 102 | return s_Epoch; 103 | } 104 | 105 | std::chrono::time_point m_Start; 106 | 107 | }; 108 | 109 | #if _WIN32 110 | typedef GeneralTimer PrecisionTimer; 111 | #elif __APPLE__ 112 | typedef GeneralTimer PrecisionTimer; 113 | #endif 114 | #endif -------------------------------------------------------------------------------- /source/VRIntroLib/QuadsLayer.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "QuadsLayer.h" 3 | #include "GLController.h" 4 | 5 | #include 6 | 7 | float Pane::m_Gap = 0.25f; 8 | float Pane::m_Stride = 16.0f; 9 | float Pane::m_Radius = 0.40f; 10 | EigenTypes::Vector2f Pane::m_Pan = EigenTypes::Vector2f::Zero(); 11 | EigenTypes::Matrix3x3f Pane::m_HeadTilt = EigenTypes::Matrix3x3f::Identity(); 12 | std::vector Pane::m_RenderBuffer; 13 | 14 | EigenTypes::Vector3f Pane::Warp(const EigenTypes::Vector3f& a) { 15 | EigenTypes::Matrix2x2f mat; 16 | mat << m_Stride, 1, -1, m_Stride; 17 | EigenTypes::Vector2f bb = 2*static_cast(M_PI)/(1 + m_Stride*m_Stride)*mat*a.block<2, 1>(0, 0); 18 | bb += m_Pan; 19 | EigenTypes::Vector3f b(sin(bb.x()), bb.y(), -cos(bb.x())); 20 | 21 | float c_phi = 2*(atan(exp(b.y())) - 0.25f*static_cast(M_PI)); 22 | return m_Radius*m_HeadTilt*EigenTypes::Vector3f(cos(c_phi)*b.x(), sin(c_phi), cos(c_phi)*b.z()); 23 | } 24 | 25 | EigenTypes::Vector2f Pane::UnwarpToYTheta(const EigenTypes::Vector3f& c) { 26 | float c_phi = asin(c.y()/m_Radius); 27 | EigenTypes::Vector2f b = EigenTypes::Vector2f(c.x(), c.z()).normalized(); 28 | float bb_y = log(tan(0.5f*c_phi + 0.25f*static_cast(M_PI))); 29 | if (!(bb_y <= FLT_MAX && bb_y >= -FLT_MAX)) { 30 | bb_y = 0; 31 | } 32 | return EigenTypes::Vector2f(atan2(b.x(), -b.y()), bb_y); 33 | } 34 | 35 | std::vector get_all_files_names_within_folder(std::string folder) { 36 | std::vector names; 37 | 38 | #if _WIN32 39 | char search_path[200]; 40 | sprintf(search_path, "%s\\*.*", folder.c_str()); 41 | WIN32_FIND_DATA fd; 42 | HANDLE hFind = ::FindFirstFile(search_path, &fd); 43 | 44 | if (hFind != INVALID_HANDLE_VALUE) { 45 | do { 46 | // read all (real) files in current folder 47 | // , delete '!' read other 2 default folder . and .. 48 | if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { 49 | std::string filename(fd.cFileName); 50 | std::string ext = filename.substr(filename.length() - 4); 51 | names.push_back(folder + "\\" + fd.cFileName); 52 | } 53 | } while (::FindNextFile(hFind, &fd)); 54 | ::FindClose(hFind); 55 | } 56 | #endif 57 | return names; 58 | } 59 | 60 | QuadsLayer::QuadsLayer(const EigenTypes::Vector3f& initialEyePos) : 61 | InteractionLayer(EigenTypes::Vector3f::Zero(), "shaders/transparent"), 62 | m_LastYTheta(EigenTypes::Vector2f::Zero()), 63 | m_DeltaYTheta(EigenTypes::Vector2f::Zero()), 64 | m_StripWidth(0.0f) { 65 | 66 | std::vector filenames = get_all_files_names_within_folder("gallery"); 67 | for (unsigned int i = 0; i < filenames.size(); i++) { 68 | try { 69 | m_Panes.push_back(std::shared_ptr(new Pane(i, m_StripWidth, filenames[i].c_str()))); 70 | } catch (std::runtime_error &e) { 71 | std::cout << "Caught a runtime_error exception: " << e.what() << '\n'; 72 | } 73 | } 74 | 75 | Pane::m_Pan = EigenTypes::Vector2f(0.5*m_StripWidth, 0); 76 | m_Buffer.Create(GL_ARRAY_BUFFER); 77 | m_Buffer.Bind(); 78 | m_Buffer.Allocate(NULL, 4*sizeof(TextureVertex)*filenames.size(), GL_DYNAMIC_DRAW); 79 | m_Buffer.Unbind(); 80 | } 81 | 82 | void QuadsLayer::Update(TimeDelta real_time_delta) { 83 | static const float FADE = 0.97f; 84 | 85 | // Find the farther hand and use it 86 | EigenTypes::Vector3f wand = EigenTypes::Vector3f::Zero(); 87 | float confidence; 88 | 89 | for (size_t i = 0; i < m_SkeletonHands.size(); i++) { 90 | const EigenTypes::Vector3f &thisHand = Pane::m_HeadTilt*(m_SkeletonHands[i].avgExtended.cast() - m_EyePos); 91 | if (thisHand.squaredNorm() > wand.squaredNorm()) { 92 | wand = thisHand; 93 | confidence = m_SkeletonHands[i].confidence; 94 | } 95 | } 96 | EigenTypes::Vector2f clutch = wand.isZero() ? EigenTypes::Vector2f::Zero() : Pane::UnwarpToYTheta(wand); 97 | 98 | float clutchStrength = exp(std::min(0.0f, 25.f*(wand.norm() + 0.005f - Pane::m_Radius))); 99 | EigenTypes::Vector2f clutchMovement = clutch - m_LastYTheta; 100 | 101 | if (clutchMovement.x() > static_cast(M_PI)) { 102 | clutchMovement.x() -= 2*static_cast(M_PI); 103 | } else if (clutchMovement.x() < -static_cast(M_PI)) { 104 | clutchMovement.x() += 2*static_cast(M_PI); 105 | } 106 | 107 | m_DeltaYTheta = clutchStrength*clutchMovement + (1 - clutchStrength)*(FADE*m_DeltaYTheta + 0.025f*(1-FADE)*EigenTypes::Vector2f(-Pane::m_Stride, 1)/(1 + Pane::m_Stride*Pane::m_Stride)); 108 | 109 | // m_DeltaYTheta = FADE*m_DeltaYTheta + (1-FADE)*(clutchStrength*clutchMovement + (1 - clutchStrength)*(0.025f*EigenTypes::Vector2f(-Pane::m_Stride, 1)/(1 + Pane::m_Stride*Pane::m_Stride))); 110 | Pane::m_Pan += m_DeltaYTheta; 111 | m_LastYTheta = clutch; 112 | float panYLimit = 2*static_cast(M_PI)*m_StripWidth/(1 + Pane::m_Stride*Pane::m_Stride); 113 | Pane::m_Pan.y() = std::min(1.1f*panYLimit, std::max(-0.1f*panYLimit, Pane::m_Pan.y())); 114 | 115 | for (auto it = m_Panes.begin(); it != m_Panes.end(); ++it) { 116 | Pane &pane = **it; 117 | pane.Update(); 118 | } 119 | } 120 | 121 | void QuadsLayer::Render(TimeDelta real_time_delta) const { 122 | m_Shader->Bind(); 123 | EigenTypes::Matrix4x4f modelView = m_ModelView; 124 | modelView.block<3, 1>(0, 3) += modelView.block<3, 3>(0, 0)*m_EyePos; 125 | 126 | Pane::m_HeadTilt = MathUtility::RotationVectorToMatrix(atan(1/Pane::m_Stride)*EigenTypes::Vector3f(modelView(2, 0), 0, modelView(2, 2))); 127 | 128 | //modelView.block<3, 3>(0, 0) = EigenTypes::Matrix3x3f::Identity(); 129 | GLShaderMatrices::UploadUniforms(*m_Shader, modelView.cast(), m_Projection.cast(), BindFlags::NONE); 130 | 131 | glActiveTexture(GL_TEXTURE0 + 0); 132 | glUniform1i(m_Shader->LocationOfUniform("texture"), 0); 133 | glUniform1f(m_Shader->LocationOfUniform("alpha"), 0.8f); 134 | 135 | m_Buffer.Bind(); 136 | m_Buffer.Write(Pane::m_RenderBuffer.data(), 4*sizeof(TextureVertex)*m_Panes.size()); 137 | 138 | glEnableVertexAttribArray(m_Shader->LocationOfAttribute("position")); 139 | glEnableVertexAttribArray(m_Shader->LocationOfAttribute("texcoord")); 140 | glVertexAttribPointer(m_Shader->LocationOfAttribute("position"), 3, GL_FLOAT, GL_TRUE, 5*sizeof(float), (GLvoid*)0); 141 | glVertexAttribPointer(m_Shader->LocationOfAttribute("texcoord"), 2, GL_FLOAT, GL_TRUE, 5*sizeof(float), (GLvoid*)(3*sizeof(float))); 142 | 143 | for (auto it = m_Panes.begin(); it != m_Panes.end(); ++it) { 144 | Pane &pane = **it; 145 | pane.Render(); 146 | } 147 | 148 | glDisableVertexAttribArray(m_Shader->LocationOfAttribute("position")); 149 | glDisableVertexAttribArray(m_Shader->LocationOfAttribute("texcoord")); 150 | m_Buffer.Unbind(); 151 | m_Shader->Unbind(); 152 | } 153 | 154 | EventHandlerAction QuadsLayer::HandleKeyboardEvent(const SDL_KeyboardEvent &ev) { 155 | //switch (ev.keysym.sym) { 156 | //default: 157 | return EventHandlerAction::PASS_ON; 158 | //} 159 | } 160 | -------------------------------------------------------------------------------- /source/VRIntroLib/QuadsLayer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Interactionlayer.h" 4 | #include "MathUtility.h" 5 | 6 | #include "GLTexture2.h" 7 | #include "GLTexture2Loader.h" 8 | 9 | class GLShader; 10 | 11 | struct TextureVertex { 12 | float x, y, z, u, v; 13 | }; 14 | 15 | struct Pane { 16 | Pane(int index, float& offset, const char* filename) : 17 | m_Index(index), 18 | m_Texture(Resource(filename)) { 19 | if (index*4 >= static_cast(m_RenderBuffer.size())) { 20 | m_RenderBuffer.resize((index + 1)*4); 21 | } 22 | m_RenderBuffer[index*4].u = 0; 23 | m_RenderBuffer[index*4].v = 0; 24 | m_RenderBuffer[index*4 + 1].u = 0; 25 | m_RenderBuffer[index*4 + 1].v = 1; 26 | m_RenderBuffer[index*4 + 2].u = 1; 27 | m_RenderBuffer[index*4 + 2].v = 0; 28 | m_RenderBuffer[index*4 + 3].u = 1; 29 | m_RenderBuffer[index*4 + 3].v = 1; 30 | 31 | float w = static_cast(m_Texture->Params().Width()); 32 | float h = static_cast(m_Texture->Params().Height()); 33 | 34 | float l = offset; 35 | float t = 1 - m_Gap; 36 | float r = offset + t*w/h; 37 | float b = 0; 38 | 39 | offset = r + m_Gap; 40 | 41 | m_Vertices[0] = EigenTypes::Vector3f(l, b, -1); 42 | m_Vertices[1] = EigenTypes::Vector3f(l, t, -1); 43 | m_Vertices[2] = EigenTypes::Vector3f(r, b, -1); 44 | m_Vertices[3] = EigenTypes::Vector3f(r, t, -1); 45 | } 46 | 47 | static EigenTypes::Vector3f Warp(const EigenTypes::Vector3f& a); 48 | static EigenTypes::Vector2f UnwarpToYTheta(const EigenTypes::Vector3f& c); 49 | 50 | void Update() { 51 | EigenTypes::Vector3f warpedVertices[4]; 52 | for (int i = 0; i < 4; i++) { 53 | warpedVertices[i] = Warp(m_Vertices[i]); 54 | } 55 | 56 | // Make panes more rectangular looking. True correction would be 0.25, but that falls prey to optical illusion 57 | EigenTypes::Vector3f shift = 0.19f*(warpedVertices[1] + warpedVertices[2] - warpedVertices[3] - warpedVertices[0]); 58 | 59 | warpedVertices[0] += shift; 60 | warpedVertices[1] -= shift; 61 | warpedVertices[2] -= shift; 62 | warpedVertices[3] += shift; 63 | 64 | for (int i = 0; i < 4; i++) { 65 | Eigen::Map(&m_RenderBuffer[4*m_Index + i].x) = warpedVertices[i]; 66 | } 67 | } 68 | 69 | void Render() { 70 | m_Texture->Bind(); 71 | glDrawArrays(GL_TRIANGLE_STRIP, 4*m_Index, 4); 72 | m_Texture->Unbind(); 73 | } 74 | 75 | EigenTypes::Vector3f m_Vertices[4]; 76 | 77 | static float m_Gap; 78 | static float m_Stride; 79 | static float m_Radius; 80 | static EigenTypes::Vector2f m_Pan; 81 | static EigenTypes::Matrix3x3f m_HeadTilt; 82 | 83 | bool m_Engaged; 84 | std::shared_ptr m_Texture; 85 | 86 | static std::vector m_RenderBuffer; 87 | int m_Index; 88 | }; 89 | 90 | class QuadsLayer : public InteractionLayer { 91 | public: 92 | QuadsLayer(const EigenTypes::Vector3f& initialEyePos); 93 | //virtual ~QuadsLayer (); 94 | 95 | virtual void Update(TimeDelta real_time_delta) override; 96 | virtual void Render(TimeDelta real_time_delta) const override; 97 | EventHandlerAction HandleKeyboardEvent(const SDL_KeyboardEvent &ev) override; 98 | 99 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW 100 | 101 | private: 102 | GLTexture2* m_image[300]; 103 | 104 | mutable GLBuffer m_Buffer; 105 | std::vector> m_Panes; 106 | 107 | EigenTypes::Vector2f m_LastYTheta; 108 | EigenTypes::Vector2f m_DeltaYTheta; 109 | float m_StripWidth; 110 | }; 111 | -------------------------------------------------------------------------------- /source/VRIntroLib/SpaceLayer.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "SpaceLayer.h" 3 | 4 | #include "GLController.h" 5 | #include "GLTexture2.h" 6 | #include "GLTexture2Loader.h" 7 | #include "GLShaderLoader.h" 8 | 9 | SpaceLayer::SpaceLayer(const EigenTypes::Vector3f& initialEyePos) : 10 | InteractionLayer(initialEyePos, "shaders/solid"), 11 | m_PopupShader(Resource("shaders/transparent")), 12 | m_PopupTexture(Resource("images/level3_popup.png")), 13 | m_OddEven(0), 14 | m_StarShowMode(0), 15 | m_StarsToShow(NUM_STARS) { 16 | m_Buffer.Create(GL_ARRAY_BUFFER); 17 | m_Buffer.Bind(); 18 | m_Buffer.Allocate(NULL, 12*sizeof(float)*NUM_STARS, GL_DYNAMIC_DRAW); 19 | m_Buffer.Unbind(); 20 | 21 | // Define popup text coordinates 22 | static const float edges[] = { 23 | -0.7f, -0.07f, -4.0f, 0, 0, 24 | -0.7f, +0.07f, -4.0f, 0, 1, 25 | +0.7f, -0.07f, -4.0f, 1, 0, 26 | +0.7f, +0.07f, -4.0f, 1, 1, 27 | }; 28 | 29 | m_PopupBuffer.Create(GL_ARRAY_BUFFER); 30 | m_PopupBuffer.Bind(); 31 | m_PopupBuffer.Allocate(edges, sizeof(edges), GL_STATIC_DRAW); 32 | m_PopupBuffer.Unbind(); 33 | 34 | m_Buf = new float[NUM_STARS*12]; 35 | InitPhysics(); 36 | } 37 | 38 | SpaceLayer::~SpaceLayer() { 39 | delete[] m_Buf; 40 | m_Buffer.Destroy(); 41 | } 42 | 43 | 44 | void SpaceLayer::Update(TimeDelta real_time_delta) { 45 | m_OddEven ^= 1; 46 | UpdateAllPhysics(); 47 | for (int i = 6*m_OddEven, j = 0; j < NUM_STARS; j++) { 48 | const EigenTypes::Vector3f& r = pos[j]; 49 | m_Buf[i++] = r.x(); 50 | m_Buf[i++] = r.y(); 51 | m_Buf[i++] = r.z(); 52 | const EigenTypes::Vector3f& v = vel[j]; 53 | m_Buf[i++] = v.x(); 54 | m_Buf[i++] = v.y(); 55 | m_Buf[i++] = v.z(); 56 | i += 6; 57 | } 58 | } 59 | 60 | void SpaceLayer::Render(TimeDelta real_time_delta) const { 61 | RenderPopup(); 62 | glDepthMask(GL_FALSE); 63 | glBlendFunc(GL_SRC_ALPHA, GL_ONE); 64 | glLineWidth(1.5); 65 | glPointSize(1.0); 66 | int start = SDL_GetTicks(); 67 | 68 | // 4 ms per million particles 69 | m_Shader->Bind(); 70 | GLShaderMatrices::UploadUniforms(*m_Shader, m_ModelView.cast(), m_Projection.cast(), BindFlags::NONE); 71 | 72 | m_Buffer.Bind(); 73 | glEnableVertexAttribArray(m_Shader->LocationOfAttribute("position")); 74 | glEnableVertexAttribArray(m_Shader->LocationOfAttribute("velocity")); 75 | glVertexAttribPointer(m_Shader->LocationOfAttribute("position"), 3, GL_FLOAT, GL_TRUE, 6*sizeof(float), 0); 76 | glVertexAttribPointer(m_Shader->LocationOfAttribute("velocity"), 3, GL_FLOAT, GL_TRUE, 6*sizeof(float), (GLvoid*)(3*sizeof(float))); 77 | 78 | m_Buffer.Write(m_Buf, 12*m_StarsToShow*sizeof(float)); 79 | glDrawArrays(GL_LINES, 0, 2*m_StarsToShow); 80 | 81 | glVertexAttribPointer(m_Shader->LocationOfAttribute("position"), 3, GL_FLOAT, GL_TRUE, 12*sizeof(float), (GLvoid*)((6*m_OddEven)*sizeof(float))); 82 | glVertexAttribPointer(m_Shader->LocationOfAttribute("velocity"), 3, GL_FLOAT, GL_TRUE, 12*sizeof(float), (GLvoid*)((6*m_OddEven + 3)*sizeof(float))); 83 | glDrawArrays(GL_POINTS, 0, m_StarsToShow); 84 | 85 | glDisableVertexAttribArray(m_Shader->LocationOfAttribute("position")); 86 | glDisableVertexAttribArray(m_Shader->LocationOfAttribute("velocity")); 87 | m_Buffer.Unbind(); 88 | 89 | m_Shader->Unbind(); 90 | //std::cout << __LINE__ << ":\t SDL_GetTicks() = " << (SDL_GetTicks() - start) << std::endl; 91 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 92 | glDepthMask(GL_TRUE); 93 | } 94 | 95 | void SpaceLayer::RenderPopup() const { 96 | m_PopupShader->Bind(); 97 | EigenTypes::Matrix4x4f modelView = m_ModelView; 98 | modelView.block<3, 1>(0, 3) += modelView.block<3, 3>(0, 0)*m_EyePos; 99 | //modelView.block<3, 3>(0, 0) = EigenTypes::Matrix3x3f::Identity(); 100 | GLShaderMatrices::UploadUniforms(*m_PopupShader, modelView.cast(), m_Projection.cast(), BindFlags::NONE); 101 | 102 | glActiveTexture(GL_TEXTURE0 + 0); 103 | glUniform1i(m_PopupShader->LocationOfUniform("texture"), 0); 104 | glUniform1f(m_PopupShader->LocationOfUniform("alpha"), 0.7f); 105 | 106 | m_PopupBuffer.Bind(); 107 | glEnableVertexAttribArray(m_PopupShader->LocationOfAttribute("position")); 108 | glEnableVertexAttribArray(m_PopupShader->LocationOfAttribute("texcoord")); 109 | glVertexAttribPointer(m_PopupShader->LocationOfAttribute("position"), 3, GL_FLOAT, GL_TRUE, 5*sizeof(float), (GLvoid*)0); 110 | glVertexAttribPointer(m_PopupShader->LocationOfAttribute("texcoord"), 2, GL_FLOAT, GL_TRUE, 5*sizeof(float), (GLvoid*)(3*sizeof(float))); 111 | 112 | m_PopupTexture->Bind(); 113 | glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 114 | glBindTexture(GL_TEXTURE_2D, 0); // Unbind 115 | 116 | glDisableVertexAttribArray(m_PopupShader->LocationOfAttribute("position")); 117 | glDisableVertexAttribArray(m_PopupShader->LocationOfAttribute("texcoord")); 118 | m_PopupBuffer.Unbind(); 119 | 120 | m_PopupShader->Unbind(); 121 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 122 | } 123 | 124 | EigenTypes::Vector3f SpaceLayer::GenerateVector(const EigenTypes::Vector3f& center, float radius) { 125 | const float rand_max(RAND_MAX); 126 | float dx, dy, dz; 127 | EigenTypes::Vector3f dr; 128 | do { 129 | dx = (2.0f*static_cast(rand())/rand_max - 1.0f)*radius; 130 | dy = (2.0f*static_cast(rand())/rand_max - 1.0f)*radius; 131 | dz = (2.0f*static_cast(rand())/rand_max - 1.0f)*radius; 132 | dr = EigenTypes::Vector3f(dx, dy, dz); 133 | } while (dr.squaredNorm() > radius*radius); 134 | return center + dr * (dr.squaredNorm()/(radius*radius)) * (dr.squaredNorm()/(radius*radius)); 135 | } 136 | 137 | EigenTypes::Vector3f SpaceLayer::InitialVelocity(float mass, const EigenTypes::Vector3f& normal, const EigenTypes::Vector3f& dr) { 138 | return std::sqrt(mass/dr.norm())*normal.cross(dr).normalized(); 139 | } 140 | 141 | void SpaceLayer::InitPhysics() { 142 | pos.resize(NUM_STARS); 143 | vel.resize(NUM_STARS); 144 | 145 | for (int i = 0; i < NUM_GALAXIES; i++) { 146 | m_GalaxyPos[i] = GenerateVector(1.2f*m_EyePos.cast(), 1.0f); 147 | if (i == 0) { 148 | m_GalaxyPos[i] = m_EyePos.cast() + m_EyeView.transpose().cast()*EigenTypes::Vector3f(0, -0.2f, -1.2f); 149 | } 150 | m_GalaxyVel[i] = GenerateVector(-1e-3f*(m_GalaxyPos[i] - 1.1f*m_EyePos.cast()), 0.0004f); 151 | m_GalaxyMass[i] = static_cast(STARS_PER)*5e-11f; 152 | m_GalaxyNormal[i] = GenerateVector(EigenTypes::Vector3f::Zero(), 1.0).normalized(); 153 | 154 | for (int j = 0; j < STARS_PER; j++) { 155 | const size_t index = i*STARS_PER + j; 156 | EigenTypes::Vector3f dr = GenerateVector(EigenTypes::Vector3f::Zero(), 0.5); 157 | 158 | // Project to disc 159 | dr -= 0.4f*atan(dr.dot(m_GalaxyNormal[i])/0.5f)*m_GalaxyNormal[i]; 160 | 161 | pos[index] = m_GalaxyPos[i] + dr; 162 | vel[index] = m_GalaxyVel[i] + InitialVelocity(m_GalaxyMass[i], m_GalaxyNormal[i], dr); 163 | } 164 | } 165 | } 166 | 167 | void SpaceLayer::UpdateV(int type, const EigenTypes::Vector3f& p, EigenTypes::Vector3f& v, int galaxy) { 168 | if (galaxy < NUM_GALAXIES) { 169 | const EigenTypes::Vector3f dr = m_GalaxyPos[galaxy] - p; 170 | v += m_GalaxyMass[galaxy]*dr.normalized()/(0.3e-3f + dr.squaredNorm()); 171 | } else { 172 | const EigenTypes::Vector3f dr = m_SkeletonHands[galaxy - NUM_GALAXIES].avgExtended.cast() - (p + (0.1f + static_cast(type)*0.00003f)*v); 173 | const EigenTypes::Vector3f dv = 1e-3f*dr/(1e-2f + dr.squaredNorm()); 174 | v += dv; 175 | } 176 | } 177 | 178 | void SpaceLayer::UpdateAllPhysics() { 179 | // Update stars 180 | for (int i = 0; i < m_StarsToShow; i++) { 181 | int type = static_cast(static_cast(i)*NUM_STARS/m_StarsToShow); 182 | EigenTypes::Vector3f tempV = vel[i]; 183 | for (size_t j = 0; j < NUM_GALAXIES + m_SkeletonHands.size(); j++) { 184 | UpdateV(type, pos[i], tempV, j); 185 | } 186 | const EigenTypes::Vector3f tempP = pos[i] + 0.667f*tempV; 187 | for (size_t j = 0; j < NUM_GALAXIES + m_SkeletonHands.size(); j++) { 188 | UpdateV(type, tempP, vel[i], j); 189 | } 190 | pos[i] += 0.25*tempV + 0.75*vel[i]; 191 | 192 | if ((pos[i] - m_EyePos.cast()).squaredNorm() > 50) { 193 | pos[i] = m_EyePos.cast() - 10*vel[i] + m_EyeView.transpose().cast()*EigenTypes::Vector3f(0, 0.5, 0); 194 | vel[i].setZero(); 195 | } 196 | } 197 | 198 | // Update galaxies 199 | for (size_t i = 0; i < NUM_GALAXIES; i++) { 200 | EigenTypes::Vector3f tempV = m_GalaxyVel[i]; 201 | for (size_t j = 0; j < NUM_GALAXIES + m_SkeletonHands.size(); j++) { 202 | if (i != j) { // Galaxy does not affect itself 203 | UpdateV(0, m_GalaxyPos[i], m_GalaxyVel[i], j); 204 | } 205 | } 206 | const EigenTypes::Vector3f tempP = m_GalaxyPos[i] + 0.667f*tempV; 207 | for (size_t j = 0; j < NUM_GALAXIES + m_SkeletonHands.size(); j++) { 208 | if (i != j) { // Galaxy does not affect itself 209 | UpdateV(0, tempP, m_GalaxyVel[i], j); 210 | } 211 | } 212 | m_GalaxyPos[i] += 0.25*tempV + 0.75*m_GalaxyVel[i]; 213 | } 214 | } 215 | 216 | EventHandlerAction SpaceLayer::HandleKeyboardEvent(const SDL_KeyboardEvent &ev) { 217 | if (ev.type == SDL_KEYDOWN) { 218 | switch (ev.keysym.sym) { 219 | case 's': 220 | m_StarShowMode++; 221 | m_StarsToShow = static_cast(0.5f + NUM_STARS*exp(-0.4*static_cast(m_StarShowMode % 10))); 222 | return EventHandlerAction::CONSUME; 223 | case SDLK_SPACE: 224 | InitPhysics(); 225 | return EventHandlerAction::CONSUME; 226 | default: 227 | return EventHandlerAction::PASS_ON; 228 | } 229 | } 230 | return EventHandlerAction::PASS_ON; 231 | } 232 | -------------------------------------------------------------------------------- /source/VRIntroLib/SpaceLayer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Interactionlayer.h" 4 | 5 | class GLShader; 6 | 7 | class SpaceLayer : public InteractionLayer { 8 | public: 9 | SpaceLayer(const EigenTypes::Vector3f& initialEyePos); 10 | virtual ~SpaceLayer(); 11 | 12 | virtual void Update(TimeDelta real_time_delta) override; 13 | virtual void Render(TimeDelta real_time_delta) const override; 14 | EventHandlerAction HandleKeyboardEvent(const SDL_KeyboardEvent &ev) override; 15 | 16 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW 17 | 18 | private: 19 | static const int NUM_GALAXIES = 1; 20 | static const int STARS_PER = 30000; 21 | static const int NUM_STARS = STARS_PER*NUM_GALAXIES; 22 | 23 | void InitPhysics(); 24 | EigenTypes::Vector3f GenerateVector(const EigenTypes::Vector3f& center, float radius); 25 | EigenTypes::Vector3f InitialVelocity(float mass, const EigenTypes::Vector3f& normal, const EigenTypes::Vector3f& dr); 26 | void UpdateV(int type, const EigenTypes::Vector3f& p, EigenTypes::Vector3f& v, int galaxy); 27 | void UpdateAllPhysics(); 28 | void RenderPopup() const; 29 | 30 | mutable GLBuffer m_Buffer; 31 | mutable GLBuffer m_PopupBuffer; 32 | std::shared_ptr m_PopupTexture; 33 | std::shared_ptr m_PopupShader; 34 | 35 | EigenTypes::Vector3f m_GalaxyPos[NUM_GALAXIES]; 36 | EigenTypes::Vector3f m_GalaxyVel[NUM_GALAXIES]; 37 | EigenTypes::Vector3f m_GalaxyNormal[NUM_GALAXIES]; 38 | float m_GalaxyMass[NUM_GALAXIES]; 39 | 40 | EigenTypes::stdvectorV3f pos; 41 | EigenTypes::stdvectorV3f vel; 42 | 43 | float *m_Buf; 44 | 45 | static float buf[NUM_STARS]; 46 | int m_OddEven; 47 | 48 | int m_StarShowMode; 49 | int m_StarsToShow; 50 | }; 51 | -------------------------------------------------------------------------------- /source/VRIntroLib/SpheresLayer.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "SpheresLayer.h" 3 | 4 | #include "GLController.h" 5 | 6 | SpheresLayer::SpheresLayer(const EigenTypes::Vector3f& initialEyePos) : 7 | InteractionLayer(initialEyePos), 8 | m_Pos(NUM_SPHERES), 9 | m_Disp(NUM_SPHERES, EigenTypes::Vector3f::Zero()), 10 | m_Vel(NUM_SPHERES, EigenTypes::Vector3f::Zero()), 11 | m_Colors(NUM_SPHERES), 12 | m_Mono(NUM_SPHERES), 13 | m_Radius(NUM_SPHERES), 14 | m_Spring(1.0f), 15 | m_Damp(1.0f), 16 | m_Well(-1.0f) { 17 | for (int i = 0; i < NUM_SPHERES; i++) { 18 | float z = (float)rand() / RAND_MAX * 2.0f - 1.0f; 19 | float theta = (float)rand() / RAND_MAX * 6.28318530718f; 20 | float xy = std::sqrt(1.0f - z*z); 21 | float x = xy*cos(theta); 22 | float y = xy*sin(theta); 23 | 24 | float r = (float)rand() / RAND_MAX; 25 | float g = (float)rand() / RAND_MAX; 26 | float b = (float)rand() / RAND_MAX; 27 | float dist = 0.40f + (float)rand() / RAND_MAX * 0.2f; 28 | m_Radius[i] = 0.020f + (float)rand() / RAND_MAX * 0.03f; 29 | m_Pos[i] = EigenTypes::Vector3f(0.0f, 1.7f, -5.0f) + EigenTypes::Vector3f(x, y, z)*dist; 30 | m_Colors[i] = EigenTypes::Vector3f(r, g, b).normalized(); 31 | m_Mono[i] = EigenTypes::Vector3f::Ones()*m_Colors[i].sum()*0.33f; 32 | } 33 | } 34 | 35 | void SpheresLayer::Update(TimeDelta real_time_delta) { 36 | ComputePhysics(real_time_delta); 37 | } 38 | 39 | void SpheresLayer::Render(TimeDelta real_time_delta) const { 40 | glEnable(GL_BLEND); 41 | m_Shader->Bind(); 42 | const EigenTypes::Vector3f desiredLightPos(0, 1.5, 0.5); 43 | const EigenTypes::Vector3f lightPos = m_EyeView*desiredLightPos; 44 | const int lightPosLoc = m_Shader->LocationOfUniform("light_position"); 45 | glUniform3f(lightPosLoc, lightPos[0], lightPos[1], lightPos[2]); 46 | 47 | // Common property 48 | m_Sphere.Material().SetAmbientLightingProportion(0.3f); 49 | 50 | for (size_t j = 0; j < NUM_SPHERES; j++) { 51 | float desaturation = 0.005f / (0.005f + m_Disp[j].squaredNorm()); 52 | EigenTypes::Vector3f color = m_Colors[j]*(1.0f - desaturation) + m_Mono[j]*desaturation; 53 | 54 | m_Sphere.SetRadius(m_Radius[j]); 55 | m_Sphere.Translation() = (m_Pos[j] + m_Disp[j]).cast(); 56 | m_Sphere.Material().SetDiffuseLightColor(Color(color.x(), color.y(), color.z(), m_Alpha)); 57 | m_Sphere.Material().SetAmbientLightColor(Color(color.x(), color.y(), color.z(), m_Alpha)); 58 | PrimitiveBase::DrawSceneGraph(m_Sphere, m_Renderer); 59 | } 60 | m_Shader->Unbind(); 61 | RenderGrid(); 62 | } 63 | 64 | void SpheresLayer::RenderGrid() const { 65 | const int divTheta = 22; 66 | const int divPhi = 40; 67 | const float radius = 0.7f; 68 | 69 | glTranslatef(m_EyePos.x(), m_EyePos.y(), m_EyePos.z()); 70 | glColor4f(0.2f, 0.6f, 1.0f, m_Alpha*0.5f); 71 | glLineWidth(1.0f); 72 | glBegin(GL_LINES); 73 | for (int i = 0; i < divPhi; i++) { 74 | float phi0 = (float)M_PI*(i/static_cast(divPhi) - 0.5f); 75 | float phi1 = (float)M_PI*((i + 1)/static_cast(divPhi) - 0.5f); 76 | for (int j = 0; j < divTheta; j++) { 77 | float theta0 = 2*(float)M_PI*(j/static_cast(divTheta)); 78 | float theta1 = 2*(float)M_PI*((j + 1)/static_cast(divTheta)); 79 | glVertex3f(radius*cos(phi0)*cos(theta0), radius*sin(phi0), radius*cos(phi0)*sin(theta0)); 80 | glVertex3f(radius*cos(phi0)*cos(theta1), radius*sin(phi0), radius*cos(phi0)*sin(theta1)); 81 | glVertex3f(radius*cos(phi0)*cos(theta0), radius*sin(phi0), radius*cos(phi0)*sin(theta0)); 82 | glVertex3f(radius*cos(phi1)*cos(theta0), radius*sin(phi1), radius*cos(phi1)*sin(theta0)); 83 | } 84 | } 85 | glEnd(); 86 | } 87 | 88 | EventHandlerAction SpheresLayer::HandleKeyboardEvent(const SDL_KeyboardEvent &ev) { 89 | //switch (ev.keysym.sym) { 90 | //default: 91 | return EventHandlerAction::PASS_ON; 92 | //} 93 | } 94 | 95 | void SpheresLayer::ComputePhysics(TimeDelta real_time_delta) { 96 | const int num_tips = static_cast(m_Tips.size()); 97 | // std::cout << __LINE__ << ":\t deltaT = " << (deltaT) << std::endl; 98 | for (int i = 0; i < NUM_SPHERES; i++) { 99 | static const float K = 10; 100 | static const float D = 3; 101 | static const float A = 0.0015f; 102 | static const float AA = 0.00005f; 103 | 104 | EigenTypes::Vector3f accel = -K*m_Spring*m_Disp[i] -D*m_Damp*m_Vel[i]; 105 | // std::cout << __LINE__ << ":\t num_tips = " << (num_tips) << std::endl; 106 | for (int j = 0; j < num_tips; j++) { 107 | 108 | // std::cout << __LINE__ << ":\t (positions[i] - tips[j]).squaredNorm() = " << ((positions[i] - tips[j]).squaredNorm()) << std::endl; 109 | const EigenTypes::Vector3f diff = m_Tips[j] - (m_Pos[i] + m_Disp[i]); 110 | float distSq = diff.squaredNorm(); 111 | if (distSq < m_Radius[i]*m_Radius[i]) { 112 | m_Vel[i] += -diff.normalized(); 113 | break; 114 | } 115 | accel += A*m_Well*diff/(AA + distSq*distSq); 116 | // accel += A*m_Well*diff/(AA + distSq*diff.norm()); 117 | } 118 | 119 | m_Disp[i] += 0.5f*m_Vel[i]*static_cast(real_time_delta); 120 | m_Vel[i] += accel*static_cast(real_time_delta); 121 | m_Disp[i] += 0.5f*m_Vel[i]*static_cast(real_time_delta); 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /source/VRIntroLib/SpheresLayer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Interactionlayer.h" 4 | 5 | class GLShader; 6 | 7 | class SpheresLayer : public InteractionLayer { 8 | public: 9 | SpheresLayer(const EigenTypes::Vector3f& initialEyePos); 10 | //virtual ~SpheresLayer (); 11 | 12 | virtual void Update(TimeDelta real_time_delta) override; 13 | virtual void Render(TimeDelta real_time_delta) const override; 14 | EventHandlerAction HandleKeyboardEvent(const SDL_KeyboardEvent &ev) override; 15 | 16 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW 17 | 18 | private: 19 | static const int NUM_SPHERES = 300; 20 | 21 | virtual void RenderGrid() const; 22 | void ComputePhysics(TimeDelta real_time_delta); 23 | 24 | EigenTypes::stdvectorV3f m_Pos; 25 | EigenTypes::stdvectorV3f m_Disp; 26 | EigenTypes::stdvectorV3f m_Vel; 27 | 28 | EigenTypes::stdvectorV3f m_Colors; 29 | EigenTypes::stdvectorV3f m_Mono; 30 | std::vector m_Radius; 31 | 32 | float m_Spring; 33 | float m_Damp; 34 | float m_Well; 35 | }; 36 | -------------------------------------------------------------------------------- /source/VRIntroLib/VRIntroApp.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Application.h" 4 | #include "GLController.h" 5 | #include "RenderableEventHandler.h" 6 | #include "SDLController.h" 7 | #include "OculusVR.h" 8 | #include "PassthroughLayer.h" 9 | #include "MessageLayer.h" 10 | #include "RenderState.h" 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | class IFrameSupplier; 18 | class HandLayer; 19 | class MessageLayer; 20 | 21 | // Interface class for top-level control of an application. 22 | class VRIntroApp : public Application { 23 | public: 24 | VRIntroApp(bool showMirror = false); 25 | // Application interface methods. See Application for comments and details. 26 | 27 | virtual void Initialize() override; 28 | virtual void Shutdown() override; 29 | void InitMirror(); 30 | void ShutdownMirror(); 31 | 32 | void SetFrameSupplier(IFrameSupplier* supplier); 33 | void Run() { RunApplication(*this); } 34 | 35 | virtual void Update(TimeDelta real_time_delta) override; 36 | virtual void Render(TimeDelta real_time_delta) const override; 37 | void RenderEye(TimeDelta real_time_delta, int i, const EigenTypes::Matrix4x4f& proj) const; 38 | 39 | virtual EventHandlerAction HandleWindowEvent(const SDL_WindowEvent &ev) override; 40 | virtual EventHandlerAction HandleKeyboardEvent(const SDL_KeyboardEvent &ev) override; 41 | virtual EventHandlerAction HandleMouseMotionEvent(const SDL_MouseMotionEvent &ev) override; 42 | virtual EventHandlerAction HandleMouseButtonEvent(const SDL_MouseButtonEvent &ev) override; 43 | virtual EventHandlerAction HandleMouseWheelEvent(const SDL_MouseWheelEvent &ev) override; 44 | virtual EventHandlerAction HandleQuitEvent(const SDL_QuitEvent &ev) override; 45 | virtual EventHandlerAction HandleGenericSDLEvent(const SDL_Event &ev) override; 46 | 47 | virtual TimePoint Time() const override; 48 | 49 | #if _WIN32 50 | // TODO: change components so const cast is not required 51 | HWND GetHwnd() const { return const_cast(&m_SDLController)->GetHWND(); } 52 | #elif __APPLE__ 53 | Uint32 GetWindowID() const { return const_cast(&m_SDLController)->GetWindowID(); } 54 | #endif 55 | 56 | private: 57 | void InitializeApplicationLayers(); 58 | void ShutdownApplicationLayers(); 59 | void SelectLayer(int i); 60 | 61 | template 62 | EventHandlerAction DispatchEventToApplicationLayers( 63 | const EventType_ &ev, 64 | EventHandlerAction(EventHandler::*HandleEvent)(const EventType_ &)) { 65 | // Give it to the passthrough layers 66 | for (int i = 0; i < 2; i++) { 67 | (*(m_PassthroughLayer[i]).*HandleEvent)(ev); 68 | } 69 | 70 | // Give each application layer a chance to handle the event, stopping if one returns EventHandlerAction::CONSUME. 71 | for (auto it = m_Layers.rbegin(); it != m_Layers.rend(); ++it) { 72 | RenderableEventHandler &layer = **it; 73 | if ((layer.*HandleEvent)(ev) == EventHandlerAction::CONSUME) { 74 | return EventHandlerAction::CONSUME; 75 | } 76 | } 77 | // No layers consumed the event, so pass it on. 78 | return EventHandlerAction::PASS_ON; 79 | } 80 | 81 | mutable OculusVR m_Oculus; 82 | SDLController m_SDLController; 83 | GLController m_GLController; 84 | TimePoint m_applicationTime; 85 | std::vector> m_Layers; 86 | std::vector> m_MappedLayers; 87 | std::shared_ptr m_HandLayer; 88 | std::shared_ptr m_GhostHandLayer; 89 | std::shared_ptr m_MessageLayer; 90 | 91 | std::shared_ptr m_PassthroughLayer[2]; 92 | IFrameSupplier* m_FrameSupplier; 93 | Uint32 SDL_Window_ID; 94 | MessageLayer* messageLayer; 95 | 96 | std::thread m_MirrorThread; 97 | #if _WIN32 98 | HWND m_MirrorHWND; 99 | #endif 100 | bool m_ShowMirror; 101 | 102 | int m_Selected; 103 | bool m_HealthWarningDismissed; 104 | bool m_HelpToggled; 105 | bool m_OculusMode; 106 | bool m_CrippleMode; 107 | bool m_CroppleMode; 108 | bool m_UseLatestImage; 109 | 110 | int m_Width; 111 | int m_Height; 112 | 113 | float m_Zoom; 114 | float m_Scale; 115 | }; 116 | -------------------------------------------------------------------------------- /source/VRIntroLib/stdafx.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | -------------------------------------------------------------------------------- /source/VRIntroLib/stdafx.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | --------------------------------------------------------------------------------