Merge pull request #12101 from hyperlogic/bug-fix/avatar-sit

Bug fix for sit script.
This commit is contained in:
John Conklin II 2018-01-08 09:59:17 -08:00 committed by GitHub
commit d660bbf6e5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 3 deletions

View file

@ -3166,6 +3166,7 @@ glm::mat4 MyAvatar::getLeftHandCalibrationMat() const {
}
bool MyAvatar::pinJoint(int index, const glm::vec3& position, const glm::quat& orientation) {
std::lock_guard<std::mutex> guard(_pinnedJointsMutex);
auto hipsIndex = getJointIndex("Hips");
if (index != hipsIndex) {
qWarning() << "Pinning is only supported for the hips joint at the moment.";
@ -3185,7 +3186,14 @@ bool MyAvatar::pinJoint(int index, const glm::vec3& position, const glm::quat& o
return true;
}
bool MyAvatar::isJointPinned(int index) {
std::lock_guard<std::mutex> guard(_pinnedJointsMutex);
auto it = std::find(_pinnedJoints.begin(), _pinnedJoints.end(), index);
return it != _pinnedJoints.end();
}
bool MyAvatar::clearPinOnJoint(int index) {
std::lock_guard<std::mutex> guard(_pinnedJointsMutex);
auto it = std::find(_pinnedJoints.begin(), _pinnedJoints.end(), index);
if (it != _pinnedJoints.end()) {
_pinnedJoints.erase(it);

View file

@ -448,9 +448,8 @@ public:
virtual void clearJointData(const QString& name) override;
virtual void clearJointsData() override;
Q_INVOKABLE bool pinJoint(int index, const glm::vec3& position, const glm::quat& orientation);
bool isJointPinned(int index);
Q_INVOKABLE bool clearPinOnJoint(int index);
Q_INVOKABLE float getIKErrorOnLastSolve() const;
@ -837,6 +836,7 @@ private:
bool getIsAway() const { return _isAway; }
void setAway(bool value);
std::mutex _pinnedJointsMutex;
std::vector<int> _pinnedJoints;
// height of user in sensor space, when standing erect.

View file

@ -34,12 +34,25 @@ Rig::CharacterControllerState convertCharacterControllerState(CharacterControlle
}
static AnimPose computeHipsInSensorFrame(MyAvatar* myAvatar, bool isFlying) {
glm::mat4 worldToSensorMat = glm::inverse(myAvatar->getSensorToWorldMatrix());
// check for pinned hips.
auto hipsIndex = myAvatar->getJointIndex("Hips");
if (myAvatar->isJointPinned(hipsIndex)) {
Transform avatarTransform = myAvatar->getTransform();
AnimPose result = AnimPose(worldToSensorMat * avatarTransform.getMatrix() * Matrices::Y_180);
result.scale() = glm::vec3(1.0f, 1.0f, 1.0f);
return result;
} else {
DebugDraw::getInstance().removeMarker("pinnedHips");
}
glm::mat4 hipsMat = myAvatar->deriveBodyFromHMDSensor();
glm::vec3 hipsPos = extractTranslation(hipsMat);
glm::quat hipsRot = glmExtractRotation(hipsMat);
glm::mat4 avatarToWorldMat = myAvatar->getTransform().getMatrix();
glm::mat4 worldToSensorMat = glm::inverse(myAvatar->getSensorToWorldMatrix());
glm::mat4 avatarToSensorMat = worldToSensorMat * avatarToWorldMat;
// dampen hips rotation, by mixing it with the avatar orientation in sensor space