Fix hand-relative movement after hand dominance notion swap.

This commit is contained in:
r3tk0n 2019-03-11 18:19:43 -07:00
parent 39342b9771
commit 6ce955d915
2 changed files with 20 additions and 34 deletions

View file

@ -2527,8 +2527,8 @@ controller::Pose MyAvatar::getControllerPoseInAvatarFrame(controller::Action act
} }
} }
glm::quat MyAvatar::getDominantHandRotation() const { glm::quat MyAvatar::getOffHandRotation() const {
auto hand = (getDominantHand() == DOMINANT_RIGHT_HAND) ? controller::Action::RIGHT_HAND : controller::Action::LEFT_HAND; auto hand = (getDominantHand() == DOMINANT_RIGHT_HAND) ? controller::Action::LEFT_HAND : controller::Action::RIGHT_HAND;
auto pose = getControllerPoseInAvatarFrame(hand); auto pose = getControllerPoseInAvatarFrame(hand);
return pose.rotation; return pose.rotation;
} }
@ -3317,23 +3317,25 @@ void MyAvatar::updateOrientation(float deltaTime) {
//} //}
float MyAvatar::calculateGearedSpeed(const float driveKey) { float MyAvatar::calculateGearedSpeed(const float driveKey) {
if (driveKey > getDriveGear5()) { float absDriveKey = abs(driveKey);
return 1.0f; float sign = (driveKey < 0.0f) ? -1.0f : 1.0f;
if (absDriveKey > getDriveGear5()) {
return sign * 1.0f;
} }
else if (driveKey > getDriveGear4()) { else if (absDriveKey > getDriveGear4()) {
return 0.8f; return sign * 0.8f;
} }
else if (driveKey > getDriveGear3()) { else if (absDriveKey > getDriveGear3()) {
return 0.6f; return sign * 0.6f;
} }
else if (driveKey > getDriveGear2()) { else if (absDriveKey > getDriveGear2()) {
return 0.4f; return sign * 0.4f;
} }
else if (driveKey > getDriveGear1()) { else if (absDriveKey > getDriveGear1()) {
return 0.2f; return sign * 0.2f;
} }
else { else {
return 0.0f; return sign * 0.0f;
} }
} }
@ -3385,21 +3387,19 @@ glm::vec3 MyAvatar::calculateScaledDirection(){
glm::vec3 forward, right; glm::vec3 forward, right;
if (qApp->isHMDMode()) { if (qApp->isHMDMode()) {
auto handRotation = getDominantHandRotation(); auto handRotation = getOffHandRotation();
glm::vec3 controllerForward(0.0f, 1.0f, 0.0f); glm::vec3 controllerForward(0.0f, 1.0f, 0.0f);
glm::vec3 controllerRight(0.0f, 0.0f, (getDominantHand() == DOMINANT_RIGHT_HAND ? -1.0f : 1.0f)); glm::vec3 controllerRight(0.0f, 0.0f, (getDominantHand() == DOMINANT_RIGHT_HAND ? 1.0f : -1.0f));
// Do shit here.
switch (getMovementReference()) { switch (getMovementReference()) {
case MOVEMENT_HAND_RELATIVE: case MOVEMENT_HAND_RELATIVE:
forward = (handRotation * controllerForward); forward = (handRotation * controllerForward);
right = (handRotation * controllerRight); right = (handRotation * controllerRight);
break; break;
case MOVEMENT_HAND_RELATIVE_LEVELED: case MOVEMENT_HAND_RELATIVE_LEVELED:
handRotation = cancelOutRoll(handRotation);
forward = (handRotation * controllerForward); forward = (handRotation * controllerForward);
//forward = glm::normalize(forward - (glm::dot(forward, Vectors::UNIT_Y) * Vectors::UNIT_Y)); forward = glm::normalize(forward - (glm::dot(forward, Vectors::UNIT_Y) * Vectors::UNIT_Y));
right = (handRotation * controllerRight); right = (handRotation * controllerRight);
//right = glm::normalize(right - (glm::dot(right, Vectors::UNIT_Y) * Vectors::UNIT_Y)); right = glm::normalize(right - (glm::dot(right, Vectors::UNIT_Y) * Vectors::UNIT_Y));
break; break;
case MOVEMENT_HMD_RELATIVE: case MOVEMENT_HMD_RELATIVE:
default: default:
@ -3411,20 +3411,6 @@ glm::vec3 MyAvatar::calculateScaledDirection(){
right = IDENTITY_RIGHT; right = IDENTITY_RIGHT;
} }
if (getMovementReference() && qApp->isHMDMode()) {
// Here we have to get the rotation of the dominant hand and apply that to the direction vector.
// If we're on the right hand, we have to flip the x-axis.
auto handRotation = getDominantHandRotation();
glm::vec3 controllerForward(0.0f, 1.0f, 0.0f);
glm::vec3 controllerRight(0.0f, 0.0f, (getDominantHand() == DOMINANT_RIGHT_HAND ? -1.0f : 1.0f));
forward = (handRotation * controllerForward);
right = (handRotation * controllerRight);
}
else {
forward = IDENTITY_FORWARD;
right = IDENTITY_RIGHT;
}
glm::vec3 direction = scaleMotorSpeed(forward, right); glm::vec3 direction = scaleMotorSpeed(forward, right);
// RKNOTE: This may need to be changed later... // RKNOTE: This may need to be changed later...

View file

@ -953,7 +953,7 @@ public:
controller::Pose getControllerPoseInSensorFrame(controller::Action action) const; controller::Pose getControllerPoseInSensorFrame(controller::Action action) const;
controller::Pose getControllerPoseInWorldFrame(controller::Action action) const; controller::Pose getControllerPoseInWorldFrame(controller::Action action) const;
controller::Pose getControllerPoseInAvatarFrame(controller::Action action) const; controller::Pose getControllerPoseInAvatarFrame(controller::Action action) const;
glm::quat getDominantHandRotation() const; glm::quat getOffHandRotation() const;
bool hasDriveInput() const; bool hasDriveInput() const;