Address feedback from code review

This commit is contained in:
Anthony J. Thibault 2016-01-22 11:54:28 -08:00
parent ca8a832818
commit 61b760038a
4 changed files with 14 additions and 14 deletions

View file

@ -1767,14 +1767,12 @@ void MyAvatar::lateUpdatePalms() {
static const float FOLLOW_TIME = 0.5f;
void MyAvatar::FollowHelper::deactivate() {
_timeTotal = FOLLOW_TIME;
_timeRemaining = 0.0f;
}
void MyAvatar::FollowHelper::activate() {
// TODO: the follow time should be proportional to the displacement.
// TODO: Perhaps, the follow time should be proportional to the displacement.
_timeRemaining = FOLLOW_TIME;
_timeTotal = FOLLOW_TIME;
}
bool MyAvatar::FollowHelper::isActive() const {
@ -1795,10 +1793,10 @@ bool MyAvatar::FollowHelper::shouldActivate(const MyAvatar& myAvatar, const glm:
const float CYLINDER_RADIUS = 0.15f;
glm::vec3 offset = extractTranslation(desiredBodyMatrix) - extractTranslation(currentBodyMatrix);
glm::vec3 truncatedOffset(offset.x, 0.0f, offset.y);
float truncatedDistance = glm::length(truncatedOffset);
glm::vec3 radialOffset(offset.x, 0.0f, offset.y);
float radialDistance = glm::length(radialOffset);
return (offset.y > CYLINDER_TOP) || (offset.y < CYLINDER_BOTTOM) || (truncatedDistance > CYLINDER_RADIUS);
return (offset.y > CYLINDER_TOP) || (offset.y < CYLINDER_BOTTOM) || (radialDistance > CYLINDER_RADIUS);
}
void MyAvatar::FollowHelper::prePhysicsUpdate(MyAvatar& myAvatar, const glm::mat4& desiredBodyMatrix, const glm::mat4& currentBodyMatrix) {

View file

@ -377,7 +377,6 @@ private:
struct FollowHelper {
glm::mat4 _desiredBodyMatrix;
float _timeRemaining { 0.0f };
float _timeTotal { 0.0f };
void deactivate();
void activate();

View file

@ -194,9 +194,10 @@ void CharacterController::playerStep(btCollisionWorld* dynaWorld, btScalar dt) {
// Rather then add this velocity to velocity the RigidBody, we explicitly teleport the RigidBody towards its goal.
// This mirrors the computation done in MyAvatar::FollowHelper::postPhysicsUpdate().
// These two computations must be kept in sync.
const float MINIMUM_TIME_REMAINING = 0.005f;
const float MAX_DISPLACEMENT = 0.5f * _radius;
_followTimeRemaining -= dt;
if (_followTimeRemaining >= 0.005f) {
if (_followTimeRemaining >= MINIMUM_TIME_REMAINING) {
btTransform bodyTransform = _rigidBody->getWorldTransform();
btVector3 startPos = bodyTransform.getOrigin();
@ -210,9 +211,9 @@ void CharacterController::playerStep(btCollisionWorld* dynaWorld, btScalar dt) {
glm::vec2 currentRight(currentFacing.y, -currentFacing.x);
glm::vec2 desiredFacing = getFacingDir2D(bulletToGLM(_followDesiredBodyTransform.getRotation()));
float deltaAngle = acosf(glm::clamp(glm::dot(currentFacing, desiredFacing), -1.0f, 1.0f));
float angularVel = deltaAngle / _followTimeRemaining;
float angularSpeed = deltaAngle / _followTimeRemaining;
float sign = copysignf(1.0f, glm::dot(desiredFacing, currentRight));
btQuaternion angularDisplacement = btQuaternion(btVector3(0.0f, 1.0f, 0.0f), sign * angularVel * dt);
btQuaternion angularDisplacement = btQuaternion(btVector3(0.0f, 1.0f, 0.0f), sign * angularSpeed * dt);
btQuaternion endRot = angularDisplacement * startRot;
// in order to accumulate displacement of avatar position, we need to take _shapeLocalOffset into account.

View file

@ -428,8 +428,9 @@ void generateBasisVectors(const glm::vec3& primaryAxis, const glm::vec3& seconda
glm::vec2 getFacingDir2D(const glm::quat& rot) {
glm::vec3 facing3D = rot * Vectors::UNIT_NEG_Z;
glm::vec2 facing2D(facing3D.x, facing3D.z);
if (glm::length(facing2D) <= 0.0001f) {
return glm::vec2(1, 0);
const float ALMOST_ZERO = 0.0001f;
if (glm::length(facing2D) < ALMOST_ZERO) {
return glm::vec2(1.0f, 0.0f);
} else {
return glm::normalize(facing2D);
}
@ -438,8 +439,9 @@ glm::vec2 getFacingDir2D(const glm::quat& rot) {
glm::vec2 getFacingDir2D(const glm::mat4& m) {
glm::vec3 facing3D = transformVector(m, Vectors::UNIT_NEG_Z);
glm::vec2 facing2D(facing3D.x, facing3D.z);
if (glm::length(facing2D) <= 0.0001f) {
return glm::vec2(1, 0);
const float ALMOST_ZERO = 0.0001f;
if (glm::length(facing2D) < ALMOST_ZERO) {
return glm::vec2(1.0f, 0.0f);
} else {
return glm::normalize(facing2D);
}