removed center from AABox to further save memory

This commit is contained in:
ZappoMan 2013-10-15 12:05:54 -07:00
parent c9b0edf345
commit 9ba39c3a84
7 changed files with 17 additions and 45 deletions

View file

@ -53,13 +53,6 @@ bool VoxelSendThread::process() {
}
}
// some debugging...
printf("ViewFrustum::getProjectedPolygonTime=%llu ViewFrustum::getProjectedPolygonCalls=%llu\n",
ViewFrustum::getProjectedPolygonTime, ViewFrustum::getProjectedPolygonCalls);
printf("ViewFrustum::getFurthestPointFromCameraTime=%llu ViewFrustum::getFurthestPointFromCameraCalls=%llu\n",
ViewFrustum::getFurthestPointFromCameraTime, ViewFrustum::getFurthestPointFromCameraCalls);
return isStillRunning(); // keep running till they terminate us
}

View file

@ -20,6 +20,12 @@ AABox::AABox(const glm::vec3& corner, float size) :
AABox::AABox() : _corner(0,0,0), _scale(0) {
};
glm::vec3 AABox::calcCenter() const {
glm::vec3 center(_corner);
center += (glm::vec3(_scale, _scale, _scale) * 0.5f);
return center;
}
glm::vec3 AABox::calcTopFarLeft() const {
glm::vec3 topFarLeft(_corner);
topFarLeft += glm::vec3(_scale, _scale, _scale);
@ -28,11 +34,9 @@ glm::vec3 AABox::calcTopFarLeft() const {
void AABox::scale(float scale) {
_corner = _corner * scale;
_center = _center * scale;
_scale = _scale * scale;
}
glm::vec3 AABox::getVertex(BoxVertex vertex) const {
switch (vertex) {
case BOTTOM_LEFT_NEAR:
@ -57,7 +61,6 @@ glm::vec3 AABox::getVertex(BoxVertex vertex) const {
void AABox::setBox(const glm::vec3& corner, float scale) {
_corner = corner;
_scale = scale;
_center = _corner + (glm::vec3(_scale, _scale, _scale) * 0.5f);
}
glm::vec3 AABox::getVertexP(const glm::vec3& normal) const {

View file

@ -36,11 +36,9 @@ enum BoxVertex {
const int FACE_COUNT = 6;
class AABox
{
class AABox {
public:
AABox(const glm::vec3& corner, float size);
AABox();
~AABox() {};
@ -54,11 +52,11 @@ public:
void scale(float scale);
const glm::vec3& getCorner() const { return _corner; };
const glm::vec3& getCenter() const { return _center; };
glm::vec3 calcTopFarLeft() const;
float getScale() const { return _scale; }
glm::vec3 calcCenter() const;
glm::vec3 calcTopFarLeft() const;
glm::vec3 getVertex(BoxVertex vertex) const;
bool contains(const glm::vec3& point) const;
@ -70,7 +68,6 @@ public:
bool findCapsulePenetration(const glm::vec3& start, const glm::vec3& end, float radius, glm::vec3& penetration) const;
private:
glm::vec3 getClosestPointOnFace(const glm::vec3& point, BoxFace face) const;
glm::vec3 getClosestPointOnFace(const glm::vec4& origin, const glm::vec4& direction, BoxFace face) const;
glm::vec4 getPlane(BoxFace face) const;
@ -78,7 +75,6 @@ private:
static BoxFace getOppositeFace(BoxFace face);
glm::vec3 _corner;
glm::vec3 _center;
float _scale;
};

View file

@ -541,14 +541,7 @@ const int hullVertexLookup[MAX_POSSIBLE_COMBINATIONS][MAX_PROJECTED_POLYGON_VERT
{6, TOP_RIGHT_NEAR, TOP_RIGHT_FAR, BOTTOM_RIGHT_FAR, BOTTOM_LEFT_FAR, BOTTOM_LEFT_NEAR, TOP_LEFT_NEAR}, // back, top, left
};
uint64_t ViewFrustum::getProjectedPolygonTime = 0;
uint64_t ViewFrustum::getProjectedPolygonCalls = 0;
#include <PerfStat.h>
VoxelProjectedPolygon ViewFrustum::getProjectedPolygon(const AABox& box) const {
getProjectedPolygonCalls++;
PerformanceWarning(false, "ViewFrustum::getProjectedPolygon", false, &getProjectedPolygonTime);
const glm::vec3& bottomNearRight = box.getCorner();
glm::vec3 topFarLeft = box.calcTopFarLeft();
@ -604,7 +597,7 @@ VoxelProjectedPolygon ViewFrustum::getProjectedPolygon(const AABox& box) const {
***/
}
// set the distance from our camera position, to the closest vertex
float distance = glm::distance(getPosition(), box.getCenter());
float distance = glm::distance(getPosition(), box.calcCenter());
projectedPolygon.setDistance(distance);
projectedPolygon.setAnyInView(anyPointsInView);
projectedPolygon.setAllInView(allPointsInView);
@ -613,18 +606,12 @@ VoxelProjectedPolygon ViewFrustum::getProjectedPolygon(const AABox& box) const {
}
uint64_t ViewFrustum::getFurthestPointFromCameraTime = 0;
uint64_t ViewFrustum::getFurthestPointFromCameraCalls = 0;
// Similar strategy to getProjectedPolygon() we use the knowledge of camera position relative to the
// axis-aligned voxels to determine which of the voxels vertices must be the furthest. No need for
// squares and square-roots. Just compares.
glm::vec3 ViewFrustum::getFurthestPointFromCamera(const AABox& box) const {
getFurthestPointFromCameraCalls++;
PerformanceWarning(false, "ViewFrustum::getFurthestPointFromCamera", false, &getFurthestPointFromCameraTime);
const glm::vec3& center = box.getCenter();
const glm::vec3& bottomNearRight = box.getCorner();
glm::vec3 center = box.calcCenter();
glm::vec3 topFarLeft = box.calcTopFarLeft();
glm::vec3 furthestPoint;

View file

@ -96,13 +96,7 @@ public:
VoxelProjectedPolygon getProjectedPolygon(const AABox& box) const;
glm::vec3 getFurthestPointFromCamera(const AABox& box) const;
static uint64_t getProjectedPolygonTime;
static uint64_t getProjectedPolygonCalls;
static uint64_t getFurthestPointFromCameraTime;
static uint64_t getFurthestPointFromCameraCalls;
private:
// Used for keyhole calculations
ViewFrustum::location pointInKeyhole(const glm::vec3& point) const;
ViewFrustum::location sphereInKeyhole(const glm::vec3& center, float radius) const;

View file

@ -394,20 +394,20 @@ float VoxelNode::furthestDistanceToCamera(const ViewFrustum& viewFrustum) const
}
float VoxelNode::distanceToCamera(const ViewFrustum& viewFrustum) const {
glm::vec3 center = _box.getCenter() * (float)TREE_SCALE;
glm::vec3 center = _box.calcCenter() * (float)TREE_SCALE;
glm::vec3 temp = viewFrustum.getPosition() - center;
float distanceToVoxelCenter = sqrtf(glm::dot(temp, temp));
return distanceToVoxelCenter;
}
float VoxelNode::distanceSquareToPoint(const glm::vec3& point) const {
glm::vec3 temp = point - _box.getCenter();
glm::vec3 temp = point - _box.calcCenter();
float distanceSquare = glm::dot(temp, temp);
return distanceSquare;
}
float VoxelNode::distanceToPoint(const glm::vec3& point) const {
glm::vec3 temp = point - _box.getCenter();
glm::vec3 temp = point - _box.calcCenter();
float distance = sqrtf(glm::dot(temp, temp));
return distance;
}

View file

@ -53,10 +53,9 @@ public:
bool collapseIdenticalLeaves();
const AABox& getAABox() const { return _box; }
const glm::vec3& getCenter() const { return _box.getCenter(); }
const glm::vec3& getCorner() const { return _box.getCorner(); }
float getScale() const { return _box.getScale(); } // voxelScale = (1 / powf(2, *node->getOctalCode())); }
int getLevel() const { return *_octalCode + 1; } // one based or zero based? this doesn't correctly handle 2 byte case
float getScale() const { return _box.getScale(); }
int getLevel() const { return numberOfThreeBitSectionsInCode(getOctalCode()) + 1; }
float getEnclosingRadius() const;