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

This commit is contained in:
2015-11-16 18:20:13 +00:00
parent c27e345c51
commit ddcd5c716a
18 changed files with 389 additions and 158 deletions

View File

@@ -32,6 +32,8 @@ GLObjectBase::GLObjectBase() {
blend_src = GL_SRC_ALPHA;
blend_dest = GL_ONE_MINUS_SRC_ALPHA;
type_ = Mesh;
raw_matrix = false;
mat_.setToIdentity();
view_ = 0;
}
@@ -44,6 +46,8 @@ GLObjectBase * GLObjectBase::clone(bool withChildren) {
o->accept_fog = accept_fog;
o->visible_ = visible_;
o->type_ = type_;
o->raw_matrix = raw_matrix;
o->mat_ = mat_;
o->pos_ = pos_;
o->angles_ = angles_;
o->scale_ = scale_;
@@ -58,8 +62,12 @@ GLObjectBase * GLObjectBase::clone(bool withChildren) {
o->puvws = puvws;
o->faces = faces;
o->uvws = uvws;
o->norms = norms;
o->normals = normals;
o->vbo = vbo;
o->vbo.vertices_ = vbo.vertices_;
o->vbo.normals_ = vbo.normals_;
o->vbo.texcoords_ = vbo.texcoords_;
o->vbo.colors_ = vbo.colors_;
o->view_ = 0;
o->children_.clear();
if (withChildren) {
@@ -126,16 +134,31 @@ void GLObjectBase::calculateBoundingBox() {
}
void GLObjectBase::setTransform(const QMatrix4x4 & t) {
raw_matrix = true;
mat_ = t;
pos_ = mat_.column(3).toVector3D();
mat_.setColumn(3, QVector4D(0., 0., 0., 1.));
buildTransform();
}
void GLObjectBase::buildTransform() {
itransform_.setToIdentity();
GLObjectBase * p = parent_;
if (p != 0)
itransform_ *= p->itransform_;
itransform_.translate(pos_);
itransform_.rotate(angles_.z(), 0., 0., 1.);
itransform_.rotate(angles_.y(), 0., 1., 0.);
itransform_.rotate(angles_.x(), 1., 0., 0.);
itransform_.scale(scale_);
if (raw_matrix) {
itransform_.translate(pos_);
itransform_ *= mat_;
//qDebug() << "raw_matrix" << itransform_;
} else {
itransform_.translate(pos_);
itransform_.rotate(angles_.z(), 0., 0., 1.);
itransform_.rotate(angles_.y(), 0., 1., 0.);
itransform_.rotate(angles_.x(), 1., 0., 0.);
itransform_.scale(scale_);
}
foreach (GLObjectBase * i, children_)
i->buildTransform();
}
@@ -151,10 +174,14 @@ void GLObjectBase::render(int * id, QMap<int, GLObjectBase * > * ids, int sh_id_
if (!visible_) return;
glPushMatrix();
if (pos_.x() != 0. || pos_.y() != 0. || pos_.z() != 0.) glTranslated(pos_.x(), pos_.y(), pos_.z());
if (angles_.z() != 0.) glRotated(angles_.z(), 0., 0., 1.);
if (angles_.y() != 0.) glRotated(angles_.y(), 0., 1., 0.);
if (angles_.x() != 0.) glRotated(angles_.x(), 1., 0., 0.);
if (scale_.x() != 1. || scale_.y() != 1. || scale_.z() != 1.) glScaled(scale_.x(), scale_.y(), scale_.z());
if (raw_matrix) {
qglMultMatrix(mat_);
} else {
if (angles_.z() != 0.) glRotated(angles_.z(), 0., 0., 1.);
if (angles_.y() != 0.) glRotated(angles_.y(), 0., 1., 0.);
if (angles_.x() != 0.) glRotated(angles_.x(), 1., 0., 0.);
if (scale_.x() != 1. || scale_.y() != 1. || scale_.z() != 1.) glScaled(scale_.x(), scale_.y(), scale_.z());
}
material_.apply();
if (id != 0) {
++(*id);