Commit 8e0716df by Kai Westerkamp

more AABB

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