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) : ModelReferential::ModelReferential(uint32_t modelID, ModelTree* tree, AvatarData* avatar) :
Referential(MODEL, avatar), Referential(MODEL, avatar),
_modelID(modelID), _modelID(modelID),
_tree(tree) _tree(tree)
{ {
const ModelItem* item = _tree->findModelByID(_modelID); const ModelItem* item = _tree->findModelByID(_modelID);
if (!isValid() || item == NULL) { if (!isValid() || item == NULL) {
@ -81,7 +81,6 @@ void ModelReferential::update() {
if (item->getPosition() != _refPosition || somethingChanged) { if (item->getPosition() != _refPosition || somethingChanged) {
_refPosition = item->getPosition(); _refPosition = item->getPosition();
_avatar->setPosition(_refPosition * (float)TREE_SCALE + _refRotation * (_translation * _refScale), true); _avatar->setPosition(_refPosition * (float)TREE_SCALE + _refRotation * (_translation * _refScale), true);
somethingChanged = true;
} }
} }
@ -158,7 +157,6 @@ void JointReferential::update() {
if (item->getPosition() != _refPosition || somethingChanged) { if (item->getPosition() != _refPosition || somethingChanged) {
model->getJointPositionInWorldFrame(_jointIndex, _refPosition); model->getJointPositionInWorldFrame(_jointIndex, _refPosition);
_avatar->setPosition(_refPosition + _refRotation * (_translation * _refScale), true); _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) { if (hasReferential) {
Referential* ref = new Referential(sourceBuffer, this); Referential* ref = new Referential(sourceBuffer, this);
if (_referential == NULL || if (_referential == NULL ||
ref->createdAt() > _referential->createdAt()) { ref->version() != _referential->version()) {
changeReferential(ref); changeReferential(ref);
} else { } else {
delete ref; delete ref;

View file

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

View file

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

View file

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