Added userHeight accessors and preference

Also made Avatar::getHeight thread-safe
This commit is contained in:
Anthony J. Thibault 2017-08-16 17:52:01 -07:00
parent d196743986
commit 80b660b258
5 changed files with 43 additions and 2 deletions

View file

@ -26,7 +26,6 @@
#include <AccountManager.h>
#include <AddressManager.h>
#include <AudioClient.h>
#include <AvatarConstants.h>
#include <display-plugins/DisplayPlugin.h>
#include <FSTReader.h>
#include <GeometryUtil.h>
@ -976,6 +975,7 @@ void MyAvatar::saveData() {
settings.setValue("collisionSoundURL", _collisionSoundURL);
settings.setValue("useSnapTurn", _useSnapTurn);
settings.setValue("clearOverlayWhenMoving", _clearOverlayWhenMoving);
settings.setValue("userHeight", getUserHeight());
settings.endGroup();
}
@ -1113,6 +1113,7 @@ void MyAvatar::loadData() {
setSnapTurn(settings.value("useSnapTurn", _useSnapTurn).toBool());
setClearOverlayWhenMoving(settings.value("clearOverlayWhenMoving", _clearOverlayWhenMoving).toBool());
setDominantHand(settings.value("dominantHand", _dominantHand).toString().toLower());
setUserHeight(settings.value("userHeight", DEFAULT_AVATAR_HEIGHT).toDouble());
settings.endGroup();
setEnableMeshVisible(Menu::getInstance()->isOptionChecked(MenuOption::MeshVisible));
@ -2619,6 +2620,14 @@ glm::mat4 MyAvatar::deriveBodyFromHMDSensor() const {
return createMatFromQuatAndPos(headOrientationYawOnly, bodyPos);
}
float MyAvatar::getUserHeight() const {
return _userHeight.get();
}
void MyAvatar::setUserHeight(float value) {
_userHeight.set(value);
}
glm::vec3 MyAvatar::getPositionForAudio() {
switch (_audioListenerMode) {
case AudioListenerMode::FROM_HEAD:

View file

@ -23,6 +23,7 @@
#include <controllers/Pose.h>
#include <controllers/Actions.h>
#include <avatars-renderer/Avatar.h>
#include <AvatarConstants.h>
#include "AtRestDetector.h"
#include "MyCharacterController.h"
@ -101,6 +102,7 @@ class MyAvatar : public Avatar {
* @property collisionsEnabled {bool} This can be used to disable collisions between the avatar and the world.
* @property useAdvancedMovementControls {bool} Stores the user preference only, does not change user mappings, this is done in the defaultScript
* "scripts/system/controllers/toggleAdvancedMovementForHandControllers.js".
* @property userHeight {number} The height of the user in sensor space. (meters).
*/
// FIXME: `glm::vec3 position` is not accessible from QML, so this exposes position in a QML-native type
@ -142,6 +144,8 @@ class MyAvatar : public Avatar {
Q_PROPERTY(float hmdRollControlDeadZone READ getHMDRollControlDeadZone WRITE setHMDRollControlDeadZone)
Q_PROPERTY(float hmdRollControlRate READ getHMDRollControlRate WRITE setHMDRollControlRate)
Q_PROPERTY(float userHeight READ getUserHeight WRITE setUserHeight)
const QString DOMINANT_LEFT_HAND = "left";
const QString DOMINANT_RIGHT_HAND = "right";
@ -521,6 +525,9 @@ public:
Q_INVOKABLE bool isUp(const glm::vec3& direction) { return glm::dot(direction, _worldUpDirection) > 0.0f; }; // true iff direction points up wrt avatar's definition of up.
Q_INVOKABLE bool isDown(const glm::vec3& direction) { return glm::dot(direction, _worldUpDirection) < 0.0f; };
float getUserHeight() const;
void setUserHeight(float value);
public slots:
void increaseSize();
void decreaseSize();
@ -794,6 +801,9 @@ private:
void setAway(bool value);
std::vector<int> _pinnedJoints;
// height of user in sensor space, when standing erect.
ThreadSafeValueCache<float> _userHeight { DEFAULT_AVATAR_HEIGHT };
};
QScriptValue audioListenModeToScriptValue(QScriptEngine* engine, const AudioListenerMode& audioListenerMode);

View file

@ -205,6 +205,16 @@ void setupPreferences() {
// which can't be changed across domain switches. Having these values loaded up when you load the Dialog each time
// is a way around this, therefore they're not specified here but in the QML.
}
{
auto getter = [=]()->float { return myAvatar->getUserHeight(); };
auto setter = [=](float value) { myAvatar->setUserHeight(value); };
auto preference = new SpinnerPreference(AVATAR_TUNING, "User height (meters)", getter, setter);
preference->setMin(1.0f);
preference->setMax(2.2f);
preference->setDecimals(3);
preference->setStep(0.001f);
preferences->addPreference(preference);
}
{
auto getter = []()->float { return DependencyManager::get<DdeFaceTracker>()->getEyeClosingThreshold(); };
auto setter = [](float value) { DependencyManager::get<DdeFaceTracker>()->setEyeClosingThreshold(value); };

View file

@ -1552,6 +1552,14 @@ void Avatar::ensureInScene(AvatarSharedPointer self, const render::ScenePointer&
// returns the avatar height, in meters, includes avatar scale factor.
float Avatar::getHeight() const {
if (QThread::currentThread() != thread()) {
float result = DEFAULT_AVATAR_HEIGHT;
BLOCKING_INVOKE_METHOD(const_cast<Avatar*>(this), "getHeight", Q_RETURN_ARG(float, result));
return result;
}
// TODO: if performance becomes a concern we can cache this value rather then computing it everytime.
// AJT: TODO: I don't know what scale is to use here... getDomainLimitedScale?
float avatarScale = getTargetScale();
if (_skeletonModel) {

View file

@ -251,7 +251,11 @@ public:
bool isFading() const { return _isFading; }
void updateFadingStatus(render::ScenePointer scene);
// returns the avatar height, in meters, includes avatar scale factor.
/**jsdoc
* Provides read only access to the current height of the avatar in world space.
* @function Avatar.getHeight
* @returns {number} height of avatar in meters
*/
Q_INVOKABLE float getHeight() const;
public slots: