diff options
28 files changed, 489 insertions, 303 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 1571556a..601f935d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,11 +30,15 @@ find_package(Qt5 COMPONENTS SerialPort QUIET) include_directories(SYSTEM ${Qt5Core_INCLUDE_DIRS} ${Qt5Xml_INCLUDE_DIRS} ${Qt5Gui_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS} ${Qt5Network_INCLUDE_DIRS}) add_definitions(${Qt5Core_DEFINITIONS} ${Qt5Xml_DEFINITIONS} ${Qt5Gui_DEFINITIONS} ${Qt5Widgets_DEFINITIONS} ${Qt5Network_DEFINITIONS}) +if(MSVC) + add_definitions(-DNOMINMAX -D_CRT_SECURE_NO_WARNINGS) +endif() + set(my-qt-deps) if(WIN32) # hack to avoid breakage on buildbot set(my-qt-deps ws2_32) endif() -set(MY_QT_LIBS ${Qt5Widgets_LIBRARIES} ${Qt5Gui_LIBRARIES} ${Qt5Network_LIBRARIES} ${Qt5Xml_LIBRARIES} ${Qt5Core_LIBRARIES} ${my-qt-deps}) +set(MY_QT_LIBS ${Qt5Core_LIBRARIES} ${Qt5Gui_LIBRARIES} ${Qt5Widgets_LIBRARIES} ${Qt5Network_LIBRARIES} ${Qt5Xml_LIBRARIES} ${my-qt-deps}) # note, hatire supports both ftnoir and opentrack # don't remove without being sure as hell -sh 20140922 @@ -65,12 +69,17 @@ if(CMAKE_COMPILER_IS_GNUCXX OR APPLE) set(CMAKE_CXX_FLAGS " -std=c++11 ${CMAKE_CXX_FLAGS} ") endif() +set_property(GLOBAL PROPERTY USE_FOLDERS OFF) + # qt broken as usual set(EXTRA-MOCS opentrack/options.hpp) macro(opentrack_module n dir) file(GLOB ${n}-c ${dir}/*.cpp ${dir}/*.c ${dir}/*.h ${dir}/*.hpp ${EXTRA-MOCS}) file(GLOB ${n}-res ${dir}/*.rc) + foreach(f ${n}-res) + set_source_files_properties(${f} PROPERTIES LANGUAGE RC) + endforeach() file(GLOB ${n}-ui ${dir}/*.ui) file(GLOB ${n}-rc ${dir}/*.qrc) endmacro() @@ -82,6 +91,13 @@ macro(opentrack_qt n) set(${n}-all ${${n}-c} ${${n}-rc} ${${n}-rcc} ${${n}-uih} ${${n}-moc} ${${n}-res}) endmacro() +set(msvc-subsystem "/VERSION:5.1 /SUBSYSTEM:WINDOWS,5.01") +function(opentrack_compat target) + if(MSVC) + set_target_properties(${target} PROPERTIES LINK_FLAGS "${msvc-subsystem} /DEBUG /OPT:ICF") + endif() +endfunction() + macro(opentrack_library n dir) cmake_parse_arguments(foolib "" "LINK;COMPILE;GNU-LINK;GNU-COMPILE;STATIC" "" ${ARGN}) if(NOT " ${foolib_UNPARSED_ARGUMENTS}" STREQUAL " ") @@ -105,7 +121,11 @@ macro(opentrack_library n dir) COMPILE_FLAGS "${foolib_COMPILE} ${foolib_GNU-COMPILE} ${visibility}" ) else() - set_target_properties(${n} PROPERTIES LINK_FLAGS ${foolib_LINK} COMPILE_FLAGS ${foolib_COMPILE}) + set(link-flags) + if(MSVC) + set(link-flags "${msvc-subsystem} /DEBUG /OPT:ICF") + endif() + set_target_properties(${n} PROPERTIES LINK_FLAGS "${link-flags} ${foolib_LINK}" COMPILE_FLAGS "${foolib_COMPILE}") endif() if (NOT foolib_STATIC) install(TARGETS ${n} RUNTIME DESTINATION . LIBRARY DESTINATION .) @@ -174,6 +194,7 @@ add_custom_target(tarball DEPENDS ${filename}) opentrack_module(opentrack-api opentrack) opentrack_qt(opentrack-api) add_library(opentrack-api STATIC ${opentrack-api-all}) +opentrack_compat(opentrack-api) target_link_libraries(opentrack-api ${MY_QT_LIBS}) if(NOT WIN32) @@ -209,13 +230,13 @@ if(SDK_XPLANE) SET_TARGET_PROPERTIES(opentrack-xplane-plugin PROPERTIES LINK_FLAGS "-Wl,--version-script=${CMAKE_SOURCE_DIR}/x-plane-plugin/version-script.txt -shared -rdynamic -nodefaultlibs -undefined_warning -fPIC" - COMPILE_FLAGS "-Wall -O2 -pipe -fPIC -DLIN -DXPLM210" + COMPILE_FLAGS "-Wall -O2 -pipe -fPIC -DLIN -DXPLM200 -DXPLM210" LIBRARY_OUTPUT_NAME "opentrack.xpl" PREFIX "" SUFFIX "") endif() if(APPLE) SET_TARGET_PROPERTIES(opentrack-xplane-plugin PROPERTIES - COMPILE_FLAGS "-iframework ${SDK_XPLANE}/Libraries/Mac/ -DAPL -DXPLM210 -framework XPLM -framework XPWidgets" + COMPILE_FLAGS "-iframework ${SDK_XPLANE}/Libraries/Mac/ -DAPL -DXPLM200 -DXPLM210 -framework XPLM -framework XPWidgets" LINK_FLAGS "-F${SDK_XPLANE}/Libraries/Mac/ -framework XPLM -framework XPWidgets") endif() if(UNIX AND NOT APPLE) @@ -224,31 +245,36 @@ if(SDK_XPLANE) endif() add_library(opentrack-compat STATIC ${opentrack-compat-c}) +opentrack_compat(opentrack-compat) # uh... if(NOT WIN32 AND NOT APPLE) target_link_libraries(opentrack-compat rt) endif() opentrack_module(opentrack-csv csv) add_library(opentrack-csv STATIC ${opentrack-csv-c}) +opentrack_compat(opentrack-csv) target_link_libraries(opentrack-csv ${MY_QT_LIBS}) opentrack_module(opentrack-pose-widget pose-widget) opentrack_qt(opentrack-pose-widget) add_library(opentrack-pose-widget STATIC ${opentrack-pose-widget-all}) +opentrack_compat(opentrack-pose-widget) target_include_directories(opentrack-pose-widget PUBLIC pose-widget/) # else Qt moc breaks target_link_libraries(opentrack-pose-widget ${MY_QT_LIBS}) opentrack_module(opentrack-spline-widget qfunctionconfigurator) opentrack_qt(opentrack-spline-widget) add_library(opentrack-spline-widget STATIC ${opentrack-spline-widget-all}) +opentrack_compat(opentrack-spline-widget) target_include_directories(opentrack-spline-widget PUBLIC qfunctionconfigurator/) target_link_libraries(opentrack-spline-widget ${MY_QT_LIBS}) -add_library(opentrack-version STATIC opentrack/version.C) +add_library(opentrack-version STATIC opentrack/version.cc) +opentrack_compat(opentrack-version) set_target_properties(opentrack-version PROPERTIES COMPILE_DEFINITIONS - "IN_VERSION_UNIT;OPENTRACK_VERSION=\"${OPENTRACK__COMMIT}\"") + "OPENTRACK_VERSION=\"${OPENTRACK__COMMIT}\"") opentrack_library(opentrack-filter-accela ftnoir_filter_accela STATIC TRUE) target_link_libraries(opentrack-filter-accela opentrack-spline-widget) @@ -258,7 +284,12 @@ opentrack_library(opentrack-proto-fgfs ftnoir_protocol_fg) if(SDK_VJOY) opentrack_library(opentrack-proto-vjoy ftnoir_protocol_vjoy GNU-LINK "-Wl,--enable-stdcall-fixup") - target_link_libraries(opentrack-proto-vjoy ${MY_QT_LIBS} ${SDK_VJOY}/VJoy.dll) + if(MSVC) + set(ext .lib) + else() + set(ext .dll) + endif() + target_link_libraries(opentrack-proto-vjoy ${MY_QT_LIBS} ${SDK_VJOY}/VJoy${ext}) target_include_directories(opentrack-proto-vjoy SYSTEM PUBLIC ${SDK_VJOY}) endif() @@ -274,6 +305,9 @@ if(SDK_FSUIPC) opentrack_library(opentrack-proto-fsuipc ftnoir_protocol_fsuipc) target_link_libraries(opentrack-proto-fsuipc ${SDK_FSUIPC}/FSUIPC_User.lib) target_include_directories(opentrack-proto-fsuipc SYSTEM PUBLIC ${SDK_FSUIPC}) + if(MSVC) + set_target_properties(opentrack-proto-fsuipc PROPERTIES LINK_FLAGS "/NODEFAULTLIB:LIBC.lib") + endif() #target_link_directories(${SDK_FSUIPC}) endif() @@ -358,12 +392,21 @@ if(SDK_RIFT AND FALSE) set(link-flags "-framework CoreFoundation -framework CoreGraphics -framework IOKit -framework Quartz") set(c-flags "-fno-strict-aliasing") else() - set(c-flags "-fno-strict-aliasing") + if(NOT MSVC) + set(c-flags "-fno-strict-aliasing") + endif() endif() opentrack_library(opentrack-tracker-rift ftnoir_tracker_rift LINK ${link-flags} COMPILE ${c-flags}) target_include_directories(opentrack-tracker-rift SYSTEM PUBLIC ${SDK_RIFT}/Include ${SDK_RIFT}/Src) if(WIN32) - target_link_libraries(opentrack-tracker-rift ${SDK_RIFT}/libLibOVR.a winmm setupapi ws2_32 imagehlp wbemuuid) + if(MSVC) + set(ext lib) + set(p) + else() + set(ext a) + set(p lib) + endif() + target_link_libraries(opentrack-tracker-rift ${SDK_RIFT}/${p}LibOVR.${ext} winmm setupapi ws2_32 imagehlp wbemuuid) else() if(NOT APPLE) target_link_libraries(opentrack-tracker-rift ${SDK_RIFT}/libLibOVR.a udev Xinerama) @@ -377,9 +420,16 @@ if(SDK_HYDRA AND FALSE) opentrack_library(opentrack-tracker-hydra ftnoir_tracker_hydra) target_include_directories(opentrack-tracker-hydra SYSTEM PUBLIC ${SDK_HYDRA}/include ${SDK_HYDRA}/include/sixense_utils) if(WIN32) + if(MSVC) + set(dir lib) + set(ext lib) + else() + set(dir bin) + set(ext dll) + endif() target_link_libraries(opentrack-tracker-hydra - "${SDK_HYDRA}/bin/win32/release_dll/sixense.dll" - #"${SDK_HYDRA}/bin/win32/release_dll/sixense_utils.dll" + "${SDK_HYDRA}/${dir}/win32/release_dll/sixense.${ext}" + #"${SDK_HYDRA}/${dir}/win32/release_dll/sixense_utils.${ext}" ) install(FILES "${SDK_HYDRA}/bin/win32/release_dll/sixense.dll" #"${SDK_HYDRA}/bin/win32/release_dll/sixense_utils.dll" @@ -442,7 +492,7 @@ endif() opentrack_qt(opentrack) add_executable(opentrack ${opentrack-win32-executable} ${opentrack-all}) target_link_libraries(opentrack opentrack-filter-accela opentrack-tracker-pt) - +opentrack_compat(opentrack) if(NOT WIN32) set_target_properties(opentrack PROPERTIES SUFFIX ".bin") endif() diff --git a/facetracknoir/main.cpp b/facetracknoir/main.cpp index c92f6980..6d29e3b5 100644 --- a/facetracknoir/main.cpp +++ b/facetracknoir/main.cpp @@ -20,7 +20,7 @@ static void add_program_library_path() { char* p = _pgmptr; { - char path[MAX_PATH]; + char path[MAX_PATH+1]; strcpy(path, p); char* ptr = strrchr(path, '\\'); if (ptr) @@ -77,13 +77,17 @@ int main(int argc, char** argv) if (use_profile) MainWindow::set_profile(profile); - MainWindow w; + auto w = std::make_shared<MainWindow>(); if (use_profile) - w.startTracker(); + w->startTracker(); - w.show(); + w->show(); app.exec(); + // on MSVC crashes in atexit +#ifdef _MSC_VER + TerminateProcess(GetCurrentProcess(), 0); +#endif return 0; } diff --git a/facetracknoir/options-dialog.cpp b/facetracknoir/options-dialog.cpp index 0fe90c93..1b64de9e 100644 --- a/facetracknoir/options-dialog.cpp +++ b/facetracknoir/options-dialog.cpp @@ -81,6 +81,15 @@ OptionsDialog::OptionsDialog(State& state) : state(state), trans_calib_running(f tie_setting(acc.rot_deadzone, ui.rot_dz_slider); tie_setting(acc.trans_deadzone, ui.trans_dz_slider); + update_rot_display(ui.rotation_slider->value()); + update_trans_display(ui.translation_slider->value()); + update_ewma_display(ui.ewma_slider->value()); + update_rot_dz_display(ui.rot_dz_slider->value()); + update_trans_dz_display(ui.trans_dz_slider->value()); + + tie_setting(pt.dynamic_pose, ui.dynamic_pose); + tie_setting(pt.init_phase_timeout, ui.init_phase_timeout); + connect(&timer,SIGNAL(timeout()), this,SLOT(poll_tracker_info())); connect( ui.tcalib_button,SIGNAL(toggled(bool)), this,SLOT(startstop_trans_calib(bool)) ); diff --git a/facetracknoir/process_detector.cpp b/facetracknoir/process_detector.cpp index 237d350d..8efc0c10 100644 --- a/facetracknoir/process_detector.cpp +++ b/facetracknoir/process_detector.cpp @@ -9,25 +9,25 @@ void settings::set_game_list(const QString &game_list) { - QSettings settings(group::org); + QSettings settings(OPENTRACK_ORG); settings.setValue("executable-list", game_list); } QString settings::get_game_list() { - QSettings settings(group::org); + QSettings settings(OPENTRACK_ORG); return settings.value("executable-list").toString(); } bool settings::is_enabled() { - QSettings settings(group::org); + QSettings settings(OPENTRACK_ORG); return settings.value("executable-detector-enabled", false).toBool(); } void settings::set_is_enabled(bool enabled) { - QSettings settings(group::org); + QSettings settings(OPENTRACK_ORG); settings.setValue("executable-detector-enabled", enabled); } @@ -68,6 +68,7 @@ int process_detector::add_row(QString exe_name, QString profile) QComboBox* cb = new QComboBox(); cb->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Maximum); + cb->addItem(""); cb->addItems(group::ini_list()); ui.tableWidget->setCellWidget(i, 1, cb); @@ -222,7 +223,7 @@ bool process_detector_worker::config_to_start(QString& str) { last_exe_name = name; str = filenames[name]; - return true; + return str != ""; } } diff --git a/facetracknoir/settings.ui b/facetracknoir/settings.ui index efe1568a..b41c09a0 100644 --- a/facetracknoir/settings.ui +++ b/facetracknoir/settings.ui @@ -297,20 +297,7 @@ <string>Camera</string> </attribute> <layout class="QGridLayout" name="gridLayout_9"> - <item row="4" column="0"> - <spacer name="verticalSpacer_2"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>40</height> - </size> - </property> - </spacer> - </item> - <item row="2" column="0"> + <item row="3" column="0"> <widget class="QGroupBox" name="groupBox_6"> <property name="title"> <string>Point extraction</string> @@ -424,6 +411,124 @@ </layout> </widget> </item> + <item row="4" column="0"> + <widget class="QGroupBox" name="groupBox_11"> + <property name="title"> + <string>Status</string> + </property> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QLabel" name="caminfo_label"> + <property name="text"> + <string>Not running</string> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="pointinfo_label"> + <property name="text"> + <string/> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item row="1" column="0"> + <widget class="QGroupBox" name="groupBox_9"> + <property name="title"> + <string>Device</string> + </property> + <layout class="QGridLayout" name="gridLayout"> + <item row="2" column="0"> + <widget class="QLabel" name="label_32"> + <property name="text"> + <string>Dynamic pose resolution</string> + </property> + </widget> + </item> + <item row="2" column="1"> + <widget class="QCheckBox" name="dynamic_pose"> + <property name="text"> + <string/> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QComboBox" name="camera_mode"> + <item> + <property name="text"> + <string>640x480, 75 Hz</string> + </property> + </item> + <item> + <property name="text"> + <string>640x480, 60 Hz</string> + </property> + </item> + <item> + <property name="text"> + <string>320x240, 189 Hz</string> + </property> + </item> + <item> + <property name="text"> + <string>320x240, 120 Hz</string> + </property> + </item> + </widget> + </item> + <item row="0" column="0"> + <widget class="QLabel" name="label_25"> + <property name="text"> + <string>Mode</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QComboBox" name="camera_fov"> + <item> + <property name="text"> + <string>56°</string> + </property> + </item> + <item> + <property name="text"> + <string>75°</string> + </property> + </item> + </widget> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>Field of view</string> + </property> + </widget> + </item> + <item row="3" column="0"> + <widget class="QLabel" name="label_33"> + <property name="text"> + <string>Dynamic pose timeout</string> + </property> + </widget> + </item> + <item row="3" column="1"> + <widget class="QSpinBox" name="init_phase_timeout"> + <property name="suffix"> + <string> ms</string> + </property> + <property name="minimum"> + <number>1</number> + </property> + <property name="maximum"> + <number>10000</number> + </property> + </widget> + </item> + </layout> + </widget> + </item> <item row="0" column="0"> <widget class="QGroupBox" name="groupBox_5"> <property name="title"> @@ -530,89 +635,18 @@ </layout> </widget> </item> - <item row="1" column="0"> - <widget class="QGroupBox" name="groupBox_9"> - <property name="title"> - <string>Device</string> + <item row="5" column="0"> + <spacer name="verticalSpacer_2"> + <property name="orientation"> + <enum>Qt::Vertical</enum> </property> - <layout class="QGridLayout" name="gridLayout"> - <item row="0" column="0"> - <widget class="QLabel" name="label_25"> - <property name="text"> - <string>Mode</string> - </property> - </widget> - </item> - <item row="0" column="1"> - <widget class="QComboBox" name="camera_mode"> - <item> - <property name="text"> - <string>640x480, 75 Hz</string> - </property> - </item> - <item> - <property name="text"> - <string>640x480, 60 Hz</string> - </property> - </item> - <item> - <property name="text"> - <string>320x240, 189 Hz</string> - </property> - </item> - <item> - <property name="text"> - <string>320x240, 120 Hz</string> - </property> - </item> - </widget> - </item> - <item row="1" column="0"> - <widget class="QLabel" name="label_2"> - <property name="text"> - <string>Field of view</string> - </property> - </widget> - </item> - <item row="1" column="1"> - <widget class="QComboBox" name="camera_fov"> - <item> - <property name="text"> - <string>56°</string> - </property> - </item> - <item> - <property name="text"> - <string>75°</string> - </property> - </item> - </widget> - </item> - </layout> - </widget> - </item> - <item row="3" column="0"> - <widget class="QGroupBox" name="groupBox_11"> - <property name="title"> - <string>Status</string> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> </property> - <layout class="QHBoxLayout" name="horizontalLayout"> - <item> - <widget class="QLabel" name="caminfo_label"> - <property name="text"> - <string>Not running</string> - </property> - </widget> - </item> - <item> - <widget class="QLabel" name="pointinfo_label"> - <property name="text"> - <string/> - </property> - </widget> - </item> - </layout> - </widget> + </spacer> </item> </layout> </widget> diff --git a/facetracknoir/ui.cpp b/facetracknoir/ui.cpp index c646808c..8cf14050 100644 --- a/facetracknoir/ui.cpp +++ b/facetracknoir/ui.cpp @@ -102,8 +102,8 @@ void MainWindow::open() { if (! fileName.isEmpty() ) { { - QSettings settings(group::org); - settings.setValue(group::filename_key, remove_app_path(fileName)); + QSettings settings(OPENTRACK_ORG); + settings.setValue(OPENTRACK_CONFIG_FILENAME_KEY, remove_app_path(fileName)); } fill_profile_combobox(); load_settings(); @@ -151,8 +151,8 @@ void MainWindow::saveAs() { (void) QFile::copy(oldFile, fileName); - QSettings settings(group::org); - settings.setValue (group::filename_key, remove_app_path(fileName)); + QSettings settings(OPENTRACK_ORG); + settings.setValue (OPENTRACK_CONFIG_FILENAME_KEY, remove_app_path(fileName)); } save(); @@ -203,14 +203,11 @@ void MainWindow::bindKeyboardShortcuts() void MainWindow::startTracker() { s.b->save(); load_settings(); - bindKeyboardShortcuts(); // tracker dtor needs run first work = nullptr; libs = SelectedLibraries(ui.video_frame, std::make_shared<Tracker_PT>(), current_protocol(), std::make_shared<FTNoIR_Filter>()); - - work = std::make_shared<Work>(s, pose, libs, this, winId()); { double p[6] = {0,0,0, 0,0,0}; @@ -223,9 +220,14 @@ void MainWindow::startTracker() { "One of libraries failed to load. Check installation.", QMessageBox::Ok, QMessageBox::NoButton); + libs = SelectedLibraries(); return; } + work = std::make_shared<Work>(s, pose, libs, this, winId()); + + bindKeyboardShortcuts(); + if (pProtocolDialog) pProtocolDialog->register_protocol(libs.pProtocol.get()); @@ -329,6 +331,7 @@ void MainWindow::showProtocolSettings() { } else { auto dialog = mk_dialog<IProtocolDialog>(current_protocol()); + if (!dialog) return; pProtocolDialog = dialog; if (libs.pProtocol != nullptr) dialog->register_protocol(libs.pProtocol.get()); @@ -397,8 +400,8 @@ void MainWindow::profileSelected(int index) return; { - QSettings settings(group::org); - settings.setValue (group::filename_key, remove_app_path(QFileInfo(group::ini_pathname()).absolutePath() + "/" + + QSettings settings(OPENTRACK_ORG); + settings.setValue (OPENTRACK_CONFIG_FILENAME_KEY, remove_app_path(QFileInfo(group::ini_pathname()).absolutePath() + "/" + ui.iconcomboProfile->itemText(index))); } load_settings(); @@ -477,6 +480,6 @@ void MainWindow::maybe_start_profile_from_executable() void MainWindow::set_profile(const QString &profile) { - QSettings settings(group::org); - settings.setValue(group::filename_key, MainWindow::remove_app_path(profile)); + QSettings settings(OPENTRACK_ORG); + settings.setValue(OPENTRACK_CONFIG_FILENAME_KEY, MainWindow::remove_app_path(profile)); } diff --git a/ftnoir_filter_accela/ftnoir_filter_accela.cpp b/ftnoir_filter_accela/ftnoir_filter_accela.cpp index 5adaea23..acb9e4ac 100644 --- a/ftnoir_filter_accela/ftnoir_filter_accela.cpp +++ b/ftnoir_filter_accela/ftnoir_filter_accela.cpp @@ -13,23 +13,27 @@ using namespace std; static constexpr double rot_gains[][2] = { - { 7, 200 }, - { 6, 100 }, - { 5, 45 }, - { 4, 15 }, - { 3, 5 }, - { 2, 1.4 }, - { 1, .4 }, - { 0, .2 }, + { 2.66, 110 }, + { 2.33, 80 }, + { 2, 50 }, + { 1.66, 30 }, + { 1.33, 15 }, + { 1, 5 }, + { .66, 1.4 }, + { .33, .4 }, + { 0, 0 }, { -1, 0 } }; + static constexpr double trans_gains[][2] = { - { 5, 180 }, - { 4, 64 }, - { 3, 20 }, - { 2, 5 }, - { 1, .7 }, - { 0, .1 }, + { 2.33, 400 }, + { 2, 150 }, + { 1.66, 60 }, + { 1.33, 20 }, + { 1, 4 }, + { .66, 1.5 }, + { .33, .2 }, + { 0, 0 }, { -1, 0 } }; @@ -88,7 +92,7 @@ void FTNoIR_Filter::filter(const double* input, double *output) const double dz = i >= 3 ? rot_dz : trans_dz; const double vec_ = max(0., fabs(vec) - dz); const double thres = i >= 3 ? rot_t : trans_t; - const double val = m.getValue(vec_ / thres) * thres; + const double val = m.getValue(vec_ / thres); const double result = last_output[i] + (vec < 0 ? -1 : 1) * dt * val; const bool negp = vec < 0.; const bool done = negp diff --git a/ftnoir_protocol_sc/ftnoir-protocol-sc.rc b/ftnoir_protocol_sc/ftnoir-protocol-sc.rc index 80b6c12c..c89eb9a7 100644 --- a/ftnoir_protocol_sc/ftnoir-protocol-sc.rc +++ b/ftnoir_protocol_sc/ftnoir-protocol-sc.rc @@ -1,4 +1,4 @@ #include <winuser.h> 142 RT_MANIFEST scserver.manifest -143 RT_MANIFEST scserver-sp2.manifest -144 RT_MANIFEST scserver-acceleration.manifest
\ No newline at end of file +143 RT_MANIFEST scserver_sp2.manifest +144 RT_MANIFEST scserver_acceleration.manifest
\ No newline at end of file diff --git a/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp b/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp index 36764edc..465d8d20 100644 --- a/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp +++ b/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp @@ -29,43 +29,37 @@ #include "ftnoir_protocol_sc.h" #include "opentrack/plugin-api.hpp" -importSimConnect_CameraSetRelative6DOF FTNoIR_Protocol::simconnect_set6DOF; -HANDLE FTNoIR_Protocol::hSimConnect = 0; // Handle to SimConnect - -float FTNoIR_Protocol::virtSCPosX = 0.0f; // Headpose -float FTNoIR_Protocol::virtSCPosY = 0.0f; -float FTNoIR_Protocol::virtSCPosZ = 0.0f; - -float FTNoIR_Protocol::virtSCRotX = 0.0f; -float FTNoIR_Protocol::virtSCRotY = 0.0f; -float FTNoIR_Protocol::virtSCRotZ = 0.0f; - -float FTNoIR_Protocol::prevSCPosX = 0.0f; // previous Headpose -float FTNoIR_Protocol::prevSCPosY = 0.0f; -float FTNoIR_Protocol::prevSCPosZ = 0.0f; - -float FTNoIR_Protocol::prevSCRotX = 0.0f; -float FTNoIR_Protocol::prevSCRotY = 0.0f; -float FTNoIR_Protocol::prevSCRotZ = 0.0f; - static QLibrary SCClientLib; -FTNoIR_Protocol::FTNoIR_Protocol() +FTNoIR_Protocol::FTNoIR_Protocol() : should_stop(false), hSimConnect(nullptr) { - blnSimConnectActive = false; - hSimConnect = 0; } FTNoIR_Protocol::~FTNoIR_Protocol() { - qDebug() << "~FTNoIR_Protocol says: inside" << FTNoIR_Protocol::hSimConnect; + should_stop = true; + wait(); +} - if (hSimConnect != 0) { - qDebug() << "~FTNoIR_Protocol says: before simconnect_close"; - if (SUCCEEDED( simconnect_close( FTNoIR_Protocol::hSimConnect ) ) ) { - qDebug() << "~FTNoIR_Protocol says: close SUCCEEDED"; - } - } +void FTNoIR_Protocol::run() +{ + if (!SUCCEEDED(simconnect_open(&hSimConnect, "FaceTrackNoIR", NULL, 0, 0, 0))) + return; +#if 0 + simconnect_subscribetosystemevent(hSimConnect, EVENT_PING, "Frame"); + + simconnect_mapclienteventtosimevent(hSimConnect, EVENT_INIT, ""); + simconnect_addclienteventtonotificationgroup(hSimConnect, GROUP0, EVENT_INIT, false); + simconnect_setnotificationgrouppriority(hSimConnect, GROUP0, SIMCONNECT_GROUP_PRIORITY_HIGHEST); +#endif + + while (!should_stop) + { + (void) (simconnect_calldispatch(hSimConnect, processNextSimconnectEvent, reinterpret_cast<void*>(this))); + Sleep(1); + } + + (void) simconnect_close(hSimConnect); } void FTNoIR_Protocol::pose( const double *headpose ) { @@ -76,26 +70,13 @@ void FTNoIR_Protocol::pose( const double *headpose ) { virtSCPosX = headpose[TX]/100.f; // cm to meters virtSCPosY = headpose[TY]/100.f; virtSCPosZ = -headpose[TZ]/100.f; - - if (!blnSimConnectActive) { - if (SUCCEEDED(simconnect_open(&hSimConnect, "FaceTrackNoIR", NULL, 0, 0, 0))) { - simconnect_subscribetosystemevent(hSimConnect, EVENT_PING, "Frame"); - - simconnect_mapclienteventtosimevent(hSimConnect, EVENT_INIT, ""); - simconnect_addclienteventtonotificationgroup(hSimConnect, GROUP0, EVENT_INIT, false); - simconnect_setnotificationgrouppriority(hSimConnect, GROUP0, SIMCONNECT_GROUP_PRIORITY_HIGHEST); - blnSimConnectActive = true; - } - } - else - (void) (simconnect_calldispatch(hSimConnect, processNextSimconnectEvent, NULL)); } #pragma GCC diagnostic ignored "-Wmissing-field-initializers" class ActivationContext { public: - ActivationContext(const int resid) { + ActivationContext(const int resid) :ok (false) { hactctx = INVALID_HANDLE_VALUE; actctx_cookie = 0; ACTCTXA actx = {0}; @@ -103,7 +84,7 @@ public: actx.lpResourceName = MAKEINTRESOURCEA(resid); actx.dwFlags = ACTCTX_FLAG_RESOURCE_NAME_VALID; #ifdef _MSC_VER -# error "MSVC support removed" +# define PREFIX "" #else # define PREFIX "lib" #endif @@ -119,7 +100,7 @@ public: hactctx = INVALID_HANDLE_VALUE; } } else { - qDebug() << "SC: can't create win32 activation context"; + qDebug() << "SC: can't create win32 activation context" << GetLastError(); } } ~ActivationContext() { @@ -129,9 +110,11 @@ public: ReleaseActCtx(hactctx); } } + bool is_ok() { return ok; } private: ULONG_PTR actctx_cookie; HANDLE hactctx; + bool ok; }; bool FTNoIR_Protocol::correct() @@ -140,11 +123,16 @@ bool FTNoIR_Protocol::correct() { ActivationContext ctx(142 + static_cast<int>(s.sxs_manifest)); - SCClientLib.setFileName("SimConnect.dll"); - if (!SCClientLib.load()) { - qDebug() << "SC load" << SCClientLib.errorString(); - return false; + if (ctx.is_ok()) + { + SCClientLib.setFileName("SimConnect.dll"); + if (!SCClientLib.load()) { + qDebug() << "SC load" << SCClientLib.errorString(); + return false; + } } + else + return false; } // @@ -199,51 +187,44 @@ bool FTNoIR_Protocol::correct() } qDebug() << "FTNoIR_Protocol::correct() says: SimConnect functions resolved in DLL!"; + + start(); return true; } -void CALLBACK FTNoIR_Protocol::processNextSimconnectEvent(SIMCONNECT_RECV* pData, DWORD, void *) +void FTNoIR_Protocol::handle() +{ + if (prevSCPosX != virtSCPosX || + prevSCPosY != virtSCPosY || + prevSCPosZ != virtSCPosZ || + prevSCRotX != virtSCRotX || + prevSCRotY != virtSCRotY || + prevSCRotZ != virtSCRotZ) + { + (void) simconnect_set6DOF(hSimConnect, virtSCPosX, virtSCPosY, virtSCPosZ, virtSCRotX, virtSCRotZ, virtSCRotY); + } + + prevSCPosX = virtSCPosX; + prevSCPosY = virtSCPosY; + prevSCPosZ = virtSCPosZ; + prevSCRotX = virtSCRotX; + prevSCRotY = virtSCRotY; + prevSCRotZ = virtSCRotZ; +} + +void CALLBACK FTNoIR_Protocol::processNextSimconnectEvent(SIMCONNECT_RECV* pData, DWORD, void *self_) { + FTNoIR_Protocol& self = *reinterpret_cast<FTNoIR_Protocol*>(self_); + switch(pData->dwID) { default: break; case SIMCONNECT_RECV_ID_EVENT_FRAME: - { - if ((prevSCPosX != virtSCPosX) || (prevSCPosY != virtSCPosY) || (prevSCPosZ != virtSCPosZ) || - (prevSCRotX != virtSCRotX) || (prevSCRotY != virtSCRotY) || (prevSCRotZ != virtSCRotZ)) { - (void) simconnect_set6DOF(hSimConnect, virtSCPosX, virtSCPosY, virtSCPosZ, virtSCRotX, virtSCRotZ, virtSCRotY); - } - prevSCPosX = virtSCPosX; - prevSCPosY = virtSCPosY; - prevSCPosZ = virtSCPosZ; - prevSCRotX = virtSCRotX; - prevSCRotY = virtSCRotY; - prevSCRotZ = virtSCRotZ; - } - case SIMCONNECT_RECV_ID_EXCEPTION: - { - SIMCONNECT_RECV_EXCEPTION *except = (SIMCONNECT_RECV_EXCEPTION*)pData; - - switch (except->dwException) - { - case SIMCONNECT_EXCEPTION_ERROR: - qDebug() << "Camera error"; - break; - - default: - qDebug() << "Exception"; - break; - } - break; - } - - case SIMCONNECT_RECV_ID_QUIT: - { + self.handle(); break; } - } } extern "C" OPENTRACK_EXPORT IProtocol* GetConstructor() diff --git a/ftnoir_protocol_sc/ftnoir_protocol_sc.h b/ftnoir_protocol_sc/ftnoir_protocol_sc.h index f8db519b..b65bac85 100644 --- a/ftnoir_protocol_sc/ftnoir_protocol_sc.h +++ b/ftnoir_protocol_sc/ftnoir_protocol_sc.h @@ -39,6 +39,7 @@ #include <SimConnect.h> #include "ui_ftnoir_sccontrols.h" +#include <QThread> #include <QMessageBox> #include <QSettings> #include <QLibrary> @@ -83,45 +84,46 @@ struct settings : opts { {} }; -class FTNoIR_Protocol : public IProtocol +class FTNoIR_Protocol : public IProtocol, private QThread { public: FTNoIR_Protocol(); ~FTNoIR_Protocol() override; bool correct(); void pose(const double* headpose); + void handle(); QString game_name() { return "FS2004/FSX"; } private: - static float virtSCPosX; - static float virtSCPosY; - static float virtSCPosZ; - - static float virtSCRotX; - static float virtSCRotY; - static float virtSCRotZ; + void run() override; + volatile bool should_stop; + + volatile float virtSCPosX; + volatile float virtSCPosY; + volatile float virtSCPosZ; + volatile float virtSCRotX; + volatile float virtSCRotY; + volatile float virtSCRotZ; - static float prevSCPosX; - static float prevSCPosY; - static float prevSCPosZ; + float prevSCPosX; + float prevSCPosY; + float prevSCPosZ; - static float prevSCRotX; - static float prevSCRotY; - static float prevSCRotZ; - - bool blnSimConnectActive; + float prevSCRotX; + float prevSCRotY; + float prevSCRotZ; importSimConnect_Open simconnect_open; // SimConnect function(s) in DLL importSimConnect_Close simconnect_close; - static importSimConnect_CameraSetRelative6DOF simconnect_set6DOF; + importSimConnect_CameraSetRelative6DOF simconnect_set6DOF; importSimConnect_CallDispatch simconnect_calldispatch; importSimConnect_SubscribeToSystemEvent simconnect_subscribetosystemevent; importSimConnect_MapClientEventToSimEvent simconnect_mapclienteventtosimevent; importSimConnect_AddClientEventToNotificationGroup simconnect_addclienteventtonotificationgroup; importSimConnect_SetNotificationGroupPriority simconnect_setnotificationgrouppriority; - static HANDLE hSimConnect; // Handle to SimConnect + HANDLE hSimConnect; // Handle to SimConnect static void CALLBACK processNextSimconnectEvent(SIMCONNECT_RECV* pData, DWORD cbData, void *pContext); settings s; }; diff --git a/ftnoir_protocol_sc/scserver-acceleration.manifest b/ftnoir_protocol_sc/scserver_acceleration.manifest index 06459587..06459587 100644 --- a/ftnoir_protocol_sc/scserver-acceleration.manifest +++ b/ftnoir_protocol_sc/scserver_acceleration.manifest diff --git a/ftnoir_protocol_sc/scserver-sp2.manifest b/ftnoir_protocol_sc/scserver_sp2.manifest index 19b123ba..3020d16c 100644 --- a/ftnoir_protocol_sc/scserver-sp2.manifest +++ b/ftnoir_protocol_sc/scserver_sp2.manifest @@ -1,13 +1,13 @@ -<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
-<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
- <dependency>
- <dependentAssembly>
- <assemblyIdentity type='win32' name='Microsoft.FlightSimulator.SimConnect ' version='10.0.60905.0' processorArchitecture='x86' publicKeyToken='67c7c14424d61b5b' />
- </dependentAssembly>
- </dependency>
- <dependency>
- <dependentAssembly>
- <assemblyIdentity type='win32' name='Microsoft.VC80.CRT' version='8.0.50608.0' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' />
- </dependentAssembly>
- </dependency>
-</assembly>
+<?xml version='1.0' encoding='UTF-8' standalone='yes'?> +<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'> + <dependency> + <dependentAssembly> + <assemblyIdentity type='win32' name='Microsoft.FlightSimulator.SimConnect ' version='10.0.60905.0' processorArchitecture='x86' publicKeyToken='67c7c14424d61b5b' /> + </dependentAssembly> + </dependency> + <dependency> + <dependentAssembly> + <assemblyIdentity type='win32' name='Microsoft.VC80.CRT' version='8.0.50608.0' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' /> + </dependentAssembly> + </dependency> +</assembly> diff --git a/ftnoir_protocol_vjoy/ftnoir_protocol_vjoy.cpp b/ftnoir_protocol_vjoy/ftnoir_protocol_vjoy.cpp index b636ffd4..63f75685 100644 --- a/ftnoir_protocol_vjoy/ftnoir_protocol_vjoy.cpp +++ b/ftnoir_protocol_vjoy/ftnoir_protocol_vjoy.cpp @@ -13,7 +13,9 @@ FTNoIR_Protocol::~FTNoIR_Protocol() } void FTNoIR_Protocol::pose( const double *headpose ) { -#pragma GCC diagnostic ignored "-Wmissing-field-initializers" +#ifdef __GNUC__ +# pragma GCC diagnostic ignored "-Wmissing-field-initializers" +#endif JOYSTICK_STATE state[2] = { 0 }; state[0].POV = (4 << 12) | (4 << 8) | (4 << 4) | 4; diff --git a/ftnoir_protocol_vjoy/ftnoir_protocol_vjoy.h b/ftnoir_protocol_vjoy/ftnoir_protocol_vjoy.h index 73496fba..a9e8ed6e 100644 --- a/ftnoir_protocol_vjoy/ftnoir_protocol_vjoy.h +++ b/ftnoir_protocol_vjoy/ftnoir_protocol_vjoy.h @@ -96,6 +96,13 @@ typedef struct _JOYSTICK_STATE UINT32 Buttons; // 32 Buttons } JOYSTICK_STATE, * PJOYSTICK_STATE; +#ifndef _MSC_VER EXTERN_C BOOL __stdcall VJoy_Initialize(PCHAR name, PCHAR serial); EXTERN_C VOID __stdcall VJoy_Shutdown(); EXTERN_C BOOL __stdcall VJoy_UpdateJoyState(int id, PJOYSTICK_STATE pJoyState); +#else +#define VJOY_API __declspec(dllimport) +VJOY_API BOOL __stdcall VJoy_Initialize(PCHAR name, PCHAR serial); +VJOY_API VOID __stdcall VJoy_Shutdown(); +VJOY_API BOOL __stdcall VJoy_UpdateJoyState(int id, PJOYSTICK_STATE pJoyState); +#endif diff --git a/ftnoir_tracker_aruco/include/exports.h b/ftnoir_tracker_aruco/include/exports.h index aaeb94e4..8f7dab8c 100644 --- a/ftnoir_tracker_aruco/include/exports.h +++ b/ftnoir_tracker_aruco/include/exports.h @@ -36,7 +36,7 @@ or implied, of Rafael Muñoz Salinas. #endif -#if (defined WIN32 || defined _WIN32 || defined WINCE) && defined DSO_EXPORTS +#if ((defined WIN32 || defined _WIN32 || defined WINCE) && defined DSO_EXPORTS) || defined(_MSC_VER) #define ARUCO_EXPORTS __declspec(dllexport) #else #define ARUCO_EXPORTS __attribute__ ((visibility ("default"))) diff --git a/ftnoir_tracker_hatire/ftnoir_tracker_hat_settings.cpp b/ftnoir_tracker_hatire/ftnoir_tracker_hat_settings.cpp index 017a8f0a..80543e7a 100644 --- a/ftnoir_tracker_hatire/ftnoir_tracker_hat_settings.cpp +++ b/ftnoir_tracker_hatire/ftnoir_tracker_hat_settings.cpp @@ -36,12 +36,12 @@ void TrackerSettings::load_ini() { #ifdef OPENTRACK_API - QSettings settings(options::group::org); // Registry settings (in HK_USER) + QSettings settings(OPENTRACK_ORG); // Registry settings (in HK_USER) #else QSettings settings("opentrack"); // Registry settings (in HK_USER) #endif #ifdef OPENTRACK_API - QString currentFile = settings.value( options::group::filename_key, QCoreApplication::applicationDirPath() + options::group::default_path ).toString(); + QString currentFile = settings.value( OPENTRACK_CONFIG_FILENAME_KEY, QCoreApplication::applicationDirPath() + OPENTRACK_DEFAULT_CONFIG_PATH ).toString(); #else QString currentFile = settings.value( "SettingsFile", QCoreApplication::applicationDirPath() + "/Settings/default.ini" ).toString(); #endif @@ -106,12 +106,12 @@ void TrackerSettings::save_ini() const { #ifdef OPENTRACK_API - QSettings settings(options::group::org); // Registry settings (in HK_USER) + QSettings settings(OPENTRACK_ORG); // Registry settings (in HK_USER) #else QSettings settings("opentrack"); // Registry settings (in HK_USER) #endif #ifdef OPENTRACK_API - QString currentFile = settings.value( options::group::filename_key, QCoreApplication::applicationDirPath() + options::group::default_path ).toString(); + QString currentFile = settings.value( OPENTRACK_CONFIG_FILENAME_KEY, QCoreApplication::applicationDirPath() + OPENTRACK_DEFAULT_CONFIG_PATH ).toString(); #else QString currentFile = settings.value( "SettingsFile", QCoreApplication::applicationDirPath() + "/Settings/default.ini" ).toString(); #endif diff --git a/ftnoir_tracker_hydra/ftnoir_tracker_hydra.cpp b/ftnoir_tracker_hydra/ftnoir_tracker_hydra.cpp index 34c27579..826cecaa 100644 --- a/ftnoir_tracker_hydra/ftnoir_tracker_hydra.cpp +++ b/ftnoir_tracker_hydra/ftnoir_tracker_hydra.cpp @@ -10,7 +10,6 @@ Hydra_Tracker::Hydra_Tracker() : should_quit(false) {} -#pragma GCC diagnostic ignored "-Wreorder" #include <sixense_math.hpp> Hydra_Tracker::~Hydra_Tracker() diff --git a/ftnoir_tracker_joystick/ftnoir_tracker_joystick.cpp b/ftnoir_tracker_joystick/ftnoir_tracker_joystick.cpp index 2dc0ad6b..264166fe 100644 --- a/ftnoir_tracker_joystick/ftnoir_tracker_joystick.cpp +++ b/ftnoir_tracker_joystick/ftnoir_tracker_joystick.cpp @@ -41,7 +41,9 @@ FTNoIR_Tracker::~FTNoIR_Tracker() } } -#pragma GCC diagnostic ignored "-Wmissing-field-initializers" +#ifdef __GNUC__ +# pragma GCC diagnostic ignored "-Wmissing-field-initializers" +#endif static BOOL CALLBACK EnumObjectsCallback( const DIDEVICEOBJECTINSTANCE* pdidoi, VOID* pContext ) diff --git a/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp b/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp index bad75238..2f852343 100644 --- a/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp +++ b/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp @@ -37,6 +37,7 @@ Tracker_PT::~Tracker_PT() delete video_widget; video_widget = NULL; if (video_frame->layout()) delete video_frame->layout(); + camera.stop(); } void Tracker_PT::set_command(Command command) @@ -98,7 +99,7 @@ void Tracker_PT::run() ever_success |= success; if (success) - point_tracker.track(points, PointModel(s), get_focal_length(), true); + point_tracker.track(points, PointModel(s), get_focal_length(), s.dynamic_pose, s.init_phase_timeout); { Affine X_CM = pose(); diff --git a/ftnoir_tracker_pt/ftnoir_tracker_pt_settings.h b/ftnoir_tracker_pt/ftnoir_tracker_pt_settings.h index 4c6bab48..00346267 100644 --- a/ftnoir_tracker_pt/ftnoir_tracker_pt_settings.h +++ b/ftnoir_tracker_pt/ftnoir_tracker_pt_settings.h @@ -21,6 +21,9 @@ struct settings_pt : opts value<int> fov, camera_mode; value<int> model_used; + value<bool> dynamic_pose; + value<int> init_phase_timeout; + settings_pt() : opts("tracker-pt"), threshold(b, "threshold-primary", 128), @@ -31,7 +34,9 @@ struct settings_pt : opts t_MH_z(b, "model-centroid-z", 0), fov(b, "camera-fov", 0), camera_mode(b, "camera-mode", 0), - model_used(b, "model-used", 0) + model_used(b, "model-used", 0), + dynamic_pose(b, "dynamic-pose-resolution", true), + init_phase_timeout(b, "init-phase-timeout", 500) {} }; diff --git a/ftnoir_tracker_pt/point_tracker.cpp b/ftnoir_tracker_pt/point_tracker.cpp index e4c999ad..bae89dbe 100644 --- a/ftnoir_tracker_pt/point_tracker.cpp +++ b/ftnoir_tracker_pt/point_tracker.cpp @@ -62,7 +62,7 @@ void PointModel::get_d_order(const std::vector<cv::Vec2f>& points, int d_order[] } -PointTracker::PointTracker() +PointTracker::PointTracker() : init_phase(true) { } @@ -96,6 +96,7 @@ PointTracker::PointOrder PointTracker::find_correspondences_previous(const vecto // if one point is closest to more than one model point, fallback if (point_taken[min_idx]) { + init_phase = true; return find_correspondences(points, model); } point_taken[min_idx] = true; @@ -104,16 +105,24 @@ PointTracker::PointOrder PointTracker::find_correspondences_previous(const vecto return p; } -void PointTracker::track(const vector<Vec2f>& points, const PointModel& model, float f, bool dynamic_pose) +void PointTracker::track(const vector<Vec2f>& points, const PointModel& model, float f, bool dynamic_pose, int init_phase_timeout) { PointOrder order; - - if (!dynamic_pose) - order = find_correspondences(points, model); - else - order = find_correspondences_previous(points, model, f); + + if (t.elapsed_ms() > init_phase_timeout) + { + t.start(); + init_phase = true; + } + + if (!dynamic_pose || init_phase) + order = find_correspondences(points, model); + else + order = find_correspondences_previous(points, model, f); POSIT(model, order, f); + init_phase = false; + t.start(); } PointTracker::PointOrder PointTracker::find_correspondences(const std::vector<cv::Vec2f>& points, const PointModel& model) diff --git a/ftnoir_tracker_pt/point_tracker.h b/ftnoir_tracker_pt/point_tracker.h index 344a05c0..1340a11d 100644 --- a/ftnoir_tracker_pt/point_tracker.h +++ b/ftnoir_tracker_pt/point_tracker.h @@ -15,7 +15,7 @@ # include <memory> #endif #include <vector> - +#include "opentrack/timer.hpp" #include "ftnoir_tracker_pt_settings.h" #include <QObject> @@ -116,7 +116,7 @@ public: // track the pose using the set of normalized point coordinates (x pos in range -0.5:0.5) // f : (focal length)/(sensor width) // dt : time since last call - void track(const std::vector<cv::Vec2f>& projected_points, const PointModel& model, float f, bool dynamic_pose); + void track(const std::vector<cv::Vec2f>& projected_points, const PointModel& model, float f, bool dynamic_pose, int init_phase_timeout); Affine pose() const { return X_CM; } cv::Vec2f project(const cv::Vec3f& v_M, float f); private: @@ -136,6 +136,9 @@ private: int POSIT(const PointModel& point_model, const PointOrder& order, float focal_length); // The POSIT algorithm, returns the number of iterations Affine X_CM; // trafo from model to camera + + Timer t; + bool init_phase; }; #endif //POINTTRACKER_H diff --git a/opentrack/export.hpp b/opentrack/export.hpp index 8c8bdc69..f0983b75 100644 --- a/opentrack/export.hpp +++ b/opentrack/export.hpp @@ -1,7 +1,13 @@ #pragma once + #ifdef _WIN32 # define OPENTRACK_LINKAGE __declspec(dllexport) #else # define OPENTRACK_LINKAGE #endif -#define OPENTRACK_EXPORT __attribute__ ((visibility ("default"))) OPENTRACK_LINKAGE + +#ifndef _MSC_VER +# define OPENTRACK_EXPORT __attribute__ ((visibility ("default"))) OPENTRACK_LINKAGE +#else +# define OPENTRACK_EXPORT OPENTRACK_LINKAGE +#endif
\ No newline at end of file diff --git a/opentrack/options.hpp b/opentrack/options.hpp index 06697631..c2fe8705 100644 --- a/opentrack/options.hpp +++ b/opentrack/options.hpp @@ -38,6 +38,10 @@ #include <memory> template<typename t> using mem = std::shared_ptr<t>; +#define OPENTRACK_CONFIG_FILENAME_KEY "settings-file" +#define OPENTRACK_DEFAULT_CONFIG_PATH "/settings/default.ini" +#define OPENTRACK_ORG "TrackHat opentrack-2.3" + namespace options { template<typename k, typename v> using map = std::map<k, v>; @@ -97,7 +101,6 @@ namespace options { } conf.endGroup(); } - static constexpr const char* org = "trackhat opentrack-2.3"; void save() { @@ -129,13 +132,10 @@ namespace options { return kvs.count(s) != 0; } - static constexpr const char* filename_key = "settings-file"; - static constexpr const char* default_path = "/settings/default.ini"; - static const QString ini_pathname() { - QSettings settings(group::org); - return settings.value(filename_key, QCoreApplication::applicationDirPath() + default_path).toString(); + QSettings settings(OPENTRACK_ORG); + return settings.value(OPENTRACK_CONFIG_FILENAME_KEY, QCoreApplication::applicationDirPath() + OPENTRACK_DEFAULT_CONFIG_PATH).toString(); } static const QStringList ini_list() diff --git a/opentrack/plugin-support.hpp b/opentrack/plugin-support.hpp index 1c334e14..7f2734af 100644 --- a/opentrack/plugin-support.hpp +++ b/opentrack/plugin-support.hpp @@ -42,7 +42,7 @@ #include <iostream> #ifdef _MSC_VER -# error "No support for MSVC anymore" +# define OPENTRACK_LIB_PREFIX "" #else # define OPENTRACK_LIB_PREFIX "lib" #endif @@ -115,7 +115,8 @@ struct dylib { { fprintf(stderr, "Error, ignoring: %s\n", err); fflush(stderr); - dlclose(handle); + if (handle) + dlclose(handle); handle = nullptr; return true; } @@ -138,6 +139,7 @@ struct dylib { return; } else { (void) _foo::err(handle); + return; } #endif diff --git a/opentrack/version.C b/opentrack/version.C deleted file mode 100644 index 0ef4ec14..00000000 --- a/opentrack/version.C +++ /dev/null @@ -1,5 +0,0 @@ -#ifdef IN_VERSION_UNIT -# define IN_CRAPOLA_COMPILE_UNIT -volatile const char* opentrack_version = OPENTRACK_VERSION; -#else -#endif diff --git a/opentrack/version.cc b/opentrack/version.cc new file mode 100644 index 00000000..026ad057 --- /dev/null +++ b/opentrack/version.cc @@ -0,0 +1,9 @@ +#include "opentrack/export.hpp" + +#ifdef __cplusplus +extern "C" +#endif +OPENTRACK_EXPORT +volatile const char* opentrack_version; + +volatile const char* opentrack_version = OPENTRACK_VERSION; diff --git a/x-plane-plugin/plugin.c b/x-plane-plugin/plugin.c index 3958c895..999f6e15 100644 --- a/x-plane-plugin/plugin.c +++ b/x-plane-plugin/plugin.c @@ -8,10 +8,9 @@ #include <unistd.h> #include <XPLMPlugin.h> -#include <XPLMDisplay.h> #include <XPLMDataAccess.h> -#include <XPLMCamera.h> #include <XPLMProcessing.h> +#include <XPLMUtilities.h> #ifndef PLUGIN_API #define PLUGIN_API @@ -41,6 +40,9 @@ static PortableLockedShm* lck_posix = NULL; static WineSHM* shm_posix = NULL; static void *view_x, *view_y, *view_z, *view_heading, *view_pitch; static float offset_x, offset_y, offset_z; +static XPLMCommandRef track_toggle = NULL, translation_disable_toggle = NULL; +static int track_disabled = 1; +static int translation_disabled; static void reinit_offset() { offset_x = XPLMGetDataf(view_x); @@ -87,21 +89,60 @@ void PortableLockedShm_unlock(PortableLockedShm* self) flock(self->fd, LOCK_UN); } -int write_head_position( - XPLMDrawingPhase OT_UNUSED(inPhase), - int OT_UNUSED(inIsBefore), - void * OT_UNUSED(inRefcon)) +float write_head_position( + float OT_UNUSED(inElapsedSinceLastCall), + float OT_UNUSED(inElapsedTimeSinceLastFlightLoop), + int OT_UNUSED(inCounter), + void * OT_UNUSED(inRefcon) ) { if (lck_posix != NULL && shm_posix != NULL) { PortableLockedShm_lock(lck_posix); - XPLMSetDataf(view_x, shm_posix->data[TX] * 1e-3 + offset_x); - XPLMSetDataf(view_y, shm_posix->data[TY] * 1e-3 + offset_y); - XPLMSetDataf(view_z, shm_posix->data[TZ] * 1e-3 + offset_z); + if (!translation_disabled) + { + XPLMSetDataf(view_x, shm_posix->data[TX] * 1e-3 + offset_x); + XPLMSetDataf(view_y, shm_posix->data[TY] * 1e-3 + offset_y); + XPLMSetDataf(view_z, shm_posix->data[TZ] * 1e-3 + offset_z); + } XPLMSetDataf(view_heading, shm_posix->data[Yaw] * 180 / 3.141592654); XPLMSetDataf(view_pitch, shm_posix->data[Pitch] * 180 / 3.141592654); PortableLockedShm_unlock(lck_posix); } - return 1; + return -1.0; +} + +static int TrackToggleHandler( XPLMCommandRef inCommand, + XPLMCommandPhase inPhase, + void * inRefCon ) +{ + if ( track_disabled ) + { + //Enable + XPLMRegisterFlightLoopCallback(write_head_position, -1.0, NULL); + + // Reinit the offsets when we re-enable the plugin + if ( !translation_disabled ) + reinit_offset(); + } + else + { + //Disable + XPLMUnregisterFlightLoopCallback(write_head_position, NULL); + } + track_disabled = !track_disabled; + return 0; +} + +static int TranslationToggleHandler( XPLMCommandRef inCommand, + XPLMCommandPhase inPhase, + void * inRefCon ) +{ + translation_disabled = !translation_disabled; + if (!translation_disabled) + { + // Reinit the offsets when we re-enable the translations so that we can "move around" + reinit_offset(); + } + return 0; } PLUGIN_API int XPluginStart ( char * outName, char * outSignature, char * outDescription ) { @@ -110,7 +151,22 @@ PLUGIN_API int XPluginStart ( char * outName, char * outSignature, char * outDes view_z = XPLMFindDataRef("sim/aircraft/view/acf_peZ"); view_heading = XPLMFindDataRef("sim/graphics/view/pilots_head_psi"); view_pitch = XPLMFindDataRef("sim/graphics/view/pilots_head_the"); - if (view_x && view_y && view_z && view_heading && view_pitch) { + + track_toggle = XPLMCreateCommand("opentrack/toggle", "Disable/Enable head tracking"); + translation_disable_toggle = XPLMCreateCommand("opentrack/toggle_translation", "Disable/Enable input translation from opentrack"); + + XPLMRegisterCommandHandler( track_toggle, + TrackToggleHandler, + 1, + (void*)0); + + XPLMRegisterCommandHandler( translation_disable_toggle, + TranslationToggleHandler, + 1, + (void*)0); + + + if (view_x && view_y && view_z && view_heading && view_pitch && track_toggle && translation_disable_toggle) { lck_posix = PortableLockedShm_init(WINE_SHM_NAME, WINE_MTX_NAME, sizeof(WineSHM)); if (lck_posix->mem == (void*)-1) { fprintf(stderr, "opentrack failed to init SHM!\n"); @@ -137,11 +193,13 @@ PLUGIN_API void XPluginStop ( void ) { } PLUGIN_API void XPluginEnable ( void ) { - XPLMRegisterDrawCallback(write_head_position, xplm_Phase_LastScene, 1, NULL); + XPLMRegisterFlightLoopCallback(write_head_position, -1.0, NULL); + track_disabled = 0; } PLUGIN_API void XPluginDisable ( void ) { - XPLMUnregisterDrawCallback(write_head_position, xplm_Phase_LastScene, 1, NULL); + XPLMUnregisterFlightLoopCallback(write_head_position, NULL); + track_disabled = 1; } PLUGIN_API void XPluginReceiveMessage( |