Showing the changes to interface/src/Application.cpp (1 of 21 files). Show all
Unified · Split
| @@ -300,6 +300,7 @@ bool setupEssentials(int& argc, char** argv) { · 299 unmodified lines | ||
| 300 | 300 | auto desktopScriptingInterface = DependencyManager::set<DesktopScriptingInterface>(); |
| 301 | 301 | auto entityScriptingInterface = DependencyManager::set<EntityScriptingInterface>(); |
| 302 | 302 | auto windowScriptingInterface = DependencyManager::set<WindowScriptingInterface>(); |
| 303 | + auto hmdScriptingInterface = DependencyManager::set<HMDScriptingInterface>(); | |
| 303 | 304 | #if defined(Q_OS_MAC) || defined(Q_OS_WIN) |
| 304 | 305 | auto speechRecognizer = DependencyManager::set<SpeechRecognizer>(); |
| 305 | 306 | #endif |
| @@ -1203,9 +1204,11 @@ void Application::paintGL() { · 897 unmodified lines | ||
| 1203 | 1204 | // right eye. There are FIXMEs in the relevant plugins |
| 1204 | 1205 | _myCamera.setProjection(displayPlugin->getProjection(Mono, _myCamera.getProjection())); |
| 1205 | 1206 | renderArgs._context->enableStereo(true); |
| 1206 | − mat4 eyeViews[2]; | |
| 1207 | + mat4 eyeOffsets[2]; | |
| 1207 | 1208 | mat4 eyeProjections[2]; |
| 1208 | 1209 | auto baseProjection = renderArgs._viewFrustum->getProjection(); |
| 1210 | + auto hmdInterface = DependencyManager::get<HMDScriptingInterface>(); | |
| 1211 | + float IPDScale = hmdInterface->getIPDScale(); | |
| 1209 | 1212 | // FIXME we probably don't need to set the projection matrix every frame, |
| 1210 | 1213 | // only when the display plugin changes (or in non-HMD modes when the user |
| 1211 | 1214 | // changes the FOV manually, which right now I don't think they can. |
| @@ -1214,14 +1217,24 @@ void Application::paintGL() { · 2 unmodified lines | ||
| 1214 | 1217 | // applied to the avatar, so we need to get the difference between the head |
| 1215 | 1218 | // pose applied to the avatar and the per eye pose, and use THAT as |
| 1216 | 1219 | // 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. | |
| 1218 | 1231 | mat4 headPose = displayPlugin->getHeadPose(); |
| 1219 | − mat4 eyeView = glm::inverse(eyePose) * headPose; | |
| 1220 | − eyeViews[eye] = eyeView; | |
| 1232 | + displayPlugin->setEyeRenderPose(eye, headPose); | |
| 1233 | + | |
| 1221 | 1234 | eyeProjections[eye] = displayPlugin->getProjection(eye, baseProjection); |
| 1222 | 1235 | }); |
| 1223 | 1236 | renderArgs._context->setStereoProjections(eyeProjections); |
| 1224 | − renderArgs._context->setStereoViews(eyeViews); | |
| 1237 | + renderArgs._context->setStereoViews(eyeOffsets); | |
| 1225 | 1238 | } |
| 1226 | 1239 | displaySide(&renderArgs, _myCamera); |
| 1227 | 1240 | renderArgs._context->enableStereo(false); |
| @@ -4130,7 +4143,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri · 2902 unmodified lines | ||
| 4130 | 4143 | |
| 4131 | 4144 | scriptEngine->registerGlobalObject("Paths", DependencyManager::get<PathUtils>().data()); |
| 4132 | 4145 | |
| 4133 | − scriptEngine->registerGlobalObject("HMD", &HMDScriptingInterface::getInstance()); | |
| 4146 | + scriptEngine->registerGlobalObject("HMD", DependencyManager::get<HMDScriptingInterface>().data()); | |
| 4134 | 4147 | scriptEngine->registerFunction("HMD", "getHUDLookAtPosition2D", HMDScriptingInterface::getHUDLookAtPosition2D, 0); |
| 4135 | 4148 | scriptEngine->registerFunction("HMD", "getHUDLookAtPosition3D", HMDScriptingInterface::getHUDLookAtPosition3D, 0); |
| 4136 | 4149 | |
| @@ -4980,19 +4993,25 @@ mat4 Application::getEyeProjection(int eye) const { · 843 unmodified lines | ||
| 4980 | 4993 | |
| 4981 | 4994 | mat4 Application::getEyePose(int eye) const { |
| 4982 | 4995 | 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; | |
| 4984 | 5008 | } |
| 4985 | − | |
| 4986 | 5009 | return mat4(); |
| 4987 | 5010 | } |
| 4988 | 5011 | |
| 4989 | 5012 | 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); | |
| 4996 | 5015 | } |
| 4997 | 5016 | |
| 4998 | 5017 | mat4 Application::getHMDSensorPose() const { |