Ignore:
Timestamp:
Apr 11, 2013 12:26:04 PM (11 years ago)
Author:
ldelgass
Message:

Some cleanups in vrmath lib, e.g. add copy/assignment ops

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/vizservers/nanovis/vrmath/BBox.cpp

    r3494 r3628  
    2020}
    2121
    22 BBox::BBox(const BBox& bbox)
     22BBox::BBox(const BBox& other) :
     23    min(other.min),
     24    max(other.max)
    2325{
    24     min = bbox.min;
    25     max = bbox.max;     
    2626}
    2727
    28 BBox::BBox(const Vector3f& minv, const Vector3f& maxv)
     28BBox::BBox(const Vector3f& minv, const Vector3f& maxv) :
     29    min(minv),
     30    max(maxv)
    2931{
    30     min = minv;
    31     max = maxv;
    3232}
    3333
     
    4040bool BBox::isEmpty()
    4141{
    42     if ((min.x > max.x) || (min.y > max.y) || (min.z > max.z)) {
    43         return true;
    44     }
     42    return (isEmptyX() && isEmptyY() && isEmptyZ());
     43}
    4544
    46     return false;
     45bool BBox::isEmptyX()
     46{
     47    return (min.x > max.x);
     48}
     49
     50bool BBox::isEmptyY()
     51{
     52    return (min.y > max.y);
     53}
     54
     55bool BBox::isEmptyZ()
     56{
     57    return (min.z > max.z);
    4758}
    4859
     
    95106void BBox::transform(const BBox& box, const Matrix4x4d& mat)
    96107{
    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;
    104114
    105115    Vector4f points[8];
    106116
    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);
    115125
    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;
    118128
    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++) {
    126130        points[i] = mat.transform(points[i]);
    127131
    128132        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;
    131134        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;
    134136        if (points[i].z > maxZ) maxZ = points[i].z;
    135         else if (points[i].z < minZ) minZ = points[i].z;
     137        if (points[i].z < minZ) minZ = points[i].z;
    136138    }
    137139
     
    149151}
    150152
    151 bool BBox::intersect(const Vector3f& point)
     153bool BBox::contains(const Vector3f& point)
    152154{
    153155    if ((point.x < min.x) || (point.x > max.x)) return false;
Note: See TracChangeset for help on using the changeset viewer.