Commit 9703db3f by Kai Westerkamp

AABB

parent 42afb638
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
Camera::Camera() Camera::Camera()
{ {
//setHome(new QQuaternion(45,0,1,0), new QVector3D(-100,0,0)); //setHome(new QQuaternion(45,0,1,0), new QVector3D(-100,0,0));
setHome(new QQuaternion(QQuaternion::fromAxisAndAngle(1,0,0,20)), new QVector3D(0,-25,-150)); setHome(new QQuaternion(QQuaternion::fromAxisAndAngle(1,0,0,20)), new QVector3D(0,0,-150));
} }
void Camera::home() void Camera::home()
......
...@@ -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();
}; max = QVector3D();
}
void Mesh::MeshEntry::init(QOpenGLFunctions_4_3_Core *f,QVector<Vertex>& Vertices, void Mesh::MeshEntry::init(QOpenGLFunctions_4_3_Core *f,QVector<Vertex>& Vertices,
QVector<unsigned int>& Indices){ QVector<unsigned int>& Indices){
...@@ -36,6 +37,22 @@ void Mesh::MeshEntry::init(QOpenGLFunctions_4_3_Core *f,QVector<Vertex>& Vertice ...@@ -36,6 +37,22 @@ void Mesh::MeshEntry::init(QOpenGLFunctions_4_3_Core *f,QVector<Vertex>& Vertice
f->glGenBuffers(1, &IB); f->glGenBuffers(1, &IB);
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
for (int i = 0; i < Vertices.size(); ++i) {
Vertex v = Vertices[i];
min.setX(qMin(min.x(),v.pos.x()));
min.setY(qMin(min.y(),v.pos.y()));
min.setZ(qMin(min.z(),v.pos.z()));
max.setX(qMax(max.x(),v.pos.x()));
max.setY(qMax(max.y(),v.pos.y()));
max.setZ(qMax(max.z(),v.pos.z()));
}
} }
Mesh::MeshEntry::~MeshEntry() Mesh::MeshEntry::~MeshEntry()
...@@ -64,6 +81,7 @@ Mesh::Node::Node() ...@@ -64,6 +81,7 @@ 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;
...@@ -138,56 +156,22 @@ Mesh::Mesh(QOpenGLFunctions_4_3_Core *f,QString fileName) ...@@ -138,56 +156,22 @@ Mesh::Mesh(QOpenGLFunctions_4_3_Core *f,QString fileName)
globalInverseTransform = rootNode.transformation.inverted(); globalInverseTransform = rootNode.transformation.inverted();
double amax = std::numeric_limits<float>::max();
QVector3D min = QVector3D(amax,amax,amax);
QVector3D max = QVector3D(-amax,-amax,-amax);
// 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;
QVector3D center = (max - min)/2;
QVector3D trans = -(max - center);
// //Test Interpolation: // Apply the scale and translation to a matrix
// if(false){ screenTransform.setToIdentity();
// const aiAnimation* animation = scene->mAnimations[0]; // screenTransform.scale(sc);
// const aiNodeAnim *nodeAnimation = findAnimOfNode(animation,"upperarm.R"); // screenTransform.translate(trans);
// qDebug()<<"KeyFrames";
// for(uint i = 0; i < nodeAnimation->mNumPositionKeys; i++){
// qDebug()<<nodeAnimation->mPositionKeys[i].mTime<<convert(nodeAnimation->mPositionKeys[i].mValue);
// }
// qDebug()<<"Interpolated";
// for(float f = 0.0; f < (float)animation->mDuration; f += 0.5f){
// qDebug()<<f<<calcInterpolatedTranslation(f,nodeAnimation);
// }
// }
// for (int i = 0; i < scene->mNumAnimations; ++i) {
// const aiAnimation* animation = scene->mAnimations[i];
// qDebug()<<"Animation"<<animation->mName.C_Str();
// switch (animation->mChannels[0]->mPreState) {
// case aiAnimBehaviour_CONSTANT:
// qDebug()<<"Pre"<<"aiAnimBehaviour_CONSTANT";
// break;
// case aiAnimBehaviour_REPEAT: // use start or end
// qDebug()<<"Pre"<<"aiAnimBehaviour_REPEAT";
// break;
// case aiAnimBehaviour_LINEAR: // linear interpolate
// qDebug()<<"Pre"<<"aiAnimBehaviour_LINEAR";
// break;
// case aiAnimBehaviour_DEFAULT: // take default node transformation
// qDebug()<<"Pre"<<"aiAnimBehaviour_DEFAULT";
// break;
// default:
// qDebug()<<"Pre"<<"not";
// }
// switch (animation->mChannels[0]->mPostState) {
// case aiAnimBehaviour_CONSTANT:
// qDebug()<<"Post"<<"aiAnimBehaviour_CONSTANT";
// break;
// case aiAnimBehaviour_REPEAT: // use start or end
// qDebug()<<"Post"<<"aiAnimBehaviour_REPEAT";
// break;
// case aiAnimBehaviour_LINEAR: // linear interpolate
// qDebug()<<"Post"<<"aiAnimBehaviour_LINEAR";
// break;
// case aiAnimBehaviour_DEFAULT: // take default node transformation
// qDebug()<<"Post"<<"aiAnimBehaviour_DEFAULT";
// break;
// default:
// qDebug()<<"Post"<<"not";
// }
// }
loaded = true; loaded = true;
} }
...@@ -365,7 +349,7 @@ void Mesh::render(QOpenGLShaderProgram *shader, QMatrix4x4 V,QMatrix4x4 P, float ...@@ -365,7 +349,7 @@ void Mesh::render(QOpenGLShaderProgram *shader, QMatrix4x4 V,QMatrix4x4 P, float
shader->setUniformValueArray("Bones",boneTransforms.constData(),boneTransforms.size()); shader->setUniformValueArray("Bones",boneTransforms.constData(),boneTransforms.size());
renderNode(shader,rootNode,V,P,QMatrix4x4()); renderNode(shader,rootNode,V*screenTransform,P,QMatrix4x4());
f->glDisableVertexAttribArray(positionIndex); f->glDisableVertexAttribArray(positionIndex);
...@@ -653,6 +637,32 @@ double Mesh::timeCatmul(QVector3D p1, QVector3D p2, double t_1){ ...@@ -653,6 +637,32 @@ double Mesh::timeCatmul(QVector3D p1, QVector3D p2, double t_1){
return t; return t;
} }
void Mesh::findObjectDimension(Node node, QMatrix4x4 transform, QVector3D &min, QVector3D &max){
transform *= node.transformation;
for (int i = 0; i < node.meshes.size(); i++) {
QVector4D temp = transform*QVector4D(entries[node.meshes[i]].min,1.0);
min.setX(qMin(min.x(),temp.x()));
min.setY(qMin(min.y(),temp.y()));
min.setZ(qMin(min.z(),temp.z()));
max.setX(qMax(max.x(),temp.x()));
max.setY(qMax(max.y(),temp.y()));
max.setZ(qMax(max.z(),temp.z()));
temp = transform*QVector4D(entries[node.meshes[i]].max,1.0);
min.setX(qMin(min.x(),temp.x()));
min.setY(qMin(min.y(),temp.y()));
min.setZ(qMin(min.z(),temp.z()));
max.setX(qMax(max.x(),temp.x()));
max.setY(qMax(max.y(),temp.y()));
max.setZ(qMax(max.z(),temp.z()));
}
for (int i = 0; i < node.children.size(); i++) {
findObjectDimension(node.children[i], transform, min, max);
}
}
...@@ -69,6 +69,9 @@ private: ...@@ -69,6 +69,9 @@ private:
int numIndex; int numIndex;
int materialIndex; int materialIndex;
QOpenGLFunctions_4_3_Core *f; QOpenGLFunctions_4_3_Core *f;
QVector3D min;
QVector3D max;
}; };
struct MaterialInfo struct MaterialInfo
...@@ -112,6 +115,8 @@ private: ...@@ -112,6 +115,8 @@ private:
Assimp::Importer importer; Assimp::Importer importer;
QMatrix4x4 globalInverseTransform; QMatrix4x4 globalInverseTransform;
QMatrix4x4 screenTransform;
QVector<MeshEntry> entries; QVector<MeshEntry> entries;
...@@ -152,6 +157,9 @@ private: ...@@ -152,6 +157,9 @@ private:
QVector3D Catmul(QVector3D before, QVector3D start, QVector3D end, QVector3D after,float Factor); QVector3D Catmul(QVector3D before, QVector3D start, QVector3D end, QVector3D after,float Factor);
double timeCatmul(QVector3D p1, QVector3D p2, double t_1); double timeCatmul(QVector3D p1, QVector3D p2, double t_1);
void findObjectDimension(Node node, QMatrix4x4 transform, QVector3D &min, QVector3D &max);
}; };
#endif // MESH_H #endif // MESH_H
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