Small optimisations and tidying of things that were noticed in passing. No behaviour should change.

* Removed the deprecated MyAvatar.setToggleHips script function and the "Toggle Hips Following" option from the Developer menu.  They had no effect on any code.
* In CharacterController::applyMotor, prevented unnecessary calls to btVector3::rotate() when the motor has no rotation.  This change also improves readability through the use of clearly-named lambdas.
* In AvatarData::getFauxJointIndex, prevented unnecessary string comparisons when the named joint is a real joint rather than a faux one.
* In Avatar::getJointIndex, removed an unnecessary call to QHash<QString, int>::contains(), by supplying a default index for QHash<QString, int>::value().
* Removed unnecessary condition "forwardLeanAmount < 0" in MyAvatar::FollowHelper::shouldActivateHorizontal_userSitting.
* Corrected the return type of MyAvatar::getSitStandStateChange from float to bool.
* Added a missing 'f' suffix to a float literal in PreferencesDialog.cpp.
This commit is contained in:
Phil Palmer 2021-02-19 21:55:08 -05:00
parent c869554d46
commit 72725e783a
8 changed files with 36 additions and 40 deletions

View file

@ -556,8 +556,6 @@ Menu::Menu() {
});
addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::FixGaze, 0, false);
addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::ToggleHipsFollowing, 0, false,
avatar.get(), SLOT(setToggleHips(bool)));
addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::AnimDebugDrawBaseOfSupport, 0, false,
avatar.get(), SLOT(setEnableDebugDrawBaseOfSupport(bool)));
addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::AnimDebugDrawDefaultPose, 0, false,

View file

@ -211,7 +211,6 @@ namespace MenuOption {
const QString ThirdPerson = "Third Person Legacy";
const QString ThreePointCalibration = "3 Point Calibration";
const QString ThrottleFPSIfNotFocus = "Throttle FPS If Not Focus"; // FIXME - this value duplicated in Basic2DWindowOpenGLDisplayPlugin.cpp
const QString ToggleHipsFollowing = "Toggle Hips Following";
const QString ToolWindow = "Tool Window";
const QString TransmitterDrive = "Transmitter Drive";
const QString TurnWithHead = "Turn using Head";

View file

@ -1392,18 +1392,6 @@ float loadSetting(Settings& settings, const QString& name, float defaultValue) {
return value;
}
void MyAvatar::setToggleHips(bool followHead) {
_follow.setToggleHipsFollowing(followHead);
}
void MyAvatar::FollowHelper::setToggleHipsFollowing(bool followHead) {
_toggleHipsFollowing = followHead;
}
bool MyAvatar::FollowHelper::getToggleHipsFollowing() const {
return _toggleHipsFollowing;
}
void MyAvatar::setEnableDebugDrawBaseOfSupport(bool isEnabled) {
_enableDebugDrawBaseOfSupport = isEnabled;
}
@ -2030,7 +2018,6 @@ void MyAvatar::loadData() {
allowAvatarLeaningPreferenceStrings[static_cast<uint>(AllowAvatarLeaningPreference::Default)])));
setEnableMeshVisible(Menu::getInstance()->isOptionChecked(MenuOption::MeshVisible));
_follow.setToggleHipsFollowing (Menu::getInstance()->isOptionChecked(MenuOption::ToggleHipsFollowing));
setEnableDebugDrawBaseOfSupport(Menu::getInstance()->isOptionChecked(MenuOption::AnimDebugDrawBaseOfSupport));
setEnableDebugDrawDefaultPose(Menu::getInstance()->isOptionChecked(MenuOption::AnimDebugDrawDefaultPose));
setEnableDebugDrawAnimPose(Menu::getInstance()->isOptionChecked(MenuOption::AnimDebugDrawAnimPose));
@ -5514,7 +5501,7 @@ void MyAvatar::setSitStandStateChange(bool stateChanged) {
}
// Determine if the user's real-world sit/stand state has changed.
float MyAvatar::getSitStandStateChange() const {
bool MyAvatar::getSitStandStateChange() const {
return _sitStandStateChange;
}
@ -5696,7 +5683,7 @@ bool MyAvatar::FollowHelper::shouldActivateHorizontal_userSitting(const MyAvatar
bool stepDetected = false;
if (forwardLeanAmount > MAX_FORWARD_LEAN) {
stepDetected = true;
} else if (forwardLeanAmount < 0 && forwardLeanAmount < -MAX_BACKWARD_LEAN) {
} else if (forwardLeanAmount < -MAX_BACKWARD_LEAN) {
stepDetected = true;
} else {
stepDetected = fabs(lateralLeanAmount) > MAX_LATERAL_LEAN;

View file

@ -1800,7 +1800,7 @@ public:
void setAnalogPlusSprintSpeed(float value);
float getAnalogPlusSprintSpeed() const;
void setSitStandStateChange(bool stateChanged);
float getSitStandStateChange() const;
bool getSitStandStateChange() const;
void updateSitStandState(float newHeightReading, float dt);
QVector<QString> getScriptUrls();
@ -2181,13 +2181,6 @@ public slots:
*/
Q_INVOKABLE void updateMotionBehaviorFromMenu();
/**jsdoc
* @function MyAvatar.setToggleHips
* @param {boolean} enabled - Enabled.
* @deprecated This function is deprecated and will be removed.
*/
void setToggleHips(bool followHead);
/**jsdoc
* Displays the base of support area debug graphics if in HMD mode. If your head goes outside this area your avatar's hips
* are moved to counterbalance your avatar, and if your head moves too far then your avatar's position is moved (i.e., a
@ -2907,8 +2900,6 @@ private:
void setForceActivateVertical(bool val);
bool getForceActivateHorizontal() const;
void setForceActivateHorizontal(bool val);
bool getToggleHipsFollowing() const;
void setToggleHipsFollowing(bool followHead);
std::atomic<bool> _forceActivateRotation { false };
std::atomic<bool> _forceActivateVertical { false };
std::atomic<bool> _forceActivateHorizontal { false };

View file

@ -364,7 +364,7 @@ void setupPreferences() {
auto preference = new SpinnerSliderPreference(VR_MOVEMENT, "Camera Sensitivity", getter, setter);
preference->setMin(0.01f);
preference->setMax(5.0f);
preference->setStep(0.1);
preference->setStep(0.1f);
preference->setDecimals(2);
preferences->addPreference(preference);
}

View file

@ -1444,9 +1444,7 @@ int Avatar::getJointIndex(const QString& name) const {
}
withValidJointIndicesCache([&]() {
if (_modelJointIndicesCache.contains(name)) {
result = _modelJointIndicesCache.value(name) - 1;
}
result = _modelJointIndicesCache.value(name, result + 1) - 1;
});
return result;
}

View file

@ -1938,6 +1938,10 @@ void AvatarData::clearJointsData() {
}
int AvatarData::getFauxJointIndex(const QString& name) const {
static constexpr QChar fauxJointFirstChar('_');// The first character of all the faux joint names.
if (!name.startsWith(fauxJointFirstChar)) {
return -1;
};
if (name == "_SENSOR_TO_WORLD_MATRIX") {
return SENSOR_TO_WORLD_MATRIX_INDEX;
}

View file

@ -696,10 +696,29 @@ void CharacterController::applyMotor(int index, btScalar dt, btVector3& worldVel
return;
}
// rotate into motor-frame
const bool motorHasRotation = !(motor.rotation == btQuaternion::getIdentity());
btVector3 axis = motor.rotation.getAxis();
btScalar angle = motor.rotation.getAngle();
btVector3 velocity = worldVelocity.rotate(axis, -angle);
// Rotate a vector from motor frame to world frame
auto rotateToWorldFrame = [&axis, &angle, &motorHasRotation](const btVector3 vectorInMotorFrame) {
if (motorHasRotation) {
return vectorInMotorFrame.rotate(axis, angle);
} else {
return vectorInMotorFrame;
}
};
// Rotate a vector from world frame to motor frame
auto rotateToMotorFrame = [&axis, &angle, &motorHasRotation](const btVector3 vectorInWorldFrame) {
if (motorHasRotation) {
return vectorInWorldFrame.rotate(axis, -angle);
} else {
return vectorInWorldFrame;
}
};
btVector3 velocity = rotateToMotorFrame(worldVelocity);
int32_t collisionMask = computeCollisionMask();
if (collisionMask == BULLET_COLLISION_MASK_COLLISIONLESS ||
@ -712,15 +731,15 @@ void CharacterController::applyMotor(int index, btScalar dt, btVector3& worldVel
velocity += tau * (motor.velocity - velocity);
// rotate back into world-frame
velocity = velocity.rotate(axis, angle);
_targetVelocity += (tau * motor.velocity).rotate(axis, angle);
velocity = rotateToWorldFrame(velocity);
_targetVelocity += rotateToWorldFrame(tau * motor.velocity);
// store the velocity and weight
velocities.push_back(velocity);
weights.push_back(tau);
} else {
// compute local UP
btVector3 up = _currentUp.rotate(axis, -angle);
btVector3 up = rotateToMotorFrame(_currentUp);
btVector3 motorVelocity = motor.velocity;
// save these non-adjusted components for later
@ -729,7 +748,7 @@ void CharacterController::applyMotor(int index, btScalar dt, btVector3& worldVel
if (_stepHeight > _minStepHeight && !_steppingUp) {
// there is a step --> compute velocity direction to go over step
btVector3 motorVelocityWF = motorVelocity.rotate(axis, angle);
btVector3 motorVelocityWF = rotateToWorldFrame(motorVelocity);
if (motorVelocityWF.dot(_stepNormal) < 0.0f) {
// the motor pushes against step
_steppingUp = true;
@ -764,8 +783,8 @@ void CharacterController::applyMotor(int index, btScalar dt, btVector3& worldVel
}
// add components back together and rotate into world-frame
velocity = (hVelocity + vVelocity).rotate(axis, angle);
_targetVelocity += maxTau * (hTargetVelocity + vTargetVelocity).rotate(axis, angle);
velocity = rotateToWorldFrame(hVelocity + vVelocity);
_targetVelocity += maxTau * rotateToWorldFrame(hTargetVelocity + vTargetVelocity);
// store velocity and weights
velocities.push_back(velocity);