Update HMD-derived avatar stuff during reset, update position under head, and remove unused vars.

This commit is contained in:
Howard Stearns 2015-10-06 20:51:53 -07:00
parent db955d894f
commit 1fc305ca6b
2 changed files with 16 additions and 11 deletions

View file

@ -78,12 +78,10 @@ const float MyAvatar::ZOOM_DEFAULT = 1.5f;
MyAvatar::MyAvatar(RigPointer rig) :
Avatar(rig),
_gravity(0.0f, 0.0f, 0.0f),
_wasPushing(false),
_isPushing(false),
_isBraking(false),
_boomLength(ZOOM_DEFAULT),
_trapDuration(0.0f),
_thrust(0.0f),
_keyboardMotorVelocity(0.0f),
_keyboardMotorTimescale(DEFAULT_KEYBOARD_MOTOR_TIMESCALE),
@ -142,16 +140,11 @@ QByteArray MyAvatar::toByteArray(bool cullSmallChanges, bool sendAll) {
void MyAvatar::reset() {
_skeletonModel.reset();
float headYaw = getHead()->getBaseYaw(); // degrees
getHead()->reset();
_targetVelocity = glm::vec3(0.0f);
setThrust(glm::vec3(0.0f));
// Reset the pitch and roll components of the avatar's orientation, preserve yaw direction
glm::vec3 eulers = safeEulerAngles(getOrientation());
eulers.x = 0.0f;
eulers.y += headYaw; // align body with head
eulers.y += glm::radians(headYaw); // align body with head
eulers.z = 0.0f;
setOrientation(glm::quat(eulers));
// This should be simpler when we have only graph animations always on.
bool isRig = _rig->getEnableRig();
@ -160,6 +153,21 @@ void MyAvatar::reset() {
qApp->setRawAvatarUpdateThreading(false);
_rig->disableHands = true;
setEnableRigAnimations(true);
_wasPushing = _isPushing = _isBraking = _billboardValid = _goToPending = _straightingLean = false;
getHead()->reset();
_targetVelocity = glm::vec3(0.0f);
setThrust(glm::vec3(0.0f));
auto worldBodyMatrix = _sensorToWorldMatrix * _bodySensorMatrix; // Assuming these are in sync and current...
setPosition(extractTranslation(worldBodyMatrix)); // ...positions body under head.
setOrientation(glm::quat(eulers)); // Not from worldBodyMatrix, in case it is NOT in sync and current.
// Make sure we have current sensor data.
_hmdSensorMatrix = qApp->getHMDSensorPose();
_hmdSensorPosition = extractTranslation(_hmdSensorMatrix);
_hmdSensorOrientation = extractRotation(_hmdSensorMatrix);
_bodySensorMatrix = deriveBodyFromHMDSensor(); // Based on new HMD position and yaw (no x/z rotation), in sensor space.
updateSensorToWorldMatrix(); // Uses updated position/orientation and _bodySensorMatrix changes
_skeletonModel.simulate(0.1f); // non-zero
setEnableRigAnimations(false);
_skeletonModel.simulate(0.1f);

View file

@ -282,8 +282,6 @@ private:
// results are in sensor space
glm::mat4 deriveBodyFromHMDSensor() const;
glm::vec3 _gravity;
float _driveKeys[MAX_DRIVE_KEYS];
bool _wasPushing;
bool _isPushing;
@ -291,7 +289,6 @@ private:
float _boomLength;
float _trapDuration; // seconds that avatar has been trapped by collisions
glm::vec3 _thrust; // impulse accumulator for outside sources
glm::vec3 _keyboardMotorVelocity; // target local-frame velocity of avatar (keyboard)