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
962962 // If not using an HMD, grab the camera orientation directly
963963 _myCamera.setRotation(_myAvatar->getHead()->getCameraOrientation());
964964 } else {
965− // In an HMD, people can look up and down with their actual neck, and the
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());
965+ _myCamera.setRotation(glm::quat_cast(_myAvatar->getSensorToWorldMatrix() * getHMDSensorPose()));
973966 }
974967
975968 /*
@@ -2608,7 +2601,7 @@ void Application::update(float deltaTime) { · 1632 unmodified lines
26082601 }
26092602
26102603 auto userInputMapper = DependencyManager::get<UserInputMapper>();
2611− userInputMapper->setSensorToWorldMat(_myAvatar->getSensorToWorldMat());
2604+ userInputMapper->setSensorToWorldMat(_myAvatar->getSensorToWorldMatrix());
26122605 userInputMapper->update(deltaTime);
26132606 _keyboardMouseDevice.update();
26142607
@@ -2688,10 +2681,8 @@ void Application::update(float deltaTime) { · 73 unmodified lines
26882681 _physicsEngine.stepSimulation();
26892682 _entities.getTree()->unlock();
26902683
2691− // AJT: FIXME due to sensitve order of operations, within MyAvatar,
2692− // delay the head pose until after the physics step.
2693− _headPosition = glm::vec3(getActiveDisplayPlugin()->getHeadPose()[3]);
2694− _headOrientation = glm::quat_cast(getActiveDisplayPlugin()->getHeadPose());
2684+ // update the avatar with the current HMD pose
2685+ _myAvatar->setHMDSensorMatrix(getHMDSensorPose());
26952686
26962687 if (_physicsEngine.hasOutgoingChanges()) {
26972688 _entities.getTree()->lockForWrite();
@@ -2821,7 +2812,7 @@ void Application::setPalmData(Hand* hand, UserInputMapper::PoseValue pose, int i · 123 unmodified lines
28212812
28222813 // transform from sensor space, to world space, to avatar model space.
28232814 glm::mat4 poseMat = createMatFromQuatAndPos(pose.getRotation(), pose.getTranslation());
2824− glm::mat4 sensorToWorldMat = _myAvatar->getSensorToWorldMat();
2815+ glm::mat4 sensorToWorldMat = _myAvatar->getSensorToWorldMatrix();
28252816 glm::mat4 modelMat = createMatFromQuatAndPos(_myAvatar->getOrientation(), _myAvatar->getPosition());
28262817 glm::mat4 objectPose = glm::inverse(modelMat) * sensorToWorldMat * poseMat;
28272818
@@ -5018,14 +5009,6 @@ void Application::initPlugins() { · 2190 unmodified lines
50185009 void Application::shutdownPlugins() {
50195010 }
50205011
5021−glm::vec3 Application::getHeadPosition() const {
5022− return _headPosition;
5023−}
5024−
5025−glm::quat Application::getHeadOrientation() const {
5026− return _headOrientation;
5027−}
5028−
50295012 glm::uvec2 Application::getCanvasSize() const {
50305013 return getActiveDisplayPlugin()->getRecommendedUiSize();
50315014 }
@@ -5159,8 +5142,8 @@ GlWindow* Application::getVisibleWindow() { · 127 unmodified lines
51595142 mat4 Application::getEyeProjection(int eye) const {
51605143 if (isHMDMode()) {
51615144 return getActiveDisplayPlugin()->getProjection((Eye)eye, _viewFrustum.getProjection());
5162− }
5163−
5145+ }
5146+
51645147 return _viewFrustum.getProjection();
51655148 }
51665149
@@ -5172,7 +5155,7 @@ mat4 Application::getEyePose(int eye) const { · 5 unmodified lines
51725155 return mat4();
51735156 }
51745157
5175−mat4 Application::getHeadPose() const {
5158+mat4 Application::getHMDSensorPose() const {
51765159 if (isHMDMode()) {
51775160 return getActiveDisplayPlugin()->getHeadPose();
51785161 }