Merge branch 'master' of git://github.com/worklist/hifi into windows_build

Conflicts:
	interface/src/DataServerClient.cpp
	interface/src/avatar/MyAvatar.cpp
	libraries/avatars/src/AvatarData.h
This commit is contained in:
Brad Hefta-Gaub 2014-01-13 15:06:26 -08:00
commit 392ff94ebe
11 changed files with 94 additions and 52 deletions

View file

@ -259,3 +259,4 @@ INSTALL(TARGETS ${TARGET_NAME}
BUNDLE DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/install COMPONENT Runtime BUNDLE DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/install COMPONENT Runtime
RUNTIME DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/install COMPONENT Runtime RUNTIME DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/install COMPONENT Runtime
) )

View file

@ -1352,8 +1352,9 @@ void Application::timer() {
// ask the node list to check in with the domain server // ask the node list to check in with the domain server
NodeList::getInstance()->sendDomainServerCheckIn(); 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.updatePosition(_myAvatar.getPosition());
_profile.updateOrientation(_myAvatar.getOrientation());
} }
static glm::vec3 getFaceVector(BoxFace face) { static glm::vec3 getFaceVector(BoxFace face) {
@ -2133,9 +2134,12 @@ void Application::updateAvatars(float deltaTime, glm::vec3 mouseRayOrigin, glm::
for (vector<Avatar*>::iterator fade = _avatarFades.begin(); fade != _avatarFades.end(); fade++) { for (vector<Avatar*>::iterator fade = _avatarFades.begin(); fade != _avatarFades.end(); fade++) {
Avatar* avatar = *fade; Avatar* avatar = *fade;
const float SHRINK_RATE = 0.9f; const float SHRINK_RATE = 0.9f;
avatar->setNewScale(avatar->getNewScale() * SHRINK_RATE);
const float MINIMUM_SCALE = 0.001f; avatar->setTargetScale(avatar->getScale() * SHRINK_RATE);
if (avatar->getNewScale() < MINIMUM_SCALE) {
const float MIN_FADE_SCALE = 0.001;
if (avatar->getTargetScale() < MIN_FADE_SCALE) {
delete avatar; delete avatar;
_avatarFades.erase(fade--); _avatarFades.erase(fade--);

View file

@ -175,25 +175,34 @@ void DataServerClient::processSendFromDataServer(unsigned char* packetData, int
} }
} }
} }
} else if (keyList[i] == DataServerKey::Domain && keyList[i + 1] == DataServerKey::Position } else if (keyList[i] == DataServerKey::Domain && keyList[i + 1] == DataServerKey::Position &&
&& valueList[i] != " " && valueList[i + 1] != " ") { keyList[i + 2] == DataServerKey::Orientation && valueList[i] != " " &&
valueList[i + 1] != " " && valueList[i + 2] != " ") {
QStringList coordinateItems = valueList[i + 1].split(','); 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 // send a node kill request, indicating to other clients that they should play the "disappeared" effect
NodeList::getInstance()->sendKillNode(&NODE_TYPE_AVATAR_MIXER, 1); NodeList::getInstance()->sendKillNode(&NODE_TYPE_AVATAR_MIXER, 1);
qDebug() << "Changing domain to" << valueList[i].toLocal8Bit().constData() << 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"; "to go to" << userString << "\n";
NodeList::getInstance()->setDomainHostname(valueList[i]); NodeList::getInstance()->setDomainHostname(valueList[i]);
// 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);
glm::vec3 newPosition(coordinateItems[0].toFloat(), // move the user a couple units away
coordinateItems[1].toFloat(), const float DISTANCE_TO_USER = 2.0f;
coordinateItems[2].toFloat()); 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); Application::getInstance()->getAvatar()->setPosition(newPosition);
} }

View file

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

View file

@ -897,7 +897,7 @@ void Menu::editPreferences() {
_maxVoxelPacketsPerSecond = maxVoxelsPPS->value(); _maxVoxelPacketsPerSecond = maxVoxelsPPS->value();
applicationInstance->getAvatar()->setLeanScale(leanScale->value()); applicationInstance->getAvatar()->setLeanScale(leanScale->value());
applicationInstance->getAvatar()->setNewScale(avatarScale->value()); applicationInstance->getAvatar()->setClampedTargetScale(avatarScale->value());
_audioJitterBufferSamples = audioJitterBufferSamples->value(); _audioJitterBufferSamples = audioJitterBufferSamples->value();
@ -1005,8 +1005,9 @@ void Menu::goToUser() {
int dialogReturn = userDialog.exec(); int dialogReturn = userDialog.exec();
if (dialogReturn == QDialog::Accepted && !userDialog.textValue().isEmpty()) { if (dialogReturn == QDialog::Accepted && !userDialog.textValue().isEmpty()) {
// there's a username entered by the user, make a request to the data-server // there's a username entered by the user, make a request to the data-server
DataServerClient::getValuesForKeysAndUserString((QStringList() << DataServerKey::Domain << DataServerKey::Position), DataServerClient::getValuesForKeysAndUserString(
userDialog.textValue()); QStringList() << DataServerKey::Domain << DataServerKey::Position << DataServerKey::Orientation,
userDialog.textValue());
} }
sendFakeEnterEvent(); sendFakeEnterEvent();

View file

@ -167,8 +167,8 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
follow(NULL); follow(NULL);
} }
if (_scale != _newScale) { if (_scale != _targetScale) {
setScale(_newScale); setScale(_targetScale);
} }
// copy velocity so we can use it later for acceleration // copy velocity so we can use it later for acceleration
@ -439,30 +439,30 @@ void Avatar::goHome() {
} }
void Avatar::increaseSize() { void Avatar::increaseSize() {
if ((1.f + SCALING_RATIO) * _newScale < MAX_SCALE) { if ((1.f + SCALING_RATIO) * _targetScale < MAX_AVATAR_SCALE) {
_newScale *= (1.f + SCALING_RATIO); _targetScale *= (1.f + SCALING_RATIO);
qDebug("Changed scale to %f\n", _newScale); qDebug("Changed scale to %f\n", _targetScale);
} }
} }
void Avatar::decreaseSize() { void Avatar::decreaseSize() {
if (MIN_SCALE < (1.f - SCALING_RATIO) * _newScale) { if (MIN_AVATAR_SCALE < (1.f - SCALING_RATIO) * _targetScale) {
_newScale *= (1.f - SCALING_RATIO); _targetScale *= (1.f - SCALING_RATIO);
qDebug("Changed scale to %f\n", _newScale); qDebug("Changed scale to %f\n", _targetScale);
} }
} }
void Avatar::resetSize() { void Avatar::resetSize() {
_newScale = 1.0f; _targetScale = 1.0f;
qDebug("Reseted scale to %f\n", _newScale); qDebug("Reseted scale to %f\n", _targetScale);
} }
void Avatar::setScale(const float scale) { void Avatar::setScale(const float scale) {
_scale = scale; _scale = scale;
if (_newScale * (1.f - RESCALING_TOLERANCE) < _scale && if (_targetScale * (1.f - RESCALING_TOLERANCE) < _scale &&
_scale < _newScale * (1.f + RESCALING_TOLERANCE)) { _scale < _targetScale * (1.f + RESCALING_TOLERANCE)) {
_scale = _newScale; _scale = _targetScale;
} }
_skeleton.setScale(_scale); _skeleton.setScale(_scale);

View file

@ -93,12 +93,12 @@ void MyAvatar::simulate(float deltaTime, Transmitter* transmitter) {
} }
// Ajust, scale, position and lookAt position when following an other avatar // Ajust, scale, position and lookAt position when following an other avatar
if (_leadingAvatar && _newScale != _leadingAvatar->getScale()) { if (_leadingAvatar && _targetScale != _leadingAvatar->getScale()) {
_newScale = _leadingAvatar->getScale(); _targetScale = _leadingAvatar->getScale();
} }
if (_scale != _newScale) { if (_scale != _targetScale) {
float scale = (1.f - SMOOTHING_RATIO) * _scale + SMOOTHING_RATIO * _newScale; float scale = (1.f - SMOOTHING_RATIO) * _scale + SMOOTHING_RATIO * _targetScale;
setScale(scale); setScale(scale);
Application::getInstance()->getCamera()->setScale(scale); Application::getInstance()->getCamera()->setScale(scale);
} }
@ -514,7 +514,7 @@ void MyAvatar::saveData(QSettings* settings) {
settings->setValue("pupilDilation", _head.getPupilDilation()); settings->setValue("pupilDilation", _head.getPupilDilation());
settings->setValue("leanScale", _leanScale); settings->setValue("leanScale", _leanScale);
settings->setValue("scale", _newScale); settings->setValue("scale", _targetScale);
settings->endGroup(); settings->endGroup();
} }
@ -536,8 +536,7 @@ void MyAvatar::loadData(QSettings* settings) {
_head.setPupilDilation(settings->value("pupilDilation", 0.0f).toFloat()); _head.setPupilDilation(settings->value("pupilDilation", 0.0f).toFloat());
_leanScale = loadSetting(settings, "leanScale", 0.05f); _leanScale = loadSetting(settings, "leanScale", 0.05f);
_targetScale = loadSetting(settings, "scale", 1.0f);
_newScale = loadSetting(settings, "scale", 1.0f);
setScale(_scale); setScale(_scale);
Application::getInstance()->getCamera()->setScale(_scale); Application::getInstance()->getCamera()->setScale(_scale);

View file

@ -18,6 +18,7 @@ Profile::Profile(const QString &username) :
_uuid(), _uuid(),
_lastDomain(), _lastDomain(),
_lastPosition(0.0, 0.0, 0.0), _lastPosition(0.0, 0.0, 0.0),
_lastOrientationSend(0),
_faceModelURL() _faceModelURL()
{ {
if (!_username.isEmpty()) { 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) { void Profile::updatePosition(const glm::vec3 position) {
if (_lastPosition != position) { if (_lastPosition != position) {
@ -90,12 +95,29 @@ void Profile::updatePosition(const glm::vec3 position) {
gettimeofday(&lastPositionSend, NULL); gettimeofday(&lastPositionSend, NULL);
// send the changed position to the data-server // 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, createByteArray(position).constData());
DataServerClient::putValueForKey(DataServerKey::Position, positionString.toLocal8Bit().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) { void Profile::saveData(QSettings* settings) {
settings->beginGroup("Profile"); settings->beginGroup("Profile");

View file

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

View file

@ -29,7 +29,7 @@ AvatarData::AvatarData(Node* owningNode) :
_bodyYaw(-90.0), _bodyYaw(-90.0),
_bodyPitch(0.0), _bodyPitch(0.0),
_bodyRoll(0.0), _bodyRoll(0.0),
_newScale(1.0f), _targetScale(1.0f),
_leaderUUID(), _leaderUUID(),
_handState(0), _handState(0),
_keyState(NO_KEY_DOWN), _keyState(NO_KEY_DOWN),
@ -76,7 +76,7 @@ int AvatarData::getBroadcastData(unsigned char* destinationBuffer) {
destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _bodyRoll); destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _bodyRoll);
// Body scale // Body scale
destinationBuffer += packFloatRatioToTwoByte(destinationBuffer, _newScale); destinationBuffer += packFloatRatioToTwoByte(destinationBuffer, _targetScale);
// Follow mode info // Follow mode info
memcpy(destinationBuffer, _leaderUUID.toRfc4122().constData(), NUM_BYTES_RFC4122_UUID); memcpy(destinationBuffer, _leaderUUID.toRfc4122().constData(), NUM_BYTES_RFC4122_UUID);
@ -198,7 +198,7 @@ int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) {
sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t*) sourceBuffer, &_bodyRoll); sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t*) sourceBuffer, &_bodyRoll);
// Body scale // Body scale
sourceBuffer += unpackFloatRatioFromTwoByte(sourceBuffer, _newScale); sourceBuffer += unpackFloatRatioFromTwoByte(sourceBuffer, _targetScale);
// Follow mode info // Follow mode info
_leaderUUID = QUuid::fromRfc4122(QByteArray((char*) sourceBuffer, NUM_BYTES_RFC4122_UUID)); _leaderUUID = QUuid::fromRfc4122(QByteArray((char*) sourceBuffer, NUM_BYTES_RFC4122_UUID));
@ -296,12 +296,10 @@ int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) {
return sourceBuffer - startPosition; return sourceBuffer - startPosition;
} }
void AvatarData::setNewScale(float newScale) { void AvatarData::setClampedTargetScale(float targetScale) {
if (newScale > MAX_SCALE) {
newScale = MAX_SCALE; targetScale = glm::clamp(targetScale, MIN_AVATAR_SCALE, MAX_AVATAR_SCALE);
} else if (newScale < MIN_SCALE) {
newScale = MIN_SCALE; _targetScale = targetScale;
} qDebug() << "Changed scale to " << _targetScale << "\n";
_newScale = newScale;
qDebug() << "Changed scale to " << _newScale << "\n";
} }

View file

@ -45,8 +45,8 @@ const int HAND_STATE_START_BIT = 2; // 3rd and 4th bits
const int IS_FACESHIFT_CONNECTED = 4; // 5th bit const int IS_FACESHIFT_CONNECTED = 4; // 5th bit
const int IS_CHAT_CIRCLING_ENABLED = 5; const int IS_CHAT_CIRCLING_ENABLED = 5;
static const float MAX_SCALE = 1000.f; static const float MAX_AVATAR_SCALE = 1000.f;
static const float MIN_SCALE = .005f; static const float MIN_AVATAR_SCALE = .005f;
const float MAX_AUDIO_LOUDNESS = 1000.0; // close enough for mouth animation const float MAX_AUDIO_LOUDNESS = 1000.0; // close enough for mouth animation
@ -95,8 +95,9 @@ public:
void setBodyRoll(float bodyRoll) { _bodyRoll = bodyRoll; } void setBodyRoll(float bodyRoll) { _bodyRoll = bodyRoll; }
// Scale // Scale
float getNewScale() const { return _newScale; } float getTargetScale() const { return _targetScale; }
void setNewScale(float); void setTargetScale(float targetScale) { _targetScale = targetScale; }
void setClampedTargetScale(float targetScale);
// Hand State // Hand State
void setHandState(char s) { _handState = s; } void setHandState(char s) { _handState = s; }
@ -145,7 +146,7 @@ protected:
float _bodyRoll; float _bodyRoll;
// Body scale // Body scale
float _newScale; float _targetScale;
// Following mode infos // Following mode infos
QUuid _leaderUUID; QUuid _leaderUUID;