This commit is contained in:
Atlante45 2014-08-06 10:40:55 -07:00
parent 110b034bcb
commit fe8839b4b8
5 changed files with 24 additions and 14 deletions

View file

@ -40,9 +40,9 @@ ModelReferential::ModelReferential(Referential* referential, ModelTree* tree, Av
}
ModelReferential::ModelReferential(uint32_t modelID, ModelTree* tree, AvatarData* avatar) :
Referential(MODEL, avatar),
_modelID(modelID),
_tree(tree)
Referential(MODEL, avatar),
_modelID(modelID),
_tree(tree)
{
const ModelItem* item = _tree->findModelByID(_modelID);
if (!isValid() || item == NULL) {
@ -81,7 +81,6 @@ void ModelReferential::update() {
if (item->getPosition() != _refPosition || somethingChanged) {
_refPosition = item->getPosition();
_avatar->setPosition(_refPosition * (float)TREE_SCALE + _refRotation * (_translation * _refScale), true);
somethingChanged = true;
}
}
@ -158,7 +157,6 @@ void JointReferential::update() {
if (item->getPosition() != _refPosition || somethingChanged) {
model->getJointPositionInWorldFrame(_jointIndex, _refPosition);
_avatar->setPosition(_refPosition + _refRotation * (_translation * _refScale), true);
somethingChanged = true;
}
}

View file

@ -449,7 +449,7 @@ int AvatarData::parseDataAtOffset(const QByteArray& packet, int offset) {
if (hasReferential) {
Referential* ref = new Referential(sourceBuffer, this);
if (_referential == NULL ||
ref->createdAt() > _referential->createdAt()) {
ref->version() != _referential->version()) {
changeReferential(ref);
} else {
delete ref;

View file

@ -282,6 +282,8 @@ public:
QElapsedTimer& getLastUpdateTimer() { return _lastUpdateTimer; }
virtual float getBoundingRadius() const { return 1.f; }
const Referential* getReferential() const { return _referential; }
public slots:
void sendIdentityPacket();

View file

@ -11,11 +11,12 @@
#include <SharedUtil.h>
#include "AvatarData.h"
#include "Referential.h"
Referential::Referential(Type type, AvatarData* avatar) :
_type(type),
_createdAt(usecTimestampNow()),
_version(0),
_isValid(true),
_avatar(avatar)
{
@ -23,6 +24,9 @@ Referential::Referential(Type type, AvatarData* avatar) :
_isValid = false;
return;
}
if (_avatar->hasReferential()) {
_version = _avatar->getReferential()->version() + 1;
}
}
Referential::Referential(const unsigned char*& sourceBuffer, AvatarData* avatar) :
@ -70,8 +74,8 @@ int Referential::unpackReferential(const unsigned char* sourceBuffer) {
int Referential::pack(unsigned char* destinationBuffer) const {
unsigned char* startPosition = destinationBuffer;
*destinationBuffer++ = (unsigned char)_type;
memcpy(destinationBuffer, &_createdAt, sizeof(_createdAt));
destinationBuffer += sizeof(_createdAt);
memcpy(destinationBuffer, &_version, sizeof(_version));
destinationBuffer += sizeof(_version);
destinationBuffer += packFloatVec3ToSignedTwoByteFixed(destinationBuffer, _translation, 0);
destinationBuffer += packOrientationQuatToBytes(destinationBuffer, _rotation);
@ -82,8 +86,11 @@ int Referential::pack(unsigned char* destinationBuffer) const {
int Referential::unpack(const unsigned char* sourceBuffer) {
const unsigned char* startPosition = sourceBuffer;
_type = (Type)*sourceBuffer++;
memcpy(&_createdAt, sourceBuffer, sizeof(_createdAt));
sourceBuffer += sizeof(_createdAt);
if (_type < 0 || _type >= NUM_TYPE) {
_type = UNKNOWN;
}
memcpy(&_version, sourceBuffer, sizeof(_version));
sourceBuffer += sizeof(_version);
sourceBuffer += unpackFloatVec3FromSignedTwoByteFixed(sourceBuffer, _translation, 0);
sourceBuffer += unpackOrientationQuatFromBytes(sourceBuffer, _rotation);

View file

@ -21,16 +21,19 @@ class AvatarData;
class Referential {
public:
enum Type {
UNKNOWN,
MODEL,
JOINT,
AVATAR
AVATAR,
NUM_TYPE
};
Referential(const unsigned char*& sourceBuffer, AvatarData* avatar);
virtual ~Referential();
Type type() const { return _type; }
quint64 createdAt() const { return _createdAt; }
quint8 version() const { return _version; }
bool isValid() const { return _isValid; }
bool hasExtraData() const { return !_extraDataBuffer.isEmpty(); }
@ -54,7 +57,7 @@ protected:
virtual int unpackExtraData(const unsigned char* sourceBuffer, int size);
Type _type;
quint64 _createdAt;
quint8 _version;
bool _isValid;
AvatarData* _avatar;
QByteArray _extraDataBuffer;