git-svn-id: svn://db.shs.com.ru/libs@319 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -138,6 +138,16 @@ void GLObjectBase::addChildren(QList<GLObjectBase * > & list, GLObjectBase * whe
|
||||
|
||||
void GLObjectBase::calculateBoundingBox() {
|
||||
bound = vbo.boundingBox();
|
||||
QVector<QVector3D> c = bound.corners(), tc;
|
||||
//QMatrix4x4 mat = itransform_.inverted();
|
||||
//qDebug() << itransform_ << mat_ << mat;
|
||||
foreach (QVector3D p, c)
|
||||
tc << (itransform_ * QVector4D(p, 1)).toVector3D();
|
||||
bound = Box3D(tc);
|
||||
foreach (GLObjectBase * i, children_) {
|
||||
i->calculateBoundingBox();
|
||||
bound |= i->boundingBox();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -175,6 +175,8 @@ public:
|
||||
const Box3D & boundingBox(bool withChildren = true) const {return bound;}
|
||||
GLVBO & VBO() {return vbo;}
|
||||
|
||||
void calculateBoundingBox();
|
||||
|
||||
QVector3D pos_h;
|
||||
QVector<Vector3d> points, puvws;
|
||||
QVector<Vector3i> faces, uvws, norms;
|
||||
@@ -186,7 +188,6 @@ protected:
|
||||
void addChildren(QList<GLObjectBase * > & list, GLObjectBase * where);
|
||||
void loadTextures(bool with_children = false) {material_.loadTextures((GLTextureManagerBase * )currentGLTextureManager); if (with_children) foreach (GLObjectBase * i, children_) i->loadTextures(); is_tex_loaded = true; checkPass();}
|
||||
//void deleteTextures() {foreach (GLuint i, textures) currentQGLView->deleteTexture(i); textures.clear();}
|
||||
void calculateBoundingBox();
|
||||
void buildTransform();
|
||||
void initInternal() {init(); loadTextures(); foreach (GLObjectBase * i, children_) i->initInternal();}
|
||||
void render(int * id = 0, QMap<int, GLObjectBase * > * ids = 0, int sh_id_loc = 0);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -236,21 +236,25 @@ struct Box3D {
|
||||
GLfloat angle_roll;
|
||||
Box3D() {x = y = z = width = length = height = angle_z = angle_xy = angle_roll = 0.f;}
|
||||
Box3D(const QVector3D & center, GLfloat hwid, GLfloat hlen, GLfloat hhei) {x = center.x() - hwid; y = center.y() - hlen; z = center.z() - hhei; width = 2 * hwid; length = 2 * hlen; height = 2 * hhei; angle_z = angle_xy = angle_roll = 0.f;}
|
||||
Box3D(const QVector<QVector3D> & points);
|
||||
bool isEmpty() const {return (qAbs(width) < 1E-6) || (qAbs(length) < 1E-6) || (qAbs(height) < 1E-6);}
|
||||
QVector3D randomPoint() const {return QVector3D(uprand(length) + x, uprand(width) + y, uprand(height) + z);}
|
||||
QVector3D pos() const {return QVector3D(x, y, z);}
|
||||
QVector3D size() const {return QVector3D(length, width, height);}
|
||||
QVector3D center() const {return QVector3D(length / 2. + x, width / 2. + y, height / 2. + z);}
|
||||
QVector3D angles() const {return QVector3D(angle_xy, angle_roll, angle_z);}
|
||||
QVector<QVector3D> corners() const;
|
||||
void setPos(const QVector3D & p) {x = p.x(); y = p.y(); z = p.z();}
|
||||
void setAngles(const QVector3D & a) {angle_xy = a.x(); angle_roll = a.y(); angle_z = a.z();}
|
||||
void setSize(const QVector3D & s) {length = s.x(); width = s.y(); height = s.z();}
|
||||
void setSize(const QVector3D & s) {length = s.x(); width = s.y(); height = s.z();}
|
||||
Box3D & moveTo(const QVector3D & v) {x = v.x(); y = v.y(); z = v.z(); return *this;}
|
||||
Box3D & move(const QVector3D & v) {x += v.x(); y += v.y(); z += v.z(); return *this;}
|
||||
Box3D movedTo(const QVector3D & v) const {Box3D t(*this); t.x = v.x(); t.y = v.y(); t.z = v.z(); return t;}
|
||||
Box3D moved(const QVector3D & v) const {Box3D t(*this); t.x += v.x(); t.y += v.y(); t.z += v.z(); return t;}
|
||||
Box3D & operator |=(const Box3D & o);
|
||||
};
|
||||
|
||||
inline QDebug operator <<(QDebug d, const Box3D & v) {d << "Box3D {center (" << v.x << "," << v.y << "," << v.z << "), size (" << v.length << "," << v.width << "," << v.height << ")}"; return d;}
|
||||
inline QDebug operator <<(QDebug d, const Box3D & v) {d << "Box3D {start (" << v.x << "," << v.y << "," << v.z << "), size (" << v.length << "," << v.width << "," << v.height << ")}"; return d;}
|
||||
|
||||
struct Vector3d;
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ void GLVBO::init() {
|
||||
#if QT_VERSION >= 0x050600
|
||||
initializeOpenGLFunctions();
|
||||
#endif
|
||||
if (!isIinit()) {
|
||||
if (!isInit()) {
|
||||
//glGenVertexArrays(1, &va_);
|
||||
glGenBuffers(1, &buffer_);
|
||||
}
|
||||
@@ -289,8 +289,9 @@ bool GLVBO::loadFromFile(const QString & filename) {
|
||||
}
|
||||
|
||||
|
||||
Box3D GLVBO::boundingBox() const {
|
||||
Box3D GLVBO::boundingBox(const QMatrix4x4 & mat) const {
|
||||
if (vertices_.size() < 3) return Box3D();
|
||||
bool mi = mat.isIdentity();
|
||||
int vcnt = vertices_.size() / 3;
|
||||
//qDebug() << "calculateBinormals" << vcnt << tcnt << vertices_.size() << texcoords_.size() << "...";
|
||||
GLfloat mix, miy, miz, max, may, maz;
|
||||
@@ -309,9 +310,9 @@ Box3D GLVBO::boundingBox() const {
|
||||
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.x = mix;
|
||||
bound.y = miy;
|
||||
bound.z = miz;
|
||||
bound.length = max - mix;
|
||||
bound.width = may - miy;
|
||||
bound.height = maz - miz;
|
||||
|
||||
@@ -43,9 +43,9 @@ public:
|
||||
void clear();
|
||||
|
||||
GLuint buffer() const {return buffer_;}
|
||||
int verticesCount() const {return vert_count;}
|
||||
bool isIinit() const {return buffer_ != 0;}
|
||||
bool isEmpty() const {return vert_count == 0;}
|
||||
int verticesCount() const {return vertices_.size() / 3;}
|
||||
bool isInit() const {return buffer_ != 0;}
|
||||
bool isEmpty() const {return vertices_.size() < 3;}
|
||||
|
||||
QVector<GLfloat> & vertices() {changed = true; return vertices_;}
|
||||
QVector<GLfloat> & normals() {changed = true; return normals_;}
|
||||
@@ -58,7 +58,7 @@ public:
|
||||
bool saveToFile(const QString & filename);
|
||||
bool loadFromFile(const QString & filename);
|
||||
|
||||
Box3D boundingBox() const;
|
||||
Box3D boundingBox(const QMatrix4x4 & mat = QMatrix4x4()) const;
|
||||
|
||||
private:
|
||||
void calculateBinormals();
|
||||
|
||||
@@ -267,7 +267,7 @@ void QGLView::paintGL() {
|
||||
renderSelection();
|
||||
if (shaders_supported) shader_select->release();
|
||||
uchar cgid[4] = {0, 0, 0, 0};
|
||||
uint iid;
|
||||
uint iid = 0;
|
||||
GLObjectBase * so = 0;
|
||||
if (!rect().contains(lastPos)) {
|
||||
if (hov_obj != 0) {
|
||||
@@ -302,6 +302,7 @@ void QGLView::paintGL() {
|
||||
|
||||
camera().apply(aspect);
|
||||
start_rp.cam_offset_matrix = camera().offsetMatrix();
|
||||
cur_mvpm = start_rp.proj_matrix * start_rp.view_matrix * start_rp.cam_offset_matrix;
|
||||
//objects_.preparePos(camera());
|
||||
|
||||
static GLRendererBase * prev_rend = 0;
|
||||
@@ -640,7 +641,7 @@ void QGLView::mouseMoveEvent(QMouseEvent * e) {
|
||||
emit glMouseMoveEvent(new QMouseEvent(QEvent::MouseMove, QPoint(dx, dy), e->button(), e->buttons(), e->modifiers()));
|
||||
return;
|
||||
}
|
||||
//emit glMouseMoveEvent(e);
|
||||
emit glMouseMoveEvent(e);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -202,6 +202,7 @@ public:
|
||||
void selectObject(GLObjectBase * o);
|
||||
|
||||
GLdouble aspect, iaspect;
|
||||
QMatrix4x4 cur_mvpm;
|
||||
//__GLShaderProgram__ * shader_rope;
|
||||
|
||||
protected:
|
||||
|
||||
@@ -53,7 +53,7 @@ fbo_g(5, true, GL_RGBA16F), fbo_out(3, false, GL_RGBA16F), fbo_hsmall(1, false,
|
||||
pal.setBrush(QPalette::Window, QColor(255, 255, 255, 192));
|
||||
df->setPalette(pal);
|
||||
if (view_)
|
||||
view_->addObject(df);
|
||||
;//view_->addObject(df);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user