mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 23:34:09 +02:00
initial changes to stop the squatty potty from happening when users are sitting down in vr mode
This commit is contained in:
parent
be76c43aec
commit
ff0d938d37
4 changed files with 81 additions and 13 deletions
|
@ -53,7 +53,7 @@ Item {
|
||||||
ListView {
|
ListView {
|
||||||
width: firstCol.width
|
width: firstCol.width
|
||||||
height: root.animStateMachines.length * 15
|
height: root.animStateMachines.length * 15
|
||||||
visible: root.animStateMchines.length > 0;
|
visible: root.animStateMachines.length > 0;
|
||||||
model: root.animStateMachines
|
model: root.animStateMachines
|
||||||
delegate: StatText {
|
delegate: StatText {
|
||||||
text: {
|
text: {
|
||||||
|
|
|
@ -3589,9 +3589,11 @@ glm::vec3 MyAvatar::computeCounterBalance() {
|
||||||
// if the height is higher than default hips, clamp to default hips
|
// if the height is higher than default hips, clamp to default hips
|
||||||
counterBalancedCg.y = tposeHips.y + 0.05f;
|
counterBalancedCg.y = tposeHips.y + 0.05f;
|
||||||
} else if (counterBalancedCg.y < sitSquatThreshold) {
|
} else if (counterBalancedCg.y < sitSquatThreshold) {
|
||||||
//do a height reset
|
// do a height reset
|
||||||
setResetMode(true);
|
setResetMode(true);
|
||||||
_follow.activate(FollowHelper::Vertical);
|
_follow.activate(FollowHelper::Vertical);
|
||||||
|
// disable cg behaviour in this case.
|
||||||
|
_isInSittingState = true;
|
||||||
}
|
}
|
||||||
return counterBalancedCg;
|
return counterBalancedCg;
|
||||||
}
|
}
|
||||||
|
@ -3832,6 +3834,10 @@ bool MyAvatar::getIsInWalkingState() const {
|
||||||
return _isInWalkingState;
|
return _isInWalkingState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MyAvatar::getIsInSittingState() const {
|
||||||
|
return _isInSittingState;
|
||||||
|
}
|
||||||
|
|
||||||
float MyAvatar::getWalkSpeed() const {
|
float MyAvatar::getWalkSpeed() const {
|
||||||
return _walkSpeed.get() * _walkSpeedScalar;
|
return _walkSpeed.get() * _walkSpeedScalar;
|
||||||
}
|
}
|
||||||
|
@ -3852,6 +3858,10 @@ void MyAvatar::setIsInWalkingState(bool isWalking) {
|
||||||
_isInWalkingState = isWalking;
|
_isInWalkingState = isWalking;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MyAvatar::setIsInSittingState(bool isSitting) {
|
||||||
|
_isInSittingState = isSitting;
|
||||||
|
}
|
||||||
|
|
||||||
void MyAvatar::setWalkSpeed(float value) {
|
void MyAvatar::setWalkSpeed(float value) {
|
||||||
_walkSpeed.set(value);
|
_walkSpeed.set(value);
|
||||||
}
|
}
|
||||||
|
@ -4029,6 +4039,33 @@ bool MyAvatar::FollowHelper::shouldActivateHorizontal(const MyAvatar& myAvatar,
|
||||||
return fabs(lateralLeanAmount) > MAX_LATERAL_LEAN;
|
return fabs(lateralLeanAmount) > MAX_LATERAL_LEAN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MyAvatar::FollowHelper::shouldActivateHorizontalSitting(MyAvatar& myAvatar) const {
|
||||||
|
|
||||||
|
// get the current readings
|
||||||
|
controller::Pose currentHeadPose = myAvatar.getControllerPoseInAvatarFrame(controller::Action::HEAD);
|
||||||
|
controller::Pose currentLeftHandPose = myAvatar.getControllerPoseInAvatarFrame(controller::Action::LEFT_HAND);
|
||||||
|
controller::Pose currentRightHandPose = myAvatar.getControllerPoseInAvatarFrame(controller::Action::RIGHT_HAND);
|
||||||
|
|
||||||
|
bool stepDetected = false;
|
||||||
|
float myScale = myAvatar.getAvatarScale();
|
||||||
|
|
||||||
|
if (!withinBaseOfSupport(currentHeadPose)) {
|
||||||
|
// a step is detected
|
||||||
|
stepDetected = true;
|
||||||
|
} else {
|
||||||
|
glm::vec3 defaultHipsPosition = myAvatar.getAbsoluteDefaultJointTranslationInObjectFrame(myAvatar.getJointIndex("Hips"));
|
||||||
|
glm::vec3 defaultHeadPosition = myAvatar.getAbsoluteDefaultJointTranslationInObjectFrame(myAvatar.getJointIndex("Head"));
|
||||||
|
glm::vec3 currentHeadPosition = currentHeadPose.getTranslation();
|
||||||
|
float anatomicalHeadToHipsDistance = glm::length(defaultHeadPosition - defaultHipsPosition);
|
||||||
|
if (!isActive(Horizontal) &&
|
||||||
|
(glm::length(currentHeadPosition - defaultHipsPosition) > (anatomicalHeadToHipsDistance + (DEFAULT_AVATAR_SPINE_STRETCH_LIMIT * anatomicalHeadToHipsDistance)))) {
|
||||||
|
myAvatar.setResetMode(true);
|
||||||
|
stepDetected = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return stepDetected;
|
||||||
|
}
|
||||||
|
|
||||||
bool MyAvatar::FollowHelper::shouldActivateHorizontalCG(MyAvatar& myAvatar) const {
|
bool MyAvatar::FollowHelper::shouldActivateHorizontalCG(MyAvatar& myAvatar) const {
|
||||||
|
|
||||||
// get the current readings
|
// get the current readings
|
||||||
|
@ -4072,33 +4109,60 @@ bool MyAvatar::FollowHelper::shouldActivateHorizontalCG(MyAvatar& myAvatar) cons
|
||||||
return stepDetected;
|
return stepDetected;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MyAvatar::FollowHelper::shouldActivateVertical(const MyAvatar& myAvatar, const glm::mat4& desiredBodyMatrix, const glm::mat4& currentBodyMatrix) const {
|
bool MyAvatar::FollowHelper::shouldActivateVertical(MyAvatar& myAvatar, const glm::mat4& desiredBodyMatrix, const glm::mat4& currentBodyMatrix) const {
|
||||||
const float CYLINDER_TOP = 0.1f;
|
const float CYLINDER_TOP = 0.1f;
|
||||||
const float CYLINDER_BOTTOM = -1.5f;
|
const float CYLINDER_BOTTOM = -1.5f;
|
||||||
|
const float SITTING_BOTTOM = -0.02f;
|
||||||
|
|
||||||
glm::vec3 offset = extractTranslation(desiredBodyMatrix) - extractTranslation(currentBodyMatrix);
|
glm::vec3 offset = extractTranslation(desiredBodyMatrix) - extractTranslation(currentBodyMatrix);
|
||||||
|
|
||||||
return (offset.y > CYLINDER_TOP) || (offset.y < CYLINDER_BOTTOM);
|
if (myAvatar.getIsInSittingState()) {
|
||||||
|
if (offset.y < SITTING_BOTTOM) {
|
||||||
|
// we recenter when sitting.
|
||||||
|
return true;
|
||||||
|
} else if (offset.y > CYLINDER_TOP) {
|
||||||
|
// if we recenter upwards then no longer in sitting state
|
||||||
|
myAvatar.setIsInSittingState(false);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return (offset.y > CYLINDER_TOP) || (offset.y < CYLINDER_BOTTOM);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyAvatar::FollowHelper::prePhysicsUpdate(MyAvatar& myAvatar, const glm::mat4& desiredBodyMatrix,
|
void MyAvatar::FollowHelper::prePhysicsUpdate(MyAvatar& myAvatar, const glm::mat4& desiredBodyMatrix,
|
||||||
const glm::mat4& currentBodyMatrix, bool hasDriveInput) {
|
const glm::mat4& currentBodyMatrix, bool hasDriveInput) {
|
||||||
|
|
||||||
if (myAvatar.getHMDLeanRecenterEnabled() &&
|
qCDebug(interfaceapp) << "in sitting state: " << myAvatar.getIsInSittingState();
|
||||||
qApp->getCamera().getMode() != CAMERA_MODE_MIRROR) {
|
|
||||||
|
if (myAvatar.getHMDLeanRecenterEnabled() && qApp->getCamera().getMode() != CAMERA_MODE_MIRROR) {
|
||||||
if (!isActive(Rotation) && (shouldActivateRotation(myAvatar, desiredBodyMatrix, currentBodyMatrix) || hasDriveInput)) {
|
if (!isActive(Rotation) && (shouldActivateRotation(myAvatar, desiredBodyMatrix, currentBodyMatrix) || hasDriveInput)) {
|
||||||
activate(Rotation);
|
activate(Rotation);
|
||||||
myAvatar.setHeadControllerFacingMovingAverage(myAvatar.getHeadControllerFacing());
|
myAvatar.setHeadControllerFacingMovingAverage(myAvatar.getHeadControllerFacing());
|
||||||
}
|
}
|
||||||
if (myAvatar.getCenterOfGravityModelEnabled()) {
|
if (myAvatar.getCenterOfGravityModelEnabled()) {
|
||||||
if (!isActive(Horizontal) && (shouldActivateHorizontalCG(myAvatar) || hasDriveInput)) {
|
if (!(myAvatar.getIsInSittingState())) {
|
||||||
activate(Horizontal);
|
if (!isActive(Horizontal) && (shouldActivateHorizontalCG(myAvatar) || hasDriveInput)) {
|
||||||
if (myAvatar.getEnableStepResetRotation()) {
|
activate(Horizontal);
|
||||||
activate(Rotation);
|
if (myAvatar.getEnableStepResetRotation()) {
|
||||||
myAvatar.setHeadControllerFacingMovingAverage(myAvatar.getHeadControllerFacing());
|
activate(Rotation);
|
||||||
|
myAvatar.setHeadControllerFacingMovingAverage(myAvatar.getHeadControllerFacing());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// you are in the sitting state with cg model enabled
|
||||||
|
if (!isActive(Horizontal) && (shouldActivateHorizontalSitting(myAvatar) || hasDriveInput)) {
|
||||||
|
activate(Horizontal);
|
||||||
|
if (myAvatar.getEnableStepResetRotation()) {
|
||||||
|
activate(Rotation);
|
||||||
|
myAvatar.setHeadControllerFacingMovingAverage(myAvatar.getHeadControllerFacing());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// center of gravity model is not enabled
|
||||||
if (!isActive(Horizontal) && (shouldActivateHorizontal(myAvatar, desiredBodyMatrix, currentBodyMatrix) || hasDriveInput)) {
|
if (!isActive(Horizontal) && (shouldActivateHorizontal(myAvatar, desiredBodyMatrix, currentBodyMatrix) || hasDriveInput)) {
|
||||||
activate(Horizontal);
|
activate(Horizontal);
|
||||||
if (myAvatar.getEnableStepResetRotation()) {
|
if (myAvatar.getEnableStepResetRotation()) {
|
||||||
|
|
|
@ -1094,6 +1094,8 @@ public:
|
||||||
|
|
||||||
void setIsInWalkingState(bool isWalking);
|
void setIsInWalkingState(bool isWalking);
|
||||||
bool getIsInWalkingState() const;
|
bool getIsInWalkingState() const;
|
||||||
|
void setIsInSittingState(bool isSitting);
|
||||||
|
bool getIsInSittingState() const;
|
||||||
void setWalkSpeed(float value);
|
void setWalkSpeed(float value);
|
||||||
float getWalkSpeed() const;
|
float getWalkSpeed() const;
|
||||||
void setWalkBackwardSpeed(float value);
|
void setWalkBackwardSpeed(float value);
|
||||||
|
@ -1708,9 +1710,10 @@ private:
|
||||||
float getMaxTimeRemaining() const;
|
float getMaxTimeRemaining() const;
|
||||||
void decrementTimeRemaining(float dt);
|
void decrementTimeRemaining(float dt);
|
||||||
bool shouldActivateRotation(const MyAvatar& myAvatar, const glm::mat4& desiredBodyMatrix, const glm::mat4& currentBodyMatrix) const;
|
bool shouldActivateRotation(const MyAvatar& myAvatar, const glm::mat4& desiredBodyMatrix, const glm::mat4& currentBodyMatrix) const;
|
||||||
bool shouldActivateVertical(const MyAvatar& myAvatar, const glm::mat4& desiredBodyMatrix, const glm::mat4& currentBodyMatrix) const;
|
bool shouldActivateVertical(MyAvatar& myAvatar, const glm::mat4& desiredBodyMatrix, const glm::mat4& currentBodyMatrix) const;
|
||||||
bool shouldActivateHorizontal(const MyAvatar& myAvatar, const glm::mat4& desiredBodyMatrix, const glm::mat4& currentBodyMatrix) const;
|
bool shouldActivateHorizontal(const MyAvatar& myAvatar, const glm::mat4& desiredBodyMatrix, const glm::mat4& currentBodyMatrix) const;
|
||||||
bool shouldActivateHorizontalCG(MyAvatar& myAvatar) const;
|
bool shouldActivateHorizontalCG(MyAvatar& myAvatar) const;
|
||||||
|
bool shouldActivateHorizontalSitting(MyAvatar& myAvatar) const;
|
||||||
void prePhysicsUpdate(MyAvatar& myAvatar, const glm::mat4& bodySensorMatrix, const glm::mat4& currentBodyMatrix, bool hasDriveInput);
|
void prePhysicsUpdate(MyAvatar& myAvatar, const glm::mat4& bodySensorMatrix, const glm::mat4& currentBodyMatrix, bool hasDriveInput);
|
||||||
glm::mat4 postPhysicsUpdate(const MyAvatar& myAvatar, const glm::mat4& currentBodyMatrix);
|
glm::mat4 postPhysicsUpdate(const MyAvatar& myAvatar, const glm::mat4& currentBodyMatrix);
|
||||||
bool getForceActivateRotation() const;
|
bool getForceActivateRotation() const;
|
||||||
|
@ -1800,6 +1803,7 @@ private:
|
||||||
ThreadSafeValueCache<float> _sprintSpeed { AVATAR_SPRINT_SPEED_SCALAR };
|
ThreadSafeValueCache<float> _sprintSpeed { AVATAR_SPRINT_SPEED_SCALAR };
|
||||||
float _walkSpeedScalar { AVATAR_WALK_SPEED_SCALAR };
|
float _walkSpeedScalar { AVATAR_WALK_SPEED_SCALAR };
|
||||||
bool _isInWalkingState { false };
|
bool _isInWalkingState { false };
|
||||||
|
bool _isInSittingState{ false };
|
||||||
|
|
||||||
// load avatar scripts once when rig is ready
|
// load avatar scripts once when rig is ready
|
||||||
bool _shouldLoadScripts { false };
|
bool _shouldLoadScripts { false };
|
||||||
|
|
|
@ -46,7 +46,7 @@ static AnimPose computeHipsInSensorFrame(MyAvatar* myAvatar, bool isFlying) {
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::mat4 hipsMat;
|
glm::mat4 hipsMat;
|
||||||
if (myAvatar->getCenterOfGravityModelEnabled() && !isFlying && !(myAvatar->getIsInWalkingState())) {
|
if (myAvatar->getCenterOfGravityModelEnabled() && !isFlying && !(myAvatar->getIsInWalkingState()) && !(myAvatar->getIsInSittingState())) {
|
||||||
// then we use center of gravity model
|
// then we use center of gravity model
|
||||||
hipsMat = myAvatar->deriveBodyUsingCgModel();
|
hipsMat = myAvatar->deriveBodyUsingCgModel();
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue