mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 17:41:12 +02:00
Merge pull request #3426 from birarda/master
don't prepend relative paths with hifi scheme, use quat for location orientation
This commit is contained in:
commit
47b061983f
6 changed files with 86 additions and 48 deletions
|
@ -1766,25 +1766,34 @@ void MyAvatar::resetSize() {
|
||||||
qDebug("Reseted scale to %f", _targetScale);
|
qDebug("Reseted scale to %f", _targetScale);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyAvatar::goToLocation(const glm::vec3& newPosition, bool hasOrientation, const glm::vec3& newOrientation) {
|
void MyAvatar::goToLocation(const glm::vec3& newPosition,
|
||||||
glm::quat quatOrientation = getOrientation();
|
bool hasOrientation, const glm::quat& newOrientation,
|
||||||
|
bool shouldFaceLocation) {
|
||||||
|
|
||||||
qDebug().nospace() << "MyAvatar goToLocation - moving to " << newPosition.x << ", "
|
qDebug().nospace() << "MyAvatar goToLocation - moving to " << newPosition.x << ", "
|
||||||
<< newPosition.y << ", " << newPosition.z;
|
<< newPosition.y << ", " << newPosition.z;
|
||||||
|
|
||||||
|
glm::vec3 shiftedPosition = newPosition;
|
||||||
|
|
||||||
if (hasOrientation) {
|
if (hasOrientation) {
|
||||||
qDebug().nospace() << "MyAvatar goToLocation - new orientation is "
|
qDebug().nospace() << "MyAvatar goToLocation - new orientation is "
|
||||||
<< newOrientation.x << ", " << newOrientation.y << ", " << newOrientation.z;
|
<< newOrientation.x << ", " << newOrientation.y << ", " << newOrientation.z << ", " << newOrientation.w;
|
||||||
|
|
||||||
// orient the user to face the target
|
// orient the user to face the target
|
||||||
glm::quat quatOrientation = glm::quat(glm::radians(newOrientation))
|
glm::quat quatOrientation = newOrientation;
|
||||||
* glm::angleAxis(PI, glm::vec3(0.0f, 1.0f, 0.0f));
|
|
||||||
|
if (shouldFaceLocation) {
|
||||||
|
|
||||||
|
quatOrientation = newOrientation * glm::angleAxis(PI, glm::vec3(0.0f, 1.0f, 0.0f));
|
||||||
|
|
||||||
|
// move the user a couple units away
|
||||||
|
const float DISTANCE_TO_USER = 2.0f;
|
||||||
|
shiftedPosition = newPosition - quatOrientation * IDENTITY_FRONT * DISTANCE_TO_USER;
|
||||||
|
}
|
||||||
|
|
||||||
setOrientation(quatOrientation);
|
setOrientation(quatOrientation);
|
||||||
}
|
}
|
||||||
|
|
||||||
// move the user a couple units away
|
|
||||||
const float DISTANCE_TO_USER = 2.0f;
|
|
||||||
glm::vec3 shiftedPosition = newPosition - quatOrientation * IDENTITY_FRONT * DISTANCE_TO_USER;
|
|
||||||
slamPosition(shiftedPosition);
|
slamPosition(shiftedPosition);
|
||||||
emit transformChanged();
|
emit transformChanged();
|
||||||
}
|
}
|
||||||
|
|
|
@ -154,7 +154,9 @@ public slots:
|
||||||
void decreaseSize();
|
void decreaseSize();
|
||||||
void resetSize();
|
void resetSize();
|
||||||
|
|
||||||
void goToLocation(const glm::vec3& newPosition, bool hasOrientation = false, const glm::vec3& newOrientation = glm::vec3());
|
void goToLocation(const glm::vec3& newPosition,
|
||||||
|
bool hasOrientation = false, const glm::quat& newOrientation = glm::quat(),
|
||||||
|
bool shouldFaceLocation = false);
|
||||||
|
|
||||||
// Set/Get update the thrust that will move the avatar around
|
// Set/Get update the thrust that will move the avatar around
|
||||||
void addThrust(glm::vec3 newThrust) { _thrust += newThrust; };
|
void addThrust(glm::vec3 newThrust) { _thrust += newThrust; };
|
||||||
|
|
|
@ -28,7 +28,7 @@ QString AddressManager::pathForPositionAndOrientation(const glm::vec3& position,
|
||||||
QString pathString = "/" + createByteArray(position);
|
QString pathString = "/" + createByteArray(position);
|
||||||
|
|
||||||
if (hasOrientation) {
|
if (hasOrientation) {
|
||||||
QString orientationString = createByteArray(glm::degrees(safeEulerAngles(orientation)));
|
QString orientationString = createByteArray(orientation);
|
||||||
pathString += "/" + orientationString;
|
pathString += "/" + orientationString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,25 +61,25 @@ bool AddressManager::handleUrl(const QUrl& lookupUrl) {
|
||||||
// 3. location string (posX,posY,posZ/eulerX,eulerY,eulerZ)
|
// 3. location string (posX,posY,posZ/eulerX,eulerY,eulerZ)
|
||||||
// 4. domain network address (IP or dns resolvable hostname)
|
// 4. domain network address (IP or dns resolvable hostname)
|
||||||
|
|
||||||
if (lookupUrl.isRelative()) {
|
// use our regex'ed helpers to figure out what we're supposed to do with this
|
||||||
// if this is a relative path then handle it as a relative viewpoint
|
if (!handleUsername(lookupUrl.authority())) {
|
||||||
handleRelativeViewpoint(lookupUrl.path());
|
// we're assuming this is either a network address or global place name
|
||||||
} else {
|
// check if it is a network address first
|
||||||
// use our regex'ed helpers to figure out what we're supposed to do with this
|
if (!handleNetworkAddress(lookupUrl.host())) {
|
||||||
if (!handleUsername(lookupUrl.authority())) {
|
// wasn't an address - lookup the place name
|
||||||
// we're assuming this is either a network address or global place name
|
attemptPlaceNameLookup(lookupUrl.host());
|
||||||
// check if it is a network address first
|
|
||||||
if (!handleNetworkAddress(lookupUrl.host())) {
|
|
||||||
// wasn't an address - lookup the place name
|
|
||||||
attemptPlaceNameLookup(lookupUrl.host());
|
|
||||||
}
|
|
||||||
|
|
||||||
// we may have a path that defines a relative viewpoint - if so we should jump to that now
|
|
||||||
handleRelativeViewpoint(lookupUrl.path());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// we may have a path that defines a relative viewpoint - if so we should jump to that now
|
||||||
|
handleRelativeViewpoint(lookupUrl.path());
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
} else if (lookupUrl.toString().startsWith('/')) {
|
||||||
|
qDebug() << "Going to relative path" << lookupUrl.path();
|
||||||
|
|
||||||
|
// if this is a relative path then handle it as a relative viewpoint
|
||||||
|
handleRelativeViewpoint(lookupUrl.path());
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -89,10 +89,18 @@ void AddressManager::handleLookupString(const QString& lookupString) {
|
||||||
if (!lookupString.isEmpty()) {
|
if (!lookupString.isEmpty()) {
|
||||||
// make this a valid hifi URL and handle it off to handleUrl
|
// make this a valid hifi URL and handle it off to handleUrl
|
||||||
QString sanitizedString = lookupString;
|
QString sanitizedString = lookupString;
|
||||||
const QRegExp HIFI_SCHEME_REGEX = QRegExp(HIFI_URL_SCHEME + ":\\/{1,2}", Qt::CaseInsensitive);
|
QUrl lookupURL;
|
||||||
sanitizedString = sanitizedString.remove(HIFI_SCHEME_REGEX);
|
|
||||||
|
|
||||||
handleUrl(QUrl(HIFI_URL_SCHEME + "://" + sanitizedString));
|
if (!lookupString.startsWith('/')) {
|
||||||
|
const QRegExp HIFI_SCHEME_REGEX = QRegExp(HIFI_URL_SCHEME + ":\\/{1,2}", Qt::CaseInsensitive);
|
||||||
|
sanitizedString = sanitizedString.remove(HIFI_SCHEME_REGEX);
|
||||||
|
|
||||||
|
lookupURL = QUrl(HIFI_URL_SCHEME + "://" + sanitizedString);
|
||||||
|
} else {
|
||||||
|
lookupURL = QUrl(lookupString);
|
||||||
|
}
|
||||||
|
|
||||||
|
handleUrl(lookupURL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,9 +132,11 @@ void AddressManager::handleAPIResponse(const QJsonObject &jsonObject) {
|
||||||
returnedPath = domainObject[LOCATION_KEY].toObject()[LOCATION_PATH_KEY].toString();
|
returnedPath = domainObject[LOCATION_KEY].toObject()[LOCATION_PATH_KEY].toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool shouldFaceViewpoint = dataObject.contains(ADDRESS_API_ONLINE_KEY);
|
||||||
|
|
||||||
if (!returnedPath.isEmpty()) {
|
if (!returnedPath.isEmpty()) {
|
||||||
// try to parse this returned path as a viewpoint, that's the only thing it could be for now
|
// try to parse this returned path as a viewpoint, that's the only thing it could be for now
|
||||||
if (!handleRelativeViewpoint(returnedPath)) {
|
if (!handleRelativeViewpoint(returnedPath, shouldFaceViewpoint)) {
|
||||||
qDebug() << "Received a location path that was could not be handled as a viewpoint -" << returnedPath;
|
qDebug() << "Received a location path that was could not be handled as a viewpoint -" << returnedPath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -183,38 +193,47 @@ bool AddressManager::handleNetworkAddress(const QString& lookupString) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AddressManager::handleRelativeViewpoint(const QString& lookupString) {
|
bool AddressManager::handleRelativeViewpoint(const QString& lookupString, bool shouldFace) {
|
||||||
const QString FLOAT_REGEX_STRING = "([-+]?[0-9]*\\.?[0-9]+(?:[eE][-+]?[0-9]+)?)";
|
const QString FLOAT_REGEX_STRING = "([-+]?[0-9]*\\.?[0-9]+(?:[eE][-+]?[0-9]+)?)";
|
||||||
const QString TRIPLE_FLOAT_REGEX_STRING = QString("\\/") + FLOAT_REGEX_STRING + "\\s*,\\s*" +
|
const QString SPACED_COMMA_REGEX_STRING = "\\s*,\\s*";
|
||||||
FLOAT_REGEX_STRING + "\\s*,\\s*" + FLOAT_REGEX_STRING + "\\s*(?:$|\\/)";
|
const QString POSITION_REGEX_STRING = QString("\\/") + FLOAT_REGEX_STRING + SPACED_COMMA_REGEX_STRING +
|
||||||
|
FLOAT_REGEX_STRING + SPACED_COMMA_REGEX_STRING + FLOAT_REGEX_STRING + "\\s*(?:$|\\/)";
|
||||||
|
const QString QUAT_REGEX_STRING = QString("\\/") + FLOAT_REGEX_STRING + SPACED_COMMA_REGEX_STRING +
|
||||||
|
FLOAT_REGEX_STRING + SPACED_COMMA_REGEX_STRING + FLOAT_REGEX_STRING + SPACED_COMMA_REGEX_STRING +
|
||||||
|
FLOAT_REGEX_STRING + "\\s*$";
|
||||||
|
|
||||||
QRegExp tripleFloatRegex(TRIPLE_FLOAT_REGEX_STRING);
|
QRegExp positionRegex(POSITION_REGEX_STRING);
|
||||||
|
|
||||||
if (tripleFloatRegex.indexIn(lookupString) != -1) {
|
if (positionRegex.indexIn(lookupString) != -1) {
|
||||||
// we have at least a position, so emit our signal to say we need to change position
|
// we have at least a position, so emit our signal to say we need to change position
|
||||||
glm::vec3 newPosition(tripleFloatRegex.cap(1).toFloat(),
|
glm::vec3 newPosition(positionRegex.cap(1).toFloat(),
|
||||||
tripleFloatRegex.cap(2).toFloat(),
|
positionRegex.cap(2).toFloat(),
|
||||||
tripleFloatRegex.cap(3).toFloat());
|
positionRegex.cap(3).toFloat());
|
||||||
|
|
||||||
if (!isNaN(newPosition.x) && !isNaN(newPosition.y) && !isNaN(newPosition.z)) {
|
if (!isNaN(newPosition.x) && !isNaN(newPosition.y) && !isNaN(newPosition.z)) {
|
||||||
glm::vec3 newOrientation;
|
glm::quat newOrientation;
|
||||||
|
|
||||||
|
QRegExp orientationRegex(QUAT_REGEX_STRING);
|
||||||
|
|
||||||
// we may also have an orientation
|
// we may also have an orientation
|
||||||
if (lookupString[tripleFloatRegex.matchedLength() - 1] == QChar('/')
|
if (lookupString[positionRegex.matchedLength() - 1] == QChar('/')
|
||||||
&& tripleFloatRegex.indexIn(lookupString, tripleFloatRegex.matchedLength() - 1) != -1) {
|
&& orientationRegex.indexIn(lookupString, positionRegex.matchedLength() - 1) != -1) {
|
||||||
|
|
||||||
glm::vec3 newOrientation(tripleFloatRegex.cap(1).toFloat(),
|
glm::quat newOrientation = glm::normalize(glm::quat(orientationRegex.cap(4).toFloat(),
|
||||||
tripleFloatRegex.cap(2).toFloat(),
|
orientationRegex.cap(1).toFloat(),
|
||||||
tripleFloatRegex.cap(3).toFloat());
|
orientationRegex.cap(2).toFloat(),
|
||||||
|
orientationRegex.cap(3).toFloat()));
|
||||||
|
|
||||||
if (!isNaN(newOrientation.x) && !isNaN(newOrientation.y) && !isNaN(newOrientation.z)) {
|
if (!isNaN(newOrientation.x) && !isNaN(newOrientation.y) && !isNaN(newOrientation.z)
|
||||||
emit locationChangeRequired(newPosition, true, newOrientation);
|
&& !isNaN(newOrientation.w)) {
|
||||||
|
emit locationChangeRequired(newPosition, true, newOrientation, shouldFace);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "Orientation parsed from lookup string is invalid. Will not use for location change.";
|
qDebug() << "Orientation parsed from lookup string is invalid. Will not use for location change.";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
emit locationChangeRequired(newPosition, false, newOrientation);
|
emit locationChangeRequired(newPosition, false, newOrientation, shouldFace);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "Could not jump to position from lookup string because it has an invalid value.";
|
qDebug() << "Could not jump to position from lookup string because it has an invalid value.";
|
||||||
|
|
|
@ -40,14 +40,16 @@ signals:
|
||||||
void lookupResultIsOffline();
|
void lookupResultIsOffline();
|
||||||
void lookupResultIsNotFound();
|
void lookupResultIsNotFound();
|
||||||
void possibleDomainChangeRequired(const QString& newHostname);
|
void possibleDomainChangeRequired(const QString& newHostname);
|
||||||
void locationChangeRequired(const glm::vec3& newPosition, bool hasOrientationChange, const glm::vec3& newOrientation);
|
void locationChangeRequired(const glm::vec3& newPosition,
|
||||||
|
bool hasOrientationChange, const glm::quat& newOrientation,
|
||||||
|
bool shouldFaceLocation);
|
||||||
private:
|
private:
|
||||||
const JSONCallbackParameters& apiCallbackParameters();
|
const JSONCallbackParameters& apiCallbackParameters();
|
||||||
|
|
||||||
bool handleUrl(const QUrl& lookupUrl);
|
bool handleUrl(const QUrl& lookupUrl);
|
||||||
|
|
||||||
bool handleNetworkAddress(const QString& lookupString);
|
bool handleNetworkAddress(const QString& lookupString);
|
||||||
bool handleRelativeViewpoint(const QString& pathSubsection);
|
bool handleRelativeViewpoint(const QString& pathSubsection, bool shouldFace = false);
|
||||||
bool handleUsername(const QString& lookupString);
|
bool handleUsername(const QString& lookupString);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -284,6 +284,11 @@ QByteArray createByteArray(const glm::vec3& vector) {
|
||||||
return QByteArray::number(vector.x) + ',' + QByteArray::number(vector.y) + ',' + QByteArray::number(vector.z);
|
return QByteArray::number(vector.x) + ',' + QByteArray::number(vector.y) + ',' + QByteArray::number(vector.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QByteArray createByteArray(const glm::quat& quat) {
|
||||||
|
return QByteArray::number(quat.x) + ',' + QByteArray::number(quat.y) + "," + QByteArray::number(quat.z) + ","
|
||||||
|
+ QByteArray::number(quat.w);
|
||||||
|
}
|
||||||
|
|
||||||
bool isSimilarOrientation(const glm::quat& orientionA, const glm::quat& orientionB, float similarEnough) {
|
bool isSimilarOrientation(const glm::quat& orientionA, const glm::quat& orientionB, float similarEnough) {
|
||||||
// Compute the angular distance between the two orientations
|
// Compute the angular distance between the two orientations
|
||||||
float angleOrientation = orientionA == orientionB ? 0.0f : glm::degrees(glm::angle(orientionA * glm::inverse(orientionB)));
|
float angleOrientation = orientionA == orientionB ? 0.0f : glm::degrees(glm::angle(orientionA * glm::inverse(orientionB)));
|
||||||
|
|
|
@ -77,6 +77,7 @@ float extractUniformScale(const glm::mat4& matrix);
|
||||||
float extractUniformScale(const glm::vec3& scale);
|
float extractUniformScale(const glm::vec3& scale);
|
||||||
|
|
||||||
QByteArray createByteArray(const glm::vec3& vector);
|
QByteArray createByteArray(const glm::vec3& vector);
|
||||||
|
QByteArray createByteArray(const glm::quat& quat);
|
||||||
|
|
||||||
/// \return bool are two orientations similar to each other
|
/// \return bool are two orientations similar to each other
|
||||||
const float ORIENTATION_SIMILAR_ENOUGH = 5.0f; // 10 degrees in any direction
|
const float ORIENTATION_SIMILAR_ENOUGH = 5.0f; // 10 degrees in any direction
|
||||||
|
|
Loading…
Reference in a new issue