bool LocationManager::goToDestination(QString destination) { QStringList coordinateItems = destination.remove(' ').split(QRegExp("_|,"), QString::SkipEmptyParts); const int NUMBER_OF_COORDINATE_ITEMS = 3; const int X_ITEM = 0; const int Y_ITEM = 1; const int Z_ITEM = 2; if (coordinateItems.size() == NUMBER_OF_COORDINATE_ITEMS) { // replace last occurrence of '_' with decimal point replaceLastOccurrence('-', '.', coordinateItems[X_ITEM]); replaceLastOccurrence('-', '.', coordinateItems[Y_ITEM]); replaceLastOccurrence('-', '.', coordinateItems[Z_ITEM]); double x = coordinateItems[X_ITEM].toDouble(); double y = coordinateItems[Y_ITEM].toDouble(); double z = coordinateItems[Z_ITEM].toDouble(); glm::vec3 newAvatarPos(x, y, z); MyAvatar* myAvatar = Application::getInstance()->getAvatar(); glm::vec3 avatarPos = myAvatar->getPosition(); if (newAvatarPos != avatarPos) { // send a node kill request, indicating to other clients that they should play the "disappeared" effect MyAvatar::sendKillAvatar(); qDebug("Going To Location: %f, %f, %f...", x, y, z); myAvatar->setPosition(newAvatarPos); emit myAvatar->transformChanged(); } return true; } // no coordinates were parsed return false; }
void LocationManager::goToOrientation(QString orientation) { if (orientation.isEmpty()) { return; } QStringList orientationItems = orientation.remove(' ').split(QRegExp("_|,"), QString::SkipEmptyParts); const int NUMBER_OF_ORIENTATION_ITEMS = 4; const int W_ITEM = 0; const int X_ITEM = 1; const int Y_ITEM = 2; const int Z_ITEM = 3; if (orientationItems.size() == NUMBER_OF_ORIENTATION_ITEMS) { // replace last occurrence of '_' with decimal point replaceLastOccurrence('-', '.', orientationItems[W_ITEM]); replaceLastOccurrence('-', '.', orientationItems[X_ITEM]); replaceLastOccurrence('-', '.', orientationItems[Y_ITEM]); replaceLastOccurrence('-', '.', orientationItems[Z_ITEM]); double w = orientationItems[W_ITEM].toDouble(); double x = orientationItems[X_ITEM].toDouble(); double y = orientationItems[Y_ITEM].toDouble(); double z = orientationItems[Z_ITEM].toDouble(); glm::quat newAvatarOrientation(w, x, y, z); MyAvatar* myAvatar = Application::getInstance()->getAvatar(); glm::quat avatarOrientation = myAvatar->getOrientation(); if (newAvatarOrientation != avatarOrientation) { myAvatar->setOrientation(newAvatarOrientation); emit myAvatar->transformChanged(); } } }