git-svn-id: svn://db.shs.com.ru/libs@73 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -137,25 +137,7 @@ void GLObjectBase::addChildren(QList<GLObjectBase * > & list, GLObjectBase * whe
|
||||
|
||||
|
||||
void GLObjectBase::calculateBoundingBox() {
|
||||
if (points.isEmpty()) return;
|
||||
GLfloat mix, miy, miz, max, may, maz;
|
||||
mix = max = points[0].x;
|
||||
miy = may = points[0].y;
|
||||
miz = maz = points[0].z;
|
||||
foreach (const Vector3d & i, points) {
|
||||
if (mix > i.x) mix = i.x;
|
||||
if (max < i.x) max = i.x;
|
||||
if (miy > i.y) miy = i.y;
|
||||
if (may < i.y) may = i.y;
|
||||
if (miz > i.z) miz = i.z;
|
||||
if (maz < i.z) maz = i.z;
|
||||
}
|
||||
bound.x = (mix + max) / 2.;
|
||||
bound.y = (miy + may) / 2.;
|
||||
bound.z = (miz + maz) / 2.;
|
||||
bound.length = max - mix;
|
||||
bound.width = may - miy;
|
||||
bound.height = maz - miz;
|
||||
bound = vbo.boundingBox();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -281,3 +281,33 @@ bool GLVBO::loadFromFile(const QString & filename) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Box3D GLVBO::boundingBox() const {
|
||||
if (vertices_.size() < 3) return Box3D();
|
||||
int vcnt = vertices_.size() / 3;
|
||||
//qDebug() << "calculateBinormals" << vcnt << tcnt << vertices_.size() << texcoords_.size() << "...";
|
||||
GLfloat mix, miy, miz, max, may, maz;
|
||||
Vector3d v0(vertices_[0], vertices_[1], vertices_[2]);
|
||||
mix = max = v0.x;
|
||||
miy = may = v0.y;
|
||||
miz = maz = v0.z;
|
||||
Box3D bound;
|
||||
for (int t = 1; t < vcnt; ++t) {
|
||||
int vi = t*3;
|
||||
Vector3d v(vertices_[vi + 0], vertices_[vi + 1], vertices_[vi + 2]);
|
||||
if (mix > v.x) mix = v.x;
|
||||
if (max < v.x) max = v.x;
|
||||
if (miy > v.y) miy = v.y;
|
||||
if (may < v.y) may = v.y;
|
||||
if (miz > v.z) miz = v.z;
|
||||
if (maz < v.z) maz = v.z;
|
||||
}
|
||||
bound.x = (mix + max) / 2.;
|
||||
bound.y = (miy + may) / 2.;
|
||||
bound.z = (miz + maz) / 2.;
|
||||
bound.length = max - mix;
|
||||
bound.width = may - miy;
|
||||
bound.height = maz - miz;
|
||||
return bound;
|
||||
}
|
||||
|
||||
@@ -55,6 +55,8 @@ public:
|
||||
bool saveToFile(const QString & filename);
|
||||
bool loadFromFile(const QString & filename);
|
||||
|
||||
Box3D boundingBox() const;
|
||||
|
||||
private:
|
||||
void calculateBinormals();
|
||||
|
||||
|
||||
@@ -201,6 +201,7 @@ void MainWindow::selectionChanged(GLObjectBase * cur, GLObjectBase * prev) {
|
||||
objectEditor->setObject(sel_obj);
|
||||
if (sel_obj == 0) return;
|
||||
matEditor->setMaterial(sel_obj->material());
|
||||
qDebug() << sel_obj->boundingBox();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user