History

Enabling programmatic access to the IPD scale

Brad Davis committed 11 years ago

Commit 19fb4e91 parent 02bb37221 files · +270 −90Browse files

Showing the changes to interface/src/Application.cpp (1 of 21 files). Show all

Unified · Split

interface/src/Application.cpp+34−14
@@ -281,6 +281,7 @@ bool setupEssentials(int& argc, char** argv) { · 280 unmodified lines
281281 Setting::init();
282282
283283 // Set dependencies
284+<<<<<<< HEAD
284285 DependencyManager::set<AddressManager>();
285286 DependencyManager::set<NodeList>(NodeType::Agent, listenPort);
286287 DependencyManager::set<GeometryCache>();
@@ -306,6 +307,7 @@ bool setupEssentials(int& argc, char** argv) { · 19 unmodified lines
306307 DependencyManager::set<DesktopScriptingInterface>();
307308 DependencyManager::set<EntityScriptingInterface>();
308309 DependencyManager::set<WindowScriptingInterface>();
310+ DependencyManager::set<HMDScriptingInterface>();
309311 #if defined(Q_OS_MAC) || defined(Q_OS_WIN)
310312 DependencyManager::set<SpeechRecognizer>();
311313 #endif
@@ -1166,9 +1168,11 @@ void Application::paintGL() { · 854 unmodified lines
11661168 // right eye. There are FIXMEs in the relevant plugins
11671169 _myCamera.setProjection(displayPlugin->getProjection(Mono, _myCamera.getProjection()));
11681170 renderArgs._context->enableStereo(true);
1169− mat4 eyeViews[2];
1171+ mat4 eyeOffsets[2];
11701172 mat4 eyeProjections[2];
11711173 auto baseProjection = renderArgs._viewFrustum->getProjection();
1174+ auto hmdInterface = DependencyManager::get<HMDScriptingInterface>();
1175+ float IPDScale = hmdInterface->getIPDScale();
11721176 // FIXME we probably don't need to set the projection matrix every frame,
11731177 // only when the display plugin changes (or in non-HMD modes when the user
11741178 // changes the FOV manually, which right now I don't think they can.
@@ -1177,14 +1181,24 @@ void Application::paintGL() { · 2 unmodified lines
11771181 // applied to the avatar, so we need to get the difference between the head
11781182 // pose applied to the avatar and the per eye pose, and use THAT as
11791183 // the per-eye stereo matrix adjustment.
1180− mat4 eyePose = displayPlugin->getEyePose(eye);
1184+ mat4 eyeToHead = displayPlugin->getEyeToHeadTransform(eye);
1185+ // Grab the translation
1186+ vec3 eyeOffset = glm::vec3(eyeToHead[3]);
1187+ // Apply IPD scaling
1188+ mat4 eyeOffsetTransform = glm::translate(mat4(), eyeOffset * -1.0f * IPDScale);
1189+ eyeOffsets[eye] = eyeOffsetTransform;
1190+
1191+ // Tell the plugin what pose we're using to render. In this case we're just using the
1192+ // unmodified head pose because the only plugin that cares (the Oculus plugin) uses it
1193+ // for rotational timewarp. If we move to support positonal timewarp, we need to
1194+ // ensure this contains the full pose composed with the eye offsets.
11811195 mat4 headPose = displayPlugin->getHeadPose();
1182− mat4 eyeView = glm::inverse(eyePose) * headPose;
1183− eyeViews[eye] = eyeView;
1196+ displayPlugin->setEyeRenderPose(eye, headPose);
1197+
11841198 eyeProjections[eye] = displayPlugin->getProjection(eye, baseProjection);
11851199 });
11861200 renderArgs._context->setStereoProjections(eyeProjections);
1187− renderArgs._context->setStereoViews(eyeViews);
1201+ renderArgs._context->setStereoViews(eyeOffsets);
11881202 }
11891203 displaySide(&renderArgs, _myCamera);
11901204 renderArgs._context->enableStereo(false);
@@ -3930,7 +3944,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri · 2739 unmodified lines
39303944
39313945 scriptEngine->registerGlobalObject("Paths", DependencyManager::get<PathUtils>().data());
39323946
3933− scriptEngine->registerGlobalObject("HMD", &HMDScriptingInterface::getInstance());
3947+ scriptEngine->registerGlobalObject("HMD", DependencyManager::get<HMDScriptingInterface>().data());
39343948 scriptEngine->registerFunction("HMD", "getHUDLookAtPosition2D", HMDScriptingInterface::getHUDLookAtPosition2D, 0);
39353949 scriptEngine->registerFunction("HMD", "getHUDLookAtPosition3D", HMDScriptingInterface::getHUDLookAtPosition3D, 0);
39363950
@@ -4740,19 +4754,25 @@ mat4 Application::getEyeProjection(int eye) const { · 803 unmodified lines
47404754
47414755 mat4 Application::getEyePose(int eye) const {
47424756 if (isHMDMode()) {
4743− return getActiveDisplayPlugin()->getEyePose((Eye)eye);
4757+ auto hmdInterface = DependencyManager::get<HMDScriptingInterface>();
4758+ float IPDScale = hmdInterface->getIPDScale();
4759+ auto displayPlugin = getActiveDisplayPlugin();
4760+ mat4 headPose = displayPlugin->getHeadPose();
4761+ mat4 eyeToHead = displayPlugin->getEyeToHeadTransform((Eye)eye);
4762+ {
4763+ vec3 eyeOffset = glm::vec3(eyeToHead[3]);
4764+ // Apply IPD scaling
4765+ mat4 eyeOffsetTransform = glm::translate(mat4(), eyeOffset * -1.0f * IPDScale);
4766+ eyeToHead[3] = vec4(eyeOffset, 1.0);
4767+ }
4768+ return eyeToHead * headPose;
47444769 }
4745−
47464770 return mat4();
47474771 }
47484772
47494773 mat4 Application::getEyeOffset(int eye) const {
4750− if (isHMDMode()) {
4751− mat4 identity;
4752− return getActiveDisplayPlugin()->getView((Eye)eye, identity);
4753− }
4754−
4755− return mat4();
4774+ // FIXME invert?
4775+ return getActiveDisplayPlugin()->getEyeToHeadTransform((Eye)eye);
47564776 }
47574777
47584778 mat4 Application::getHMDSensorPose() const {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t