Commit 8e0716df by Kai Westerkamp

more AABB

parent 491d6a74
......@@ -2,4 +2,6 @@
/A4/hellocube.pro.user
*.zip
/assimp-3.1.1-win-binaries
*build-*
\ No newline at end of file
*build-*
/A5/ogldev-source
/A5/DisplayModel
......@@ -120,8 +120,8 @@ void MainWidget::loadNewMesh(){
if(fn.isEmpty())
return;
qDebug()<<"Opening File:"<<fn;
mesh = new Mesh(this,fn);
Mesh* temp = new Mesh(this,fn);
mesh = temp;
mesh->setAnimation(linear);
}
......
......@@ -21,8 +21,9 @@ Mesh::MeshEntry::MeshEntry()
numIndex = 0;
VB = 0xFFFFFFFF;
IB = 0xFFFFFFFF;
min = QVector3D();
max = QVector3D();
double amax = std::numeric_limits<float>::max();
min = QVector3D(amax,amax,amax);
max = QVector3D(-amax,-amax,-amax);
}
void Mesh::MeshEntry::init(QOpenGLFunctions_4_3_Core *f,QVector<Vertex>& Vertices,
......@@ -38,10 +39,6 @@ void Mesh::MeshEntry::init(QOpenGLFunctions_4_3_Core *f,QVector<Vertex>& Vertice
f->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IB);
f->glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int) * numIndex, &Indices[0], GL_STATIC_DRAW);
double amax = std::numeric_limits<float>::max();
min = QVector3D(amax,amax,amax);
max = QVector3D(-amax,-amax,-amax);
//calc AABB
for (int i = 0; i < Vertices.size(); ++i) {
Vertex v = Vertices[i];
......@@ -81,7 +78,6 @@ Mesh::Node::Node()
Mesh::Mesh(QOpenGLFunctions_4_3_Core *f,QString fileName)
{
screenTransform = QMatrix4x4();
loaded = false;
linear = false;
this->f =f;
......@@ -160,18 +156,18 @@ Mesh::Mesh(QOpenGLFunctions_4_3_Core *f,QString fileName)
QVector3D min = QVector3D(amax,amax,amax);
QVector3D max = QVector3D(-amax,-amax,-amax);
// findObjectDimension(rootNode,QMatrix4x4(),min,max);
findObjectDimension(rootNode,QMatrix4x4(),min,max);
qDebug()<<"AABB"<<min<<max;
float dist = qMax(max.x() - min.x(), qMax(max.y()-min.y(), max.z() - min.z()));
float sc = 75.0/dist;
float sc = 100.0/dist;
QVector3D center = (max - min)/2;
QVector3D trans = -(max - center);
// Apply the scale and translation to a matrix
screenTransform.setToIdentity();
// screenTransform.scale(sc);
// screenTransform.translate(trans);
screenTransform.scale(sc);
screenTransform.translate(trans);
loaded = true;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment