From a33bc3722d35fad462b3e105d5454fffd4d3e224 Mon Sep 17 00:00:00 2001 From: RebeccaStankus Date: Fri, 30 Aug 2019 11:10:27 -0700 Subject: [PATCH 1/3] Add feetPosition to avatar properties --- libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp | 7 +++++++ libraries/avatars-renderer/src/avatars-renderer/Avatar.h | 1 + libraries/avatars/src/AvatarData.h | 3 +++ libraries/avatars/src/ScriptAvatarData.cpp | 7 +++++++ libraries/avatars/src/ScriptAvatarData.h | 3 +++ 5 files changed, 21 insertions(+) diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp index 7f363dd36f..c222853088 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp @@ -1848,6 +1848,13 @@ void Avatar::setPositionViaScript(const glm::vec3& position) { updateAttitude(getWorldOrientation()); } +void Avatar::setFeetPositionViaScript(const glm::vec3& position) { + auto feetAjustment = getWorldPosition() - getWorldFeetPosition(); + auto _goToPosition = position + feetAjustment; + setWorldPosition(_goToPosition); + updateAttitude(getWorldOrientation()); +} + void Avatar::setOrientationViaScript(const glm::quat& orientation) { setWorldOrientation(orientation); updateAttitude(orientation); diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.h b/libraries/avatars-renderer/src/avatars-renderer/Avatar.h index 7bb15ecbf7..891f125b28 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.h +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.h @@ -437,6 +437,7 @@ public: Q_INVOKABLE glm::vec3 getWorldFeetPosition(); void setPositionViaScript(const glm::vec3& position) override; + void setFeetPositionViaScript(const glm::vec3& position) override; void setOrientationViaScript(const glm::quat& orientation) override; /**jsdoc diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index 59a2e2a53e..5857a7dcaa 100755 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -488,6 +488,7 @@ class AvatarData : public QObject, public SpatiallyNestable { // IMPORTANT: The JSDoc for the following properties should be copied to MyAvatar.h and ScriptableAvatar.h. /* * @property {Vec3} position - The position of the avatar. + * @property {Vec3} feetPosition - The feet position of the avatar. * @property {number} scale=1.0 - The scale of the avatar. The value can be set to anything between 0.005 and * 1000.0. When the scale value is fetched, it may temporarily be further limited by the domain's settings. * @property {number} density - The density of the avatar in kg/m3. The density is used to work out its mass in @@ -536,6 +537,7 @@ class AvatarData : public QObject, public SpatiallyNestable { * Read-only. */ Q_PROPERTY(glm::vec3 position READ getWorldPosition WRITE setPositionViaScript) + Q_PROPERTY(glm::vec3 feetPosition READ getWorldFeetPosition WRITE setFeetPositionViaScript) Q_PROPERTY(float scale READ getDomainLimitedScale WRITE setTargetScale) Q_PROPERTY(float density READ getDensity) Q_PROPERTY(glm::vec3 handPosition READ getHandPosition WRITE setHandPosition) @@ -629,6 +631,7 @@ public: void setBodyRoll(float bodyRoll); virtual void setPositionViaScript(const glm::vec3& position); + virtual void setFeetPositionViaScript(const glm::vec3& position); virtual void setOrientationViaScript(const glm::quat& orientation); virtual void updateAttitude(const glm::quat& orientation) {} diff --git a/libraries/avatars/src/ScriptAvatarData.cpp b/libraries/avatars/src/ScriptAvatarData.cpp index 18717c8ca3..3228445f81 100644 --- a/libraries/avatars/src/ScriptAvatarData.cpp +++ b/libraries/avatars/src/ScriptAvatarData.cpp @@ -31,6 +31,13 @@ glm::vec3 ScriptAvatarData::getPosition() const { return glm::vec3(); } } +glm::vec3 ScriptAvatarData::getFeetPosition() const { + if (AvatarSharedPointer sharedAvatarData = _avatarData.lock()) { + return sharedAvatarData->getWorldFeetPosition(); + } else { + return glm::vec3(); + } +} float ScriptAvatarData::getTargetScale() const { if (AvatarSharedPointer sharedAvatarData = _avatarData.lock()) { return sharedAvatarData->getTargetScale(); diff --git a/libraries/avatars/src/ScriptAvatarData.h b/libraries/avatars/src/ScriptAvatarData.h index 9c5c2c6918..5b962d23df 100644 --- a/libraries/avatars/src/ScriptAvatarData.h +++ b/libraries/avatars/src/ScriptAvatarData.h @@ -20,6 +20,7 @@ * Information about an avatar. * @typedef {object} AvatarData * @property {Vec3} position - The avatar's position. + * @property {Vec3} feetPosition - The avatar's feet position. * @property {number} scale - The target scale of the avatar without any restrictions on permissible values imposed by the * domain. * @property {Vec3} handPosition - A user-defined hand position, in world coordinates. The position moves with the avatar but @@ -70,6 +71,7 @@ class ScriptAvatarData : public QObject { // PHYSICAL PROPERTIES: POSITION AND ORIENTATION // Q_PROPERTY(glm::vec3 position READ getPosition) + Q_PROPERTY(glm::vec3 feetPosition READ getFeetPosition) Q_PROPERTY(float scale READ getTargetScale) Q_PROPERTY(glm::vec3 handPosition READ getHandPosition) Q_PROPERTY(float bodyPitch READ getBodyPitch) @@ -124,6 +126,7 @@ public: // PHYSICAL PROPERTIES: POSITION AND ORIENTATION // glm::vec3 getPosition() const; + glm::vec3 getFeetPosition() const; float getTargetScale() const; glm::vec3 getHandPosition() const; float getBodyPitch() const; From 5fadfa52757f261eb2f36e4115724e3ea29e4b6a Mon Sep 17 00:00:00 2001 From: RebeccaStankus Date: Fri, 30 Aug 2019 13:41:46 -0700 Subject: [PATCH 2/3] Updated property in MyAvatar.h --- interface/src/avatar/MyAvatar.h | 2 ++ libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp | 7 ------- libraries/avatars-renderer/src/avatars-renderer/Avatar.h | 1 - libraries/avatars/src/AvatarData.h | 3 --- libraries/avatars/src/ScriptAvatarData.cpp | 7 ------- libraries/avatars/src/ScriptAvatarData.h | 3 --- 6 files changed, 2 insertions(+), 21 deletions(-) diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index bb6f036533..ef7af9abae 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -154,6 +154,7 @@ class MyAvatar : public Avatar { * * @property {Vec3} qmlPosition - A synonym for position for use by QML. * + * @property {Vec3} feetPosition - The position of the avatar's feet. * @property {boolean} shouldRenderLocally=true - If true then your avatar is rendered for you in Interface, * otherwise it is not rendered for you (but it is still rendered for other users). * @property {Vec3} motorVelocity=Vec3.ZERO - The target velocity of your avatar to be achieved by a scripted motor. @@ -340,6 +341,7 @@ class MyAvatar : public Avatar { Q_PROPERTY(QVector3D qmlPosition READ getQmlPosition) QVector3D getQmlPosition() { auto p = getWorldPosition(); return QVector3D(p.x, p.y, p.z); } + Q_PROPERTY(glm::vec3 feetPosition READ getWorldFeetPosition WRITE goToFeetLocation) Q_PROPERTY(bool shouldRenderLocally READ getShouldRenderLocally WRITE setShouldRenderLocally) Q_PROPERTY(glm::vec3 motorVelocity READ getScriptedMotorVelocity WRITE setScriptedMotorVelocity) Q_PROPERTY(float motorTimescale READ getScriptedMotorTimescale WRITE setScriptedMotorTimescale) diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp index c222853088..7f363dd36f 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp @@ -1848,13 +1848,6 @@ void Avatar::setPositionViaScript(const glm::vec3& position) { updateAttitude(getWorldOrientation()); } -void Avatar::setFeetPositionViaScript(const glm::vec3& position) { - auto feetAjustment = getWorldPosition() - getWorldFeetPosition(); - auto _goToPosition = position + feetAjustment; - setWorldPosition(_goToPosition); - updateAttitude(getWorldOrientation()); -} - void Avatar::setOrientationViaScript(const glm::quat& orientation) { setWorldOrientation(orientation); updateAttitude(orientation); diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.h b/libraries/avatars-renderer/src/avatars-renderer/Avatar.h index 891f125b28..7bb15ecbf7 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.h +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.h @@ -437,7 +437,6 @@ public: Q_INVOKABLE glm::vec3 getWorldFeetPosition(); void setPositionViaScript(const glm::vec3& position) override; - void setFeetPositionViaScript(const glm::vec3& position) override; void setOrientationViaScript(const glm::quat& orientation) override; /**jsdoc diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index 5857a7dcaa..59a2e2a53e 100755 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -488,7 +488,6 @@ class AvatarData : public QObject, public SpatiallyNestable { // IMPORTANT: The JSDoc for the following properties should be copied to MyAvatar.h and ScriptableAvatar.h. /* * @property {Vec3} position - The position of the avatar. - * @property {Vec3} feetPosition - The feet position of the avatar. * @property {number} scale=1.0 - The scale of the avatar. The value can be set to anything between 0.005 and * 1000.0. When the scale value is fetched, it may temporarily be further limited by the domain's settings. * @property {number} density - The density of the avatar in kg/m3. The density is used to work out its mass in @@ -537,7 +536,6 @@ class AvatarData : public QObject, public SpatiallyNestable { * Read-only. */ Q_PROPERTY(glm::vec3 position READ getWorldPosition WRITE setPositionViaScript) - Q_PROPERTY(glm::vec3 feetPosition READ getWorldFeetPosition WRITE setFeetPositionViaScript) Q_PROPERTY(float scale READ getDomainLimitedScale WRITE setTargetScale) Q_PROPERTY(float density READ getDensity) Q_PROPERTY(glm::vec3 handPosition READ getHandPosition WRITE setHandPosition) @@ -631,7 +629,6 @@ public: void setBodyRoll(float bodyRoll); virtual void setPositionViaScript(const glm::vec3& position); - virtual void setFeetPositionViaScript(const glm::vec3& position); virtual void setOrientationViaScript(const glm::quat& orientation); virtual void updateAttitude(const glm::quat& orientation) {} diff --git a/libraries/avatars/src/ScriptAvatarData.cpp b/libraries/avatars/src/ScriptAvatarData.cpp index 3228445f81..18717c8ca3 100644 --- a/libraries/avatars/src/ScriptAvatarData.cpp +++ b/libraries/avatars/src/ScriptAvatarData.cpp @@ -31,13 +31,6 @@ glm::vec3 ScriptAvatarData::getPosition() const { return glm::vec3(); } } -glm::vec3 ScriptAvatarData::getFeetPosition() const { - if (AvatarSharedPointer sharedAvatarData = _avatarData.lock()) { - return sharedAvatarData->getWorldFeetPosition(); - } else { - return glm::vec3(); - } -} float ScriptAvatarData::getTargetScale() const { if (AvatarSharedPointer sharedAvatarData = _avatarData.lock()) { return sharedAvatarData->getTargetScale(); diff --git a/libraries/avatars/src/ScriptAvatarData.h b/libraries/avatars/src/ScriptAvatarData.h index 5b962d23df..9c5c2c6918 100644 --- a/libraries/avatars/src/ScriptAvatarData.h +++ b/libraries/avatars/src/ScriptAvatarData.h @@ -20,7 +20,6 @@ * Information about an avatar. * @typedef {object} AvatarData * @property {Vec3} position - The avatar's position. - * @property {Vec3} feetPosition - The avatar's feet position. * @property {number} scale - The target scale of the avatar without any restrictions on permissible values imposed by the * domain. * @property {Vec3} handPosition - A user-defined hand position, in world coordinates. The position moves with the avatar but @@ -71,7 +70,6 @@ class ScriptAvatarData : public QObject { // PHYSICAL PROPERTIES: POSITION AND ORIENTATION // Q_PROPERTY(glm::vec3 position READ getPosition) - Q_PROPERTY(glm::vec3 feetPosition READ getFeetPosition) Q_PROPERTY(float scale READ getTargetScale) Q_PROPERTY(glm::vec3 handPosition READ getHandPosition) Q_PROPERTY(float bodyPitch READ getBodyPitch) @@ -126,7 +124,6 @@ public: // PHYSICAL PROPERTIES: POSITION AND ORIENTATION // glm::vec3 getPosition() const; - glm::vec3 getFeetPosition() const; float getTargetScale() const; glm::vec3 getHandPosition() const; float getBodyPitch() const; From a34a533c07dcaa99c2dabd88dad4376263c31113 Mon Sep 17 00:00:00 2001 From: RebeccaStankus Date: Tue, 3 Sep 2019 10:04:11 -0700 Subject: [PATCH 3/3] Added defaults for some params --- interface/src/avatar/MyAvatar.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index ef7af9abae..0108fb5eda 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -1940,9 +1940,8 @@ public slots: * @param {boolean} [shouldFaceLocation=false] - Set to true to position the avatar a short distance away from * the new position and orientate the avatar to face the position. */ - void goToFeetLocation(const glm::vec3& newPosition, - bool hasOrientation, const glm::quat& newOrientation, - bool shouldFaceLocation); + void goToFeetLocation(const glm::vec3& newPosition, bool hasOrientation = false, + const glm::quat& newOrientation = glm::quat(), bool shouldFaceLocation = false); /**jsdoc * Moves the avatar to a new position and/or orientation in the domain.