mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 12:04:18 +02:00
replace some "InDomainUnits" calls with "InMeters"
This commit is contained in:
parent
c2e78931c6
commit
90b69b1ee0
4 changed files with 16 additions and 15 deletions
|
@ -992,8 +992,8 @@ void EntityItem::setRadius(float value) {
|
|||
// ... radius = cornerToCornerLength / 2.0f
|
||||
// ... cornerToCornerLength = sqrt(3 x maxDimension ^ 2)
|
||||
// ... radius = sqrt(3 x maxDimension ^ 2) / 2.0f;
|
||||
float EntityItem::getRadius() const {
|
||||
float length = glm::length(_dimensions);
|
||||
float EntityItem::getRadiusInMeters() const {
|
||||
float length = glm::length(_dimensions) * (float)TREE_SCALE;
|
||||
float radius = length / 2.0f;
|
||||
return radius;
|
||||
}
|
||||
|
|
|
@ -250,8 +250,8 @@ public:
|
|||
const QString& getUserData() const { return _userData; }
|
||||
void setUserData(const QString& value) { _userData = value; }
|
||||
|
||||
// TODO: We need to get rid of these users of getRadius()...
|
||||
float getRadius() const;
|
||||
// TODO: get rid of users of getRadius()...
|
||||
float getRadiusInMeters() const;
|
||||
|
||||
virtual bool containsInMeters(const glm::vec3& point) const { return getAABoxInMeters().contains(point); }
|
||||
virtual bool contains(const glm::vec3& point) const { return getAABox().contains(point); }
|
||||
|
|
|
@ -424,8 +424,9 @@ bool EntityTree::findNearPointOperation(OctreeElement* element, void* extraData)
|
|||
EntityTreeElement* entityTreeElement = static_cast<EntityTreeElement*>(element);
|
||||
|
||||
glm::vec3 penetration;
|
||||
bool sphereIntersection = entityTreeElement->getAACube().findSpherePenetration(args->position,
|
||||
args->targetRadius, penetration);
|
||||
AACube cube = entityTreeElement->getAACube();
|
||||
cube *= (float)TREE_SCALE;
|
||||
bool sphereIntersection = cube.findSpherePenetration(args->position, args->targetRadius, penetration);
|
||||
|
||||
// If this entityTreeElement contains the point, then search it...
|
||||
if (sphereIntersection) {
|
||||
|
@ -433,7 +434,7 @@ bool EntityTree::findNearPointOperation(OctreeElement* element, void* extraData)
|
|||
|
||||
// we may have gotten NULL back, meaning no entity was available
|
||||
if (thisClosestEntity) {
|
||||
glm::vec3 entityPosition = thisClosestEntity->getPositionInDomainUnits();
|
||||
glm::vec3 entityPosition = thisClosestEntity->getPositionInMeters();
|
||||
float distanceFromPointToEntity = glm::distance(entityPosition, args->position);
|
||||
|
||||
// If we're within our target radius
|
||||
|
@ -457,7 +458,7 @@ bool EntityTree::findNearPointOperation(OctreeElement* element, void* extraData)
|
|||
|
||||
const EntityItem* EntityTree::findClosestEntity(glm::vec3 position, float targetRadius) {
|
||||
// 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 };
|
||||
FindNearPointArgs args = { position, targetRadius, false, NULL, FLT_MAX };
|
||||
lockForRead();
|
||||
// NOTE: This should use recursion, since this is a spatial operation
|
||||
recurseTreeWithOperation(findNearPointOperation, &args);
|
||||
|
|
|
@ -549,8 +549,8 @@ bool EntityTreeElement::findSpherePenetration(const glm::vec3& center, float rad
|
|||
QList<EntityItem*>::const_iterator entityEnd = _entityItems->end();
|
||||
while(entityItr != entityEnd) {
|
||||
EntityItem* entity = (*entityItr);
|
||||
glm::vec3 entityCenter = entity->getPositionInDomainUnits();
|
||||
float entityRadius = entity->getRadius();
|
||||
glm::vec3 entityCenter = entity->getPositionInMeters();
|
||||
float entityRadius = entity->getRadiusInMeters();
|
||||
|
||||
// don't penetrate yourself
|
||||
if (entityCenter == center && entityRadius == radius) {
|
||||
|
@ -585,7 +585,7 @@ const EntityItem* EntityTreeElement::getClosestEntity(glm::vec3 position) const
|
|||
float closestEntityDistance = FLT_MAX;
|
||||
uint16_t numberOfEntities = _entityItems->size();
|
||||
for (uint16_t i = 0; i < numberOfEntities; i++) {
|
||||
float distanceToEntity = glm::distance(position, (*_entityItems)[i]->getPositionInDomainUnits());
|
||||
float distanceToEntity = glm::distance(position, (*_entityItems)[i]->getPositionInMeters());
|
||||
if (distanceToEntity < closestEntityDistance) {
|
||||
closestEntity = (*_entityItems)[i];
|
||||
}
|
||||
|
@ -598,8 +598,8 @@ void EntityTreeElement::getEntities(const glm::vec3& searchPosition, float searc
|
|||
uint16_t numberOfEntities = _entityItems->size();
|
||||
for (uint16_t i = 0; i < numberOfEntities; i++) {
|
||||
const EntityItem* entity = (*_entityItems)[i];
|
||||
float distance = glm::length(entity->getPositionInDomainUnits() - searchPosition);
|
||||
if (distance < searchRadius + entity->getRadius()) {
|
||||
float distance = glm::length(entity->getPositionInMeters() - searchPosition);
|
||||
if (distance < searchRadius + entity->getRadiusInMeters()) {
|
||||
foundEntities.push_back(entity);
|
||||
}
|
||||
}
|
||||
|
@ -612,11 +612,11 @@ void EntityTreeElement::getEntities(const AACube& box, QVector<EntityItem*>& fou
|
|||
AACube entityCube;
|
||||
while(entityItr != entityEnd) {
|
||||
EntityItem* entity = (*entityItr);
|
||||
float radius = entity->getRadius();
|
||||
float radius = entity->getRadiusInMeters();
|
||||
// NOTE: we actually do cube-cube collision queries here, which is sloppy but good enough for now
|
||||
// TODO: decide whether to replace entityCube-cube query with sphere-cube (requires a square root
|
||||
// but will be slightly more accurate).
|
||||
entityCube.setBox(entity->getPositionInDomainUnits() - glm::vec3(radius), 2.0f * radius);
|
||||
entityCube.setBox(entity->getPositionInMeters() - glm::vec3(radius), 2.0f * radius);
|
||||
if (entityCube.touches(box)) {
|
||||
foundEntities.push_back(entity);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue