History

Enabling programmatic access to the IPD scale

Brad Davis committed 11 years ago

Commit 725ed261 parent a42bb5f21 files · +281 −81Browse files

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

Unified · Split

interface/src/Application.cpp+33−14
@@ -300,6 +300,7 @@ bool setupEssentials(int& argc, char** argv) { · 299 unmodified lines
300300 auto desktopScriptingInterface = DependencyManager::set<DesktopScriptingInterface>();
301301 auto entityScriptingInterface = DependencyManager::set<EntityScriptingInterface>();
302302 auto windowScriptingInterface = DependencyManager::set<WindowScriptingInterface>();
303+ auto hmdScriptingInterface = DependencyManager::set<HMDScriptingInterface>();
303304 #if defined(Q_OS_MAC) || defined(Q_OS_WIN)
304305 auto speechRecognizer = DependencyManager::set<SpeechRecognizer>();
305306 #endif
@@ -1203,9 +1204,11 @@ void Application::paintGL() { · 897 unmodified lines
12031204 // right eye. There are FIXMEs in the relevant plugins
12041205 _myCamera.setProjection(displayPlugin->getProjection(Mono, _myCamera.getProjection()));
12051206 renderArgs._context->enableStereo(true);
1206− mat4 eyeViews[2];
1207+ mat4 eyeOffsets[2];
12071208 mat4 eyeProjections[2];
12081209 auto baseProjection = renderArgs._viewFrustum->getProjection();
1210+ auto hmdInterface = DependencyManager::get<HMDScriptingInterface>();
1211+ float IPDScale = hmdInterface->getIPDScale();
12091212 // FIXME we probably don't need to set the projection matrix every frame,
12101213 // only when the display plugin changes (or in non-HMD modes when the user
12111214 // changes the FOV manually, which right now I don't think they can.
@@ -1214,14 +1217,24 @@ void Application::paintGL() { · 2 unmodified lines
12141217 // applied to the avatar, so we need to get the difference between the head
12151218 // pose applied to the avatar and the per eye pose, and use THAT as
12161219 // the per-eye stereo matrix adjustment.
1217− mat4 eyePose = displayPlugin->getEyePose(eye);
1220+ mat4 eyeToHead = displayPlugin->getEyeToHeadTransform(eye);
1221+ // Grab the translation
1222+ vec3 eyeOffset = glm::vec3(eyeToHead[3]);
1223+ // Apply IPD scaling
1224+ mat4 eyeOffsetTransform = glm::translate(mat4(), eyeOffset * -1.0f * IPDScale);
1225+ eyeOffsets[eye] = eyeOffsetTransform;
1226+
1227+ // Tell the plugin what pose we're using to render. In this case we're just using the
1228+ // unmodified head pose because the only plugin that cares (the Oculus plugin) uses it
1229+ // for rotational timewarp. If we move to support positonal timewarp, we need to
1230+ // ensure this contains the full pose composed with the eye offsets.
12181231 mat4 headPose = displayPlugin->getHeadPose();
1219− mat4 eyeView = glm::inverse(eyePose) * headPose;
1220− eyeViews[eye] = eyeView;
1232+ displayPlugin->setEyeRenderPose(eye, headPose);
1233+
12211234 eyeProjections[eye] = displayPlugin->getProjection(eye, baseProjection);
12221235 });
12231236 renderArgs._context->setStereoProjections(eyeProjections);
1224− renderArgs._context->setStereoViews(eyeViews);
1237+ renderArgs._context->setStereoViews(eyeOffsets);
12251238 }
12261239 displaySide(&renderArgs, _myCamera);
12271240 renderArgs._context->enableStereo(false);
@@ -4130,7 +4143,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri · 2902 unmodified lines
41304143
41314144 scriptEngine->registerGlobalObject("Paths", DependencyManager::get<PathUtils>().data());
41324145
4133− scriptEngine->registerGlobalObject("HMD", &HMDScriptingInterface::getInstance());
4146+ scriptEngine->registerGlobalObject("HMD", DependencyManager::get<HMDScriptingInterface>().data());
41344147 scriptEngine->registerFunction("HMD", "getHUDLookAtPosition2D", HMDScriptingInterface::getHUDLookAtPosition2D, 0);
41354148 scriptEngine->registerFunction("HMD", "getHUDLookAtPosition3D", HMDScriptingInterface::getHUDLookAtPosition3D, 0);
41364149
@@ -4980,19 +4993,25 @@ mat4 Application::getEyeProjection(int eye) const { · 843 unmodified lines
49804993
49814994 mat4 Application::getEyePose(int eye) const {
49824995 if (isHMDMode()) {
4983− return getActiveDisplayPlugin()->getEyePose((Eye)eye);
4996+ auto hmdInterface = DependencyManager::get<HMDScriptingInterface>();
4997+ float IPDScale = hmdInterface->getIPDScale();
4998+ auto displayPlugin = getActiveDisplayPlugin();
4999+ mat4 headPose = displayPlugin->getHeadPose();
5000+ mat4 eyeToHead = displayPlugin->getEyeToHeadTransform((Eye)eye);
5001+ {
5002+ vec3 eyeOffset = glm::vec3(eyeToHead[3]);
5003+ // Apply IPD scaling
5004+ mat4 eyeOffsetTransform = glm::translate(mat4(), eyeOffset * -1.0f * IPDScale);
5005+ eyeToHead[3] = vec4(eyeOffset, 1.0);
5006+ }
5007+ return eyeToHead * headPose;
49845008 }
4985−
49865009 return mat4();
49875010 }
49885011
49895012 mat4 Application::getEyeOffset(int eye) const {
4990− if (isHMDMode()) {
4991− mat4 identity;
4992− return getActiveDisplayPlugin()->getView((Eye)eye, identity);
4993− }
4994−
4995− return mat4();
5013+ // FIXME invert?
5014+ return getActiveDisplayPlugin()->getEyeToHeadTransform((Eye)eye);
49965015 }
49975016
49985017 mat4 Application::getHMDSensorPose() const {