zaru stuff

This commit is contained in:
howard-stearns 2017-06-01 17:08:22 -07:00
parent 1068a4a9bd
commit 6b2e4c5abc
3 changed files with 16 additions and 10 deletions

View file

@ -439,7 +439,7 @@ void MyAvatar::update(float deltaTime) {
}
if (_physicsSafetyPending && qApp->isPhysicsEnabled() && _characterController.isEnabledAndReady()) { // fix only when needed and ready
_physicsSafetyPending = false;
safeLanding(_goToPosition); // no-op if already safe
safeLanding(_goToPosition, _characterController.isStuck()); // no-op if already safe
}
Head* head = getHead();
@ -2236,7 +2236,7 @@ void MyAvatar::goToLocationAndEnableCollisions(const glm::vec3& position) { // S
goToLocation(position);
QMetaObject::invokeMethod(this, "setCollisionsEnabled", Qt::QueuedConnection, Q_ARG(bool, true));
}
bool MyAvatar::safeLanding(const glm::vec3& position) {
bool MyAvatar::safeLanding(const glm::vec3& position, bool force) {
// Considers all collision hull or non-collisionless primitive intersections on a vertical line through the point.
// There needs to be a "landing" if:
// a) the closest above and the closest below are less than the avatar capsule height apart, or
@ -2253,7 +2253,7 @@ bool MyAvatar::safeLanding(const glm::vec3& position) {
return result;
}
glm::vec3 better;
if (!requiresSafeLanding(position, better)) {
if (!requiresSafeLanding(position, better, force)) {
return false;
}
qDebug() << "rechecking" << position << " => " << better << " collisions:" << getCollisionsEnabled() << " physics:" << qApp->isPhysicsEnabled();
@ -2269,7 +2269,7 @@ bool MyAvatar::safeLanding(const glm::vec3& position) {
}
// If position is not reliably safe from being stuck by physics, answer true and place a candidate better position in betterPositionOut.
bool MyAvatar::requiresSafeLanding(const glm::vec3& positionIn, glm::vec3& betterPositionOut) {
bool MyAvatar::requiresSafeLanding(const glm::vec3& positionIn, glm::vec3& betterPositionOut, bool force) {
// We could repeat this whole test for each of the four corners of our bounding box, in case the surface is uneven. However:
// 1) This is only meant to cover the most important cases, and even the four corners won't handle random spikes in the surfaces or avatar.
// 2) My feeling is that this code is already at the limit of what can realistically be reviewed and maintained.
@ -2324,7 +2324,11 @@ bool MyAvatar::requiresSafeLanding(const glm::vec3& positionIn, glm::vec3& bette
if (!findIntersection(capsuleCenter, up, upperIntersection, upperId, upperNormal)) {
// We currently believe that physics will reliably push us out if our feet are embedded,
// as long as our capsule center is out and there's room above us. Here we have those
// conditions, so no need to check our feet below.
// conditions, so no need to check our feet below, unless forced.
if (force) {
upperIntersection = capsuleCenter;
return mustMove();
}
return ok("nothing above");
}

View file

@ -523,7 +523,7 @@ public slots:
bool shouldFaceLocation = false);
void goToLocation(const QVariant& properties);
void goToLocationAndEnableCollisions(const glm::vec3& newPosition);
bool safeLanding(const glm::vec3& position);
bool safeLanding(const glm::vec3& position, bool force = false);
void restrictScaleFromDomainSettings(const QJsonObject& domainSettingsObject);
void clearScaleRestriction();
@ -571,7 +571,7 @@ private:
glm::vec3 getWorldBodyPosition() const;
glm::quat getWorldBodyOrientation() const;
bool requiresSafeLanding(const glm::vec3& positionIn, glm::vec3& positionOut);
bool requiresSafeLanding(const glm::vec3& positionIn, glm::vec3& positionOut, bool force = false);
virtual QByteArray toByteArrayStateful(AvatarDataDetail dataDetail) override;

View file

@ -172,10 +172,12 @@ bool CharacterController::checkForSupport(btCollisionWorld* collisionWorld) {
btScalar hitHeight = _halfHeight + _radius + pointOnCharacter.dot(_currentUp);
// If there's non-trivial penetration with a big impulse for several steps, we're probably stuck.
// Note it here in the controller, and let MyAvatar figure out what to do about it.
const float STUCK_PENETRATION = -0.1f; // always negative into the object.
const float STUCK_PENETRATION = -0.05f; // always negative into the object.
const float STUCK_IMPULSE = 500.0f;
const int STUCK_LIFETIME = 50;
if ((contact.getDistance() < -STUCK_PENETRATION) && (contact.getAppliedImpulse() > STUCK_IMPULSE) && (contact.getLifeTime() > STUCK_LIFETIME)) {
const int STUCK_LIFETIME = 3;
//if (contact.getDistance() < STUCK_PENETRATION) qDebug() << "FIXME checking contact:" << contact.getDistance() << " impulse:" << contact.getAppliedImpulse() << " lifetime:" << contact.getLifeTime();
if ((contact.getDistance() < STUCK_PENETRATION) && (contact.getAppliedImpulse() > STUCK_IMPULSE) && (contact.getLifeTime() > STUCK_LIFETIME)) {
qDebug() << "FIXME stuck contact:" << contact.getDistance() << " impulse:" << contact.getAppliedImpulse() << " lifetime:" << contact.getLifeTime();
isStuck = true; // latch on
}
if (hitHeight < _maxStepHeight && normal.dot(_currentUp) > _minFloorNormalDotUp) {