From 0377ca1adb2209b25176335fd045b8b5ecc58aac Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Tue, 21 May 2013 13:32:41 -0700 Subject: [PATCH] Compute nodes' enclosing radius in the same place. --- libraries/voxels/src/VoxelNode.cpp | 4 ++++ libraries/voxels/src/VoxelNode.h | 2 ++ libraries/voxels/src/VoxelTree.cpp | 10 ++-------- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/libraries/voxels/src/VoxelNode.cpp b/libraries/voxels/src/VoxelNode.cpp index 6bab72cf61..e79e06e3a3 100644 --- a/libraries/voxels/src/VoxelNode.cpp +++ b/libraries/voxels/src/VoxelNode.cpp @@ -247,6 +247,10 @@ void VoxelNode::printDebugDetails(const char* label) const { printOctalCode(_octalCode); } +float VoxelNode::getEnclosingRadius() const { + return getScale() * sqrtf(3.0f) / 2.0f; +} + bool VoxelNode::isInView(const ViewFrustum& viewFrustum) const { AABox box = _box; // use temporary box so we can scale it box.scale(TREE_SCALE); diff --git a/libraries/voxels/src/VoxelNode.h b/libraries/voxels/src/VoxelNode.h index cf80bcab46..5ce12199c8 100644 --- a/libraries/voxels/src/VoxelNode.h +++ b/libraries/voxels/src/VoxelNode.h @@ -57,6 +57,8 @@ public: float getScale() const { return _box.getSize().x; /* voxelScale = (1 / powf(2, *node->getOctalCode())); */ }; int getLevel() const { return *_octalCode + 1; /* one based or zero based? */ }; + float getEnclosingRadius() const; + bool isColored() const { return (_trueColor[3]==1); }; bool isInView(const ViewFrustum& viewFrustum) const; ViewFrustum::location inFrustum(const ViewFrustum& viewFrustum) const; diff --git a/libraries/voxels/src/VoxelTree.cpp b/libraries/voxels/src/VoxelTree.cpp index 8e570bca86..cf8615bd3b 100644 --- a/libraries/voxels/src/VoxelTree.cpp +++ b/libraries/voxels/src/VoxelTree.cpp @@ -693,12 +693,9 @@ bool findSpherePenetrationOp(VoxelNode* node, void* extraData) { // currently, we treat each node as a sphere enveloping the box const glm::vec3& nodeCenter = node->getCenter(); - float halfNodeScale = node->getScale() * 0.5f; - float halfNodeScale2 = halfNodeScale * halfNodeScale; - float nodeRadius = sqrtf(halfNodeScale2*3.0f); glm::vec3 vector = args->center - nodeCenter; float vectorLength = glm::length(vector); - float distance = vectorLength - nodeRadius - args->radius; + float distance = vectorLength - node->getEnclosingRadius() - args->radius; if (distance >= 0.0f) { return false; } @@ -748,12 +745,9 @@ bool findCapsulePenetrationOp(VoxelNode* node, void* extraData) { // currently, we treat each node as a sphere enveloping the box const glm::vec3& nodeCenter = node->getCenter(); - float halfNodeScale = node->getScale() * 0.5f; - float halfNodeScale2 = halfNodeScale * halfNodeScale; - float nodeRadius = sqrtf(halfNodeScale2*3.0f); glm::vec3 vector = computeVectorFromPointToSegment(nodeCenter, args->start, args->end); float vectorLength = glm::length(vector); - float distance = vectorLength - nodeRadius - args->radius; + float distance = vectorLength - node->getEnclosingRadius() - args->radius; if (distance >= 0.0f) { return false; }