git-svn-id: svn://db.shs.com.ru/libs@319 a8b55f48-bf90-11e4-a774-851b48703e85

This commit is contained in:
2017-11-17 11:54:18 +00:00
parent e03e8e24c0
commit cdba136c66
9 changed files with 76 additions and 15 deletions

View File

@@ -305,3 +305,46 @@ const Camera & QGLViewBase::camera() const {
void QGLViewBase::setCamera(const Camera & camera) {
*camera_ = camera;
}
Box3D::Box3D(const QVector<QVector3D> & points) {
x = y = z = width = length = height = angle_z = angle_xy = angle_roll = 0.f;
if (points.isEmpty()) return;
float ix, iy, iz, ax, ay, az;
ix = ax = points[0].x();
iy = ay = points[0].y();
iz = az = points[0].z();
for (int i = 1; i < points.size(); ++i) {
ix = qMin<double>(ix, points[i].x()); ax = qMax<double>(ax, points[i].x());
iy = qMin<double>(iy, points[i].y()); ay = qMax<double>(ay, points[i].y());
iz = qMin<double>(iz, points[i].z()); az = qMax<double>(az, points[i].z());
}
x = ix;
y = iy;
z = iz;
length = ax - ix;
width = ay - iy;
height = az - iz;
}
QVector<QVector3D> Box3D::corners() const {
QVector<QVector3D> ret;
ret << QVector3D(x, y, z) << QVector3D(x, y + width, z) << QVector3D(x, y, z + height) << QVector3D(x, y + width, z + height)
<< QVector3D(x + length, y, z) << QVector3D(x + length, y + width, z)
<< QVector3D(x + length, y, z + height) << QVector3D(x + length, y + width, z + height);
return ret;
}
Box3D & Box3D::operator |=(const Box3D & o) {
if (isEmpty()) *this = o;
else {
GLfloat mx = x + length, my = y + width, mz = z + height;
GLfloat omx = o.x + o.length, omy = o.y + o.width, omz = o.z + o.height;
x = qMin(x, o.x); y = qMin(y, o.y); z = qMin(z, o.z);
mx = qMax(mx, omx); my = qMax(my, omy); mz = qMax(mz, omz);
length = mx - x; width = my - y; height = mz - z;
}
return *this;
}