Commit 9e817f2e by Kai Westerkamp

removed Animation

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