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
281 Setting::init();281 Setting::init();
282 282
283 // Set dependencies283 // Set dependencies
284<<<<<<< HEAD
284 DependencyManager::set<AddressManager>();285 DependencyManager::set<AddressManager>();
285 DependencyManager::set<NodeList>(NodeType::Agent, listenPort);286 DependencyManager::set<NodeList>(NodeType::Agent, listenPort);
286 DependencyManager::set<GeometryCache>();287 DependencyManager::set<GeometryCache>();
@@ -306,6 +307,7 @@ bool setupEssentials(int& argc, char** argv) { · 19 unmodified lines
306 DependencyManager::set<DesktopScriptingInterface>();307 DependencyManager::set<DesktopScriptingInterface>();
307 DependencyManager::set<EntityScriptingInterface>();308 DependencyManager::set<EntityScriptingInterface>();
308 DependencyManager::set<WindowScriptingInterface>();309 DependencyManager::set<WindowScriptingInterface>();
310 DependencyManager::set<HMDScriptingInterface>();
309#if defined(Q_OS_MAC) || defined(Q_OS_WIN)311#if defined(Q_OS_MAC) || defined(Q_OS_WIN)
310 DependencyManager::set<SpeechRecognizer>();312 DependencyManager::set<SpeechRecognizer>();
311#endif313#endif
@@ -1166,9 +1168,11 @@ void Application::paintGL() { · 854 unmodified lines
1166 // right eye. There are FIXMEs in the relevant plugins1168 // right eye. There are FIXMEs in the relevant plugins
1167 _myCamera.setProjection(displayPlugin->getProjection(Mono, _myCamera.getProjection()));1169 _myCamera.setProjection(displayPlugin->getProjection(Mono, _myCamera.getProjection()));
1168 renderArgs._context->enableStereo(true);1170 renderArgs._context->enableStereo(true);
1169 mat4 eyeViews[2];1171 mat4 eyeOffsets[2];
1170 mat4 eyeProjections[2];1172 mat4 eyeProjections[2];
1171 auto baseProjection = renderArgs._viewFrustum->getProjection();1173 auto baseProjection = renderArgs._viewFrustum->getProjection();
1174 auto hmdInterface = DependencyManager::get<HMDScriptingInterface>();
1175 float IPDScale = hmdInterface->getIPDScale();
1172 // FIXME we probably don't need to set the projection matrix every frame,1176 // FIXME we probably don't need to set the projection matrix every frame,
1173 // only when the display plugin changes (or in non-HMD modes when the user 1177 // only when the display plugin changes (or in non-HMD modes when the user
1174 // changes the FOV manually, which right now I don't think they can.1178 // changes the FOV manually, which right now I don't think they can.
@@ -1177,14 +1181,24 @@ void Application::paintGL() { · 2 unmodified lines
1177 // applied to the avatar, so we need to get the difference between the head 1181 // applied to the avatar, so we need to get the difference between the head
1178 // pose applied to the avatar and the per eye pose, and use THAT as1182 // pose applied to the avatar and the per eye pose, and use THAT as
1179 // the per-eye stereo matrix adjustment.1183 // 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.
1181 mat4 headPose = displayPlugin->getHeadPose();1195 mat4 headPose = displayPlugin->getHeadPose();
1182 mat4 eyeView = glm::inverse(eyePose) * headPose;1196 displayPlugin->setEyeRenderPose(eye, headPose);
1183 eyeViews[eye] = eyeView;1197
1184 eyeProjections[eye] = displayPlugin->getProjection(eye, baseProjection);1198 eyeProjections[eye] = displayPlugin->getProjection(eye, baseProjection);
1185 });1199 });
1186 renderArgs._context->setStereoProjections(eyeProjections);1200 renderArgs._context->setStereoProjections(eyeProjections);
1187 renderArgs._context->setStereoViews(eyeViews);1201 renderArgs._context->setStereoViews(eyeOffsets);
1188 }1202 }
1189 displaySide(&renderArgs, _myCamera);1203 displaySide(&renderArgs, _myCamera);
1190 renderArgs._context->enableStereo(false);1204 renderArgs._context->enableStereo(false);
@@ -3930,7 +3944,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri · 2739 unmodified lines
3930 3944
3931 scriptEngine->registerGlobalObject("Paths", DependencyManager::get<PathUtils>().data());3945 scriptEngine->registerGlobalObject("Paths", DependencyManager::get<PathUtils>().data());
3932 3946
3933 scriptEngine->registerGlobalObject("HMD", &HMDScriptingInterface::getInstance());3947 scriptEngine->registerGlobalObject("HMD", DependencyManager::get<HMDScriptingInterface>().data());
3934 scriptEngine->registerFunction("HMD", "getHUDLookAtPosition2D", HMDScriptingInterface::getHUDLookAtPosition2D, 0);3948 scriptEngine->registerFunction("HMD", "getHUDLookAtPosition2D", HMDScriptingInterface::getHUDLookAtPosition2D, 0);
3935 scriptEngine->registerFunction("HMD", "getHUDLookAtPosition3D", HMDScriptingInterface::getHUDLookAtPosition3D, 0);3949 scriptEngine->registerFunction("HMD", "getHUDLookAtPosition3D", HMDScriptingInterface::getHUDLookAtPosition3D, 0);
3936 3950
@@ -4740,19 +4754,25 @@ mat4 Application::getEyeProjection(int eye) const { · 803 unmodified lines
4740 4754
4741mat4 Application::getEyePose(int eye) const {4755mat4 Application::getEyePose(int eye) const {
4742 if (isHMDMode()) {4756 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;
4744 }4769 }
4745
4746 return mat4();4770 return mat4();
4747}4771}
4748 4772
4749mat4 Application::getEyeOffset(int eye) const {4773mat4 Application::getEyeOffset(int eye) const {
4750 if (isHMDMode()) {4774 // FIXME invert?
4751 mat4 identity;4775 return getActiveDisplayPlugin()->getEyeToHeadTransform((Eye)eye);
4752 return getActiveDisplayPlugin()->getView((Eye)eye, identity);
4753 }
4754
4755 return mat4();
4756}4776}
4757 4777
4758mat4 Application::getHMDSensorPose() const {4778mat4 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