mirror of
https://github.com/AleziaKurdis/overte.git
synced 2025-04-07 13:12:39 +02:00
EntityTree::findClosestEntity() now takes meters
This commit is contained in:
parent
9ad88c3793
commit
93c77d557a
5 changed files with 24 additions and 29 deletions
|
@ -180,8 +180,7 @@ EntityItemID EntityScriptingInterface::findClosestEntity(const glm::vec3& center
|
|||
EntityItemID result(UNKNOWN_ENTITY_ID, UNKNOWN_ENTITY_TOKEN, false);
|
||||
if (_entityTree) {
|
||||
_entityTree->lockForRead();
|
||||
const EntityItem* closestEntity = _entityTree->findClosestEntity(center/(float)TREE_SCALE,
|
||||
radius/(float)TREE_SCALE);
|
||||
const EntityItem* closestEntity = _entityTree->findClosestEntity(center, radius);
|
||||
_entityTree->unlock();
|
||||
if (closestEntity) {
|
||||
result.id = closestEntity->getID();
|
||||
|
|
|
@ -456,7 +456,8 @@ bool EntityTree::findNearPointOperation(OctreeElement* element, void* extraData)
|
|||
}
|
||||
|
||||
const EntityItem* EntityTree::findClosestEntity(glm::vec3 position, float targetRadius) {
|
||||
FindNearPointArgs args = { position, targetRadius, false, NULL, FLT_MAX };
|
||||
// position and targetRadius are in meters, so we need to convert to TreeUnits in FindNearPointArgs
|
||||
FindNearPointArgs args = { position / (float)TREE_SCALE, targetRadius / (float)TREE_SCALE, false, NULL, FLT_MAX };
|
||||
lockForRead();
|
||||
// NOTE: This should use recursion, since this is a spatial operation
|
||||
recurseTreeWithOperation(findNearPointOperation, &args);
|
||||
|
|
|
@ -95,6 +95,8 @@ public:
|
|||
void deleteEntities(QSet<EntityItemID> entityIDs, bool force = false);
|
||||
void removeEntityFromSimulation(EntityItem* entity);
|
||||
|
||||
/// \param position point of query in world-frame (meters)
|
||||
/// \param targetRadius radius of query (meters)
|
||||
const EntityItem* findClosestEntity(glm::vec3 position, float targetRadius);
|
||||
EntityItem* findEntityByID(const QUuid& id);
|
||||
EntityItem* findEntityByEntityItemID(const EntityItemID& entityID);
|
||||
|
|
|
@ -30,7 +30,7 @@ const float DEFAULT_KEYHOLE_RADIUS = 3.0f;
|
|||
const float DEFAULT_FIELD_OF_VIEW_DEGREES = 45.0f;
|
||||
const float DEFAULT_ASPECT_RATIO = 16.0f/9.0f;
|
||||
const float DEFAULT_NEAR_CLIP = 0.08f;
|
||||
const float DEFAULT_FAR_CLIP = TREE_SCALE;
|
||||
const float DEFAULT_FAR_CLIP = (float)TREE_SCALE;
|
||||
|
||||
class ViewFrustum {
|
||||
public:
|
||||
|
@ -119,7 +119,6 @@ public:
|
|||
OctreeProjectedPolygon getProjectedPolygon(const AACube& box) const;
|
||||
void getFurthestPointFromCamera(const AACube& box, glm::vec3& furthestPoint) const;
|
||||
|
||||
// assumes box is in voxel scale, not TREE_SCALE, will scale view frustum's position accordingly
|
||||
void getFurthestPointFromCameraVoxelScale(const AACube& box, glm::vec3& furthestPoint) const;
|
||||
|
||||
float distanceToCamera(const glm::vec3& point) const;
|
||||
|
@ -134,7 +133,7 @@ private:
|
|||
void calculateOrthographic();
|
||||
|
||||
// camera location/orientation attributes
|
||||
glm::vec3 _position = glm::vec3(0.0f); // the position in TREE_SCALE
|
||||
glm::vec3 _position = glm::vec3(0.0f); // the position in world-frame
|
||||
glm::vec3 _positionVoxelScale = glm::vec3(0.0f); // the position in voxel scale
|
||||
glm::quat _orientation = glm::quat();
|
||||
|
||||
|
|
|
@ -45,12 +45,9 @@ void EntityTests::entityTreeTests(bool verbose) {
|
|||
entityID.isKnownID = false; // this is a temporary workaround to allow local tree entities to be added with known IDs
|
||||
EntityItemProperties properties;
|
||||
float oneMeter = 1.0f;
|
||||
//float halfMeter = oneMeter / 2.0f;
|
||||
float halfOfDomain = TREE_SCALE * 0.5f;
|
||||
glm::vec3 positionNearOriginInMeters(oneMeter, oneMeter, oneMeter); // when using properties, these are in meter not tree units
|
||||
glm::vec3 positionAtCenterInMeters(halfOfDomain, halfOfDomain, halfOfDomain);
|
||||
glm::vec3 positionNearOriginInTreeUnits = positionNearOriginInMeters / (float)TREE_SCALE;
|
||||
glm::vec3 positionAtCenterInTreeUnits = positionAtCenterInMeters / (float)TREE_SCALE;
|
||||
glm::vec3 positionNearOrigin(oneMeter, oneMeter, oneMeter); // when using properties, these are in meter not tree units
|
||||
glm::vec3 positionAtCenter(halfOfDomain, halfOfDomain, halfOfDomain);
|
||||
|
||||
{
|
||||
testsTaken++;
|
||||
|
@ -59,15 +56,14 @@ void EntityTests::entityTreeTests(bool verbose) {
|
|||
qDebug() << "Test" << testsTaken <<":" << qPrintable(testName);
|
||||
}
|
||||
|
||||
properties.setPosition(positionAtCenterInMeters);
|
||||
properties.setPosition(positionAtCenter);
|
||||
// TODO: Fix these unit tests.
|
||||
//properties.setRadius(halfMeter);
|
||||
//properties.setModelURL("http://s3.amazonaws.com/hifi-public/ozan/theater.fbx");
|
||||
|
||||
tree.addEntity(entityID, properties);
|
||||
|
||||
float targetRadius = oneMeter * 2.0 / (float)TREE_SCALE; // in tree units
|
||||
const EntityItem* foundEntityByRadius = tree.findClosestEntity(positionAtCenterInTreeUnits, targetRadius);
|
||||
float targetRadius = oneMeter * 2.0f;
|
||||
const EntityItem* foundEntityByRadius = tree.findClosestEntity(positionAtCenter, targetRadius);
|
||||
const EntityItem* foundEntityByID = tree.findEntityByEntityItemID(entityID);
|
||||
EntityTreeElement* containingElement = tree.getContainingElement(entityID);
|
||||
AACube elementCube = containingElement ? containingElement->getAACube() : AACube();
|
||||
|
@ -103,14 +99,14 @@ void EntityTests::entityTreeTests(bool verbose) {
|
|||
qDebug() << "Test" << testsTaken <<":" << qPrintable(testName);
|
||||
}
|
||||
|
||||
glm::vec3 newPosition = positionNearOriginInMeters;
|
||||
glm::vec3 newPosition = positionNearOrigin;
|
||||
|
||||
properties.setPosition(newPosition);
|
||||
|
||||
tree.updateEntity(entityID, properties, true);
|
||||
|
||||
float targetRadius = oneMeter * 2.0 / (float)TREE_SCALE; // in tree units
|
||||
const EntityItem* foundEntityByRadius = tree.findClosestEntity(positionNearOriginInTreeUnits, targetRadius);
|
||||
float targetRadius = oneMeter * 2.0f;
|
||||
const EntityItem* foundEntityByRadius = tree.findClosestEntity(positionNearOrigin, targetRadius);
|
||||
const EntityItem* foundEntityByID = tree.findEntityByEntityItemID(entityID);
|
||||
EntityTreeElement* containingElement = tree.getContainingElement(entityID);
|
||||
AACube elementCube = containingElement ? containingElement->getAACube() : AACube();
|
||||
|
@ -143,14 +139,14 @@ void EntityTests::entityTreeTests(bool verbose) {
|
|||
qDebug() << "Test" << testsTaken <<":" << qPrintable(testName);
|
||||
}
|
||||
|
||||
glm::vec3 newPosition = positionAtCenterInMeters;
|
||||
glm::vec3 newPosition = positionAtCenter;
|
||||
|
||||
properties.setPosition(newPosition);
|
||||
|
||||
tree.updateEntity(entityID, properties, true);
|
||||
|
||||
float targetRadius = oneMeter * 2.0 / (float)TREE_SCALE; // in tree units
|
||||
const EntityItem* foundEntityByRadius = tree.findClosestEntity(positionAtCenterInTreeUnits, targetRadius);
|
||||
float targetRadius = oneMeter * 2.0f;
|
||||
const EntityItem* foundEntityByRadius = tree.findClosestEntity(positionAtCenter, targetRadius);
|
||||
const EntityItem* foundEntityByID = tree.findEntityByEntityItemID(entityID);
|
||||
EntityTreeElement* containingElement = tree.getContainingElement(entityID);
|
||||
AACube elementCube = containingElement ? containingElement->getAACube() : AACube();
|
||||
|
@ -184,11 +180,11 @@ void EntityTests::entityTreeTests(bool verbose) {
|
|||
qDebug() << "Test" << testsTaken <<":" << qPrintable(testName);
|
||||
}
|
||||
|
||||
float targetRadius = oneMeter * 2.0 / (float)TREE_SCALE; // in tree units
|
||||
float targetRadius = oneMeter * 2.0f;
|
||||
quint64 start = usecTimestampNow();
|
||||
const EntityItem* foundEntityByRadius = NULL;
|
||||
for (int i = 0; i < TEST_ITERATIONS; i++) {
|
||||
foundEntityByRadius = tree.findClosestEntity(positionAtCenterInTreeUnits, targetRadius);
|
||||
foundEntityByRadius = tree.findClosestEntity(positionAtCenter, targetRadius);
|
||||
}
|
||||
quint64 end = usecTimestampNow();
|
||||
|
||||
|
@ -262,13 +258,11 @@ void EntityTests::entityTreeTests(bool verbose) {
|
|||
float randomX = randFloatInRange(1.0f ,(float)TREE_SCALE - 1.0f);
|
||||
float randomY = randFloatInRange(1.0f ,(float)TREE_SCALE - 1.0f);
|
||||
float randomZ = randFloatInRange(1.0f ,(float)TREE_SCALE - 1.0f);
|
||||
glm::vec3 randomPositionInMeters(randomX,randomY,randomZ);
|
||||
glm::vec3 randomPositionInTreeUnits = randomPositionInMeters / (float)TREE_SCALE;
|
||||
glm::vec3 randomPosition(randomX,randomY,randomZ);
|
||||
|
||||
properties.setPosition(randomPositionInMeters);
|
||||
properties.setPosition(randomPosition);
|
||||
|
||||
// TODO: fix these unit tests
|
||||
//properties.setRadius(halfMeter);
|
||||
//properties.setModelURL("http://s3.amazonaws.com/hifi-public/ozan/theater.fbx");
|
||||
|
||||
if (extraVerbose) {
|
||||
|
@ -287,8 +281,8 @@ void EntityTests::entityTreeTests(bool verbose) {
|
|||
}
|
||||
|
||||
quint64 startFind = usecTimestampNow();
|
||||
float targetRadius = oneMeter * 2.0 / (float)TREE_SCALE; // in tree units
|
||||
const EntityItem* foundEntityByRadius = tree.findClosestEntity(randomPositionInTreeUnits, targetRadius);
|
||||
float targetRadius = oneMeter * 2.0f;
|
||||
const EntityItem* foundEntityByRadius = tree.findClosestEntity(randomPosition, targetRadius);
|
||||
const EntityItem* foundEntityByID = tree.findEntityByEntityItemID(entityID);
|
||||
quint64 endFind = usecTimestampNow();
|
||||
totalElapsedFind += (endFind - startFind);
|
||||
|
|
Loading…
Reference in a new issue