summaryrefslogtreecommitdiff
path: root/src/core/frontend/emu_window.cpp
diff options
context:
space:
mode:
authorGravatar bunnei2017-01-07 12:39:20 -0500
committerGravatar GitHub2017-01-07 12:39:20 -0500
commit7cfe3ef0463ace034b1e5786c9581cfa5f2e810c (patch)
tree6b06cb03d276b29070ca29599fc4c5fcf77edb39 /src/core/frontend/emu_window.cpp
parentMerge pull request #2410 from Subv/sleepthread (diff)
parentFrontend: make motion sensor interfaced thread-safe (diff)
downloadyuzu-7cfe3ef0463ace034b1e5786c9581cfa5f2e810c.tar.gz
yuzu-7cfe3ef0463ace034b1e5786c9581cfa5f2e810c.tar.xz
yuzu-7cfe3ef0463ace034b1e5786c9581cfa5f2e810c.zip
Merge pull request #1951 from wwylele/motion-sensor
Emulate motion sensor in frontend
Diffstat (limited to 'src/core/frontend/emu_window.cpp')
-rw-r--r--src/core/frontend/emu_window.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/core/frontend/emu_window.cpp b/src/core/frontend/emu_window.cpp
index f6f90f9e1..1541cc39d 100644
--- a/src/core/frontend/emu_window.cpp
+++ b/src/core/frontend/emu_window.cpp
@@ -5,6 +5,7 @@
5#include <algorithm> 5#include <algorithm>
6#include <cmath> 6#include <cmath>
7#include "common/assert.h" 7#include "common/assert.h"
8#include "common/profiler_reporting.h"
8#include "core/frontend/emu_window.h" 9#include "core/frontend/emu_window.h"
9#include "core/frontend/key_map.h" 10#include "core/frontend/key_map.h"
10#include "video_core/video_core.h" 11#include "video_core/video_core.h"
@@ -89,6 +90,30 @@ void EmuWindow::TouchMoved(unsigned framebuffer_x, unsigned framebuffer_y) {
89 TouchPressed(framebuffer_x, framebuffer_y); 90 TouchPressed(framebuffer_x, framebuffer_y);
90} 91}
91 92
93void EmuWindow::AccelerometerChanged(float x, float y, float z) {
94 constexpr float coef = 512;
95
96 std::lock_guard<std::mutex> lock(accel_mutex);
97
98 // TODO(wwylele): do a time stretch as it in GyroscopeChanged
99 // The time stretch formula should be like
100 // stretched_vector = (raw_vector - gravity) * stretch_ratio + gravity
101 accel_x = x * coef;
102 accel_y = y * coef;
103 accel_z = z * coef;
104}
105
106void EmuWindow::GyroscopeChanged(float x, float y, float z) {
107 constexpr float FULL_FPS = 60;
108 float coef = GetGyroscopeRawToDpsCoefficient();
109 float stretch =
110 FULL_FPS / Common::Profiling::GetTimingResultsAggregator()->GetAggregatedResults().fps;
111 std::lock_guard<std::mutex> lock(gyro_mutex);
112 gyro_x = x * coef * stretch;
113 gyro_y = y * coef * stretch;
114 gyro_z = z * coef * stretch;
115}
116
92void EmuWindow::UpdateCurrentFramebufferLayout(unsigned width, unsigned height) { 117void EmuWindow::UpdateCurrentFramebufferLayout(unsigned width, unsigned height) {
93 Layout::FramebufferLayout layout; 118 Layout::FramebufferLayout layout;
94 switch (Settings::values.layout_option) { 119 switch (Settings::values.layout_option) {