Few modifications to how avatars update their positions

This commit is contained in:
Atlante45 2014-08-05 12:03:53 -07:00
parent 283beab05d
commit 39a74cbc28
4 changed files with 42 additions and 20 deletions

View file

@ -182,10 +182,12 @@ void Avatar::simulate(float deltaTime) {
}
if (_referential) {
if (_referential->hasExtraData()) {
qDebug() << "Has extra data";
switch (_referential->type()) {
case Referential::MODEL:
qDebug() << "[DEBUG] Switching to the right referential";
_referential = new ModelReferential(_referential, this);
_referential = new ModelReferential(_referential,
Application::getInstance()->getModels()->getTree(), this);
break;
default:
qDebug() << "Non handled referential type";
@ -234,6 +236,12 @@ static TextRenderer* textRenderer(TextRendererType type) {
}
void Avatar::render(const glm::vec3& cameraPosition, RenderMode renderMode) {
// make sure we have the right position
_skeletonModel.setTranslation(getPosition());
static const glm::quat refOrientation = glm::angleAxis(PI, glm::vec3(0.0f, 1.0f, 0.0f));
_skeletonModel.setRotation(getOrientation() * refOrientation);
const float MODEL_SCALE = 0.0006f;
_skeletonModel.setScale(glm::vec3(1.0f, 1.0f, 1.0f) * getScale() * MODEL_SCALE);
if (glm::distance(Application::getInstance()->getAvatar()->getPosition(),
_position) < 10.0f) {
@ -456,12 +464,6 @@ void Avatar::renderBody(RenderMode renderMode, float glowLevel) {
return;
}
// make sure we have the right position
_skeletonModel.setTranslation(getPosition());
static const glm::quat refOrientation = glm::angleAxis(PI, glm::vec3(0.0f, 1.0f, 0.0f));
_skeletonModel.setRotation(getOrientation() * refOrientation);
const float MODEL_SCALE = 0.0006f;
_skeletonModel.setScale(glm::vec3(1.0f, 1.0f, 1.0f) * getScale() * MODEL_SCALE);
_skeletonModel.render(1.0f, modelRenderMode, Menu::getInstance()->isOptionChecked(MenuOption::AvatarsReceiveShadows));
renderAttachments(renderMode);
getHand()->render(false, modelRenderMode);

View file

@ -128,7 +128,7 @@ void MyAvatar::update(float deltaTime) {
simulate(deltaTime);
bool WANT_REFERENTIAL = true;
bool WANT_REFERENTIAL = false;
if (WANT_REFERENTIAL) {
int id = 12340;
const ModelItem* item = Application::getInstance()->getModels()->getTree()->findModelByID(id);
@ -138,7 +138,8 @@ void MyAvatar::update(float deltaTime) {
} else if (item != NULL) {
const Model* model = Application::getInstance()->getModels()->getModelForModelItem(*item);
if (model != NULL) {
_referential = new ModelReferential(id, Application::getInstance()->getModels()->getTree(), this);
_referential = new ModelReferential(id,
Application::getInstance()->getModels()->getTree(), this);
}
}
}

View file

@ -73,6 +73,29 @@ const glm::vec3& AvatarData::getPosition() {
return _position;
}
void AvatarData::setPosition(const glm::vec3 position, bool overideReferential) {
if (!_referential || overideReferential) {
_position = position;
}
}
glm::quat AvatarData::getOrientation() const {
if (_referential) {
_referential->update();
}
return glm::quat(glm::radians(glm::vec3(_bodyPitch, _bodyYaw, _bodyRoll)));
}
void AvatarData::setOrientation(const glm::quat& orientation, bool overideReferential) {
if (!_referential || overideReferential) {
glm::vec3 eulerAngles = glm::degrees(safeEulerAngles(orientation));
_bodyPitch = eulerAngles.x;
_bodyYaw = eulerAngles.y;
_bodyRoll = eulerAngles.z;
}
}
glm::vec3 AvatarData::getHandPosition() const {
return getOrientation() * _handPosition + _position;
}
@ -402,8 +425,9 @@ int AvatarData::parseDataAtOffset(const QByteArray& packet, int offset) {
// Referential
if (hasReferential) {
qDebug() << "Has referencial: " << hasReferential;
const unsigned char* start = sourceBuffer;
if (_referential == NULL) {
qDebug() << "New referential";
_referential = new Referential(sourceBuffer, this);
} else {
Referential* ref = new Referential(sourceBuffer, this);
@ -415,6 +439,8 @@ int AvatarData::parseDataAtOffset(const QByteArray& packet, int offset) {
delete ref;
}
}
//qDebug() << "Read " << sourceBuffer - start << " bytes.";
_referential->update();
} else if (_referential != NULL) {
qDebug() << "Erasing referencial";
delete _referential;
@ -851,13 +877,6 @@ void AvatarData::setClampedTargetScale(float targetScale) {
qDebug() << "Changed scale to " << _targetScale;
}
void AvatarData::setOrientation(const glm::quat& orientation) {
glm::vec3 eulerAngles = glm::degrees(safeEulerAngles(orientation));
_bodyPitch = eulerAngles.x;
_bodyYaw = eulerAngles.y;
_bodyRoll = eulerAngles.z;
}
void AvatarData::sendIdentityPacket() {
QByteArray identityPacket = byteArrayWithPopulatedHeader(PacketTypeAvatarIdentity);
identityPacket.append(identityByteArray());

View file

@ -144,7 +144,7 @@ public:
const QUuid& getSessionUUID() { return _sessionUUID; }
const glm::vec3& getPosition();
void setPosition(const glm::vec3 position) { _position = position; }
void setPosition(const glm::vec3 position, bool overideReferential = false);
glm::vec3 getHandPosition() const;
void setHandPosition(const glm::vec3& handPosition);
@ -167,8 +167,8 @@ public:
float getBodyRoll() const { return _bodyRoll; }
void setBodyRoll(float bodyRoll) { _bodyRoll = bodyRoll; }
glm::quat getOrientation() const { return glm::quat(glm::radians(glm::vec3(_bodyPitch, _bodyYaw, _bodyRoll))); }
void setOrientation(const glm::quat& orientation);
glm::quat getOrientation() const;
void setOrientation(const glm::quat& orientation, bool overideReferential = false);
glm::quat getHeadOrientation() const { return _headData->getOrientation(); }
void setHeadOrientation(const glm::quat& orientation) { _headData->setOrientation(orientation); }