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