This commit is contained in:
Philip Rosedale 2014-01-13 14:17:40 -08:00
commit c78f4184df
6 changed files with 53 additions and 12 deletions

View file

@ -1347,8 +1347,9 @@ void Application::timer() {
// ask the node list to check in with the domain server
NodeList::getInstance()->sendDomainServerCheckIn();
// give the MyAvatar object position to the Profile so it can propagate to the data-server
// give the MyAvatar object position, orientation to the Profile so it can propagate to the data-server
_profile.updatePosition(_myAvatar.getPosition());
_profile.updateOrientation(_myAvatar.getOrientation());
}
static glm::vec3 getFaceVector(BoxFace face) {

View file

@ -175,25 +175,35 @@ void DataServerClient::processSendFromDataServer(unsigned char* packetData, int
}
}
}
} else if (keyList[i] == DataServerKey::Domain && keyList[i + 1] == DataServerKey::Position
&& valueList[i] != " " && valueList[i + 1] != " ") {
} else if (keyList[i] == DataServerKey::Domain && keyList[i + 1] == DataServerKey::Position &&
keyList[i + 2] == DataServerKey::Orientation && valueList[i] != " " &&
valueList[i + 1] != " " && valueList[i + 2] != " ") {
QStringList coordinateItems = valueList[i + 1].split(',');
QStringList orientationItems = valueList[i + 2].split(',');
if (coordinateItems.size() == 3) {
if (coordinateItems.size() == 3 && orientationItems.size() == 3) {
// send a node kill request, indicating to other clients that they should play the "disappeared" effect
NodeList::getInstance()->sendKillNode(&NODE_TYPE_AVATAR_MIXER, 1);
qDebug() << "Changing domain to" << valueList[i].toLocal8Bit().constData() <<
"and position to" << valueList[i + 1].toLocal8Bit().constData() <<
", position to" << valueList[i + 1].toLocal8Bit().constData() <<
", and orientation to" << valueList[i + 2].toLocal8Bit().constData() <<
"to go to" << userString << "\n";
NodeList::getInstance()->setDomainHostname(valueList[i]);
glm::vec3 newPosition(coordinateItems[0].toFloat(),
coordinateItems[1].toFloat(),
coordinateItems[2].toFloat());
// orient the user to face the target
glm::quat newOrientation = glm::quat(glm::radians(glm::vec3(orientationItems[0].toFloat(),
orientationItems[1].toFloat(), orientationItems[2].toFloat()))) *
glm::angleAxis(180.0f, 0.0f, 1.0f, 0.0f);
Application::getInstance()->getAvatar()->setOrientation(newOrientation);
// move the user a couple units away
const float DISTANCE_TO_USER = 2.0f;
glm::vec3 newPosition = glm::vec3(coordinateItems[0].toFloat(), coordinateItems[1].toFloat(),
coordinateItems[2].toFloat()) - newOrientation * IDENTITY_FRONT * DISTANCE_TO_USER;
Application::getInstance()->getAvatar()->setPosition(newPosition);
}

View file

@ -41,6 +41,7 @@ namespace DataServerKey {
const QString FaceMeshURL = "mesh";
const QString SkeletonURL = "skeleton";
const QString Position = "position";
const QString Orientation = "orientation";
const QString UUID = "uuid";
}

View file

@ -999,8 +999,9 @@ void Menu::goToUser() {
int dialogReturn = userDialog.exec();
if (dialogReturn == QDialog::Accepted && !userDialog.textValue().isEmpty()) {
// there's a username entered by the user, make a request to the data-server
DataServerClient::getValuesForKeysAndUserString((QStringList() << DataServerKey::Domain << DataServerKey::Position),
userDialog.textValue());
DataServerClient::getValuesForKeysAndUserString(
QStringList() << DataServerKey::Domain << DataServerKey::Position << DataServerKey::Orientation,
userDialog.textValue());
}
sendFakeEnterEvent();

View file

@ -18,6 +18,7 @@ Profile::Profile(const QString &username) :
_uuid(),
_lastDomain(),
_lastPosition(0.0, 0.0, 0.0),
_lastOrientationSend(0),
_faceModelURL()
{
if (!_username.isEmpty()) {
@ -69,6 +70,10 @@ void Profile::updateDomain(const QString& domain) {
}
}
static QByteArray createByteArray(const glm::vec3& vector) {
return QByteArray::number(vector.x) + ',' + QByteArray::number(vector.y) + ',' + QByteArray::number(vector.z);
}
void Profile::updatePosition(const glm::vec3 position) {
if (_lastPosition != position) {
@ -90,12 +95,29 @@ void Profile::updatePosition(const glm::vec3 position) {
gettimeofday(&lastPositionSend, NULL);
// send the changed position to the data-server
QString positionString = QString("%1,%2,%3").arg(position.x).arg(position.y).arg(position.z);
DataServerClient::putValueForKey(DataServerKey::Position, positionString.toLocal8Bit().constData());
DataServerClient::putValueForKey(DataServerKey::Position, createByteArray(position).constData());
}
}
}
void Profile::updateOrientation(const glm::quat& orientation) {
glm::vec3 eulerAngles = safeEulerAngles(orientation);
if (_lastOrientation == eulerAngles) {
return;
}
const uint64_t DATA_SERVER_ORIENTATION_UPDATE_INTERVAL_USECS = 5 * 1000 * 1000;
const float DATA_SERVER_ORIENTATION_CHANGE_THRESHOLD_DEGREES = 5.0f;
uint64_t now = usecTimestampNow();
if (now - _lastOrientationSend >= DATA_SERVER_ORIENTATION_UPDATE_INTERVAL_USECS &&
glm::distance(_lastOrientation, eulerAngles) >= DATA_SERVER_ORIENTATION_CHANGE_THRESHOLD_DEGREES) {
DataServerClient::putValueForKey(DataServerKey::Orientation, createByteArray(eulerAngles).constData());
_lastOrientation = eulerAngles;
_lastOrientationSend = now;
}
}
void Profile::saveData(QSettings* settings) {
settings->beginGroup("Profile");

View file

@ -9,11 +9,14 @@
#ifndef __hifi__Profile__
#define __hifi__Profile__
#include <stdint.h>
#include <QtCore/QString>
#include <QtCore/QUrl>
#include <QtCore/QUuid>
#include <glm/glm.hpp>
#include <glm/gtc/quaternion.hpp>
class Profile {
public:
@ -34,6 +37,7 @@ public:
void updateDomain(const QString& domain);
void updatePosition(const glm::vec3 position);
void updateOrientation(const glm::quat& orientation);
QString getLastDomain() const { return _lastDomain; }
const glm::vec3& getLastPosition() const { return _lastPosition; }
@ -45,6 +49,8 @@ private:
QUuid _uuid;
QString _lastDomain;
glm::vec3 _lastPosition;
glm::vec3 _lastOrientation;
uint64_t _lastOrientationSend;
QUrl _faceModelURL;
QUrl _skeletonModelURL;
};