{"action":"created","comment":{"url":"https://api.github.com/repos/wwylele/citra/pulls/comments/67494198","id":67494198,"diff_hunk":"@@ -0,0 +1,114 @@\n+// Copyright 2016 Citra Emulator Project\n+// Licensed under GPLv2 or any later version\n+// Refer to the license.txt file included.\n+\n+#include \"common/emu_window.h\"\n+#include \"common/math_util.h\"\n+#include \"common/motion_emu.h\"\n+#include \"common/thread.h\"\n+#include \"common/vector_math.h\"\n+\n+namespace MotionEmu {\n+\n+static std::unique_ptr<std::thread> motion_emu_thread;\n+static Common::Event shutdown_event;\n+\n+static constexpr int update_millisecond = 100;\n+static constexpr std::chrono::steady_clock::duration update_duration(\n+    std::chrono::duration_cast<std::chrono::steady_clock::duration>(std::chrono::milliseconds(update_millisecond)));\n+static constexpr float PI = 3.14159265f;\n+\n+static Math::Vec2<int> mouse_origin;\n+\n+static std::mutex tilt_mutex;\n+static Math::Vec2<float> tilt_direction;\n+static float tilt_angle;\n+\n+static bool is_tilting;\n+\n+static void MotionEmuThread(EmuWindow& emu_window) {\n+    auto update_time = std::chrono::steady_clock::now();\n+    Math::Vec3<float> gravitiy = Math::MakeVec(0.0f, -1.0f, 0.0f);\n+\n+    while (!shutdown_event.WaitUntil(update_time)) {\n+        update_time += update_duration;\n+        Math::Vec3<float> old_gravitiy = gravitiy, axis;\n+        float cos, sin;\n+\n+        {\n+            std::lock_guard<std::mutex> guard(tilt_mutex);\n+            cos = std::cos(tilt_angle);\n+            sin = std::sin(tilt_angle);\n+\n+            // Find the gravity vector in 3DS space\n+            gravitiy = Math::MakeVec(tilt_direction.x, 0.0f, tilt_direction.y) * -sin;\n+            gravitiy.y = -cos;\n+\n+            // Find the tilting axis in world space\n+            axis = Math::MakeVec(-tilt_direction.y, 0.0f, tilt_direction.x);\n+        }\n+\n+        // Find the rotation vector in world space by two gravity vectors\n+        auto rotation = Math::Cross(gravitiy, old_gravitiy);\n+\n+        // Find the angle in rad between two gravity vectors\n+        float angle = std::asin(rotation.Normalize());\n+\n+        // Negative dot product means an obtuse angle\n+        if (Math::Dot(gravitiy, old_gravitiy) < 0)\n+            angle = PI - angle;\n+\n+        // Calculate the angular rate in deg/sec and apply to the rotation vector\n+        rotation *= angle * 1000 / update_millisecond / PI * 180;\n+\n+        // Transform the rotation vector from world space to 3DS space using Rodrigues' rotation formula\n+        rotation = rotation * cos + Math::Cross(axis, rotation) * sin + axis * Math::Dot(axis, rotation) * (1 - cos);","path":"src/common/motion_emu.cpp","position":65,"original_position":65,"commit_id":"a2bab2da90e4e4025cac267911726aef6ed9a08f","original_commit_id":"a2bab2da90e4e4025cac267911726aef6ed9a08f","user":{"login":"JayFoxRox","id":360330,"avatar_url":"https://avatars.githubusercontent.com/u/360330?v=3","gravatar_id":"","url":"https://api.github.com/users/JayFoxRox","html_url":"https://github.com/JayFoxRox","followers_url":"https://api.github.com/users/JayFoxRox/followers","following_url":"https://api.github.com/users/JayFoxRox/following{/other_user}","gists_url":"https://api.github.com/users/JayFoxRox/gists{/gist_id}","starred_url":"https://api.github.com/users/JayFoxRox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JayFoxRox/subscriptions","organizations_url":"https://api.github.com/users/JayFoxRox/orgs","repos_url":"https://api.github.com/users/JayFoxRox/repos","events_url":"https://api.github.com/users/JayFoxRox/events{/privacy}","received_events_url":"https://api.github.com/users/JayFoxRox/received_events","type":"User","site_admin":false},"body":"Why exactly is this necessary? Why do we work in different spaces here?\r\n(It just feels complicated imo and I can't really imagine where they are coming from?)\r\n\r\nIs there any diagrams which show the relation between:\r\n- 3DS Rotation\r\n- Sensor rotation\r\n- Sensor data\r\n\r\nI'd have assumed that 3DS rotation = sensor rotation = sensor data. So really I don't see where seperate spaces are coming from.\r\n\r\nIt's also hard to tell that cos and sin are variables imho.\r\nThey should probably get more descriptive names.","created_at":"2016-06-17T11:04:34Z","updated_at":"2016-06-17T11:04:34Z","html_url":"https://github.com/wwylele/citra/pull/2#discussion_r67494198","pull_request_url":"https://api.github.com/repos/wwylele/citra/pulls/2","_links":{"self":{"href":"https://api.github.com/repos/wwylele/citra/pulls/comments/67494198"},"html":{"href":"https://github.com/wwylele/citra/pull/2#discussion_r67494198"},"pull_request":{"href":"https://api.github.com/repos/wwylele/citra/pulls/2"}}},"pull_request":{"url":"https://api.github.com/repos/wwylele/citra/pulls/2","id":74149401,"html_url":"https://github.com/wwylele/citra/pull/2","diff_url":"https://github.com/wwylele/citra/pull/2.diff","patch_url":"https://github.com/wwylele/citra/pull/2.patch","issue_url":"https://api.github.com/repos/wwylele/citra/issues/2","number":2,"state":"open","locked":false,"title":"Emulate motion sensor in frontend","user":{"login":"wwylele","id":4592895,"avatar_url":"https://avatars.githubusercontent.com/u/4592895?v=3","gravatar_id":"","url":"https://api.github.com/users/wwylele","html_url":"https://github.com/wwylele","followers_url":"https://api.github.com/users/wwylele/followers","following_url":"https://api.github.com/users/wwylele/following{/other_user}","gists_url":"https://api.github.com/users/wwylele/gists{/gist_id}","starred_url":"https://api.github.com/users/wwylele/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wwylele/subscriptions","organizations_url":"https://api.github.com/users/wwylele/orgs","repos_url":"https://api.github.com/users/wwylele/repos","events_url":"https://api.github.com/users/wwylele/events{/privacy}","received_events_url":"https://api.github.com/users/wwylele/received_events","type":"User","site_admin":false},"body":"_DRAFT_\r\nUsage: move mouse in the emulation window while holding the right button.\r\nEmulate the accelerometer and gyroscope in a limited range: it can only tilt in the direction of mouse movement, no rotate about the vertical (y) axis, and no linear acceleration. I don't have many games using motion sensor, so not sure if there is other common motion.\r\n\r\n_TODO_\r\n - [ ] TODO\r\n - [ ] Document\r\n - [ ] Time stretch\r\n - [ ] Review","created_at":"2016-06-16T20:47:14Z","updated_at":"2016-06-17T11:04:34Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a16fb8b41af4bcf92f95916cb593f641a894c270","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/wwylele/citra/pulls/2/commits","review_comments_url":"https://api.github.com/repos/wwylele/citra/pulls/2/comments","review_comment_url":"https://api.github.com/repos/wwylele/citra/pulls/comments{/number}","comments_url":"https://api.github.com/repos/wwylele/citra/issues/2/comments","statuses_url":"https://api.github.com/repos/wwylele/citra/statuses/a2bab2da90e4e4025cac267911726aef6ed9a08f","head":{"label":"wwylele:motion-sensor","ref":"motion-sensor","sha":"a2bab2da90e4e4025cac267911726aef6ed9a08f","user":{"login":"wwylele","id":4592895,"avatar_url":"https://avatars.githubusercontent.com/u/4592895?v=3","gravatar_id":"","url":"https://api.github.com/users/wwylele","html_url":"https://github.com/wwylele","followers_url":"https://api.github.com/users/wwylele/followers","following_url":"https://api.github.com/users/wwylele/following{/other_user}","gists_url":"https://api.github.com/users/wwylele/gists{/gist_id}","starred_url":"https://api.github.com/users/wwylele/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wwylele/subscriptions","organizations_url":"https://api.github.com/users/wwylele/orgs","repos_url":"https://api.github.com/users/wwylele/repos","events_url":"https://api.github.com/users/wwylele/events{/privacy}","received_events_url":"https://api.github.com/users/wwylele/received_events","type":"User","site_admin":false},"repo":{"id":53776373,"name":"citra","full_name":"wwylele/citra","owner":{"login":"wwylele","id":4592895,"avatar_url":"https://avatars.githubusercontent.com/u/4592895?v=3","gravatar_id":"","url":"https://api.github.com/users/wwylele","html_url":"https://github.com/wwylele","followers_url":"https://api.github.com/users/wwylele/followers","following_url":"https://api.github.com/users/wwylele/following{/other_user}","gists_url":"https://api.github.com/users/wwylele/gists{/gist_id}","starred_url":"https://api.github.com/users/wwylele/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wwylele/subscriptions","organizations_url":"https://api.github.com/users/wwylele/orgs","repos_url":"https://api.github.com/users/wwylele/repos","events_url":"https://api.github.com/users/wwylele/events{/privacy}","received_events_url":"https://api.github.com/users/wwylele/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/wwylele/citra","description":"Nintendo 3DS Emulator","fork":true,"url":"https://api.github.com/repos/wwylele/citra","forks_url":"https://api.github.com/repos/wwylele/citra/forks","keys_url":"https://api.github.com/repos/wwylele/citra/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wwylele/citra/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wwylele/citra/teams","hooks_url":"https://api.github.com/repos/wwylele/citra/hooks","issue_events_url":"https://api.github.com/repos/wwylele/citra/issues/events{/number}","events_url":"https://api.github.com/repos/wwylele/citra/events","assignees_url":"https://api.github.com/repos/wwylele/citra/assignees{/user}","branches_url":"https://api.github.com/repos/wwylele/citra/branches{/branch}","tags_url":"https://api.github.com/repos/wwylele/citra/tags","blobs_url":"https://api.github.com/repos/wwylele/citra/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wwylele/citra/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wwylele/citra/git/refs{/sha}","trees_url":"https://api.github.com/repos/wwylele/citra/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wwylele/citra/statuses/{sha}","languages_url":"https://api.github.com/repos/wwylele/citra/languages","stargazers_url":"https://api.github.com/repos/wwylele/citra/stargazers","contributors_url":"https://api.github.com/repos/wwylele/citra/contributors","subscribers_url":"https://api.github.com/repos/wwylele/citra/subscribers","subscription_url":"https://api.github.com/repos/wwylele/citra/subscription","commits_url":"https://api.github.com/repos/wwylele/citra/commits{/sha}","git_commits_url":"https://api.github.com/repos/wwylele/citra/git/commits{/sha}","comments_url":"https://api.github.com/repos/wwylele/citra/comments{/number}","issue_comment_url":"https://api.github.com/repos/wwylele/citra/issues/comments{/number}","contents_url":"https://api.github.com/repos/wwylele/citra/contents/{+path}","compare_url":"https://api.github.com/repos/wwylele/citra/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wwylele/citra/merges","archive_url":"https://api.github.com/repos/wwylele/citra/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wwylele/citra/downloads","issues_url":"https://api.github.com/repos/wwylele/citra/issues{/number}","pulls_url":"https://api.github.com/repos/wwylele/citra/pulls{/number}","milestones_url":"https://api.github.com/repos/wwylele/citra/milestones{/number}","notifications_url":"https://api.github.com/repos/wwylele/citra/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wwylele/citra/labels{/name}","releases_url":"https://api.github.com/repos/wwylele/citra/releases{/id}","deployments_url":"https://api.github.com/repos/wwylele/citra/deployments","created_at":"2016-03-13T09:09:07Z","updated_at":"2016-05-24T14:55:31Z","pushed_at":"2016-06-17T07:59:47Z","git_url":"git://github.com/wwylele/citra.git","ssh_url":"git@github.com:wwylele/citra.git","clone_url":"https://github.com/wwylele/citra.git","svn_url":"https://github.com/wwylele/citra","homepage":"https://citra-emu.org","size":12991,"stargazers_count":3,"watchers_count":3,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":3,"default_branch":"master"}},"base":{"label":"wwylele:master","ref":"master","sha":"ffa8f5c7dccbdf4ed8504f0b1f2ce2fe35454a0b","user":{"login":"wwylele","id":4592895,"avatar_url":"https://avatars.githubusercontent.com/u/4592895?v=3","gravatar_id":"","url":"https://api.github.com/users/wwylele","html_url":"https://github.com/wwylele","followers_url":"https://api.github.com/users/wwylele/followers","following_url":"https://api.github.com/users/wwylele/following{/other_user}","gists_url":"https://api.github.com/users/wwylele/gists{/gist_id}","starred_url":"https://api.github.com/users/wwylele/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wwylele/subscriptions","organizations_url":"https://api.github.com/users/wwylele/orgs","repos_url":"https://api.github.com/users/wwylele/repos","events_url":"https://api.github.com/users/wwylele/events{/privacy}","received_events_url":"https://api.github.com/users/wwylele/received_events","type":"User","site_admin":false},"repo":{"id":53776373,"name":"citra","full_name":"wwylele/citra","owner":{"login":"wwylele","id":4592895,"avatar_url":"https://avatars.githubusercontent.com/u/4592895?v=3","gravatar_id":"","url":"https://api.github.com/users/wwylele","html_url":"https://github.com/wwylele","followers_url":"https://api.github.com/users/wwylele/followers","following_url":"https://api.github.com/users/wwylele/following{/other_user}","gists_url":"https://api.github.com/users/wwylele/gists{/gist_id}","starred_url":"https://api.github.com/users/wwylele/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wwylele/subscriptions","organizations_url":"https://api.github.com/users/wwylele/orgs","repos_url":"https://api.github.com/users/wwylele/repos","events_url":"https://api.github.com/users/wwylele/events{/privacy}","received_events_url":"https://api.github.com/users/wwylele/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/wwylele/citra","description":"Nintendo 3DS Emulator","fork":true,"url":"https://api.github.com/repos/wwylele/citra","forks_url":"https://api.github.com/repos/wwylele/citra/forks","keys_url":"https://api.github.com/repos/wwylele/citra/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wwylele/citra/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wwylele/citra/teams","hooks_url":"https://api.github.com/repos/wwylele/citra/hooks","issue_events_url":"https://api.github.com/repos/wwylele/citra/issues/events{/number}","events_url":"https://api.github.com/repos/wwylele/citra/events","assignees_url":"https://api.github.com/repos/wwylele/citra/assignees{/user}","branches_url":"https://api.github.com/repos/wwylele/citra/branches{/branch}","tags_url":"https://api.github.com/repos/wwylele/citra/tags","blobs_url":"https://api.github.com/repos/wwylele/citra/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wwylele/citra/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wwylele/citra/git/refs{/sha}","trees_url":"https://api.github.com/repos/wwylele/citra/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wwylele/citra/statuses/{sha}","languages_url":"https://api.github.com/repos/wwylele/citra/languages","stargazers_url":"https://api.github.com/repos/wwylele/citra/stargazers","contributors_url":"https://api.github.com/repos/wwylele/citra/contributors","subscribers_url":"https://api.github.com/repos/wwylele/citra/subscribers","subscription_url":"https://api.github.com/repos/wwylele/citra/subscription","commits_url":"https://api.github.com/repos/wwylele/citra/commits{/sha}","git_commits_url":"https://api.github.com/repos/wwylele/citra/git/commits{/sha}","comments_url":"https://api.github.com/repos/wwylele/citra/comments{/number}","issue_comment_url":"https://api.github.com/repos/wwylele/citra/issues/comments{/number}","contents_url":"https://api.github.com/repos/wwylele/citra/contents/{+path}","compare_url":"https://api.github.com/repos/wwylele/citra/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wwylele/citra/merges","archive_url":"https://api.github.com/repos/wwylele/citra/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wwylele/citra/downloads","issues_url":"https://api.github.com/repos/wwylele/citra/issues{/number}","pulls_url":"https://api.github.com/repos/wwylele/citra/pulls{/number}","milestones_url":"https://api.github.com/repos/wwylele/citra/milestones{/number}","notifications_url":"https://api.github.com/repos/wwylele/citra/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wwylele/citra/labels{/name}","releases_url":"https://api.github.com/repos/wwylele/citra/releases{/id}","deployments_url":"https://api.github.com/repos/wwylele/citra/deployments","created_at":"2016-03-13T09:09:07Z","updated_at":"2016-05-24T14:55:31Z","pushed_at":"2016-06-17T07:59:47Z","git_url":"git://github.com/wwylele/citra.git","ssh_url":"git@github.com:wwylele/citra.git","clone_url":"https://github.com/wwylele/citra.git","svn_url":"https://github.com/wwylele/citra","homepage":"https://citra-emu.org","size":12991,"stargazers_count":3,"watchers_count":3,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":3,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/wwylele/citra/pulls/2"},"html":{"href":"https://github.com/wwylele/citra/pull/2"},"issue":{"href":"https://api.github.com/repos/wwylele/citra/issues/2"},"comments":{"href":"https://api.github.com/repos/wwylele/citra/issues/2/comments"},"review_comments":{"href":"https://api.github.com/repos/wwylele/citra/pulls/2/comments"},"review_comment":{"href":"https://api.github.com/repos/wwylele/citra/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/wwylele/citra/pulls/2/commits"},"statuses":{"href":"https://api.github.com/repos/wwylele/citra/statuses/a2bab2da90e4e4025cac267911726aef6ed9a08f"}}}}
{"actor":{"display_login":"JayFoxRox"}}