Commit 9e817f2e by Kai Westerkamp

removed Animation

parent 17e76809
Pipeline #72 skipped
...@@ -6,10 +6,7 @@ MainWidget::MainWidget(Camera *cam) ...@@ -6,10 +6,7 @@ MainWidget::MainWidget(Camera *cam)
startTime = QTime::currentTime(); startTime = QTime::currentTime();
rotTime = QTime::currentTime(); rotTime = QTime::currentTime();
linear = false;
rotation = true; rotation = true;
animate = true;
Animation = 0;
} }
QSize MainWidget::minimumSizeHint() const QSize MainWidget::minimumSizeHint() const
...@@ -96,7 +93,7 @@ QVector3D* MainWidget::trackballPoint(int x, int y){ ...@@ -96,7 +93,7 @@ QVector3D* MainWidget::trackballPoint(int x, int y){
void MainWidget::initializeGL(){ void MainWidget::initializeGL(){
bool glFunctionsOK = initializeOpenGLFunctions(); bool glFunctionsOK = initializeOpenGLFunctions();
//Q_ASSERT(glFunctionsOK); Q_ASSERT(glFunctionsOK);
if(!glFunctionsOK){ if(!glFunctionsOK){
qDebug()<<"ContextFormat"<<this->context()->format(); qDebug()<<"ContextFormat"<<this->context()->format();
exit(4); exit(4);
...@@ -107,7 +104,7 @@ void MainWidget::initializeGL(){ ...@@ -107,7 +104,7 @@ void MainWidget::initializeGL(){
glDisable(GL_CULL_FACE); glDisable(GL_CULL_FACE);
// Shader // Shader
animationShader = initShader(QLatin1String(":/animate.frag"),QLatin1String(":/animate.vert")); subdevisionShader = initShader();
loadNewMesh(); loadNewMesh();
} }
...@@ -122,15 +119,6 @@ void MainWidget::loadNewMesh(){ ...@@ -122,15 +119,6 @@ void MainWidget::loadNewMesh(){
qDebug()<<"Opening File:"<<fn; qDebug()<<"Opening File:"<<fn;
Mesh* temp = new Mesh(this,fn); Mesh* temp = new Mesh(this,fn);
mesh = temp; mesh = temp;
mesh->setAnimation(linear);
}
void MainWidget::setInterpolation(bool linear){
qDebug()<<"linear"<<linear;
this->linear = linear;
if(mesh)
mesh->setAnimation(linear);
} }
void MainWidget::setRotation(bool started){ void MainWidget::setRotation(bool started){
...@@ -141,28 +129,11 @@ void MainWidget::setRotation(bool started){ ...@@ -141,28 +129,11 @@ void MainWidget::setRotation(bool started){
} }
void MainWidget::setAnimating(bool started){ QOpenGLShaderProgram* MainWidget::initShader(){
qDebug()<<"animating"<<started; QString fragSource = QLatin1String(":/animate.frag");
this->animate = started; QString vertSource = QLatin1String(":/animate.vert");
if(started){
startTime = QTime::currentTime();
}
}
void MainWidget::nextAnimation(){
Animation++;
Animation = Animation % mesh->scene->mNumAnimations;
startTime = QTime::currentTime();
qDebug()<<"Animation"<<Animation;
} QOpenGLShader *vert = new QOpenGLShader(QOpenGLShader::Vertex);
QOpenGLShaderProgram* MainWidget::initShader(QString fragSource, QString vertSource){
QOpenGLShader *vert = new QOpenGLShader(QOpenGLShader::Vertex);
if(!vert->compileSourceFile(vertSource)){ if(!vert->compileSourceFile(vertSource)){
qCritical()<< "Fragment Shader"<<vertSource<<"failed"<< vert->log(); qCritical()<< "Fragment Shader"<<vertSource<<"failed"<< vert->log();
exit(5); exit(5);
...@@ -200,18 +171,13 @@ void MainWidget::paintGL(){ ...@@ -200,18 +171,13 @@ void MainWidget::paintGL(){
rot.rotate(time/100.0*36/5,QVector3D(0,1,0)); rot.rotate(time/100.0*36/5,QVector3D(0,1,0));
} }
animationShader->bind(); subdevisionShader->bind();
animationShader->setUniformValue("colorTexture",0); subdevisionShader->setUniformValue("colorTexture",0);
animationShader->setUniformValue("LightPos",QVector3D(0,100,100)); subdevisionShader->setUniformValue("LightPos",QVector3D(0,100,100));
float ftime = startTime.msecsTo(QTime::currentTime()) /1000.0; mesh->render(subdevisionShader,cam->getMatrix()*rot, m_projection);
if(!animate)
ftime = 0;
subdevisionShader->release();
mesh->render(animationShader,cam->getMatrix()*rot, m_projection,(float) ftime,Animation);
animationShader->release();
update(); update();
} }
...@@ -220,7 +186,5 @@ void MainWidget::resizeGL(int width, int height){ ...@@ -220,7 +186,5 @@ void MainWidget::resizeGL(int width, int height){
m_projection = QMatrix4x4(); m_projection = QMatrix4x4();
m_projection.perspective(45.0f,1.0*width/height,0.01f,1000.0f); m_projection.perspective(45.0f,1.0*width/height,0.01f,1000.0f);
} }
...@@ -24,10 +24,8 @@ public: ...@@ -24,10 +24,8 @@ public:
public slots: public slots:
void loadNewMesh(); void loadNewMesh();
void setInterpolation(bool linear);
void setRotation(bool started); void setRotation(bool started);
void setAnimating(bool started);
void nextAnimation();
protected: protected:
...@@ -46,7 +44,7 @@ private: ...@@ -46,7 +44,7 @@ private:
Camera *cam; Camera *cam;
QOpenGLShaderProgram* animationShader; QOpenGLShaderProgram* subdevisionShader;
QMatrix4x4 m_projection; QMatrix4x4 m_projection;
QTime startTime; QTime startTime;
QTime rotTime; QTime rotTime;
...@@ -56,16 +54,11 @@ private: ...@@ -56,16 +54,11 @@ private:
QVector3D *lastSpeherePos; QVector3D *lastSpeherePos;
QPointF * lastScreenPos; QPointF * lastScreenPos;
boolean linear;
boolean rotation; boolean rotation;
boolean animate;
int Animation;
Mesh *mesh; Mesh *mesh;
QOpenGLShaderProgram* initShader(QString fragSource, QString vertSource); QOpenGLShaderProgram* initShader();
}; };
#endif // MAINWIDGET_H #endif // MAINWIDGET_H
...@@ -16,28 +16,12 @@ MainWindow::MainWindow(QWidget *parent) : ...@@ -16,28 +16,12 @@ MainWindow::MainWindow(QWidget *parent) :
connect(loadMesh, SIGNAL(triggered()), m_centralWidget, SLOT(loadNewMesh())); connect(loadMesh, SIGNAL(triggered()), m_centralWidget, SLOT(loadNewMesh()));
toolBar->addAction(loadMesh); toolBar->addAction(loadMesh);
switchInterpolation = new QAction("Lin Interpol",this);
switchInterpolation->setCheckable(true);
switchInterpolation->setChecked(false);
connect(switchInterpolation, SIGNAL(triggered(bool)), m_centralWidget, SLOT(setInterpolation(bool)));
toolBar->addAction(switchInterpolation);
switchRotation = new QAction("Rotation",this); switchRotation = new QAction("Rotation",this);
switchRotation->setCheckable(true); switchRotation->setCheckable(true);
switchRotation->setChecked(true); switchRotation->setChecked(true);
connect(switchRotation, SIGNAL(triggered(bool)), m_centralWidget, SLOT(setRotation(bool))); connect(switchRotation, SIGNAL(triggered(bool)), m_centralWidget, SLOT(setRotation(bool)));
toolBar->addAction(switchRotation); toolBar->addAction(switchRotation);
stopAnimation = new QAction("Start/Stop",this);
stopAnimation->setCheckable(true);
stopAnimation->setChecked(true);
connect(stopAnimation, SIGNAL(triggered(bool)), m_centralWidget, SLOT(setAnimating(bool)));
toolBar->addAction(stopAnimation);
nextAnimation = new QAction("Next",this);
nextAnimation->setCheckable(false);
connect(nextAnimation, SIGNAL(triggered()), m_centralWidget, SLOT(nextAnimation()));
toolBar->addAction(nextAnimation);
CamHome = new QAction("Cam",this); CamHome = new QAction("Cam",this);
CamHome->setCheckable(false); CamHome->setCheckable(false);
...@@ -45,7 +29,6 @@ MainWindow::MainWindow(QWidget *parent) : ...@@ -45,7 +29,6 @@ MainWindow::MainWindow(QWidget *parent) :
toolBar->addAction(CamHome); toolBar->addAction(CamHome);
this->setCentralWidget(m_centralWidget); this->setCentralWidget(m_centralWidget);
// showMaximized(); // showMaximized();
......
...@@ -23,10 +23,7 @@ private: ...@@ -23,10 +23,7 @@ private:
QToolBar *toolBar; QToolBar *toolBar;
QAction *loadMesh; QAction *loadMesh;
QAction *switchInterpolation;
QAction *switchRotation; QAction *switchRotation;
QAction *stopAnimation;
QAction *nextAnimation;
QAction *CamHome; QAction *CamHome;
......
...@@ -11,8 +11,6 @@ ...@@ -11,8 +11,6 @@
#define positionIndex 0 #define positionIndex 0
#define normalIndex 1 #define normalIndex 1
#define uvIndex 2 #define uvIndex 2
#define boneIndex 3
#define boneweightIndex 4
#define EPSILON 0.00001 #define EPSILON 0.00001
...@@ -21,23 +19,15 @@ struct Vertex ...@@ -21,23 +19,15 @@ struct Vertex
QVector3D pos; QVector3D pos;
QVector3D normal; QVector3D normal;
QVector2D tex; QVector2D tex;
uint IDs[4];
float weights[4];
Vertex(){} Vertex(){}
Vertex(const QVector3D& pos, const QVector3D& normal, const QVector2D& tex) Vertex(const QVector3D& pos, const QVector3D& normal, const QVector2D& tex)
{ {
for(int i = 0; i < 4; i++){
IDs[i] = 0;
weights[i] = 0;
}
this->pos = pos; this->pos = pos;
this->tex = tex; this->tex = tex;
this->normal = normal; this->normal = normal;
} }
void AddBoneData(uint BoneID, float Weight);
}; };
class Mesh class Mesh
...@@ -46,15 +36,11 @@ public: ...@@ -46,15 +36,11 @@ public:
Mesh(QOpenGLFunctions_4_3_Core *f,QString filename); Mesh(QOpenGLFunctions_4_3_Core *f,QString filename);
~Mesh(); ~Mesh();
void render(QOpenGLShaderProgram *shader, QMatrix4x4 V,QMatrix4x4 P);
void render(QOpenGLShaderProgram *shader, QMatrix4x4 V,QMatrix4x4 P, float TimeInSeconds, int animation);
void setAnimation(bool linear){this->linear = linear;}
const aiScene *scene; const aiScene *scene;
private: private:
struct MeshEntry{ struct MeshEntry{
MeshEntry(); MeshEntry();
~MeshEntry(); ~MeshEntry();
...@@ -85,24 +71,6 @@ private: ...@@ -85,24 +71,6 @@ private:
float Shininess; float Shininess;
}; };
struct LightInfo
{
QVector4D Position;
QVector3D Intensity;
};
struct BoneInfo
{
QMatrix4x4 BoneOffset;
QMatrix4x4 FinalTransformation;
BoneInfo()
{
BoneOffset.setToIdentity();
FinalTransformation.setToIdentity();
}
};
struct Node struct Node
{ {
Node(); Node();
...@@ -117,45 +85,21 @@ private: ...@@ -117,45 +85,21 @@ private:
QMatrix4x4 globalInverseTransform; QMatrix4x4 globalInverseTransform;
QMatrix4x4 screenTransform; QMatrix4x4 screenTransform;
QVector<MeshEntry> entries; QVector<MeshEntry> entries;
QVector<MaterialInfo> materials; QVector<MaterialInfo> materials;
QVector<BoneInfo> bones;
QMap<QString,int> boneMap;
int numberOfBones;
Node rootNode; Node rootNode;
QOpenGLFunctions_4_3_Core *f; QOpenGLFunctions_4_3_Core *f;
bool loaded; bool loaded;
bool linear;
void initMeshEntry(int i,aiMesh * entry); void initMeshEntry(int i,aiMesh * entry);
void initMaterial(QString dir, unsigned int i, const aiMaterial* material); void initMaterial(QString dir, unsigned int i, const aiMaterial* material);
void initNode(const aiScene *scene, aiNode *node, Node &newNode, QString debugoffset); void initNode(const aiScene *scene, aiNode *node, Node &newNode, QString debugoffset);
void updateBoneTransform(float TimeInSeconds, int animation);
void updateBoneHeirachy(float AnimTime,const aiAnimation* animation, Node node, QMatrix4x4 parentTransform);
const aiNodeAnim *findAnimOfNode(const aiAnimation* animation, QString NodeName);
QVector3D calcInterpolatedScaling(float AnimTime,const aiNodeAnim *nodeAnimation);
QQuaternion calcInterpolatedRotation(float AnimTime,const aiNodeAnim *nodeAnimation);
QVector3D calcInterpolatedTranslation(float AnimTime, const aiNodeAnim *nodeAnimation);
QVector3D calcInterpolatedVectorKey(float AnimTime,const aiNodeAnim *nodeAnimation, const aiVectorKey* keys, const int numberOfKeys);
void renderNode(QOpenGLShaderProgram *shader, Node &node, QMatrix4x4 V,QMatrix4x4 P,QMatrix4x4 M); void renderNode(QOpenGLShaderProgram *shader, Node &node, QMatrix4x4 V,QMatrix4x4 P,QMatrix4x4 M);
void renderMesh(QOpenGLShaderProgram *shader, int index); void renderMesh(QOpenGLShaderProgram *shader, int index);
QVector3D convert(aiVector3D in){ return QVector3D(in.x,in.y,in.z);}
QQuaternion convert(aiQuaternion quat){ return QQuaternion(quat.w,quat.x,quat.y,quat.z);}
QVector3D linInterpolate(QVector3D start, QVector3D end, float Factor){ return (1.0-Factor)*start + Factor*end;}
QVector3D Catmul(QVector3D before, QVector3D start, QVector3D end, QVector3D after,float Factor);
double timeCatmul(QVector3D p1, QVector3D p2, double t_1);
void findObjectDimension(Node node, QMatrix4x4 transform, QVector3D &min, QVector3D &max); void findObjectDimension(Node node, QMatrix4x4 transform, QVector3D &min, QVector3D &max);
......
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