History

Refactor of MyAvatar and Application HMD sensor

MyAvatar now uses a cached copy of the HMDSensor location, instead of calling into Application for every access. This allows us to simplify application to always return the most recent pose, instead of a different one pre and post physics. Added accessors to HMD Sensor in MyAvatar, besides being helpful, it also an optimization to avoid extracting quaternions from the HMD matrix on every access.

Anthony J. Thibault committed 11 years ago

Commit d07a02c1 parent ac9e1386 files · +88 −88Browse files

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

Unified · Split

interface/src/Application.cpp+8−25
@@ -962,14 +962,7 @@ void Application::paintGL() { · 961 unmodified lines
962 // If not using an HMD, grab the camera orientation directly962 // If not using an HMD, grab the camera orientation directly
963 _myCamera.setRotation(_myAvatar->getHead()->getCameraOrientation());963 _myCamera.setRotation(_myAvatar->getHead()->getCameraOrientation());
964 } else {964 } else {
965 // In an HMD, people can look up and down with their actual neck, and the965 _myCamera.setRotation(glm::quat_cast(_myAvatar->getSensorToWorldMatrix() * getHMDSensorPose()));
966 // per-eye HMD pose will be applied later. So set the camera orientation
967 // to only the yaw, excluding pitch and roll, i.e. an orientation that
968 // is orthongonal to the (body's) Y axis
969 //_myCamera.setRotation(_myAvatar->getWorldAlignedOrientation());
970
971 // AJT: no actually we do want the roll and pitch
972 _myCamera.setRotation(glm::quat_cast(_myAvatar->getSensorToWorldMat()) * getHeadOrientation());
973 }966 }
974 967
975 /*968 /*
@@ -2608,7 +2601,7 @@ void Application::update(float deltaTime) { · 1632 unmodified lines
2608 }2601 }
2609 2602
2610 auto userInputMapper = DependencyManager::get<UserInputMapper>();2603 auto userInputMapper = DependencyManager::get<UserInputMapper>();
2611 userInputMapper->setSensorToWorldMat(_myAvatar->getSensorToWorldMat());2604 userInputMapper->setSensorToWorldMat(_myAvatar->getSensorToWorldMatrix());
2612 userInputMapper->update(deltaTime);2605 userInputMapper->update(deltaTime);
2613 _keyboardMouseDevice.update();2606 _keyboardMouseDevice.update();
2614 2607
@@ -2688,10 +2681,8 @@ void Application::update(float deltaTime) { · 73 unmodified lines
2688 _physicsEngine.stepSimulation();2681 _physicsEngine.stepSimulation();
2689 _entities.getTree()->unlock();2682 _entities.getTree()->unlock();
2690 2683
2691 // AJT: FIXME due to sensitve order of operations, within MyAvatar,2684 // update the avatar with the current HMD pose
2692 // delay the head pose until after the physics step.2685 _myAvatar->setHMDSensorMatrix(getHMDSensorPose());
2693 _headPosition = glm::vec3(getActiveDisplayPlugin()->getHeadPose()[3]);
2694 _headOrientation = glm::quat_cast(getActiveDisplayPlugin()->getHeadPose());
2695 2686
2696 if (_physicsEngine.hasOutgoingChanges()) {2687 if (_physicsEngine.hasOutgoingChanges()) {
2697 _entities.getTree()->lockForWrite();2688 _entities.getTree()->lockForWrite();
@@ -2821,7 +2812,7 @@ void Application::setPalmData(Hand* hand, UserInputMapper::PoseValue pose, int i · 123 unmodified lines
2821 2812
2822 // transform from sensor space, to world space, to avatar model space.2813 // transform from sensor space, to world space, to avatar model space.
2823 glm::mat4 poseMat = createMatFromQuatAndPos(pose.getRotation(), pose.getTranslation());2814 glm::mat4 poseMat = createMatFromQuatAndPos(pose.getRotation(), pose.getTranslation());
2824 glm::mat4 sensorToWorldMat = _myAvatar->getSensorToWorldMat();2815 glm::mat4 sensorToWorldMat = _myAvatar->getSensorToWorldMatrix();
2825 glm::mat4 modelMat = createMatFromQuatAndPos(_myAvatar->getOrientation(), _myAvatar->getPosition());2816 glm::mat4 modelMat = createMatFromQuatAndPos(_myAvatar->getOrientation(), _myAvatar->getPosition());
2826 glm::mat4 objectPose = glm::inverse(modelMat) * sensorToWorldMat * poseMat;2817 glm::mat4 objectPose = glm::inverse(modelMat) * sensorToWorldMat * poseMat;
2827 2818
@@ -5018,14 +5009,6 @@ void Application::initPlugins() { · 2190 unmodified lines
5018void Application::shutdownPlugins() {5009void Application::shutdownPlugins() {
5019}5010}
5020 5011
5021glm::vec3 Application::getHeadPosition() const {
5022 return _headPosition;
5023}
5024
5025glm::quat Application::getHeadOrientation() const {
5026 return _headOrientation;
5027}
5028
5029glm::uvec2 Application::getCanvasSize() const {5012glm::uvec2 Application::getCanvasSize() const {
5030 return getActiveDisplayPlugin()->getRecommendedUiSize();5013 return getActiveDisplayPlugin()->getRecommendedUiSize();
5031}5014}
@@ -5159,8 +5142,8 @@ GlWindow* Application::getVisibleWindow() { · 127 unmodified lines
5159mat4 Application::getEyeProjection(int eye) const {5142mat4 Application::getEyeProjection(int eye) const {
5160 if (isHMDMode()) {5143 if (isHMDMode()) {
5161 return getActiveDisplayPlugin()->getProjection((Eye)eye, _viewFrustum.getProjection());5144 return getActiveDisplayPlugin()->getProjection((Eye)eye, _viewFrustum.getProjection());
5162 } 5145 }
5163 5146
5164 return _viewFrustum.getProjection();5147 return _viewFrustum.getProjection();
5165}5148}
5166 5149
@@ -5172,7 +5155,7 @@ mat4 Application::getEyePose(int eye) const { · 5 unmodified lines
5172 return mat4();5155 return mat4();
5173}5156}
5174 5157
5175mat4 Application::getHeadPose() const {5158mat4 Application::getHMDSensorPose() const {
5176 if (isHMDMode()) {5159 if (isHMDMode()) {
5177 return getActiveDisplayPlugin()->getHeadPose();5160 return getActiveDisplayPlugin()->getHeadPose();
5178 }5161 }