Add feetPosition to avatar properties

This commit is contained in:
RebeccaStankus 2019-08-30 11:10:27 -07:00
parent c4c29dd093
commit a33bc3722d
5 changed files with 21 additions and 0 deletions

View file

@ -1848,6 +1848,13 @@ void Avatar::setPositionViaScript(const glm::vec3& position) {
updateAttitude(getWorldOrientation()); 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) { void Avatar::setOrientationViaScript(const glm::quat& orientation) {
setWorldOrientation(orientation); setWorldOrientation(orientation);
updateAttitude(orientation); updateAttitude(orientation);

View file

@ -437,6 +437,7 @@ public:
Q_INVOKABLE glm::vec3 getWorldFeetPosition(); Q_INVOKABLE glm::vec3 getWorldFeetPosition();
void setPositionViaScript(const glm::vec3& position) override; void setPositionViaScript(const glm::vec3& position) override;
void setFeetPositionViaScript(const glm::vec3& position) override;
void setOrientationViaScript(const glm::quat& orientation) override; void setOrientationViaScript(const glm::quat& orientation) override;
/**jsdoc /**jsdoc

View file

@ -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. // 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} 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 <code>0.005</code> and * @property {number} scale=1.0 - The scale of the avatar. The value can be set to anything between <code>0.005</code> and
* <code>1000.0</code>. When the scale value is fetched, it may temporarily be further limited by the domain's settings. * <code>1000.0</code>. 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/m<sup>3</sup>. The density is used to work out its mass in * @property {number} density - The density of the avatar in kg/m<sup>3</sup>. The density is used to work out its mass in
@ -536,6 +537,7 @@ class AvatarData : public QObject, public SpatiallyNestable {
* <em>Read-only.</em> * <em>Read-only.</em>
*/ */
Q_PROPERTY(glm::vec3 position READ getWorldPosition WRITE setPositionViaScript) 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 scale READ getDomainLimitedScale WRITE setTargetScale)
Q_PROPERTY(float density READ getDensity) Q_PROPERTY(float density READ getDensity)
Q_PROPERTY(glm::vec3 handPosition READ getHandPosition WRITE setHandPosition) Q_PROPERTY(glm::vec3 handPosition READ getHandPosition WRITE setHandPosition)
@ -629,6 +631,7 @@ public:
void setBodyRoll(float bodyRoll); void setBodyRoll(float bodyRoll);
virtual void setPositionViaScript(const glm::vec3& position); virtual void setPositionViaScript(const glm::vec3& position);
virtual void setFeetPositionViaScript(const glm::vec3& position);
virtual void setOrientationViaScript(const glm::quat& orientation); virtual void setOrientationViaScript(const glm::quat& orientation);
virtual void updateAttitude(const glm::quat& orientation) {} virtual void updateAttitude(const glm::quat& orientation) {}

View file

@ -31,6 +31,13 @@ glm::vec3 ScriptAvatarData::getPosition() const {
return glm::vec3(); return glm::vec3();
} }
} }
glm::vec3 ScriptAvatarData::getFeetPosition() const {
if (AvatarSharedPointer sharedAvatarData = _avatarData.lock()) {
return sharedAvatarData->getWorldFeetPosition();
} else {
return glm::vec3();
}
}
float ScriptAvatarData::getTargetScale() const { float ScriptAvatarData::getTargetScale() const {
if (AvatarSharedPointer sharedAvatarData = _avatarData.lock()) { if (AvatarSharedPointer sharedAvatarData = _avatarData.lock()) {
return sharedAvatarData->getTargetScale(); return sharedAvatarData->getTargetScale();

View file

@ -20,6 +20,7 @@
* Information about an avatar. * Information about an avatar.
* @typedef {object} AvatarData * @typedef {object} AvatarData
* @property {Vec3} position - The avatar's position. * @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 * @property {number} scale - The target scale of the avatar without any restrictions on permissible values imposed by the
* domain. * domain.
* @property {Vec3} handPosition - A user-defined hand position, in world coordinates. The position moves with the avatar but * @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 // PHYSICAL PROPERTIES: POSITION AND ORIENTATION
// //
Q_PROPERTY(glm::vec3 position READ getPosition) Q_PROPERTY(glm::vec3 position READ getPosition)
Q_PROPERTY(glm::vec3 feetPosition READ getFeetPosition)
Q_PROPERTY(float scale READ getTargetScale) Q_PROPERTY(float scale READ getTargetScale)
Q_PROPERTY(glm::vec3 handPosition READ getHandPosition) Q_PROPERTY(glm::vec3 handPosition READ getHandPosition)
Q_PROPERTY(float bodyPitch READ getBodyPitch) Q_PROPERTY(float bodyPitch READ getBodyPitch)
@ -124,6 +126,7 @@ public:
// PHYSICAL PROPERTIES: POSITION AND ORIENTATION // PHYSICAL PROPERTIES: POSITION AND ORIENTATION
// //
glm::vec3 getPosition() const; glm::vec3 getPosition() const;
glm::vec3 getFeetPosition() const;
float getTargetScale() const; float getTargetScale() const;
glm::vec3 getHandPosition() const; glm::vec3 getHandPosition() const;
float getBodyPitch() const; float getBodyPitch() const;