Use head orientation for sitting

This commit is contained in:
Atlante45 2017-02-21 18:39:41 -08:00
parent 0629c6dbf7
commit cbaaaa21c6
3 changed files with 33 additions and 20 deletions

View file

@ -260,6 +260,11 @@ QByteArray MyAvatar::toByteArrayStateful(AvatarDataDetail dataDetail) {
return AvatarData::toByteArrayStateful(dataDetail); return AvatarData::toByteArrayStateful(dataDetail);
} }
void MyAvatar::resetSensorsAndBody() {
qApp->getActiveDisplayPlugin()->resetSensors();
reset(true, false, true);
}
void MyAvatar::centerBody() { void MyAvatar::centerBody() {
if (QThread::currentThread() != thread()) { if (QThread::currentThread() != thread()) {
QMetaObject::invokeMethod(this, "centerBody"); QMetaObject::invokeMethod(this, "centerBody");
@ -2481,7 +2486,6 @@ bool MyAvatar::pinJoint(int index, const glm::vec3& position, const glm::quat& o
qWarning() << "Pinning is only supported for the hips joint at the moment."; qWarning() << "Pinning is only supported for the hips joint at the moment.";
return false; return false;
} }
qApp->getActiveDisplayPlugin()->resetSensors();
auto jointTranslation = getAbsoluteJointTranslationInObjectFrame(index); auto jointTranslation = getAbsoluteJointTranslationInObjectFrame(index);
auto jointRotation = getAbsoluteJointRotationInObjectFrame(index); auto jointRotation = getAbsoluteJointRotationInObjectFrame(index);

View file

@ -99,6 +99,7 @@ public:
void reset(bool andRecenter = false, bool andReload = true, bool andHead = true); void reset(bool andRecenter = false, bool andReload = true, bool andHead = true);
Q_INVOKABLE void resetSensorsAndBody();
Q_INVOKABLE void centerBody(); // thread-safe Q_INVOKABLE void centerBody(); // thread-safe
Q_INVOKABLE void clearIKJointLimitHistory(); // thread-safe Q_INVOKABLE void clearIKJointLimitHistory(); // thread-safe

View file

@ -12,6 +12,7 @@
var MAX_IK_ERROR = 20; var MAX_IK_ERROR = 20;
var DESKTOP_UI_CHECK_INTERVAL = 250; var DESKTOP_UI_CHECK_INTERVAL = 250;
var DESKTOP_MAX_DISTANCE = 5; var DESKTOP_MAX_DISTANCE = 5;
var SIT_DELAY = 20
this.entityID = null; this.entityID = null;
this.timers = {}; this.timers = {};
@ -48,40 +49,47 @@
return; return;
} }
MyAvatar.overrideRoleAnimation(ROLE, ANIMATION_URL, ANIMATION_FPS, true, ANIMATION_FIRST_FRAME, ANIMATION_LAST_FRAME); MyAvatar.resetSensors();
MyAvatar.setParentID(this.entityID);
MyAvatar.characterControllerEnabled = false;
MyAvatar.hmdLeanRecenterEnabled = false;
var properties = Entities.getEntityProperties(this.entityID, ["position", "rotation"]); var that = this;
var index = MyAvatar.getJointIndex("Hips"); Script.setTimeout(function() {
MyAvatar.pinJoint(index, properties.position, properties.rotation); MyAvatar.setParentID(that.entityID);
MyAvatar.characterControllerEnabled = false;
MyAvatar.hmdLeanRecenterEnabled = false;
MyAvatar.overrideRoleAnimation(ROLE, ANIMATION_URL, ANIMATION_FPS, true, ANIMATION_FIRST_FRAME, ANIMATION_LAST_FRAME);
this.animStateHandlerID = MyAvatar.addAnimationStateHandler(function(props) { var properties = Entities.getEntityProperties(that.entityID, ["position", "rotation"]);
return { headType: 0 }; var index = MyAvatar.getJointIndex("Hips");
}, ["headType"]); MyAvatar.pinJoint(index, properties.position, properties.rotation);
Script.update.connect(this, this.update); that.animStateHandlerID = MyAvatar.addAnimationStateHandler(function(props) {
Controller.keyPressEvent.connect(this, this.keyPressed); return { headType: 0 };
Controller.keyReleaseEvent.connect(this, this.keyReleased); }, ["headType"]);
for (var i in RELEASE_KEYS) {
Controller.captureKeyEvents({ text: RELEASE_KEYS[i] }); Script.update.connect(that, that.update);
} Controller.keyPressEvent.connect(that, that.keyPressed);
Controller.keyReleaseEvent.connect(that, that.keyReleased);
for (var i in RELEASE_KEYS) {
Controller.captureKeyEvents({ text: RELEASE_KEYS[i] });
}
}, SIT_DELAY);
} }
this.sitUp = function() { this.sitUp = function() {
MyAvatar.bodyPitch = 0.0;
MyAvatar.bodyRoll = 0.0;
MyAvatar.restoreRoleAnimation(ROLE); MyAvatar.restoreRoleAnimation(ROLE);
MyAvatar.setParentID("");
MyAvatar.characterControllerEnabled = true; MyAvatar.characterControllerEnabled = true;
MyAvatar.hmdLeanRecenterEnabled = true; MyAvatar.hmdLeanRecenterEnabled = true;
MyAvatar.setParentID("");
var index = MyAvatar.getJointIndex("Hips"); var index = MyAvatar.getJointIndex("Hips");
MyAvatar.clearPinOnJoint(index); MyAvatar.clearPinOnJoint(index);
MyAvatar.removeAnimationStateHandler(this.animStateHandlerID); MyAvatar.removeAnimationStateHandler(this.animStateHandlerID);
MyAvatar.bodyPitch = 0.0; MyAvatar.resetSensors();
MyAvatar.bodyRoll = 0.0;
Script.update.disconnect(this, this.update); Script.update.disconnect(this, this.update);
Controller.keyPressEvent.disconnect(this, this.keyPressed); Controller.keyPressEvent.disconnect(this, this.keyPressed);