mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 17:03:58 +02:00
added experimental MyAvatar.setSkeletonOffset()
for improved walk animations
This commit is contained in:
parent
864dd0152d
commit
01a3eaa26b
7 changed files with 54 additions and 6 deletions
|
@ -24,6 +24,7 @@
|
|||
#include <PacketHeaders.h>
|
||||
#include <PerfStat.h>
|
||||
#include <SharedUtil.h>
|
||||
#include <StreamUtils.h> // adebug
|
||||
|
||||
#include "Application.h"
|
||||
#include "Avatar.h"
|
||||
|
@ -52,6 +53,7 @@ const float DISPLAYNAME_BACKGROUND_ALPHA = 0.4f;
|
|||
Avatar::Avatar() :
|
||||
AvatarData(),
|
||||
_skeletonModel(this),
|
||||
_skeletonOffset(0.0f),
|
||||
_bodyYawDelta(0.0f),
|
||||
_velocity(0.0f),
|
||||
_positionDeltaAccumulator(0.0f),
|
||||
|
@ -762,6 +764,21 @@ bool Avatar::findCollisions(const QVector<const Shape*>& shapes, CollisionList&
|
|||
return collided;
|
||||
}
|
||||
|
||||
void Avatar::setSkeletonOffset(const glm::vec3& offset) {
|
||||
const float MAX_OFFSET_LENGTH = _scale * 0.5f;
|
||||
float offsetLength = glm::length(offset);
|
||||
if (offsetLength > MAX_OFFSET_LENGTH) {
|
||||
_skeletonOffset = (MAX_OFFSET_LENGTH / offsetLength) * offset;
|
||||
} else {
|
||||
_skeletonOffset = offset;
|
||||
}
|
||||
std::cout << "adebug set offset = " << offset << std::endl; // adebug
|
||||
}
|
||||
|
||||
glm::vec3 Avatar::getSkeletonPosition() const {
|
||||
return _position + _skeletonOffset;
|
||||
}
|
||||
|
||||
QVector<glm::quat> Avatar::getJointRotations() const {
|
||||
if (QThread::currentThread() != thread()) {
|
||||
return AvatarData::getJointRotations();
|
||||
|
|
|
@ -69,6 +69,7 @@ class Texture;
|
|||
class Avatar : public AvatarData {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(quint32 collisionGroups READ getCollisionGroups WRITE setCollisionGroups)
|
||||
Q_PROPERTY(glm::vec3 skeletonOffset READ getSkeletonOffset WRITE setSkeletonOffset)
|
||||
|
||||
public:
|
||||
Avatar();
|
||||
|
@ -146,6 +147,10 @@ public:
|
|||
|
||||
quint32 getCollisionGroups() const { return _collisionGroups; }
|
||||
virtual void setCollisionGroups(quint32 collisionGroups) { _collisionGroups = (collisionGroups & VALID_COLLISION_GROUPS); }
|
||||
|
||||
Q_INVOKABLE void setSkeletonOffset(const glm::vec3& offset);
|
||||
Q_INVOKABLE glm::vec3 getSkeletonOffset() { return _skeletonOffset; }
|
||||
virtual glm::vec3 getSkeletonPosition() const;
|
||||
|
||||
Q_INVOKABLE glm::vec3 getJointPosition(int index) const;
|
||||
Q_INVOKABLE glm::vec3 getJointPosition(const QString& name) const;
|
||||
|
@ -184,6 +189,7 @@ signals:
|
|||
protected:
|
||||
Hair _hair;
|
||||
SkeletonModel _skeletonModel;
|
||||
glm::vec3 _skeletonOffset;
|
||||
QVector<Model*> _attachmentModels;
|
||||
float _bodyYawDelta;
|
||||
|
||||
|
|
|
@ -108,6 +108,20 @@ MyAvatar::~MyAvatar() {
|
|||
_lookAtTargetAvatar.clear();
|
||||
}
|
||||
|
||||
QByteArray MyAvatar::toByteArray() {
|
||||
CameraMode mode = Application::getInstance()->getCamera()->getMode();
|
||||
if (mode == CAMERA_MODE_THIRD_PERSON || mode == CAMERA_MODE_INDEPENDENT) {
|
||||
// fake the avatar position that is sent up to the AvatarMixer
|
||||
glm::vec3 oldPosition = _position;
|
||||
_position += _skeletonOffset;
|
||||
QByteArray array = AvatarData::toByteArray();
|
||||
// copy the correct position back
|
||||
_position = oldPosition;
|
||||
return array;
|
||||
}
|
||||
return AvatarData::toByteArray();
|
||||
}
|
||||
|
||||
void MyAvatar::reset() {
|
||||
_skeletonModel.reset();
|
||||
getHead()->reset();
|
||||
|
@ -1052,6 +1066,14 @@ void MyAvatar::setAttachmentData(const QVector<AttachmentData>& attachmentData)
|
|||
_billboardValid = false;
|
||||
}
|
||||
|
||||
glm::vec3 MyAvatar::getSkeletonPosition() const {
|
||||
CameraMode mode = Application::getInstance()->getCamera()->getMode();
|
||||
if (mode == CAMERA_MODE_THIRD_PERSON || mode == CAMERA_MODE_INDEPENDENT) {
|
||||
return Avatar::getSkeletonPosition();
|
||||
}
|
||||
return Avatar::getPosition();
|
||||
}
|
||||
|
||||
QString MyAvatar::getScriptedMotorFrame() const {
|
||||
QString frame = "avatar";
|
||||
if (_scriptedMotorFrame == SCRIPTED_MOTOR_CAMERA_FRAME) {
|
||||
|
|
|
@ -41,7 +41,8 @@ class MyAvatar : public Avatar {
|
|||
public:
|
||||
MyAvatar();
|
||||
~MyAvatar();
|
||||
|
||||
|
||||
QByteArray toByteArray();
|
||||
void reset();
|
||||
void update(float deltaTime);
|
||||
void simulate(float deltaTime);
|
||||
|
@ -133,6 +134,8 @@ public:
|
|||
virtual void setFaceModelURL(const QUrl& faceModelURL);
|
||||
virtual void setSkeletonModelURL(const QUrl& skeletonModelURL);
|
||||
virtual void setAttachmentData(const QVector<AttachmentData>& attachmentData);
|
||||
|
||||
virtual glm::vec3 getSkeletonPosition() const;
|
||||
|
||||
void clearJointAnimationPriorities();
|
||||
|
||||
|
|
|
@ -77,7 +77,7 @@ const float PALM_PRIORITY = DEFAULT_PRIORITY;
|
|||
const float LEAN_PRIORITY = DEFAULT_PRIORITY;
|
||||
|
||||
void SkeletonModel::simulate(float deltaTime, bool fullUpdate) {
|
||||
setTranslation(_owningAvatar->getPosition());
|
||||
setTranslation(_owningAvatar->getSkeletonPosition());
|
||||
static const glm::quat refOrientation = glm::angleAxis(PI, glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
setRotation(_owningAvatar->getOrientation() * refOrientation);
|
||||
setScale(glm::vec3(1.0f, 1.0f, 1.0f) * _owningAvatar->getScale() * MODEL_SCALE);
|
||||
|
|
|
@ -67,7 +67,7 @@ AvatarData::~AvatarData() {
|
|||
delete _referential;
|
||||
}
|
||||
|
||||
const glm::vec3& AvatarData::getPosition() {
|
||||
const glm::vec3& AvatarData::getPosition() const {
|
||||
if (_referential) {
|
||||
_referential->update();
|
||||
}
|
||||
|
|
|
@ -138,15 +138,15 @@ public:
|
|||
AvatarData();
|
||||
virtual ~AvatarData();
|
||||
|
||||
const QUuid& getSessionUUID() { return _sessionUUID; }
|
||||
const QUuid& getSessionUUID() const { return _sessionUUID; }
|
||||
|
||||
const glm::vec3& getPosition();
|
||||
const glm::vec3& getPosition() const;
|
||||
virtual void setPosition(const glm::vec3 position, bool overideReferential = false);
|
||||
|
||||
glm::vec3 getHandPosition() const;
|
||||
void setHandPosition(const glm::vec3& handPosition);
|
||||
|
||||
QByteArray toByteArray();
|
||||
virtual QByteArray toByteArray();
|
||||
|
||||
/// \return true if an error should be logged
|
||||
bool shouldLogError(const quint64& now);
|
||||
|
|
Loading…
Reference in a new issue