mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-04-10 02:44:34 +02:00
get avatars in range
This commit is contained in:
parent
f3918ad216
commit
ff0b632978
2 changed files with 16 additions and 0 deletions
|
@ -30,6 +30,20 @@ QVector<QUuid> AvatarHashMap::getAvatarIdentifiers() {
|
|||
return _avatarHash.keys().toVector();
|
||||
}
|
||||
|
||||
QVector<QUuid> AvatarHashMap::getAvatarsInRange(const glm::vec3& position, float rangeMeters) const {
|
||||
auto hashCopy = getHashCopy();
|
||||
QVector<QUuid> avatarsInRange;
|
||||
auto rangeMeters2 = rangeMeters * rangeMeters;
|
||||
for (const AvatarSharedPointer& sharedAvatar : hashCopy) {
|
||||
glm::vec3 avatarPosition = sharedAvatar->getWorldPosition();
|
||||
auto distance2 = glm::distance2(avatarPosition, position);
|
||||
if (distance2 < rangeMeters2) {
|
||||
avatarsInRange.push_back(sharedAvatar->getSessionUUID());
|
||||
}
|
||||
}
|
||||
return avatarsInRange;
|
||||
}
|
||||
|
||||
bool AvatarHashMap::isAvatarInRange(const glm::vec3& position, const float range) {
|
||||
auto hashCopy = getHashCopy();
|
||||
foreach(const AvatarSharedPointer& sharedAvatar, hashCopy) {
|
||||
|
|
|
@ -35,10 +35,12 @@ class AvatarHashMap : public QObject, public Dependency {
|
|||
|
||||
public:
|
||||
AvatarHash getHashCopy() { QReadLocker lock(&_hashLock); return _avatarHash; }
|
||||
const AvatarHash getHashCopy() const { QReadLocker lock(&_hashLock); return _avatarHash; }
|
||||
int size() { return _avatarHash.size(); }
|
||||
|
||||
// Currently, your own avatar will be included as the null avatar id.
|
||||
Q_INVOKABLE QVector<QUuid> getAvatarIdentifiers();
|
||||
Q_INVOKABLE QVector<QUuid> getAvatarsInRange(const glm::vec3& position, float rangeMeters) const;
|
||||
|
||||
// Null/Default-constructed QUuids will return MyAvatar
|
||||
Q_INVOKABLE virtual ScriptAvatarData* getAvatar(QUuid avatarID) { return new ScriptAvatarData(getAvatarBySessionID(avatarID)); }
|
||||
|
|
Loading…
Reference in a new issue