Changeset 3628 for trunk/packages/vizservers/nanovis/vrmath/BBox.cpp
- Timestamp:
- Apr 11, 2013 12:26:04 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/vizservers/nanovis/vrmath/BBox.cpp
r3494 r3628 20 20 } 21 21 22 BBox::BBox(const BBox& bbox) 22 BBox::BBox(const BBox& other) : 23 min(other.min), 24 max(other.max) 23 25 { 24 min = bbox.min;25 max = bbox.max;26 26 } 27 27 28 BBox::BBox(const Vector3f& minv, const Vector3f& maxv) 28 BBox::BBox(const Vector3f& minv, const Vector3f& maxv) : 29 min(minv), 30 max(maxv) 29 31 { 30 min = minv;31 max = maxv;32 32 } 33 33 … … 40 40 bool BBox::isEmpty() 41 41 { 42 if ((min.x > max.x) || (min.y > max.y) || (min.z > max.z)) { 43 return true; 44 } 42 return (isEmptyX() && isEmptyY() && isEmptyZ()); 43 } 45 44 46 return false; 45 bool BBox::isEmptyX() 46 { 47 return (min.x > max.x); 48 } 49 50 bool BBox::isEmptyY() 51 { 52 return (min.y > max.y); 53 } 54 55 bool BBox::isEmptyZ() 56 { 57 return (min.z > max.z); 47 58 } 48 59 … … 95 106 void BBox::transform(const BBox& box, const Matrix4x4d& mat) 96 107 { 97 float halfSizeX = (box.max.x - box.min.x) * 0.5f; 98 float halfSizeY = (box.max.y - box.min.y) * 0.5f; 99 float halfSizeZ = (box.max.z - box.min.z) * 0.5f; 100 101 float centerX = (box.max.x + box.min.x) * 0.5f; 102 float centerY = (box.max.y + box.min.y) * 0.5f; 103 float centerZ = (box.max.z + box.min.z) * 0.5f; 108 float x0 = box.min.x; 109 float y0 = box.min.y; 110 float z0 = box.min.z; 111 float x1 = box.max.x; 112 float y1 = box.max.y; 113 float z1 = box.max.z; 104 114 105 115 Vector4f points[8]; 106 116 107 points[0].set( centerX + halfSizeX, centerY + halfSizeY, centerZ + halfSizeZ, 1);108 points[1].set( centerX + halfSizeX, centerY + halfSizeY, centerZ - halfSizeZ, 1);109 points[2].set( centerX - halfSizeX, centerY + halfSizeY, centerZ - halfSizeZ, 1);110 points[3].set( centerX - halfSizeX, centerY + halfSizeY, centerZ + halfSizeZ, 1);111 points[4].set( centerX - halfSizeX, centerY - halfSizeY, centerZ + halfSizeZ, 1);112 points[5].set( centerX - halfSizeX, centerY - halfSizeY, centerZ - halfSizeZ, 1);113 points[6].set( centerX + halfSizeX, centerY - halfSizeY, centerZ - halfSizeZ, 1);114 points[7].set( centerX + halfSizeX, centerY - halfSizeY, centerZ + halfSizeZ, 1);117 points[0].set(x0, y0, z0, 1); 118 points[1].set(x1, y0, z0, 1); 119 points[2].set(x0, y1, z0, 1); 120 points[3].set(x0, y0, z1, 1); 121 points[4].set(x1, y1, z0, 1); 122 points[5].set(x1, y0, z1, 1); 123 points[6].set(x0, y1, z1, 1); 124 points[7].set(x1, y1, z1, 1); 115 125 116 float minX , minY, minZ;117 float maxX , maxY, maxZ;126 float minX = FLT_MAX, minY = FLT_MAX, minZ = FLT_MAX; 127 float maxX = -FLT_MAX, maxY = -FLT_MAX, maxZ = -FLT_MAX; 118 128 119 points[0] = mat.transform(points[0]); 120 121 minX = maxX = points[0].x; 122 minY = maxY = points[0].y; 123 minZ = maxZ = points[0].z; 124 125 for (int i = 1; i < 8; i++) { 129 for (int i = 0; i < 8; i++) { 126 130 points[i] = mat.transform(points[i]); 127 131 128 132 if (points[i].x > maxX) maxX = points[i].x; 129 else if (points[i].x < minX) minX = points[i].x; 130 133 if (points[i].x < minX) minX = points[i].x; 131 134 if (points[i].y > maxY) maxY = points[i].y; 132 else if (points[i].y < minY) minY = points[i].y; 133 135 if (points[i].y < minY) minY = points[i].y; 134 136 if (points[i].z > maxZ) maxZ = points[i].z; 135 elseif (points[i].z < minZ) minZ = points[i].z;137 if (points[i].z < minZ) minZ = points[i].z; 136 138 } 137 139 … … 149 151 } 150 152 151 bool BBox:: intersect(const Vector3f& point)153 bool BBox::contains(const Vector3f& point) 152 154 { 153 155 if ((point.x < min.x) || (point.x > max.x)) return false;
Note: See TracChangeset
for help on using the changeset viewer.