entity cubes are in meters

This commit is contained in:
Andrew Meadows 2015-03-06 15:32:03 -08:00
parent 6936d65db9
commit 373be95297
41 changed files with 221 additions and 286 deletions

View file

@ -2262,7 +2262,6 @@ void Application::queryOctree(NodeType_t serverType, PacketType packetType, Node
VoxelPositionSize rootDetails;
voxelDetailsForCode(rootCode, rootDetails);
AACube serverBounds(glm::vec3(rootDetails.x, rootDetails.y, rootDetails.z), rootDetails.s);
serverBounds.scale(TREE_SCALE);
ViewFrustum::location serverFrustumLocation = _viewFrustum.cubeInFrustum(serverBounds);
@ -2326,7 +2325,6 @@ void Application::queryOctree(NodeType_t serverType, PacketType packetType, Node
VoxelPositionSize rootDetails;
voxelDetailsForCode(rootCode, rootDetails);
AACube serverBounds(glm::vec3(rootDetails.x, rootDetails.y, rootDetails.z), rootDetails.s);
serverBounds.scale(TREE_SCALE);
ViewFrustum::location serverFrustumLocation = _viewFrustum.cubeInFrustum(serverBounds);
if (serverFrustumLocation != ViewFrustum::OUTSIDE) {

View file

@ -31,9 +31,9 @@ ModelReferential::ModelReferential(Referential* referential, EntityTree* tree, A
const EntityItem* item = _tree->findEntityByID(_entityID);
if (item != NULL) {
_lastRefDimension = item->getDimensionsInMeters();
_lastRefDimension = item->getDimensions();
_refRotation = item->getRotation();
_refPosition = item->getPositionInMeters();
_refPosition = item->getPosition();
update();
}
}
@ -50,9 +50,9 @@ ModelReferential::ModelReferential(const QUuid& entityID, EntityTree* tree, Avat
return;
}
_lastRefDimension = item->getDimensionsInMeters();
_lastRefDimension = item->getDimensions();
_refRotation = item->getRotation();
_refPosition = item->getPositionInMeters();
_refPosition = item->getPosition();
glm::quat refInvRot = glm::inverse(_refRotation);
_rotation = refInvRot * _avatar->getOrientation();
@ -66,9 +66,9 @@ void ModelReferential::update() {
}
bool somethingChanged = false;
if (item->getDimensionsInMeters() != _lastRefDimension) {
if (item->getDimensions() != _lastRefDimension) {
glm::vec3 oldDimension = _lastRefDimension;
_lastRefDimension = item->getDimensionsInMeters();
_lastRefDimension = item->getDimensions();
_translation *= _lastRefDimension / oldDimension;
somethingChanged = true;
}
@ -77,8 +77,8 @@ void ModelReferential::update() {
_avatar->setOrientation(_refRotation * _rotation, true);
somethingChanged = true;
}
if (item->getPositionInMeters() != _refPosition || somethingChanged) {
_refPosition = item->getPositionInMeters();
if (item->getPosition() != _refPosition || somethingChanged) {
_refPosition = item->getPosition();
_avatar->setPosition(_refPosition + _refRotation * _translation, true);
}
}
@ -107,7 +107,7 @@ JointReferential::JointReferential(Referential* referential, EntityTree* tree, A
const EntityItem* item = _tree->findEntityByID(_entityID);
const Model* model = getModel(item);
if (!isValid() || model == NULL || _jointIndex >= (uint32_t)(model->getJointStateCount())) {
_lastRefDimension = item->getDimensionsInMeters();
_lastRefDimension = item->getDimensions();
model->getJointRotationInWorldFrame(_jointIndex, _refRotation);
model->getJointPositionInWorldFrame(_jointIndex, _refPosition);
}
@ -127,7 +127,7 @@ JointReferential::JointReferential(uint32_t jointIndex, const QUuid& entityID, E
return;
}
_lastRefDimension = item->getDimensionsInMeters();
_lastRefDimension = item->getDimensions();
model->getJointRotationInWorldFrame(_jointIndex, _refRotation);
model->getJointPositionInWorldFrame(_jointIndex, _refPosition);
@ -145,9 +145,9 @@ void JointReferential::update() {
}
bool somethingChanged = false;
if (item->getDimensionsInMeters() != _lastRefDimension) {
if (item->getDimensions() != _lastRefDimension) {
glm::vec3 oldDimension = _lastRefDimension;
_lastRefDimension = item->getDimensionsInMeters();
_lastRefDimension = item->getDimensions();
_translation *= _lastRefDimension / oldDimension;
somethingChanged = true;
}
@ -156,7 +156,7 @@ void JointReferential::update() {
_avatar->setOrientation(_refRotation * _rotation, true);
somethingChanged = true;
}
if (item->getPositionInMeters() != _refPosition || somethingChanged) {
if (item->getPosition() != _refPosition || somethingChanged) {
model->getJointPositionInWorldFrame(_jointIndex, _refPosition);
_avatar->setPosition(_refPosition + _refRotation * _translation, true);
}

View file

@ -42,7 +42,7 @@ void OctreeFade::render() {
glDisable(GL_LIGHTING);
glPushMatrix();
glScalef(TREE_SCALE, TREE_SCALE, TREE_SCALE);
glScalef(1.0f, 1.0f, 1.0f);
glTranslatef(voxelDetails.x + voxelDetails.s * 0.5f,
voxelDetails.y + voxelDetails.s * 0.5f,
voxelDetails.z + voxelDetails.s * 0.5f);

View file

@ -71,20 +71,19 @@ void NodeBounds::draw() {
voxelDetailsForCode(rootCode, rootDetails);
serverJurisdictions->unlock();
glm::vec3 location(rootDetails.x, rootDetails.y, rootDetails.z);
location *= (float)TREE_SCALE;
AACube serverBounds(location, rootDetails.s * TREE_SCALE);
AACube serverBounds(location, rootDetails.s);
glm::vec3 center = serverBounds.getVertex(BOTTOM_RIGHT_NEAR)
+ ((serverBounds.getVertex(TOP_LEFT_FAR) - serverBounds.getVertex(BOTTOM_RIGHT_NEAR)) / 2.0f);
const float ENTITY_NODE_SCALE = 0.99f;
float scaleFactor = rootDetails.s * TREE_SCALE;
float scaleFactor = rootDetails.s;
// Scale by 0.92 - 1.00 depending on the scale of the node. This allows smaller nodes to scale in
// a bit and not overlap larger nodes.
scaleFactor *= 0.92 + (rootDetails.s * 0.08);
scaleFactor *= 0.92f + (rootDetails.s * 0.08f);
// Scale different node types slightly differently because it's common for them to overlap.
if (nodeType == NodeType::EntityServer) {

View file

@ -273,7 +273,6 @@ void OctreeStatsDialog::showOctreeServersOfType(int& serverCount, NodeType_t ser
VoxelPositionSize rootDetails;
voxelDetailsForCode(rootCode, rootDetails);
AACube serverBounds(glm::vec3(rootDetails.x, rootDetails.y, rootDetails.z), rootDetails.s);
serverBounds.scale(TREE_SCALE);
serverDetails << " jurisdiction: "
<< qPrintable(rootCodeHex)
<< " ["

View file

@ -48,7 +48,6 @@ EntityTreeRenderer::EntityTreeRenderer(bool wantScripts, AbstractViewStateInterf
_displayModelElementProxy(false),
_dontDoPrecisionPicking(false)
{
std::cout << "adebug " << (void*)(this) << " EntityTreeRenderer ctor" << std::endl; // adebug
REGISTER_ENTITY_TYPE_WITH_FACTORY(Model, RenderableModelEntityItem::factory)
REGISTER_ENTITY_TYPE_WITH_FACTORY(Box, RenderableBoxEntityItem::factory)
REGISTER_ENTITY_TYPE_WITH_FACTORY(Sphere, RenderableSphereEntityItem::factory)
@ -285,11 +284,11 @@ void EntityTreeRenderer::checkEnterLeaveEntities() {
QVector<EntityItemID> entitiesContainingAvatar;
// find the entities near us
static_cast<EntityTree*>(_tree)->findEntitiesInMeters(avatarPosition, radius, foundEntities);
static_cast<EntityTree*>(_tree)->findEntities(avatarPosition, radius, foundEntities);
// create a list of entities that actually contain the avatar's position
foreach(const EntityItem* entity, foundEntities) {
if (entity->containsInMeters(avatarPosition)) {
if (entity->contains(avatarPosition)) {
entitiesContainingAvatar << entity->getEntityItemID();
}
}
@ -417,8 +416,8 @@ const Model* EntityTreeRenderer::getModelForEntityItem(const EntityItem* entityI
}
void EntityTreeRenderer::renderElementProxy(EntityTreeElement* entityTreeElement) {
glm::vec3 elementCenter = entityTreeElement->getAACube().calcCenter() * (float) TREE_SCALE;
float elementSize = entityTreeElement->getScale() * (float) TREE_SCALE;
glm::vec3 elementCenter = entityTreeElement->getAACube().calcCenter();
float elementSize = entityTreeElement->getScale();
glPushMatrix();
glTranslatef(elementCenter.x, elementCenter.y, elementCenter.z);
DependencyManager::get<DeferredLightingEffect>()->renderWireCube(elementSize, glm::vec4(1.0f, 0.0f, 0.0f, 1.0f));
@ -477,10 +476,7 @@ void EntityTreeRenderer::renderProxies(const EntityItem* entity, RenderArgs* arg
AACube maxCube = entity->getMaximumAACube();
AACube minCube = entity->getMinimumAACube();
AABox entityBox = entity->getAABoxInMeters();
maxCube.scale((float) TREE_SCALE);
minCube.scale((float) TREE_SCALE);
AABox entityBox = entity->getAABox();
glm::vec3 maxCenter = maxCube.calcCenter();
glm::vec3 minCenter = minCube.calcCenter();
@ -507,9 +503,9 @@ void EntityTreeRenderer::renderProxies(const EntityItem* entity, RenderArgs* arg
glPopMatrix();
glm::vec3 position = entity->getPositionInMeters();
glm::vec3 center = entity->getCenterInMeters();
glm::vec3 dimensions = entity->getDimensionsInMeters();
glm::vec3 position = entity->getPosition();
glm::vec3 center = entity->getCenter();
glm::vec3 dimensions = entity->getDimensions();
glm::quat rotation = entity->getRotation();
glPushMatrix();
@ -548,7 +544,7 @@ void EntityTreeRenderer::renderElement(OctreeElement* element, RenderArgs* args)
if (entityItem->isVisible()) {
// render entityItem
AABox entityBox = entityItem->getAABoxInMeters();
AABox entityBox = entityItem->getAABox();
// TODO: some entity types (like lights) might want to be rendered even
// when they are outside of the view frustum...
@ -672,16 +668,10 @@ RayToEntityIntersectionResult EntityTreeRenderer::findRayIntersectionWorker(cons
(void**)&intersectedEntity, lockType, &result.accurate,
precisionPicking);
if (result.intersects && intersectedEntity) {
std::cout << "adebug " << (void*)(this) << " EntityTreeRenderer's tree = " << (void*)(_tree) << std::endl; // adebug
int foo = 0;
result.entityID = intersectedEntity->getEntityItemID();
foo = 1;
result.properties = intersectedEntity->getProperties();
foo = 2;
result.intersection = ray.origin + (ray.direction * result.distance);
foo = 3;
result.entity = intersectedEntity;
std::cout << "adebug foo = " << foo << std::endl; // adebug
}
}
return result;

View file

@ -25,9 +25,9 @@ EntityItem* RenderableBoxEntityItem::factory(const EntityItemID& entityID, const
void RenderableBoxEntityItem::render(RenderArgs* args) {
PerformanceTimer perfTimer("RenderableBoxEntityItem::render");
assert(getType() == EntityTypes::Box);
glm::vec3 position = getPositionInMeters();
glm::vec3 center = getCenterInMeters();
glm::vec3 dimensions = getDimensionsInMeters();
glm::vec3 position = getPosition();
glm::vec3 center = getCenter();
glm::vec3 dimensions = getDimensions();
glm::quat rotation = getRotation();
const float MAX_COLOR = 255.0f;

View file

@ -26,8 +26,8 @@ EntityItem* RenderableLightEntityItem::factory(const EntityItemID& entityID, con
void RenderableLightEntityItem::render(RenderArgs* args) {
PerformanceTimer perfTimer("RenderableLightEntityItem::render");
assert(getType() == EntityTypes::Light);
glm::vec3 position = getPositionInMeters();
glm::vec3 dimensions = getDimensionsInMeters();
glm::vec3 position = getPosition();
glm::vec3 dimensions = getDimensions();
glm::quat rotation = getRotation();
float largestDiameter = glm::max(dimensions.x, dimensions.y, dimensions.z);
@ -67,7 +67,7 @@ void RenderableLightEntityItem::render(RenderArgs* args) {
#endif
};
bool RenderableLightEntityItem::findDetailedRayIntersectionInMeters(const glm::vec3& origin, const glm::vec3& direction,
bool RenderableLightEntityItem::findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
void** intersectedObject, bool precisionPicking) const {

View file

@ -24,7 +24,7 @@ public:
virtual void render(RenderArgs* args);
virtual bool supportsDetailedRayIntersection() const { return true; }
virtual bool findDetailedRayIntersectionInMeters(const glm::vec3& origin, const glm::vec3& direction,
virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
void** intersectedObject, bool precisionPicking) const;
};

View file

@ -114,8 +114,8 @@ void RenderableModelEntityItem::render(RenderArgs* args) {
bool drawAsModel = hasModel();
glm::vec3 position = getPositionInMeters();
glm::vec3 dimensions = getDimensionsInMeters();
glm::vec3 position = getPosition();
glm::vec3 dimensions = getDimensions();
float size = glm::length(dimensions);
if (drawAsModel) {
@ -254,13 +254,13 @@ EntityItemProperties RenderableModelEntityItem::getProperties() const {
return properties;
}
bool RenderableModelEntityItem::findDetailedRayIntersectionInMeters(const glm::vec3& origin, const glm::vec3& direction,
bool RenderableModelEntityItem::findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
void** intersectedObject, bool precisionPicking) const {
if (!_model) {
return true;
}
//qDebug() << "RenderableModelEntityItem::findDetailedRayIntersectionInMeters() precisionPicking:" << precisionPicking;
//qDebug() << "RenderableModelEntityItem::findDetailedRayIntersection() precisionPicking:" << precisionPicking;
QString extraInfo;
return _model->findRayIntersectionAgainstSubMeshes(origin, direction, distance, face, extraInfo, precisionPicking);

View file

@ -44,7 +44,7 @@ public:
virtual void render(RenderArgs* args);
virtual bool supportsDetailedRayIntersection() const { return true; }
virtual bool findDetailedRayIntersectionInMeters(const glm::vec3& origin, const glm::vec3& direction,
virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
void** intersectedObject, bool precisionPicking) const;

View file

@ -26,9 +26,9 @@ EntityItem* RenderableSphereEntityItem::factory(const EntityItemID& entityID, co
void RenderableSphereEntityItem::render(RenderArgs* args) {
PerformanceTimer perfTimer("RenderableSphereEntityItem::render");
assert(getType() == EntityTypes::Sphere);
glm::vec3 position = getPositionInMeters();
glm::vec3 center = getCenterInMeters();
glm::vec3 dimensions = getDimensionsInMeters();
glm::vec3 position = getPosition();
glm::vec3 center = getCenter();
glm::vec3 dimensions = getDimensions();
glm::quat rotation = getRotation();
const float MAX_COLOR = 255.0f;

View file

@ -30,8 +30,8 @@ EntityItem* RenderableTextEntityItem::factory(const EntityItemID& entityID, cons
void RenderableTextEntityItem::render(RenderArgs* args) {
PerformanceTimer perfTimer("RenderableTextEntityItem::render");
assert(getType() == EntityTypes::Text);
glm::vec3 position = getPositionInMeters();
glm::vec3 dimensions = getDimensionsInMeters();
glm::vec3 position = getPosition();
glm::vec3 dimensions = getDimensions();
glm::vec3 halfDimensions = dimensions / 2.0f;
glm::quat rotation = getRotation();
float leftMargin = 0.1f;

View file

@ -25,7 +25,7 @@ AddEntityOperator::AddEntityOperator(EntityTree* tree,
{
// caller must have verified existence of newEntity
assert(_newEntity);
_newEntityBox = _newEntity->getMaximumAACube().clamp(0.0f, 1.0f);
_newEntityBox = _newEntity->getMaximumAACube().clamp(0.0f, (float)TREE_SCALE);
}
bool AddEntityOperator::preRecursion(OctreeElement* element) {
@ -43,7 +43,7 @@ bool AddEntityOperator::preRecursion(OctreeElement* element) {
if (!_foundNew && element->getAACube().contains(_newEntityBox)) {
// If this element is the best fit for the new entity properties, then add/or update it
if (entityTreeElement->bestFitBounds(_newEntityBox)) {
if (entityTreeElement->bestFitBoundsInMeters(_newEntityBox)) {
entityTreeElement->addEntityItem(_newEntity);
_tree->setContainingElement(_newEntity->getEntityItemID(), entityTreeElement);

View file

@ -41,7 +41,6 @@ EntityItemProperties BoxEntityItem::getProperties() const {
properties._glowLevel = getGlowLevel();
properties._glowLevelChanged = false;
std::cout << "adebug end of BoxEntityItem::getProperties()" << std::endl; // adebug
return properties;
}

View file

@ -60,7 +60,7 @@ bool DeleteEntityOperator::subTreeContainsSomeEntitiesToDelete(OctreeElement* el
// If we don't have an old entity, then we don't contain the entity, otherwise
// check the bounds
if (_entitiesToDelete.size() > 0) {
AACube elementCube = element->getAACube();
const AACube& elementCube = element->getAACube();
foreach(const EntityToDeleteDetails& details, _entitiesToDelete) {
if (elementCube.contains(details.cube)) {
containsEntity = true;

View file

@ -221,12 +221,12 @@ OctreeElement::AppendState EntityItem::appendEntityData(OctreePacketData* packet
// PROP_PAGED_PROPERTY,
// PROP_CUSTOM_PROPERTIES_INCLUDED,
APPEND_ENTITY_PROPERTY(PROP_POSITION, appendPosition, getPositionInMeters());
APPEND_ENTITY_PROPERTY(PROP_DIMENSIONS, appendValue, getDimensionsInMeters()); // NOTE: PROP_RADIUS obsolete
APPEND_ENTITY_PROPERTY(PROP_POSITION, appendPosition, getPosition());
APPEND_ENTITY_PROPERTY(PROP_DIMENSIONS, appendValue, getDimensions()); // NOTE: PROP_RADIUS obsolete
APPEND_ENTITY_PROPERTY(PROP_ROTATION, appendValue, getRotation());
APPEND_ENTITY_PROPERTY(PROP_DENSITY, appendValue, getDensity());
APPEND_ENTITY_PROPERTY(PROP_VELOCITY, appendValue, getVelocityInMeters());
APPEND_ENTITY_PROPERTY(PROP_GRAVITY, appendValue, getGravityInMeters());
APPEND_ENTITY_PROPERTY(PROP_VELOCITY, appendValue, getVelocity());
APPEND_ENTITY_PROPERTY(PROP_GRAVITY, appendValue, getGravity());
APPEND_ENTITY_PROPERTY(PROP_DAMPING, appendValue, getDamping());
APPEND_ENTITY_PROPERTY(PROP_LIFETIME, appendValue, getLifetime());
APPEND_ENTITY_PROPERTY(PROP_SCRIPT, appendValue, getScript());
@ -503,7 +503,7 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
bytesRead += propertyFlags.getEncodedLength();
bool useMeters = (args.bitstreamVersion == VERSION_ENTITIES_USE_METERS);
if (useMeters) {
READ_ENTITY_PROPERTY_SETTER(PROP_POSITION, glm::vec3, updatePositionInMeters);
READ_ENTITY_PROPERTY_SETTER(PROP_POSITION, glm::vec3, updatePosition);
} else {
READ_ENTITY_PROPERTY_SETTER(PROP_POSITION, glm::vec3, updatePositionInDomainUnits);
}
@ -521,7 +521,7 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
}
} else {
if (useMeters) {
READ_ENTITY_PROPERTY_SETTER(PROP_DIMENSIONS, glm::vec3, setDimensionsInMeters);
READ_ENTITY_PROPERTY_SETTER(PROP_DIMENSIONS, glm::vec3, setDimensions);
} else {
READ_ENTITY_PROPERTY_SETTER(PROP_DIMENSIONS, glm::vec3, setDimensionsInDomainUnits);
}
@ -530,8 +530,8 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
READ_ENTITY_PROPERTY_QUAT_SETTER(PROP_ROTATION, updateRotation);
READ_ENTITY_PROPERTY_SETTER(PROP_DENSITY, float, updateDensity);
if (useMeters) {
READ_ENTITY_PROPERTY_SETTER(PROP_VELOCITY, glm::vec3, updateVelocityInMeters);
READ_ENTITY_PROPERTY_SETTER(PROP_GRAVITY, glm::vec3, updateGravityInMeters);
READ_ENTITY_PROPERTY_SETTER(PROP_VELOCITY, glm::vec3, updateVelocity);
READ_ENTITY_PROPERTY_SETTER(PROP_GRAVITY, glm::vec3, updateGravity);
} else {
READ_ENTITY_PROPERTY_SETTER(PROP_VELOCITY, glm::vec3, updateVelocityInDomainUnits);
READ_ENTITY_PROPERTY_SETTER(PROP_GRAVITY, glm::vec3, updateGravityInDomainUnits);
@ -726,7 +726,7 @@ void EntityItem::simulateKinematicMotion(float timeElapsed) {
if (hasVelocity()) {
// linear damping
glm::vec3 velocity = getVelocityInMeters();
glm::vec3 velocity = getVelocity();
if (_damping > 0.0f) {
velocity *= powf(1.0f - _damping, timeElapsed);
#ifdef WANT_DEBUG
@ -738,7 +738,7 @@ void EntityItem::simulateKinematicMotion(float timeElapsed) {
}
// integrate position forward
glm::vec3 position = getPositionInMeters();
glm::vec3 position = getPosition();
glm::vec3 newPosition = position + (velocity * timeElapsed);
#ifdef WANT_DEBUG
@ -758,19 +758,19 @@ void EntityItem::simulateKinematicMotion(float timeElapsed) {
if (hasGravity()) {
// handle resting on surface case, this is definitely a bit of a hack, and it only works on the
// "ground" plane of the domain, but for now it's what we've got
velocity += getGravityInMeters() * timeElapsed;
velocity += getGravity() * timeElapsed;
}
float speed = glm::length(velocity);
const float EPSILON_LINEAR_VELOCITY_LENGTH = 0.001f; // 1mm/sec
if (speed < EPSILON_LINEAR_VELOCITY_LENGTH) {
setVelocityInMeters(ENTITY_ITEM_ZERO_VEC3);
setVelocity(ENTITY_ITEM_ZERO_VEC3);
if (speed > 0.0f) {
_dirtyFlags |= EntityItem::DIRTY_MOTION_TYPE;
}
} else {
setPositionInMeters(position);
setVelocityInMeters(velocity);
setPosition(position);
setVelocity(velocity);
}
#ifdef WANT_DEBUG
@ -795,7 +795,6 @@ quint64 EntityItem::getExpiry() const {
}
EntityItemProperties EntityItem::getProperties() const {
std::cout << "adebug EntityItem::getProperties" << std::endl; // adebug
EntityItemProperties properties;
properties._id = getID();
properties._idSet = true;
@ -803,12 +802,12 @@ EntityItemProperties EntityItem::getProperties() const {
properties._type = getType();
COPY_ENTITY_PROPERTY_TO_PROPERTIES(position, getPositionInMeters);
COPY_ENTITY_PROPERTY_TO_PROPERTIES(dimensions, getDimensionsInMeters); // NOTE: radius is obsolete
COPY_ENTITY_PROPERTY_TO_PROPERTIES(position, getPosition);
COPY_ENTITY_PROPERTY_TO_PROPERTIES(dimensions, getDimensions); // NOTE: radius is obsolete
COPY_ENTITY_PROPERTY_TO_PROPERTIES(rotation, getRotation);
COPY_ENTITY_PROPERTY_TO_PROPERTIES(density, getDensity);
COPY_ENTITY_PROPERTY_TO_PROPERTIES(velocity, getVelocityInMeters);
COPY_ENTITY_PROPERTY_TO_PROPERTIES(gravity, getGravityInMeters);
COPY_ENTITY_PROPERTY_TO_PROPERTIES(velocity, getVelocity);
COPY_ENTITY_PROPERTY_TO_PROPERTIES(gravity, getGravity);
COPY_ENTITY_PROPERTY_TO_PROPERTIES(damping, getDamping);
COPY_ENTITY_PROPERTY_TO_PROPERTIES(lifetime, getLifetime);
COPY_ENTITY_PROPERTY_TO_PROPERTIES(script, getScript);
@ -825,19 +824,18 @@ EntityItemProperties EntityItem::getProperties() const {
properties._defaultSettings = false;
std::cout << "adebug about to delete properties" << std::endl; // adebug
return properties;
}
bool EntityItem::setProperties(const EntityItemProperties& properties) {
bool somethingChanged = false;
SET_ENTITY_PROPERTY_FROM_PROPERTIES(position, updatePositionInMeters); // this will call recalculate collision shape if needed
SET_ENTITY_PROPERTY_FROM_PROPERTIES(dimensions, updateDimensionsInMeters); // NOTE: radius is obsolete
SET_ENTITY_PROPERTY_FROM_PROPERTIES(position, updatePosition); // this will call recalculate collision shape if needed
SET_ENTITY_PROPERTY_FROM_PROPERTIES(dimensions, updateDimensions); // NOTE: radius is obsolete
SET_ENTITY_PROPERTY_FROM_PROPERTIES(rotation, updateRotation);
SET_ENTITY_PROPERTY_FROM_PROPERTIES(density, updateDensity);
SET_ENTITY_PROPERTY_FROM_PROPERTIES(velocity, updateVelocityInMeters);
SET_ENTITY_PROPERTY_FROM_PROPERTIES(gravity, updateGravityInMeters);
SET_ENTITY_PROPERTY_FROM_PROPERTIES(velocity, updateVelocity);
SET_ENTITY_PROPERTY_FROM_PROPERTIES(gravity, updateGravity);
SET_ENTITY_PROPERTY_FROM_PROPERTIES(damping, updateDamping);
SET_ENTITY_PROPERTY_FROM_PROPERTIES(lifetime, updateLifetime);
SET_ENTITY_PROPERTY_FROM_PROPERTIES(script, setScript);
@ -900,7 +898,7 @@ void EntityItem::recordCreationTime() {
// TODO: doesn't this need to handle rotation?
glm::vec3 EntityItem::getCenterInMeters() const {
glm::vec3 EntityItem::getCenter() const {
return _position + (_dimensions * (glm::vec3(0.5f,0.5f,0.5f) - _registrationPoint));
}
@ -957,7 +955,7 @@ AACube EntityItem::getMinimumAACube() const {
return AACube(cornerOfCube, longestSide);
}
AABox EntityItem::getAABoxInMeters() const {
AABox EntityItem::getAABox() const {
// _position represents the position of the registration point.
glm::vec3 registrationRemainder = glm::vec3(1.0f, 1.0f, 1.0f) - _registrationPoint;
@ -973,8 +971,8 @@ AABox EntityItem::getAABoxInMeters() const {
}
AABox EntityItem::getAABoxInDomainUnits() const {
AABox box = getAABoxInMeters();
box *= 1.0f / (float)TREE_SCALE;
AABox box = getAABox();
box.scale(1.0f / (float)TREE_SCALE);
return box;
}
@ -1001,12 +999,12 @@ 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::getRadiusInMeters() const {
float EntityItem::getRadius() const {
return 0.5f * glm::length(_dimensions);
}
void EntityItem::computeShapeInfo(ShapeInfo& info) const {
info.setParams(getShapeType(), 0.5f * getDimensionsInMeters());
info.setParams(getShapeType(), 0.5f * getDimensions());
}
const float MIN_POSITION_DELTA = 0.0001f;
@ -1019,27 +1017,25 @@ const float MIN_SPIN_DELTA = 0.0003f;
void EntityItem::updatePositionInDomainUnits(const glm::vec3& value) {
glm::vec3 position = value * (float)TREE_SCALE;
updatePositionInMeters(position);
updatePosition(position);
}
void EntityItem::updatePositionInMeters(const glm::vec3& value) {
void EntityItem::updatePosition(const glm::vec3& value) {
if (glm::distance(_position, value) > MIN_POSITION_DELTA) {
_position = value;
_dirtyFlags |= EntityItem::DIRTY_POSITION;
std::cout << "adebug updatePositionInMeters = " << _position << std::endl; // adebug
}
}
void EntityItem::updateDimensionsInDomainUnits(const glm::vec3& value) {
glm::vec3 dimensions = value * (float)TREE_SCALE;
updateDimensionsInMeters(dimensions);
updateDimensions(dimensions);
}
void EntityItem::updateDimensionsInMeters(const glm::vec3& value) {
void EntityItem::updateDimensions(const glm::vec3& value) {
if (glm::distance(_dimensions, value) > MIN_DIMENSIONS_DELTA) {
_dimensions = value;
_dirtyFlags |= (EntityItem::DIRTY_SHAPE | EntityItem::DIRTY_MASS);
std::cout << "adebug updateDimensionsInMeters = " << value << std::endl; // adebug
}
}
@ -1076,10 +1072,10 @@ void EntityItem::updateMass(float mass) {
void EntityItem::updateVelocityInDomainUnits(const glm::vec3& value) {
glm::vec3 velocity = value * (float)TREE_SCALE;
updateVelocityInMeters(velocity);
updateVelocity(velocity);
}
void EntityItem::updateVelocityInMeters(const glm::vec3& value) {
void EntityItem::updateVelocity(const glm::vec3& value) {
if (glm::distance(_velocity, value) > MIN_VELOCITY_DELTA) {
if (glm::length(value) < MIN_VELOCITY_DELTA) {
_velocity = ENTITY_ITEM_ZERO_VEC3;
@ -1099,10 +1095,10 @@ void EntityItem::updateDamping(float value) {
void EntityItem::updateGravityInDomainUnits(const glm::vec3& value) {
glm::vec3 gravity = value * (float) TREE_SCALE;
updateGravityInMeters(gravity);
updateGravity(gravity);
}
void EntityItem::updateGravityInMeters(const glm::vec3& value) {
void EntityItem::updateGravity(const glm::vec3& value) {
if ( glm::distance(_gravity, value) > MIN_GRAVITY_DELTA) {
_gravity = value;
_dirtyFlags |= EntityItem::DIRTY_VELOCITY;

View file

@ -22,7 +22,6 @@
#include <OctreeElement.h> // for OctreeElement::AppendState
#include <OctreePacketData.h>
#include <ShapeInfo.h>
#include <StreamUtils.h> // adebug
#include "EntityItemID.h"
#include "EntityItemProperties.h"
@ -140,34 +139,33 @@ public:
virtual void debugDump() const;
virtual bool supportsDetailedRayIntersection() const { return false; }
virtual bool findDetailedRayIntersectionInMeters(const glm::vec3& origin, const glm::vec3& direction,
virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
void** intersectedObject, bool precisionPicking) const { return true; }
// attributes applicable to all entity types
EntityTypes::EntityType getType() const { return _type; }
glm::vec3 getPositionInDomainUnits() const { return _position / (float)TREE_SCALE; } /// get position in domain scale units (0.0 - 1.0)
const glm::vec3& getPositionInMeters() const { return _position; } /// get position in meters
const glm::vec3& getPosition() const { return _position; } /// get position in meters
/// set position in domain scale units (0.0 - 1.0)
void setPositionInDomainUnits(const glm::vec3& value)
{ setPositionInMeters(glm::clamp(value, 0.0f, 1.0f) * (float)TREE_SCALE); }
void setPositionInMeters(const glm::vec3& value) {
{ setPosition(glm::clamp(value, 0.0f, 1.0f) * (float)TREE_SCALE); }
void setPosition(const glm::vec3& value) {
_position = value;
std::cout << "adebug setPosition = " << _position << std::endl; // adebug
}
glm::vec3 getCenterInDomainUnits() const { return getCenterInMeters() / (float) TREE_SCALE; }
glm::vec3 getCenterInMeters() const;
glm::vec3 getCenterInDomainUnits() const { return getCenter() / (float) TREE_SCALE; }
glm::vec3 getCenter() const;
glm::vec3 getDimensionsInDomainUnits() const { return _dimensions / (float)TREE_SCALE; } /// get dimensions in domain scale units (0.0 - 1.0)
const glm::vec3& getDimensionsInMeters() const { return _dimensions; } /// get dimensions in meters
const glm::vec3& getDimensions() const { return _dimensions; } /// get dimensions in meters
/// set dimensions in domain scale units (0.0 - 1.0)
virtual void setDimensionsInDomainUnits(const glm::vec3& value) { _dimensions = glm::abs(value) * (float)TREE_SCALE; }
/// set dimensions in meter units (0.0 - TREE_SCALE)
virtual void setDimensionsInMeters(const glm::vec3& value) { _dimensions = glm::abs(value); }
virtual void setDimensions(const glm::vec3& value) { _dimensions = glm::abs(value); }
const glm::quat& getRotation() const { return _rotation; }
void setRotation(const glm::quat& rotation) { _rotation = rotation; }
@ -185,15 +183,15 @@ public:
float getDensity() const { return _density; }
glm::vec3 getVelocityInDomainUnits() const { return _velocity / (float)TREE_SCALE; } /// velocity in domain scale units (0.0-1.0) per second
const glm::vec3 getVelocityInMeters() const { return _velocity; } /// get velocity in meters
const glm::vec3 getVelocity() const { return _velocity; } /// get velocity in meters
void setVelocityInDomainUnits(const glm::vec3& value) { _velocity = value * (float)TREE_SCALE; } /// velocity in domain scale units (0.0-1.0) per second
void setVelocityInMeters(const glm::vec3& value) { _velocity = value; } /// velocity in meters
void setVelocity(const glm::vec3& value) { _velocity = value; } /// velocity in meters
bool hasVelocity() const { return _velocity != ENTITY_ITEM_ZERO_VEC3; }
glm::vec3 getGravityInDomainUnits() const { return _gravity / (float)TREE_SCALE; } /// gravity in domain scale units (0.0-1.0) per second squared
const glm::vec3& getGravityInMeters() const { return _gravity; } /// get gravity in meters
const glm::vec3& getGravity() const { return _gravity; } /// get gravity in meters
void setGravityInDomainUnits(const glm::vec3& value) { _gravity = value * (float)TREE_SCALE; } /// gravity in domain scale units (0.0-1.0) per second squared
void setGravityInMeters(const glm::vec3& value) { _gravity = value; } /// gravity in meters
void setGravity(const glm::vec3& value) { _gravity = value; } /// gravity in meters
bool hasGravity() const { return _gravity != ENTITY_ITEM_ZERO_VEC3; }
float getDamping() const { return _damping; }
@ -217,7 +215,7 @@ public:
// position, size, and bounds related helpers
AACube getMaximumAACube() const;
AACube getMinimumAACube() const;
AABox getAABoxInMeters() const; /// axis aligned bounding box in world-frame (meters)
AABox getAABox() const; /// axis aligned bounding box in world-frame (meters)
AABox getAABoxInDomainUnits() const; /// axis aligned bounding box in domain scale units (0.0 - 1.0)
const QString& getScript() const { return _script; }
@ -254,9 +252,9 @@ public:
void setUserData(const QString& value) { _userData = value; }
// TODO: get rid of users of getRadius()...
float getRadiusInMeters() const;
float getRadius() 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); }
virtual bool containsInDomainUnits(const glm::vec3& point) const { return getAABoxInDomainUnits().contains(point); }
virtual void computeShapeInfo(ShapeInfo& info) const;
@ -265,17 +263,17 @@ public:
// updateFoo() methods to be used when changes need to be accumulated in the _dirtyFlags
void updatePositionInDomainUnits(const glm::vec3& value);
void updatePositionInMeters(const glm::vec3& value);
void updatePosition(const glm::vec3& value);
void updateDimensionsInDomainUnits(const glm::vec3& value);
void updateDimensionsInMeters(const glm::vec3& value);
void updateDimensions(const glm::vec3& value);
void updateRotation(const glm::quat& rotation);
void updateDensity(float value);
void updateMass(float value);
void updateVelocityInDomainUnits(const glm::vec3& value);
void updateVelocityInMeters(const glm::vec3& value);
void updateVelocity(const glm::vec3& value);
void updateDamping(float value);
void updateGravityInDomainUnits(const glm::vec3& value);
void updateGravityInMeters(const glm::vec3& value);
void updateGravity(const glm::vec3& value);
void updateAngularVelocity(const glm::vec3& value);
void updateAngularDamping(float value);
void updateIgnoreForCollisions(bool value);

View file

@ -80,7 +80,6 @@ EntityItemProperties::EntityItemProperties() :
}
EntityItemProperties::~EntityItemProperties() {
std::cout << "adebug delete properties" << std::endl; // adebug
}
void EntityItemProperties::setSittingPoints(const QVector<SittingPoint>& sittingPoints) {
@ -296,7 +295,7 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine) cons
sittingPoints.setProperty("length", _sittingPoints.size());
COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(sittingPoints, sittingPoints); // gettable, but not settable
AABox aaBox = getAABoxInMeters();
AABox aaBox = getAABox();
QScriptValue boundingBox = engine->newObject();
QScriptValue bottomRightNear = vec3toScriptValue(engine, aaBox.getCorner());
QScriptValue topFarLeft = vec3toScriptValue(engine, aaBox.calcTopFarLeft());
@ -821,16 +820,10 @@ void EntityItemProperties::markAllChanged() {
_shapeTypeChanged = true;
}
AACube EntityItemProperties::getMaximumAACubeInTreeUnits() const {
AACube maxCube = getMaximumAACubeInMeters();
maxCube.scale(1.0f / (float)TREE_SCALE);
return maxCube;
}
/// The maximum bounding cube for the entity, independent of it's rotation.
/// This accounts for the registration point (upon which rotation occurs around).
///
AACube EntityItemProperties::getMaximumAACubeInMeters() const {
AACube EntityItemProperties::getMaximumAACube() const {
// * we know that the position is the center of rotation
glm::vec3 centerOfRotation = _position; // also where _registration point is
@ -854,7 +847,7 @@ AACube EntityItemProperties::getMaximumAACubeInMeters() const {
}
// The minimum bounding box for the entity.
AABox EntityItemProperties::getAABoxInMeters() const {
AABox EntityItemProperties::getAABox() const {
// _position represents the position of the registration point.
glm::vec3 registrationRemainder = glm::vec3(1.0f, 1.0f, 1.0f) - _registrationPoint;

View file

@ -129,9 +129,8 @@ public:
/// used by EntityScriptingInterface to return EntityItemProperties for unknown models
void setIsUnknownID() { _id = UNKNOWN_ENTITY_ID; _idSet = true; }
AACube getMaximumAACubeInTreeUnits() const;
AACube getMaximumAACubeInMeters() const;
AABox getAABoxInMeters() const;
AACube getMaximumAACube() const;
AABox getAABox() const;
void debugDump() const;
void setLastEdited(quint64 usecTime);

View file

@ -206,7 +206,7 @@ QVector<EntityItemID> EntityScriptingInterface::findEntities(const glm::vec3& ce
if (_entityTree) {
_entityTree->lockForRead();
QVector<const EntityItem*> entities;
_entityTree->findEntitiesInMeters(center, radius, entities);
_entityTree->findEntities(center, radius, entities);
_entityTree->unlock();
foreach (const EntityItem* entity, entities) {

View file

@ -87,7 +87,7 @@ void EntitySimulation::sortEntitiesThatMoved() {
// External changes to entity position/shape are expected to be sorted outside of the EntitySimulation.
PerformanceTimer perfTimer("sortingEntities");
MovingEntitiesOperator moveOperator(_entityTree);
AACube domainBounds(glm::vec3(0.0f,0.0f,0.0f), 1.0f);
AACube domainBounds(glm::vec3(0.0f,0.0f,0.0f), (float)TREE_SCALE);
QSet<EntityItem*>::iterator itemItr = _entitiesToBeSorted.begin();
while (itemItr != _entitiesToBeSorted.end()) {
EntityItem* entity = *itemItr;
@ -150,7 +150,7 @@ void EntitySimulation::entityChanged(EntityItem* entity) {
bool wasRemoved = false;
uint32_t dirtyFlags = entity->getDirtyFlags();
if (dirtyFlags & EntityItem::DIRTY_POSITION) {
AACube domainBounds(glm::vec3(0.0f,0.0f,0.0f), 1.0f);
AACube domainBounds(glm::vec3(0.0f,0.0f,0.0f), (float)TREE_SCALE);
AACube newCube = entity->getMaximumAACube();
if (!domainBounds.touches(newCube)) {
qDebug() << "Entity " << entity->getEntityItemID() << " moved out of domain bounds.";

View file

@ -424,9 +424,7 @@ bool EntityTree::findNearPointOperation(OctreeElement* element, void* extraData)
EntityTreeElement* entityTreeElement = static_cast<EntityTreeElement*>(element);
glm::vec3 penetration;
AACube cube = entityTreeElement->getAACube();
cube.scale((float)TREE_SCALE);
bool sphereIntersection = cube.findSpherePenetration(args->position, args->targetRadius, penetration);
bool sphereIntersection = entityTreeElement->getAACube().findSpherePenetration(args->position, args->targetRadius, penetration);
// If this entityTreeElement contains the point, then search it...
if (sphereIntersection) {
@ -434,7 +432,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->getPositionInMeters();
glm::vec3 entityPosition = thisClosestEntity->getPosition();
float distanceFromPointToEntity = glm::distance(entityPosition, args->position);
// If we're within our target radius
@ -457,7 +455,6 @@ 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, targetRadius, false, NULL, FLT_MAX };
lockForRead();
// NOTE: This should use recursion, since this is a spatial operation
@ -477,9 +474,7 @@ public:
bool EntityTree::findInSphereOperation(OctreeElement* element, void* extraData) {
FindAllNearPointArgs* args = static_cast<FindAllNearPointArgs*>(extraData);
glm::vec3 penetration;
AACube cube = element->getAACube();
cube.scale((float)TREE_SCALE);
bool sphereIntersection = cube.findSpherePenetration(args->position, args->targetRadius, penetration);
bool sphereIntersection = element->getAACube().findSpherePenetration(args->position, args->targetRadius, penetration);
// If this element contains the point, then search it...
if (sphereIntersection) {
@ -493,8 +488,7 @@ bool EntityTree::findInSphereOperation(OctreeElement* element, void* extraData)
}
// NOTE: assumes caller has handled locking
void EntityTree::findEntitiesInMeters(const glm::vec3& center, float radius, QVector<const EntityItem*>& foundEntities) {
// position and targetRadius are in meters, so we need to convert to TreeUnits in FindNearPointArgs
void EntityTree::findEntities(const glm::vec3& center, float radius, QVector<const EntityItem*>& foundEntities) {
FindAllNearPointArgs args = { center, radius };
// NOTE: This should use recursion, since this is a spatial operation
recurseTreeWithOperation(findInSphereOperation, &args);
@ -515,9 +509,7 @@ public:
bool EntityTree::findInCubeOperation(OctreeElement* element, void* extraData) {
FindEntitiesInCubeArgs* args = static_cast<FindEntitiesInCubeArgs*>(extraData);
AACube elementCube = element->getAACube();
elementCube.scale((float)TREE_SCALE);
if (elementCube.touches(args->_cube)) {
if (element->getAACube().touches(args->_cube)) {
EntityTreeElement* entityTreeElement = static_cast<EntityTreeElement*>(element);
entityTreeElement->getEntities(args->_cube, args->_foundEntities);
return true;

View file

@ -109,7 +109,7 @@ public:
/// \param radius the radius of the sphere in world-frame (meters)
/// \param foundEntities[out] vector of const EntityItem*
/// \remark Side effect: any initial contents in foundEntities will be lost
void findEntitiesInMeters(const glm::vec3& center, float radius, QVector<const EntityItem*>& foundEntities);
void findEntities(const glm::vec3& center, float radius, QVector<const EntityItem*>& foundEntities);
/// finds all entities that touch a cube
/// \param cube the query cube in world-frame (meters)

View file

@ -22,15 +22,9 @@ EntityTreeElement::EntityTreeElement(unsigned char* octalCode) : OctreeElement()
};
EntityTreeElement::~EntityTreeElement() {
int bar = 0;
_octreeMemoryUsage -= sizeof(EntityTreeElement);
bar = 1;
std::cout << "adebug EntityTreeElement " << (void*)(this) << " deletes old entityItems = " << (void*)(_entityItems) << std::endl; // adebug
delete _entityItems;
bar = 2;
_entityItems = NULL;
bar = 3;
std::cout << "adebug bar = " << bar << std::endl; // adebug
}
// This will be called primarily on addChildAt(), which means we're adding a child of our
@ -45,7 +39,6 @@ OctreeElement* EntityTreeElement::createNewElement(unsigned char* octalCode) {
void EntityTreeElement::init(unsigned char* octalCode) {
OctreeElement::init(octalCode);
_entityItems = new QList<EntityItem*>;
std::cout << "adebug EntityTreeElement " << (void*)(this) << " gets new entityItems = " << (void*)(_entityItems) << std::endl; // adebug
_octreeMemoryUsage += sizeof(EntityTreeElement);
}
@ -57,7 +50,7 @@ EntityTreeElement* EntityTreeElement::addChildAtIndex(int index) {
void EntityTreeElement::debugExtraEncodeData(EncodeBitstreamParams& params) const {
qDebug() << "EntityTreeElement::debugExtraEncodeData()... ";
qDebug() << " element:" << getAACube();
qDebug() << " element:" << _cube;
OctreeElementExtraEncodeData* extraEncodeData = params.extraEncodeData;
assert(extraEncodeData); // EntityTrees always require extra encode data on their encoding passes
@ -166,7 +159,7 @@ void EntityTreeElement::elementEncodeComplete(EncodeBitstreamParams& params, Oct
const bool wantDebug = false;
if (wantDebug) {
qDebug() << "EntityTreeElement::elementEncodeComplete() element:" << getAACube();
qDebug() << "EntityTreeElement::elementEncodeComplete() element:" << _cube;
}
OctreeElementExtraEncodeData* extraEncodeData = params.extraEncodeData;
@ -201,7 +194,7 @@ void EntityTreeElement::elementEncodeComplete(EncodeBitstreamParams& params, Oct
= static_cast<EntityTreeElementExtraEncodeData*>(extraEncodeData->value(childElement));
if (wantDebug) {
qDebug() << "checking child: " << childElement->getAACube();
qDebug() << "checking child: " << childElement->_cube;
qDebug() << " childElement->isLeaf():" << childElement->isLeaf();
qDebug() << " childExtraEncodeData->elementCompleted:" << childExtraEncodeData->elementCompleted;
qDebug() << " childExtraEncodeData->subtreeCompleted:" << childExtraEncodeData->subtreeCompleted;
@ -222,7 +215,7 @@ void EntityTreeElement::elementEncodeComplete(EncodeBitstreamParams& params, Oct
}
if (wantDebug) {
qDebug() << "for this element: " << getAACube();
qDebug() << "for this element: " << _cube;
qDebug() << " WAS elementCompleted:" << thisExtraEncodeData->elementCompleted;
qDebug() << " WAS subtreeCompleted:" << thisExtraEncodeData->subtreeCompleted;
}
@ -309,7 +302,6 @@ OctreeElement::AppendState EntityTreeElement::appendElementData(OctreePacketData
// the entity may not be in view and then in view a frame later, let the client side handle it's view
// frustum culling on rendering.
AACube entityCube = entity->getMaximumAACube();
entityCube.scale(TREE_SCALE);
if (params.viewFrustum->cubeInFrustum(entityCube) == ViewFrustum::OUTSIDE) {
includeThisEntity = false; // out of view, don't include it
}
@ -448,14 +440,14 @@ bool EntityTreeElement::bestFitBounds(const AABox& bounds) const {
}
bool EntityTreeElement::containsBounds(const glm::vec3& minPoint, const glm::vec3& maxPoint) const {
glm::vec3 clampedMin = glm::clamp(minPoint, 0.0f, 1.0f);
glm::vec3 clampedMax = glm::clamp(maxPoint, 0.0f, 1.0f);
glm::vec3 clampedMin = glm::clamp(minPoint, 0.0f, (float)TREE_SCALE);
glm::vec3 clampedMax = glm::clamp(maxPoint, 0.0f, (float)TREE_SCALE);
return _cube.contains(clampedMin) && _cube.contains(clampedMax);
}
bool EntityTreeElement::bestFitBounds(const glm::vec3& minPoint, const glm::vec3& maxPoint) const {
glm::vec3 clampedMin = glm::clamp(minPoint, 0.0f, 1.0f);
glm::vec3 clampedMax = glm::clamp(maxPoint, 0.0f, 1.0f);
glm::vec3 clampedMin = glm::clamp(minPoint, 0.0f, (float)TREE_SCALE);
glm::vec3 clampedMax = glm::clamp(maxPoint, 0.0f, (float)TREE_SCALE);
if (_cube.contains(clampedMin) && _cube.contains(clampedMax)) {
@ -476,7 +468,7 @@ bool EntityTreeElement::bestFitBounds(const glm::vec3& minPoint, const glm::vec3
return false;
}
bool EntityTreeElement::findDetailedRayIntersectionInMeters(const glm::vec3& origin, const glm::vec3& direction,
bool EntityTreeElement::findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
void** intersectedObject, bool precisionPicking, float distanceToElementCube) {
@ -492,7 +484,7 @@ bool EntityTreeElement::findDetailedRayIntersectionInMeters(const glm::vec3& ori
while(entityItr != entityEnd) {
EntityItem* entity = (*entityItr);
AABox entityBox = entity->getAABoxInMeters();
AABox entityBox = entity->getAABox();
float localDistance;
BoxFace localFace;
@ -501,11 +493,11 @@ bool EntityTreeElement::findDetailedRayIntersectionInMeters(const glm::vec3& ori
// extents is the entity relative, scaled, centered extents of the entity
glm::mat4 rotation = glm::mat4_cast(entity->getRotation());
glm::mat4 translation = glm::translate(entity->getPositionInMeters());
glm::mat4 translation = glm::translate(entity->getPosition());
glm::mat4 entityToWorldMatrix = translation * rotation;
glm::mat4 worldToEntityMatrix = glm::inverse(entityToWorldMatrix);
glm::vec3 dimensions = entity->getDimensionsInMeters();
glm::vec3 dimensions = entity->getDimensions();
glm::vec3 registrationPoint = entity->getRegistrationPoint();
glm::vec3 corner = -(dimensions * registrationPoint);
@ -520,7 +512,7 @@ bool EntityTreeElement::findDetailedRayIntersectionInMeters(const glm::vec3& ori
if (localDistance < distance) {
// now ask the entity if we actually intersect
if (entity->supportsDetailedRayIntersection()) {
if (entity->findDetailedRayIntersectionInMeters(origin, direction, keepSearching, element, localDistance,
if (entity->findDetailedRayIntersection(origin, direction, keepSearching, element, localDistance,
localFace, intersectedObject, precisionPicking)) {
if (localDistance < distance) {
@ -556,8 +548,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->getPositionInMeters();
float entityRadius = entity->getRadiusInMeters();
glm::vec3 entityCenter = entity->getPosition();
float entityRadius = entity->getRadius();
// don't penetrate yourself
if (entityCenter == center && entityRadius == radius) {
@ -592,7 +584,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]->getPositionInMeters());
float distanceToEntity = glm::distance(position, (*_entityItems)[i]->getPosition());
if (distanceToEntity < closestEntityDistance) {
closestEntity = (*_entityItems)[i];
}
@ -605,8 +597,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->getPositionInMeters() - searchPosition);
if (distance < searchRadius + entity->getRadiusInMeters()) {
float distance = glm::length(entity->getPosition() - searchPosition);
if (distance < searchRadius + entity->getRadius()) {
foundEntities.push_back(entity);
}
}
@ -619,11 +611,11 @@ void EntityTreeElement::getEntities(const AACube& box, QVector<EntityItem*>& fou
AACube entityCube;
while(entityItr != entityEnd) {
EntityItem* entity = (*entityItr);
float radius = entity->getRadiusInMeters();
float radius = entity->getRadius();
// 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->getPositionInMeters() - glm::vec3(radius), 2.0f * radius);
entityCube.setBox(entity->getPosition() - glm::vec3(radius), 2.0f * radius);
if (entityCube.touches(box)) {
foundEntities.push_back(entity);
}
@ -830,9 +822,7 @@ bool EntityTreeElement::pruneChildren() {
void EntityTreeElement::debugDump() {
qDebug() << "EntityTreeElement...";
AACube temp = getAACube();
temp.scale((float)TREE_SCALE);
qDebug() << " cube:" << temp;
qDebug() << " cube:" << _cube;
qDebug() << " has child elements:" << getChildCount();
if (_entityItems->size()) {
qDebug() << " has entities:" << _entityItems->size();

View file

@ -73,7 +73,6 @@ public:
class EntityTreeElement : public OctreeElement {
friend class EntityTree; // to allow createElement to new us...
EntityTreeElement();
EntityTreeElement(unsigned char* octalCode = NULL);
virtual OctreeElement* createNewElement(unsigned char* octalCode = NULL);
@ -136,7 +135,7 @@ public:
virtual bool deleteApproved() const { return !hasEntities(); }
virtual bool canRayIntersect() const { return hasEntities(); }
virtual bool findDetailedRayIntersectionInMeters(const glm::vec3& origin, const glm::vec3& direction,
virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
void** intersectedObject, bool precisionPicking, float distanceToElementCube);

View file

@ -255,8 +255,8 @@ void ModelEntityItem::update(const quint64& now) {
void ModelEntityItem::debugDump() const {
qDebug() << "ModelEntityItem id:" << getEntityItemID();
qDebug() << " edited ago:" << getEditedAgo();
qDebug() << " position:" << getPositionInMeters();
qDebug() << " dimensions:" << getDimensionsInMeters();
qDebug() << " position:" << getPosition();
qDebug() << " dimensions:" << getDimensions();
qDebug() << " model URL:" << getModelURL();
}

View file

@ -51,7 +51,7 @@ MovingEntitiesOperator::~MovingEntitiesOperator() {
void MovingEntitiesOperator::addEntityToMoveList(EntityItem* entity, const AACube& newCube) {
EntityTreeElement* oldContainingElement = _tree->getContainingElement(entity->getEntityItemID());
AABox newCubeClamped = newCube.clamp(0.0f, 1.0f);
AABox newCubeClamped = newCube.clamp(0.0f, (float)TREE_SCALE);
if (_wantDebug) {
qDebug() << "MovingEntitiesOperator::addEntityToMoveList() -----------------------------";
@ -114,7 +114,7 @@ bool MovingEntitiesOperator::shouldRecurseSubTree(OctreeElement* element) {
// If we don't have an old entity, then we don't contain the entity, otherwise
// check the bounds
if (_entitiesToMove.size() > 0) {
AACube elementCube = element->getAACube();
const AACube& elementCube = element->getAACube();
int detailIndex = 0;
foreach(const EntityToMoveDetails& details, _entitiesToMove) {

View file

@ -15,11 +15,11 @@
class EntityToMoveDetails {
public:
EntityItem* entity;
AACube oldCube;
AACube newCube;
AABox newCubeClamped;
AACube oldCube; // meters
AACube newCube; // meters
AABox newCubeClamped; // meters
EntityTreeElement* oldContainingElement;
AACube oldContainingElementCube;
AACube oldContainingElementCube; // meters
bool oldFound;
bool newFound;
};

View file

@ -91,13 +91,13 @@ void SphereEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBi
APPEND_ENTITY_PROPERTY(PROP_COLOR, appendColor, getColor());
}
bool SphereEntityItem::findDetailedRayIntersectionInMeters(const glm::vec3& origin, const glm::vec3& direction,
bool SphereEntityItem::findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
void** intersectedObject, bool precisionPicking) const {
// determine the ray in the frame of the entity transformed from a unit sphere
glm::mat4 translation = glm::translate(getPositionInMeters());
glm::mat4 translation = glm::translate(getPosition());
glm::mat4 rotation = glm::mat4_cast(getRotation());
glm::mat4 scale = glm::scale(getDimensionsInMeters());
glm::mat4 scale = glm::scale(getDimensions());
glm::mat4 registration = glm::translate(glm::vec3(0.5f, 0.5f, 0.5f) - getRegistrationPoint());
glm::mat4 entityToWorldMatrix = translation * rotation * scale * registration;
glm::mat4 worldToEntityMatrix = glm::inverse(entityToWorldMatrix);

View file

@ -56,7 +56,7 @@ public:
virtual ShapeType getShapeType() const { return SHAPE_TYPE_SPHERE; }
virtual bool supportsDetailedRayIntersection() const { return true; }
virtual bool findDetailedRayIntersectionInMeters(const glm::vec3& origin, const glm::vec3& direction,
virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
void** intersectedObject, bool precisionPicking) const;

View file

@ -42,7 +42,7 @@ TextEntityItem::TextEntityItem(const EntityItemID& entityItemID, const EntityIte
const float TEXT_ENTITY_ITEM_FIXED_DEPTH = 0.01f;
void TextEntityItem::setDimensionsInMeters(const glm::vec3& value) {
void TextEntityItem::setDimensions(const glm::vec3& value) {
// NOTE: Text Entities always have a "depth" of 1cm.
_dimensions = glm::vec3(value.x, value.y, TEXT_ENTITY_ITEM_FIXED_DEPTH);
}
@ -128,7 +128,7 @@ void TextEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBits
}
bool TextEntityItem::findDetailedRayIntersectionInMeters(const glm::vec3& origin, const glm::vec3& direction,
bool TextEntityItem::findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
void** intersectedObject, bool precisionPicking) const {
@ -142,7 +142,7 @@ bool TextEntityItem::findDetailedRayIntersectionInMeters(const glm::vec3& origin
const glm::vec3 UNROTATED_NORMAL(0.0f, 0.0f, -1.0f);
glm::vec3 normal = _rotation * UNROTATED_NORMAL;
plane.setNormal(normal);
plane.setPoint(getPositionInMeters()); // the position is definitely a point on our plane
plane.setPoint(getPosition()); // the position is definitely a point on our plane
bool intersects = plane.findRayIntersection(rayInfo);
@ -151,11 +151,11 @@ bool TextEntityItem::findDetailedRayIntersectionInMeters(const glm::vec3& origin
// now we know the point the ray hit our plane
glm::mat4 rotation = glm::mat4_cast(getRotation());
glm::mat4 translation = glm::translate(getPositionInMeters());
glm::mat4 translation = glm::translate(getPosition());
glm::mat4 entityToWorldMatrix = translation * rotation;
glm::mat4 worldToEntityMatrix = glm::inverse(entityToWorldMatrix);
glm::vec3 dimensions = getDimensionsInMeters();
glm::vec3 dimensions = getDimensions();
glm::vec3 registrationPoint = getRegistrationPoint();
glm::vec3 corner = -(dimensions * registrationPoint);
AABox entityFrameBox(corner, dimensions);

View file

@ -23,7 +23,7 @@ public:
ALLOW_INSTANTIATION // This class can be instantiated
/// set dimensions in domain scale units (0.0 - 1.0) this will also reset radius appropriately
virtual void setDimensionsInMeters(const glm::vec3& value);
virtual void setDimensions(const glm::vec3& value);
virtual void setDimensionsInDomainUnits(const glm::vec3& value);
virtual ShapeType getShapeType() const { return SHAPE_TYPE_BOX; }
@ -47,7 +47,7 @@ public:
EntityPropertyFlags& propertyFlags, bool overwriteLocalData);
virtual bool supportsDetailedRayIntersection() const { return true; }
virtual bool findDetailedRayIntersectionInMeters(const glm::vec3& origin, const glm::vec3& direction,
virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
void** intersectedObject, bool precisionPicking) const;

View file

@ -46,7 +46,7 @@ UpdateEntityOperator::UpdateEntityOperator(EntityTree* tree,
// which can handle all potential rotations?
// the getMaximumAACube is the relaxed form.
_oldEntityCube = _existingEntity->getMaximumAACube();
_oldEntityBox = _oldEntityCube.clamp(0.0f, 1.0f); // clamp to domain bounds
_oldEntityBox = _oldEntityCube.clamp(0.0f, (float)TREE_SCALE); // clamp to domain bounds
// If the old properties doesn't contain the properties required to calculate a bounding box,
// get them from the existing entity. Registration point is required to correctly calculate
@ -59,8 +59,8 @@ UpdateEntityOperator::UpdateEntityOperator(EntityTree* tree,
// get the old property value and set it in our properties in order for our bounds
// calculations to work.
if (_properties.containsPositionChange() && !_properties.containsDimensionsChange()) {
glm::vec3 oldDimensionsInMeters = _existingEntity->getDimensionsInMeters();
_properties.setDimensions(oldDimensionsInMeters);
glm::vec3 oldDimensions= _existingEntity->getDimensions();
_properties.setDimensions(oldDimensions);
if (_wantDebug) {
qDebug() << " ** setting properties dimensions - had position change, no dimension change **";
@ -68,8 +68,8 @@ UpdateEntityOperator::UpdateEntityOperator(EntityTree* tree,
}
if (!_properties.containsPositionChange() && _properties.containsDimensionsChange()) {
glm::vec3 oldPositionInMeters = _existingEntity->getPositionInMeters();
_properties.setPosition(oldPositionInMeters);
glm::vec3 oldPosition= _existingEntity->getPosition();
_properties.setPosition(oldPosition);
if (_wantDebug) {
qDebug() << " ** setting properties position - had dimensions change, no position change **";
@ -114,7 +114,7 @@ UpdateEntityOperator::UpdateEntityOperator(EntityTree* tree,
}
} else {
_newEntityCube = _properties.getMaximumAACubeInTreeUnits();
_newEntityCube = _properties.getMaximumAACube();
_removeOld = true; // our properties are going to move us, so remember this for later processing
if (_wantDebug) {
@ -122,7 +122,7 @@ UpdateEntityOperator::UpdateEntityOperator(EntityTree* tree,
}
}
_newEntityBox = _newEntityCube.clamp(0.0f, 1.0f); // clamp to domain bounds
_newEntityBox = _newEntityCube.clamp(0.0f, (float)TREE_SCALE); // clamp to domain bounds
if (_wantDebug) {

View file

@ -274,7 +274,7 @@ int Octree::readElementData(OctreeElement* destinationElement, const unsigned ch
if (destinationElement->getScale() < SCALE_AT_DANGEROUSLY_DEEP_RECURSION) {
qDebug() << "UNEXPECTED: readElementData() destination element is unreasonably small ["
<< destinationElement->getScale() * (float)TREE_SCALE << " meters] "
<< destinationElement->getScale() << " meters] "
<< " Discarding " << bytesAvailable << " remaining bytes.";
return bytesAvailable; // assume we read the entire buffer...
}
@ -748,12 +748,8 @@ public:
bool findSpherePenetrationOp(OctreeElement* element, void* extraData) {
SphereArgs* args = static_cast<SphereArgs*>(extraData);
// the details in args is in meters (world-frame) so we have to scale the element cube up
AACube box = element->getAACube();
box.scale((float)TREE_SCALE);
// coarse check against bounds
if (!box.expandedContains(args->center, args->radius)) {
if (!element->getAACube().expandedContains(args->center, args->radius)) {
return false;
}
if (element->hasContent()) {
@ -837,14 +833,12 @@ bool findCapsulePenetrationOp(OctreeElement* element, void* extraData) {
CapsuleArgs* args = static_cast<CapsuleArgs*>(extraData);
// coarse check against bounds
AACube box = element->getAACube();
box.scale((float)TREE_SCALE);
if (!box.expandedIntersectsSegment(args->start, args->end, args->radius)) {
if (!element->getAACube().expandedIntersectsSegment(args->start, args->end, args->radius)) {
return false;
}
if (element->hasContent()) {
glm::vec3 nodePenetration;
if (box.findCapsulePenetration(args->start, args->end, args->radius, nodePenetration)) {
if (element->getAACube().findCapsulePenetration(args->start, args->end, args->radius, nodePenetration)) {
args->penetration = addPenetrations(args->penetration, nodePenetration);
args->found = true;
}
@ -872,8 +866,7 @@ bool findContentInCubeOp(OctreeElement* element, void* extraData) {
ContentArgs* args = static_cast<ContentArgs*>(extraData);
// coarse check against bounds
AACube cube = element->getAACube();
cube.scale(TREE_SCALE);
const AACube& cube = element->getAACube();
if (!cube.touches(args->cube)) {
return false;
}
@ -940,8 +933,7 @@ public:
// Find the smallest colored voxel enclosing a point (if there is one)
bool getElementEnclosingOperation(OctreeElement* element, void* extraData) {
GetElementEnclosingArgs* args = static_cast<GetElementEnclosingArgs*>(extraData);
AACube elementBox = element->getAACube();
if (elementBox.contains(args->point)) {
if (element->getAACube().contains(args->point)) {
if (element->hasContent() && element->isLeaf()) {
// we've reached a solid leaf containing the point, return the element.
args->element = element;
@ -1207,9 +1199,8 @@ int Octree::encodeTreeBitstreamRecursion(OctreeElement* element,
// If the user also asked for occlusion culling, check if this element is occluded, but only if it's not a leaf.
// leaf occlusion is handled down below when we check child nodes
if (params.wantOcclusionCulling && !element->isLeaf()) {
AACube voxelBox = element->getAACube();
voxelBox.scale(TREE_SCALE);
OctreeProjectedPolygon* voxelPolygon = new OctreeProjectedPolygon(params.viewFrustum->getProjectedPolygon(voxelBox));
OctreeProjectedPolygon* voxelPolygon =
new OctreeProjectedPolygon(params.viewFrustum->getProjectedPolygon(element->getAACube()));
// In order to check occlusion culling, the shadow has to be "all in view" otherwise, we will ignore occlusion
// culling and proceed as normal
@ -1360,10 +1351,8 @@ int Octree::encodeTreeBitstreamRecursion(OctreeElement* element,
if (params.wantOcclusionCulling && childElement->isLeaf()) {
// Don't check occlusion here, just add them to our distance ordered array...
AACube voxelBox = childElement->getAACube();
voxelBox.scale(TREE_SCALE);
OctreeProjectedPolygon* voxelPolygon = new OctreeProjectedPolygon(
params.viewFrustum->getProjectedPolygon(voxelBox));
params.viewFrustum->getProjectedPolygon(childElement->getAACube()));
// In order to check occlusion culling, the shadow has to be "all in view" otherwise, we ignore occlusion
// culling and proceed as normal

View file

@ -270,6 +270,9 @@ public:
void recurseTreeWithOperation(RecurseOctreeOperation operation, void* extraData = NULL);
void recurseTreeWithPostOperation(RecurseOctreeOperation operation, void* extraData = NULL);
/// \param operation type of operation
/// \param point point in world-frame (meters)
/// \param extraData hook for user data to be interpreted by special context
void recurseTreeWithOperationDistanceSorted(RecurseOctreeOperation operation,
const glm::vec3& point, void* extraData = NULL);
@ -308,8 +311,13 @@ public:
bool findCapsulePenetration(const glm::vec3& start, const glm::vec3& end, float radius, glm::vec3& penetration,
Octree::lockType lockType = Octree::TryLock, bool* accurateResult = NULL);
/// \param cube query cube in world-frame (meters)
/// \param[out] cubes list of cubes (world-frame) of child elements that have content
bool findContentInCube(const AACube& cube, CubeList& cubes);
/// \param point query point in world-frame (meters)
/// \param lockType how to lock the tree (Lock, TryLock, NoLock)
/// \param[out] accurateResult pointer to output result, will be set "true" or "false" if non-null
OctreeElement* getElementEnclosingPoint(const glm::vec3& point,
Octree::lockType lockType = Octree::TryLock, bool* accurateResult = NULL);

View file

@ -194,14 +194,14 @@ void OctreeElement::setShouldRender(bool shouldRender) {
}
void OctreeElement::calculateAACube() {
glm::vec3 corner;
// copy corner into cube
copyFirstVertexForCode(getOctalCode(),(float*)&corner);
glm::vec3 corner;
copyFirstVertexForCode(getOctalCode(), (float*)&corner);
// this tells you the "size" of the voxel
float voxelScale = 1 / powf(2, numberOfThreeBitSectionsInCode(getOctalCode()));
_cube.setBox(corner,voxelScale);
float voxelScale = (float)TREE_SCALE / powf(2.0f, numberOfThreeBitSectionsInCode(getOctalCode()));
corner *= (float)TREE_SCALE;
_cube.setBox(corner, voxelScale);
}
void OctreeElement::deleteChildAtIndex(int childIndex) {
@ -1221,9 +1221,7 @@ float OctreeElement::getEnclosingRadius() const {
}
ViewFrustum::location OctreeElement::inFrustum(const ViewFrustum& viewFrustum) const {
AACube cube = _cube; // use temporary cube so we can scale it
cube.scale(TREE_SCALE);
return viewFrustum.cubeInFrustum(cube);
return viewFrustum.cubeInFrustum(_cube);
}
// There are two types of nodes for which we want to "render"
@ -1257,16 +1255,13 @@ bool OctreeElement::calculateShouldRender(const ViewFrustum* viewFrustum, float
// does as much math as possible in voxel scale and then scales up to TREE_SCALE at end
float OctreeElement::furthestDistanceToCamera(const ViewFrustum& viewFrustum) const {
glm::vec3 furthestPoint;
AACube cube = getAACube();
cube.scale((float)TREE_SCALE);
viewFrustum.getFurthestPointFromCamera(cube, furthestPoint);
viewFrustum.getFurthestPointFromCamera(_cube, furthestPoint);
glm::vec3 temp = viewFrustum.getPosition() - furthestPoint;
float distanceToFurthestPoint = sqrtf(glm::dot(temp, temp));
return distanceToFurthestPoint;
return sqrtf(glm::dot(temp, temp));
}
float OctreeElement::distanceToCamera(const ViewFrustum& viewFrustum) const {
glm::vec3 center = _cube.calcCenter() * (float)TREE_SCALE;
glm::vec3 center = _cube.calcCenter();
glm::vec3 temp = viewFrustum.getPosition() - center;
float distanceToVoxelCenter = sqrtf(glm::dot(temp, temp));
return distanceToVoxelCenter;
@ -1339,14 +1334,12 @@ bool OctreeElement::findRayIntersection(const glm::vec3& origin, const glm::vec3
keepSearching = true; // assume that we will continue searching after this.
AACube cube = getAACube();
cube.scale((float)TREE_SCALE);
float distanceToElementCube = std::numeric_limits<float>::max();
float distanceToElementDetails = distance;
BoxFace localFace;
// if the ray doesn't intersect with our cube, we can stop searching!
if (!cube.findRayIntersection(origin, direction, distanceToElementCube, localFace)) {
if (!_cube.findRayIntersection(origin, direction, distanceToElementCube, localFace)) {
keepSearching = false; // no point in continuing to search
return false; // we did not intersect
}
@ -1358,7 +1351,7 @@ bool OctreeElement::findRayIntersection(const glm::vec3& origin, const glm::vec3
// if the distance to the element cube is not less than the current best distance, then it's not possible
// for any details inside the cube to be closer so we don't need to consider them.
if (cube.contains(origin) || distanceToElementCube < distance) {
if (_cube.contains(origin) || distanceToElementCube < distance) {
if (findDetailedRayIntersection(origin, direction, keepSearching, element, distanceToElementDetails,
face, intersectedObject, precisionPicking, distanceToElementCube)) {
@ -1393,9 +1386,7 @@ bool OctreeElement::findDetailedRayIntersection(const glm::vec3& origin, const g
bool OctreeElement::findSpherePenetration(const glm::vec3& center, float radius,
glm::vec3& penetration, void** penetratedObject) const {
// center and radius are in meters, so we have to scale the _cube into world-frame
AACube cube = _cube;
cube.scale((float)TREE_SCALE);
return cube.findSpherePenetration(center, radius, penetration);
return _cube.findSpherePenetration(center, radius, penetration);
}
// TODO: consider removing this, or switching to using getOrCreateChildElementContaining(const AACube& box)...
@ -1532,15 +1523,15 @@ int OctreeElement::getMyChildContaining(const AACube& cube) const {
if (cubeScale > ourScale) {
qDebug() << "UNEXPECTED -- OctreeElement::getMyChildContaining() -- (cubeScale > ourScale)";
qDebug() << " cube=" << cube;
qDebug() << " elements AACube=" << getAACube();
qDebug() << " elements AACube=" << _cube;
qDebug() << " cubeScale=" << cubeScale;
qDebug() << " ourScale=" << ourScale;
assert(false);
}
// Determine which of our children the minimum and maximum corners of the cube live in...
glm::vec3 cubeCornerMinimum = glm::clamp(cube.getCorner(), 0.0f, 1.0f);
glm::vec3 cubeCornerMaximum = glm::clamp(cube.calcTopFarLeft(), 0.0f, 1.0f);
glm::vec3 cubeCornerMinimum = glm::clamp(cube.getCorner(), 0.0f, (float)TREE_SCALE);
glm::vec3 cubeCornerMaximum = glm::clamp(cube.calcTopFarLeft(), 0.0f, (float)TREE_SCALE);
if (_cube.contains(cubeCornerMinimum) && _cube.contains(cubeCornerMaximum)) {
int childIndexCubeMinimum = getMyChildContainingPoint(cubeCornerMinimum);

View file

@ -101,7 +101,6 @@ void OctreeHeadlessViewer::queryOctree() {
voxelDetailsForCode(rootCode, rootDetails);
jurisdictions.unlock();
AACube serverBounds(glm::vec3(rootDetails.x, rootDetails.y, rootDetails.z), rootDetails.s);
serverBounds.scale(TREE_SCALE);
ViewFrustum::location serverFrustumLocation = _viewFrustum.cubeInFrustum(serverBounds);
@ -170,7 +169,6 @@ void OctreeHeadlessViewer::queryOctree() {
voxelDetailsForCode(rootCode, rootDetails);
jurisdictions.unlock();
AACube serverBounds(glm::vec3(rootDetails.x, rootDetails.y, rootDetails.z), rootDetails.s);
serverBounds.scale(TREE_SCALE);
ViewFrustum::location serverFrustumLocation = _viewFrustum.cubeInFrustum(serverBounds);
if (serverFrustumLocation != ViewFrustum::OUTSIDE) {

View file

@ -22,13 +22,11 @@ OctreeRenderer::OctreeRenderer() :
_managedTree(false),
_viewFrustum(NULL)
{
std::cout << "adebug " << (void*)(this) << " OctreeRenderer() _tree = " << (void*)(_tree) << std::endl; // adebug
}
void OctreeRenderer::init() {
if (!_tree) {
_tree = createTree();
std::cout << "adebug " << (void*)(this) << " init _tree = " << (void*)(_tree) << std::endl; // adebug
_managedTree = true;
}
}
@ -45,7 +43,6 @@ void OctreeRenderer::setTree(Octree* newTree) {
_managedTree = false;
}
_tree = newTree;
std::cout << "adebug " << (void*)(this) << " setTree() _tree = " << (void*)(_tree) << std::endl; // adebug
}
void OctreeRenderer::processDatagram(const QByteArray& dataByteArray, const SharedNodePointer& sourceNode) {

View file

@ -84,19 +84,19 @@ void EntityMotionState::getWorldTransform(btTransform& worldTrans) const {
// bypass const-ness so we can remember the substep
const_cast<EntityMotionState*>(this)->_lastKinematicSubstep = substep;
}
worldTrans.setOrigin(glmToBullet(_entity->getPositionInMeters() - ObjectMotionState::getWorldOffset()));
worldTrans.setOrigin(glmToBullet(_entity->getPosition() - ObjectMotionState::getWorldOffset()));
worldTrans.setRotation(glmToBullet(_entity->getRotation()));
}
// This callback is invoked by the physics simulation at the end of each simulation frame...
// iff the corresponding RigidBody is DYNAMIC and has moved.
void EntityMotionState::setWorldTransform(const btTransform& worldTrans) {
_entity->setPositionInMeters(bulletToGLM(worldTrans.getOrigin()) + ObjectMotionState::getWorldOffset());
_entity->setPosition(bulletToGLM(worldTrans.getOrigin()) + ObjectMotionState::getWorldOffset());
_entity->setRotation(bulletToGLM(worldTrans.getRotation()));
glm::vec3 v;
getVelocity(v);
_entity->setVelocityInMeters(v);
_entity->setVelocity(v);
getAngularVelocity(v);
// DANGER! EntityItem stores angularVelocity in degrees/sec!!!
@ -119,7 +119,7 @@ void EntityMotionState::setWorldTransform(const btTransform& worldTrans) {
void EntityMotionState::updateObjectEasy(uint32_t flags, uint32_t frame) {
if (flags & (EntityItem::DIRTY_POSITION | EntityItem::DIRTY_VELOCITY)) {
if (flags & EntityItem::DIRTY_POSITION) {
_sentPosition = _entity->getPositionInMeters() - ObjectMotionState::getWorldOffset();
_sentPosition = _entity->getPosition() - ObjectMotionState::getWorldOffset();
btTransform worldTrans;
worldTrans.setOrigin(glmToBullet(_sentPosition));
@ -156,14 +156,14 @@ void EntityMotionState::updateObjectEasy(uint32_t flags, uint32_t frame) {
void EntityMotionState::updateObjectVelocities() {
if (_body) {
_sentVelocity = _entity->getVelocityInMeters();
_sentVelocity = _entity->getVelocity();
setVelocity(_sentVelocity);
// DANGER! EntityItem stores angularVelocity in degrees/sec!!!
_sentAngularVelocity = glm::radians(_entity->getAngularVelocity());
setAngularVelocity(_sentAngularVelocity);
_sentAcceleration = _entity->getGravityInMeters();
_sentAcceleration = _entity->getGravity();
setGravity(_sentAcceleration);
_body->setActivationState(ACTIVE_TAG);

View file

@ -66,17 +66,17 @@ void EntityTests::entityTreeTests(bool verbose) {
const EntityItem* foundEntityByRadius = tree.findClosestEntity(positionAtCenter, targetRadius);
const EntityItem* foundEntityByID = tree.findEntityByEntityItemID(entityID);
EntityTreeElement* containingElement = tree.getContainingElement(entityID);
AACube elementCube = containingElement ? containingElement->getAACube() : AACube();
const AACube& elementCube = containingElement ? containingElement->getAACube() : AACube();
if (verbose) {
qDebug() << "foundEntityByRadius=" << foundEntityByRadius;
qDebug() << "foundEntityByID=" << foundEntityByID;
qDebug() << "containingElement=" << containingElement;
qDebug() << "containingElement.box="
<< elementCube.getCorner().x * TREE_SCALE << ","
<< elementCube.getCorner().y * TREE_SCALE << ","
<< elementCube.getCorner().z * TREE_SCALE << ":"
<< elementCube.getScale() * TREE_SCALE;
<< elementCube.getCorner().x << ","
<< elementCube.getCorner().y << ","
<< elementCube.getCorner().z << ":"
<< elementCube.getScale();
qDebug() << "elementCube.getScale()=" << elementCube.getScale();
//containingElement->printDebugDetails("containingElement");
}
@ -109,17 +109,17 @@ void EntityTests::entityTreeTests(bool verbose) {
const EntityItem* foundEntityByRadius = tree.findClosestEntity(positionNearOrigin, targetRadius);
const EntityItem* foundEntityByID = tree.findEntityByEntityItemID(entityID);
EntityTreeElement* containingElement = tree.getContainingElement(entityID);
AACube elementCube = containingElement ? containingElement->getAACube() : AACube();
const AACube& elementCube = containingElement ? containingElement->getAACube() : AACube();
if (verbose) {
qDebug() << "foundEntityByRadius=" << foundEntityByRadius;
qDebug() << "foundEntityByID=" << foundEntityByID;
qDebug() << "containingElement=" << containingElement;
qDebug() << "containingElement.box="
<< elementCube.getCorner().x * TREE_SCALE << ","
<< elementCube.getCorner().y * TREE_SCALE << ","
<< elementCube.getCorner().z * TREE_SCALE << ":"
<< elementCube.getScale() * TREE_SCALE;
<< elementCube.getCorner().x << ","
<< elementCube.getCorner().y << ","
<< elementCube.getCorner().z << ":"
<< elementCube.getScale();
//containingElement->printDebugDetails("containingElement");
}
@ -149,17 +149,17 @@ void EntityTests::entityTreeTests(bool verbose) {
const EntityItem* foundEntityByRadius = tree.findClosestEntity(positionAtCenter, targetRadius);
const EntityItem* foundEntityByID = tree.findEntityByEntityItemID(entityID);
EntityTreeElement* containingElement = tree.getContainingElement(entityID);
AACube elementCube = containingElement ? containingElement->getAACube() : AACube();
const AACube& elementCube = containingElement ? containingElement->getAACube() : AACube();
if (verbose) {
qDebug() << "foundEntityByRadius=" << foundEntityByRadius;
qDebug() << "foundEntityByID=" << foundEntityByID;
qDebug() << "containingElement=" << containingElement;
qDebug() << "containingElement.box="
<< elementCube.getCorner().x * TREE_SCALE << ","
<< elementCube.getCorner().y * TREE_SCALE << ","
<< elementCube.getCorner().z * TREE_SCALE << ":"
<< elementCube.getScale() * TREE_SCALE;
<< elementCube.getCorner().x << ","
<< elementCube.getCorner().y << ","
<< elementCube.getCorner().z << ":"
<< elementCube.getScale();
//containingElement->printDebugDetails("containingElement");
}
@ -288,7 +288,7 @@ void EntityTests::entityTreeTests(bool verbose) {
totalElapsedFind += (endFind - startFind);
EntityTreeElement* containingElement = tree.getContainingElement(entityID);
AACube elementCube = containingElement ? containingElement->getAACube() : AACube();
const AACube& elementCube = containingElement ? containingElement->getAACube() : AACube();
bool elementIsBestFit = containingElement->bestFitEntityBounds(foundEntityByID);
@ -297,10 +297,10 @@ void EntityTests::entityTreeTests(bool verbose) {
qDebug() << "foundEntityByID=" << foundEntityByID;
qDebug() << "containingElement=" << containingElement;
qDebug() << "containingElement.box="
<< elementCube.getCorner().x * TREE_SCALE << ","
<< elementCube.getCorner().y * TREE_SCALE << ","
<< elementCube.getCorner().z * TREE_SCALE << ":"
<< elementCube.getScale() * TREE_SCALE;
<< elementCube.getCorner().x << ","
<< elementCube.getCorner().y << ","
<< elementCube.getCorner().z << ":"
<< elementCube.getScale();
qDebug() << "elementCube.getScale()=" << elementCube.getScale();
//containingElement->printDebugDetails("containingElement");
qDebug() << "elementIsBestFit=" << elementIsBestFit;