if ( vl.x < v2.x ) {
minPoint.x = vl.x; maxPoint.x = v2.x;
}
else
Простейшие геометрические алгоритмы и структуры
minPoint.x = v2.x; maxPoint.x = vl.x;
if ( vl.y < v2.y )
minPoint.y = vl.y;
maxPoint.y = v2.y;
else
minPoint.y = v2.y;
maxPoint.y = vl.y;
if ( vl.z < v2.z )
minPoint.z = vl.z; maxPoint.z = v2.z;
else
minPoint.z = v2.z; maxPoint.z = vl.z;
}
BoundingBox () {
reset ();
}
void addVertex ( const Vector3D& v ) {
if ( v.x < minPoint.x ) minPoint.x = v.x;
if ( v.x > maxPoint.x ) maxPoint.x = v.x;
if ( v.y < minPoint.y ) minPoint.y = v.y;
if ( v.y > maxPoint.y ) maxPoint.y = v.y;
if ( v.z < minPoint.z ) minPoint. z = v.z;
if ( v.z > maxPoint.z ) maxPoint. z = v.z;
}
void addVertices ( const Vector3D * v, int numVertices ) {
for ( register int i = 0,- i < numVertices; i++ ) {
if ( v [i].x < minPoint.x )
minPoint.x = v [i].x;
if ( v [i].x > maxPoint.x )
maxPoint.x = v [i].x;
if ( v [i].y < minPoint.y )
minPoint.y = v [i].y;
if ( v [i].y > maxPoint.y )
maxPoint.y = v [i].y;
if ( v [i].z < minPoint.z )
minPoint.z = v [i].z;
if ( v [i].z > maxPoint.z )
maxPoint.z = v [i].z;
}
}
int classify ( const Plane& plane ) const {
Vector3D nearPoint = plane .makeNearPoint
( minPoint, maxPoint );
if ( plane.classify ( nearPoint ) == IN_FRONT ) return IN_FRONT;
Vector3D farPoint = plane .makeFarPoint
( minPoint, maxPoint );
if ( plane. classify ( farPoint ) == IN_BACK ) return IN_BACK;
return IN_B0TH;
}
Простейшие геометрические алгоритмы и структуры
bool contains ( const Vector3D& pos ) const {
return pos.x >= minPoint.x && pos.x <= maxPoint.x && pos.y >= minPoint.y && pos.y <= maxPoint.y && pos.z >= minPoint.z && pos.z <= maxPoint.z;
}
bool isEmpty () const {
return minPoint.x > maxPoint.x | minPoint.y > maxPoint.y | minPoint.z > maxPoint.z;
}
bool intersects ( const BoundingBox& box ) const {
⇐ Предыдущая| |Следующая ⇒