Clean up AABox to coding standard, made several methods const

- Cleaned up AABox to be consistent with the coding standard
- converted some methods to const and fixed up callers
This commit is contained in:
ZappoMan 2013-04-21 22:46:13 -07:00
parent e93ece0f52
commit 358efb472d
6 changed files with 82 additions and 83 deletions

View file

@ -460,12 +460,12 @@ bool VoxelSystem::falseColorizeInViewOperation(VoxelNode* node, bool down, void*
voxelBox.scale(TREE_SCALE);
printf("voxelBox corner=(%f,%f,%f) x=%f y=%f z=%f\n",
voxelBox.corner.x, voxelBox.corner.y, voxelBox.corner.z,
voxelBox.x, voxelBox.y, voxelBox.z);
printf("voxelBox corner=(%f,%f,%f) x=%f\n",
voxelBox.getCorner().x, voxelBox.getCorner().y, voxelBox.getCorner().z,
voxelBox.getSize().x);
// If the voxel is outside of the view frustum, then false color it red
if (ViewFrustum::OUTSIDE == viewFrustum->pointInFrustum(voxelBox.corner)) {
if (ViewFrustum::OUTSIDE == viewFrustum->pointInFrustum(voxelBox.getCorner())) {
// Out of view voxels are colored RED
unsigned char newR = 255;
unsigned char newG = 0;

View file

@ -1,85 +1,68 @@
/* ------------------------------------------------------
Axis Aligned Boxes - Lighthouse3D
-----------------------------------------------------*/
//
// AABox.h - Axis Aligned Boxes
// hifi
//
// Added by Brad Hefta-Gaub on 04/11/13.
// Originally from lighthouse3d. Modified to utilize glm::vec3 and clean up to our coding standards
//
// Simple axis aligned box class.
//
#include "AABox.h"
AABox::AABox(const glm::vec3& corner, float x, float y, float z) {
setBox(corner,x,y,z);
}
AABox::AABox(void) {
corner.x = 0; corner.y = 0; corner.z = 0;
x = 1.0f;
y = 1.0f;
z = 1.0f;
}
AABox::~AABox() {
// nothing to do
}
void AABox::scale(float scale) {
corner = corner*scale;
x *= scale;
y *= scale;
z *= scale;
_corner = _corner*scale;
_size = _size*scale;
}
void AABox::setBox(const glm::vec3& corner, float x, float y, float z) {
this->corner = corner;
if (x < 0.0) {
x = -x;
this->corner.x -= x;
void AABox::setBox(const glm::vec3& corner, const glm::vec3& size) {
_corner = corner;
_size = size;
// In the event that the caller gave us negative sizes, fix things up to be reasonable
if (_size.x < 0.0) {
_size.x = -size.x;
_corner.x -= _size.x;
}
if (y < 0.0) {
y = -y;
this->corner.y -= y;
if (_size.y < 0.0) {
_size.y = -size.y;
_corner.y -= _size.y;
}
if (z < 0.0) {
z = -z;
this->corner.z -= z;
if (_size.z < 0.0) {
_size.z = -size.z;
_corner.z -= _size.z;
}
this->x = x;
this->y = y;
this->z = z;
}
glm::vec3 AABox::getVertexP(const glm::vec3 &normal) {
glm::vec3 res = corner;
glm::vec3 AABox::getVertexP(const glm::vec3 &normal) const {
glm::vec3 res = _corner;
if (normal.x > 0)
res.x += x;
res.x += _size.x;
if (normal.y > 0)
res.y += y;
res.y += _size.y;
if (normal.z > 0)
res.z += z;
res.z += _size.z;
return(res);
}
glm::vec3 AABox::getVertexN(const glm::vec3 &normal) {
glm::vec3 res = corner;
glm::vec3 AABox::getVertexN(const glm::vec3 &normal) const {
glm::vec3 res = _corner;
if (normal.x < 0)
res.x += x;
res.x += _size.x;
if (normal.y < 0)
res.y += y;
res.y += _size.y;
if (normal.z < 0)
res.z += z;
res.z += _size.z;
return(res);
}

View file

@ -1,9 +1,12 @@
/* ------------------------------------------------------
Axis Aligned Boxes - Lighthouse3D
-----------------------------------------------------*/
//
// AABox.h - Axis Aligned Boxes
// hifi
//
// Added by Brad Hefta-Gaub on 04/11/13.
// Originally from lighthouse3d. Modified to utilize glm::vec3 and clean up to our coding standards
//
// Simple axis aligned box class.
//
#ifndef _AABOX_
#define _AABOX_
@ -15,20 +18,26 @@ class AABox
public:
glm::vec3 corner;
float x,y,z;
AABox(const glm::vec3& corner, float x, float y, float z) : _corner(corner), _size(x,y,z) { };
AABox(const glm::vec3& corner, const glm::vec3& size) : _corner(corner), _size(size) { };
AABox() : _corner(0,0,0), _size(0,0,0) { }
~AABox() { }
AABox(const glm::vec3 &corner, float x, float y, float z);
AABox(void);
~AABox();
void setBox(const glm::vec3& corner, float x, float y, float z);
void setBox(const glm::vec3& corner, float x, float y, float z) { setBox(corner,glm::vec3(x,y,z)); };
void setBox(const glm::vec3& corner, const glm::vec3& size);
// for use in frustum computations
glm::vec3 getVertexP(const glm::vec3& normal);
glm::vec3 getVertexN(const glm::vec3& normal);
glm::vec3 getVertexP(const glm::vec3& normal) const;
glm::vec3 getVertexN(const glm::vec3& normal) const;
void scale(float scale);
const glm::vec3& getCorner() const { return _corner; };
const glm::vec3& getSize() const { return _size; };
private:
glm::vec3 _corner;
glm::vec3 _size;
};

View file

@ -158,17 +158,17 @@ const char* ViewFrustum::debugPlaneName (int plane) const {
}
int ViewFrustum::pointInFrustum(glm::vec3 &p) {
int ViewFrustum::pointInFrustum(const glm::vec3& point) {
int result = INSIDE;
for(int i=0; i < 6; i++) {
if (_planes[i].distance(p) < 0) {
if (_planes[i].distance(point) < 0) {
return OUTSIDE;
}
}
return(result);
}
int ViewFrustum::sphereInFrustum(glm::vec3 &center, float radius) {
int ViewFrustum::sphereInFrustum(const glm::vec3& center, float radius) {
int result = INSIDE;
float distance;
for(int i=0; i < 6; i++) {
@ -182,9 +182,10 @@ int ViewFrustum::sphereInFrustum(glm::vec3 &center, float radius) {
}
int ViewFrustum::boxInFrustum(AABox &b) {
int ViewFrustum::boxInFrustum(const AABox& box) {
printf("ViewFrustum::boxInFrustum() box.corner=%f,%f,%f x=%f\n",b.corner.x,b.corner.y,b.corner.z,b.x);
printf("ViewFrustum::boxInFrustum() box.corner=%f,%f,%f x=%f\n",
box.getCorner().x,box.getCorner().y,box.getCorner().z,box.getSize().x);
int result = INSIDE;
for(int i=0; i < 6; i++) {
@ -195,10 +196,10 @@ int ViewFrustum::boxInFrustum(AABox &b) {
);
glm::vec3 normal = _planes[i].getNormal();
glm::vec3 boxVertexP = b.getVertexP(normal);
glm::vec3 boxVertexP = box.getVertexP(normal);
float planeToBoxVertexPDistance = _planes[i].distance(boxVertexP);
glm::vec3 boxVertexN = b.getVertexN(normal);
glm::vec3 boxVertexN = box.getVertexN(normal);
float planeToBoxVertexNDistance = _planes[i].distance(boxVertexN);

View file

@ -94,9 +94,9 @@ public:
enum {OUTSIDE, INTERSECT, INSIDE};
int pointInFrustum(glm::vec3 &p);
int sphereInFrustum(glm::vec3 &center, float radius);
int boxInFrustum(AABox &b);
int pointInFrustum(const glm::vec3& point);
int sphereInFrustum(const glm::vec3& center, float radius);
int boxInFrustum(const AABox& box);
};

View file

@ -41,12 +41,18 @@ VoxelNode::~VoxelNode() {
}
void VoxelNode::getAABox(AABox& box) const {
glm::vec3 corner;
glm::vec3 size;
// copy corner into box
copyFirstVertexForCode(octalCode,(float*)&box.corner);
copyFirstVertexForCode(octalCode,(float*)&corner);
// this tells you the "size" of the voxel
float voxelScale = 1 / powf(2, *octalCode);
box.x = box.y = box.z = voxelScale;
size = glm::vec3(voxelScale,voxelScale,voxelScale);
box.setBox(corner,size);
}
void VoxelNode::addChildAtIndex(int childIndex) {