goToLocation should work properly in standing HMD mode

This commit is contained in:
Anthony J. Thibault 2015-07-15 19:13:47 -07:00
parent ef0a157111
commit 157c20e57b
2 changed files with 29 additions and 25 deletions

View file

@ -108,7 +108,10 @@ MyAvatar::MyAvatar() :
_hmdSensorPosition(), _hmdSensorPosition(),
_bodySensorMatrix(), _bodySensorMatrix(),
_sensorToWorldMatrix(), _sensorToWorldMatrix(),
_standingHMDSensorMode(false) _standingHMDSensorMode(false),
_goToPending(false),
_goToPosition(),
_goToOrientation()
{ {
_firstPersonSkeletonModel.setIsFirstPerson(true); _firstPersonSkeletonModel.setIsFirstPerson(true);
@ -159,6 +162,12 @@ void MyAvatar::reset() {
void MyAvatar::update(float deltaTime) { void MyAvatar::update(float deltaTime) {
if (_goToPending) {
setPosition(_goToPosition);
setOrientation(_goToOrientation);
_goToPending = false;
}
if (_referential) { if (_referential) {
_referential->update(); _referential->update();
} }
@ -262,7 +271,6 @@ glm::mat4 MyAvatar::getSensorToWorldMatrix() const {
// update sensor to world matrix from current body position and hmd sensor. // update sensor to world matrix from current body position and hmd sensor.
// This is so the correct camera can be used for rendering. // This is so the correct camera can be used for rendering.
void MyAvatar::updateFromHMDSensorMatrix(const glm::mat4& hmdSensorMatrix) { void MyAvatar::updateFromHMDSensorMatrix(const glm::mat4& hmdSensorMatrix) {
// update the sensorMatrices based on the new hmd pose // update the sensorMatrices based on the new hmd pose
_hmdSensorMatrix = hmdSensorMatrix; _hmdSensorMatrix = hmdSensorMatrix;
_hmdSensorPosition = extractTranslation(hmdSensorMatrix); _hmdSensorPosition = extractTranslation(hmdSensorMatrix);
@ -1635,35 +1643,27 @@ void MyAvatar::goToLocation(const glm::vec3& newPosition,
qCDebug(interfaceapp).nospace() << "MyAvatar goToLocation - moving to " << newPosition.x << ", " qCDebug(interfaceapp).nospace() << "MyAvatar goToLocation - moving to " << newPosition.x << ", "
<< newPosition.y << ", " << newPosition.z; << newPosition.y << ", " << newPosition.z;
if (qApp->isHMDMode() && getStandingHMDSensorMode()) { _goToPending = true;
// AJT: FIXME, does not work with orientation. _goToPosition = newPosition;
// AJT: FIXME, does not work with shouldFaceLocation flag. _goToOrientation = getOrientation();
// Set the orientation of the sensor room, not the avatar itself. if (hasOrientation) {
glm::mat4 m; qCDebug(interfaceapp).nospace() << "MyAvatar goToLocation - new orientation is "
m[3] = glm::vec4(newPosition, 1); << newOrientation.x << ", " << newOrientation.y << ", " << newOrientation.z << ", " << newOrientation.w;
_sensorToWorldMatrix = m;
} else {
glm::vec3 shiftedPosition = newPosition;
if (hasOrientation) {
qCDebug(interfaceapp).nospace() << "MyAvatar goToLocation - new orientation is "
<< newOrientation.x << ", " << newOrientation.y << ", " << newOrientation.z << ", " << newOrientation.w;
// orient the user to face the target // orient the user to face the target
glm::quat quatOrientation = newOrientation; glm::quat quatOrientation = newOrientation;
if (shouldFaceLocation) { if (shouldFaceLocation) {
quatOrientation = newOrientation * glm::angleAxis(PI, glm::vec3(0.0f, 1.0f, 0.0f)); quatOrientation = newOrientation * glm::angleAxis(PI, glm::vec3(0.0f, 1.0f, 0.0f));
// move the user a couple units away // move the user a couple units away
const float DISTANCE_TO_USER = 2.0f; const float DISTANCE_TO_USER = 2.0f;
shiftedPosition = newPosition - quatOrientation * IDENTITY_FRONT * DISTANCE_TO_USER; _goToPosition = newPosition - quatOrientation * IDENTITY_FRONT * DISTANCE_TO_USER;
}
setOrientation(quatOrientation);
} }
slamPosition(shiftedPosition); _goToOrientation = quatOrientation;
} }
emit transformChanged(); emit transformChanged();
} }

View file

@ -331,6 +331,10 @@ private:
glm::mat4 _sensorToWorldMatrix; glm::mat4 _sensorToWorldMatrix;
bool _standingHMDSensorMode; bool _standingHMDSensorMode;
bool _goToPending;
glm::vec3 _goToPosition;
glm::quat _goToOrientation;
}; };
#endif // hifi_MyAvatar_h #endif // hifi_MyAvatar_h