Browse Source

Refactor animation handling... does not yet work, but we're close

master
Skia 3 years ago
parent
commit
014ba3028a
13 changed files with 295 additions and 211 deletions
  1. 4
    3
      Makefile
  2. 4
    4
      animation.h
  3. 2
    1
      bone.cpp
  4. 3
    1
      bone.h
  5. 40
    40
      boneAnim.h
  6. 176
    0
      mesh.cpp
  7. 16
    130
      mesh.h
  8. 9
    18
      scene.cpp
  9. 17
    11
      scene.h
  10. 19
    1
      utils.cpp
  11. 2
    0
      utils.h
  12. 1
    0
      vectInterpolation.h
  13. 2
    2
      vertice.h

+ 4
- 3
Makefile View File

@@ -6,10 +6,11 @@ LIBS=-lassimp

TARGET=IN55.exe

SOURCES=main.cpp\
scene.cpp\
camera.cpp\
SOURCES=main.cpp \
scene.cpp \
camera.cpp \
bone.cpp \
mesh.cpp \
utils.cpp

OBJECTS=$(SOURCES:.cpp=.o)

+ 4
- 4
animation.h View File

@@ -36,15 +36,15 @@ class Animation
}
}

BoneAnim* getBoneAnim(aiString boneName){
BoneAnim* getBoneAnim(const aiString &boneName){
int i=0;
while(listBoneAnim[i]->getName() != boneName && i < nbBoneAnim){
while ( i < nbBoneAnim && listBoneAnim[i]->getName() != boneName) {
i++;
}

if(i<nbBoneAnim){
if (i < nbBoneAnim) {
return listBoneAnim[i];
}else{
} else {
return NULL;
}
}

+ 2
- 1
bone.cpp View File

@@ -1,8 +1,9 @@
#include <bone.h>

Bone::Bone(aiString id, aiString p){
Bone::Bone(aiString id, aiString p, aiMatrix4x4 &o){
name=id;
parentName = p;
offset = o;
nbVertice=0;
verticeIDList=(int*)malloc(nbVertice*sizeof(int));
}

+ 3
- 1
bone.h View File

@@ -15,14 +15,16 @@ class Bone{
private:
aiString name;
aiString parentName;
aiMatrix4x4 offset;
int* verticeIDList;
int nbVertice;

public:
Bone(aiString id, aiString p);
Bone(aiString id, aiString p, aiMatrix4x4 &o);

aiString getName() { return name; };
aiString getParentName() { return parentName; };
aiMatrix4x4 getOffset() { return offset; };
void addVertice(int vert_id);

int* getListofVertices();

+ 40
- 40
boneAnim.h View File

@@ -13,30 +13,20 @@
class BoneAnim
{
private:
aiString boneName;
//Keyframe* keyframeList;
aiString boneName;
aiVectorKey* transList;
aiVectorKey* scalList;
aiQuatKey* rotList;
//int nbKeyframe;
int nbTrans,nbScal,nbRot;
//int* indexKeyframeList;
//int currentindex;
int ciT,ciS,ciR;
int nbTrans, nbRot, nbScal;

public:
/*BoneAnim(int nbKf){
nbKeyframe = nbKf;
keyframeList = (Keyframe*)malloc(nbKf*sizeof(Keyframe));
indexKeyframeList = (int*)malloc(nbKf*sizeof(int));
currentindex=0;
}*/

BoneAnim(int nt, int nr, int ns, aiString name){
boneName=name;
nbTrans=nt;
nbRot=nr;
nbScal=ns;

BoneAnim(int nt, int nr, int ns, const aiString &name){
boneName = name;
nbTrans = nt;
nbRot = nr;
nbScal = ns;
transList = (aiVectorKey*)malloc(nbTrans*sizeof(aiVectorKey));
rotList = (aiQuatKey*)malloc(nbRot*sizeof(aiQuatKey));
scalList = (aiVectorKey*)malloc(nbScal*sizeof(aiVectorKey));
@@ -65,37 +55,47 @@ class BoneAnim
ciR++;
}
}
aiString getName(){return boneName;};

aiString &getName() {return boneName; };

int getNbTrans(){return nbTrans;};
int getNbScal(){return nbScal;};
int getNbRot(){return nbRot;};

aiVectorKey* getTrans(){return transList;};
aiVectorKey* getScal(){return scalList;};
aiQuatKey* getRot(){return rotList;};

aiVectorKey getTrans(int i){return transList[i]; };
aiVectorKey getScal(int i){return scalList[i]; };
aiQuatKey getRot(int i) {return rotList[i]; };

/*void addKeyFrame(Keyframe nKeyframe){
int nIndex=nKeyframe.getIndex();
if(currentindex<nbKeyframe){
keyframeList[currentindex]=nKeyframe;
indexKeyframeList[currentindex]=nIndex;
currentindex++;
}
}

Keyframe* getKeyframes(){
return keyframeList;
};
unsigned int findScaling(float AnimationTime) {
assert(this->nbScal > 0);
for (int i = 0 ; i < this->nbScal - 1 ; i++) {
if (AnimationTime < (float)this->scalList[i + 1].mTime) {
return i;
}
}
assert(0);
}

int* getIndexKeyframes(){
return indexKeyframeList;
};
unsigned int findPosition(float AnimationTime) {
assert(this->nbTrans > 0);
for (int i = 0 ; i < this->nbTrans - 1 ; i++) {
if (AnimationTime < (float)this->transList[i + 1].mTime) {
return i;
}
}
assert(0);
}

int getNbKeyframes(){
return nbKeyframe;
}*/
unsigned int findRotation(float AnimationTime) {
assert(this->nbRot > 0);
for (int i = 0 ; i < this->nbRot - 1 ; i++) {
if (AnimationTime < (float)this->rotList[i + 1].mTime) {
return i;
}
}
assert(0);
}

};


+ 176
- 0
mesh.cpp View File

@@ -0,0 +1,176 @@
/*
* Skia < lordbanana25 AT mailoo DOT org >
*
* Beerware licensed software - 2015
*/
#include <iostream>

#include <mesh.h>
#include <utils.h>

void Mesh::initAnimList(const aiScene *scene) {
animList = (Animation**) malloc(scene->mNumAnimations * sizeof(Animation*));
for (unsigned int i = 0; i < scene->mNumAnimations; i++) {
const aiAnimation *anim = scene->mAnimations[i];
Animation *my_anim = new Animation(boneNb, scene->mAnimations[i]->mDuration, scene->mAnimations[i]->mTicksPerSecond);
for (int j = 0; j < boneNb; j++) {
const aiNodeAnim *nodeAnim = findNodeAnim(anim, getBone(j)->getName());
BoneAnim *boneAnim = new BoneAnim(
nodeAnim->mNumPositionKeys,
nodeAnim->mNumRotationKeys,
nodeAnim->mNumScalingKeys,
getBone(j)->getName());
for (unsigned int k = 0; k < nodeAnim->mNumPositionKeys; k++)
boneAnim->addTrans(nodeAnim->mPositionKeys[k]);
for (unsigned int k = 0; k < nodeAnim->mNumRotationKeys; k++)
boneAnim->addRot(nodeAnim->mRotationKeys[k]);
for (unsigned int k = 0; k < nodeAnim->mNumScalingKeys; k++)
boneAnim->addScal(nodeAnim->mScalingKeys[k]);
my_anim->addBoneAnim(boneAnim);
}
animList[animNb++] = my_anim;
}
};

void Mesh::render(bool anim) {
int i, j;
bool use_normal = false;
if (this->getNormal(0) != NULL) {
use_normal = true;
}

if(use_normal) {
glEnable(GL_LIGHTING);
} else {
glDisable(GL_LIGHTING);
}

for (i = 0; i < this->getFaceNumber(); i++) {
Face *f = this->getFace(i);
glBegin(f->getType());
for (j = 0; j < f->getIndexNumber(); j++) {
// glPushMatrix();
int index = f->getIndex(j);
if (anim) {
Vertice *v = this->getVertex(index);
aiMatrix4x4 t;
for (int k = 0; k < v->getBoneNumber(); k++) {
t += v->getBonesWeight(k) * boneStateList[this->getBoneIndex(v->getBonesID(k))];
}
std::cout << "Mat: " << t.a1 << t.a2 << t.a3 << t.a4 << "\n";
std::cout << " " << t.b1 << t.b2 << t.b3 << t.b4 << "\n";
std::cout << " " << t.c1 << t.c2 << t.c3 << t.c4 << "\n";
std::cout << " " << t.d1 << t.d2 << t.d3 << t.d4 << "\n";
glMultMatrixf(&t.Transpose().a1);
}
if (this->getNormal(index) != NULL) {
glNormal3fv(&this->getNormal(index)->x);
}
glVertex3fv(&(this->getVertex(index)->getPosition()).x);
// glPopMatrix();
}
glEnd();
}
}

void CalcInterpolatedScaling(aiVector3D& Out, float AnimationTime, BoneAnim* boneAnim)
{
// we need at least two values to interpolate...
if (boneAnim->getNbScal() == 1) {
Out = boneAnim->getScal(0).mValue;
return;
}

unsigned int ScalingIndex = boneAnim->findScaling(AnimationTime);
unsigned int NextScalingIndex = (ScalingIndex + 1);
float d = boneAnim->getScal(NextScalingIndex).mTime - boneAnim->getScal(ScalingIndex).mTime;
float f = (AnimationTime - (float)boneAnim->getScal(ScalingIndex).mTime) / d;
// assert(f >= 0.0f && f <= 1.0f);
const aiVector3D& StartPositionV = boneAnim->getScal(ScalingIndex).mValue;
const aiVector3D& EndPositionV = boneAnim->getScal(NextScalingIndex).mValue;
Out = (1 - f) * StartPositionV + f * EndPositionV;
}
void CalcInterpolatedPosition(aiVector3D& Out, float AnimationTime, BoneAnim* boneAnim)
{
// we need at least two values to interpolate...
if (boneAnim->getNbTrans() == 1) {
Out = boneAnim->getTrans(0).mValue;
return;
}

unsigned int PositionIndex = boneAnim->findPosition(AnimationTime);
unsigned int NextPositionIndex = (PositionIndex + 1);
float d = boneAnim->getTrans(NextPositionIndex).mTime - boneAnim->getTrans(PositionIndex).mTime;
float f = (AnimationTime - (float)boneAnim->getTrans(PositionIndex).mTime) / d;
std::cout << "AnimationTime: " << AnimationTime << "\n";
std::cout << "f: " << f << "\n";
// assert(f >= 0.0f && f <= 1.0f);
const aiVector3D& StartPositionV = boneAnim->getTrans(PositionIndex).mValue;
const aiVector3D& EndPositionV = boneAnim->getTrans(NextPositionIndex).mValue;
Out = (1 - f) * StartPositionV + f * EndPositionV;
// *pos = (1-t)*prevKeyframe.mValue + t*nextKeyframe.mValue;
//Out = Out.Normalize();
}
void CalcInterpolatedRotation(aiQuaternion& Out, float AnimationTime, BoneAnim* boneAnim)
{
// we need at least two values to interpolate...
if (boneAnim->getNbRot() == 1) {
Out = boneAnim->getRot(0).mValue;
return;
}

unsigned int RotationIndex = boneAnim->findRotation(AnimationTime);
unsigned int NextRotationIndex = (RotationIndex + 1);
float d = boneAnim->getRot(NextRotationIndex).mTime - boneAnim->getRot(RotationIndex).mTime;
float f = (AnimationTime - (float)boneAnim->getRot(RotationIndex).mTime) / d;
// assert(f >= 0.0f && f <= 1.0f);
const aiQuaternion& StartRotationQ = boneAnim->getRot(RotationIndex).mValue;
const aiQuaternion& EndRotationQ = boneAnim->getRot(NextRotationIndex).mValue;
aiQuaternion::Interpolate(Out, StartRotationQ, EndRotationQ, f);
Out = Out.Normalize();
}

void Mesh::updateBoneStateList(float AnimationTime, const aiNode* pNode, const aiMatrix4x4& ParentTransform)
{
aiString NodeName(pNode->mName.data);

Animation* anim = animList[currentAnimation];

aiMatrix4x4 NodeTransformation(pNode->mTransformation);

BoneAnim* boneAnim = anim->getBoneAnim(NodeName);

if (boneAnim) {
// Interpolate scaling and generate scaling transformation matrix
aiVector3D Scaling;
CalcInterpolatedScaling(Scaling, AnimationTime, boneAnim);
aiMatrix4x4 ScalingM;
aiMatrix4x4::Scaling(aiVector3D(Scaling.x, Scaling.y, Scaling.z), ScalingM);

// Interpolate rotation and generate rotation transformation matrix
aiQuaternion RotationQ;
CalcInterpolatedRotation(RotationQ, AnimationTime, boneAnim);
aiMatrix4x4 RotationM = aiMatrix4x4(RotationQ.GetMatrix());

// Interpolate translation and generate translation transformation matrix
aiVector3D Translation;
CalcInterpolatedPosition(Translation, AnimationTime, boneAnim);
aiMatrix4x4 TranslationM;
aiMatrix4x4::Translation(aiVector3D(Translation.x, Translation.y, Translation.z), TranslationM);

// Combine the above transformations
NodeTransformation = TranslationM * RotationM * ScalingM;
}

aiMatrix4x4 GlobalTransformation = ParentTransform * NodeTransformation;

int BoneIndex = -1;
if ((BoneIndex = getBoneIndex(NodeName)) != -1) {
//boneStateList[BoneIndex] = GlobalTransformation * getBone(BoneIndex)->getOffset();
boneStateList[BoneIndex] = GlobalTransformation;
}

for (unsigned int i = 0 ; i < pNode->mNumChildren ; i++) {
this->updateBoneStateList(AnimationTime, pNode->mChildren[i], GlobalTransformation);
}
}

+ 16
- 130
mesh.h View File

@@ -14,7 +14,6 @@
#include <bone.h>
#include <boneState.h>
#include <animation.h>
#include <scene.h>
#include <utils.h>

class Face
@@ -56,10 +55,11 @@ class Mesh
aiVector3D **normalList;
Face **faceList;
Bone **boneList;
BoneState **boneStateList;
aiMatrix4x4 *boneStateList;
Animation **animList;
int vertNb, boneNb, faceNb, animNb, maxFaceNb;
int mesh_id;
int currentAnimation;

public:
Mesh(int id, int vertSize, int boneSize, int faceSize){
@@ -72,142 +72,24 @@ class Mesh
verticeList = (Vertice**)malloc(vertNb * sizeof(Vertice*));
normalList = (aiVector3D**)malloc(vertNb * sizeof(aiVector3D*));
boneList = (Bone**)malloc(boneNb * sizeof(Bone*));
boneStateList = (BoneState**)malloc(boneNb * sizeof(BoneState*));
boneStateList = (aiMatrix4x4*) malloc(boneNb * sizeof(aiMatrix4x4));
faceList = (Face**)malloc(faceSize * sizeof(Face*));
currentAnimation = 0;
};

void initAnimList(const aiScene *scene) {
animList = (Animation**) malloc(scene->mNumAnimations * sizeof(Animation*));
for (unsigned int i = 0; i < scene->mNumAnimations; i++) {
const aiAnimation *anim = scene->mAnimations[i];
Animation *my_anim = new Animation(boneNb, scene->mAnimations[i]->mDuration, scene->mAnimations[i]->mTicksPerSecond);
for (int j = 0; j < boneNb; j++) {
const aiNodeAnim *nodeAnim = findNodeAnim(anim, getBone(j)->getName());
BoneAnim *boneAnim = new BoneAnim(
nodeAnim->mNumPositionKeys,
nodeAnim->mNumRotationKeys,
nodeAnim->mNumScalingKeys,
getBone(j)->getName());
for (unsigned int k = 0; k < nodeAnim->mNumPositionKeys; k++)
boneAnim->addTrans(nodeAnim->mPositionKeys[k]);
for (unsigned int k = 0; k < nodeAnim->mNumRotationKeys; k++)
boneAnim->addRot(nodeAnim->mRotationKeys[k]);
for (unsigned int k = 0; k < nodeAnim->mNumScalingKeys; k++)
boneAnim->addScal(nodeAnim->mScalingKeys[k]);
my_anim->addBoneAnim(boneAnim);
}
animList[animNb++] = my_anim;
}
initBoneStateList();
};

void initBoneStateList() {
float tps = animList[0]->getTicksPerSecond();
for(int i = 0; i < boneNb; i++) {
BoneAnim *bAnim = animList[0]->getBoneAnim(boneList[i]->getName());
BoneState *tmpBoneState = new BoneState(boneList[i]->getName());
tmpBoneState->initTrans(bAnim->getTrans(), bAnim->getTrans()+1, tps);
tmpBoneState->initRot(bAnim->getRot(), bAnim->getRot()+1, tps);
tmpBoneState->initScal(bAnim->getScal(), bAnim->getScal()+1, tps);
boneStateList[i]=tmpBoneState;
}
}

void updateBoneStateList(int numFrame){
float tps = animList[0]->getTicksPerSecond();
for(int i = 0; i < boneNb; i++) {
BoneAnim *bAnim = animList[0]->getBoneAnim(boneList[i]->getName());
BoneState *tmpBoneState = boneStateList[i];
if(tmpBoneState->getTransLastIndex()>= numFrame){
tmpBoneState->updateTransLastKey(bAnim->getTrans()+tmpBoneState->getiT(),tps);
}
if(tmpBoneState->getScalLastIndex()>= numFrame){
tmpBoneState->updateScalLastKey(bAnim->getScal()+tmpBoneState->getiS(),tps);
}
if(tmpBoneState->getRotLastIndex()>= numFrame){
tmpBoneState->updateRotLastKey(bAnim->getRot()+tmpBoneState->getiR(),tps);
}
tmpBoneState->updateTransValue(numFrame);
tmpBoneState->updateScalValue(numFrame);
tmpBoneState->updateRotValue(numFrame);
boneStateList[i]=tmpBoneState;
}

}

void render(bool anim) {
int i, j;
bool use_normal = false;
if (this->getNormal(0) != NULL) {
use_normal = true;
}

if(use_normal) {
glEnable(GL_LIGHTING);
void setCurrentAnim(int n) {
if (0 < n && n <= animNb) {
currentAnimation = n-1;
} else {
glDisable(GL_LIGHTING);
currentAnimation = 0;
}
};

for (i = 0; i < this->getFaceNumber(); i++) {
Face *f = this->getFace(i);
glBegin(f->getType());
for (j = 0; j < f->getIndexNumber(); j++) {
//pushMatrix
int index = f->getIndex(j);
if(anim){
this->movePoint(this->getVertex(index));
}
if (this->getNormal(index) != NULL) {
glNormal3fv(&this->getNormal(index)->x);
}
glVertex3fv(&(this->getVertex(index)->getPosition()).x);
//popMatrix
}
glEnd();
}

}

void movePoint(Vertice* vert){
aiString *bones = vert->getBonesID();
float *bWeight = vert->getBonesWeight();
aiVector3D* trans = new aiVector3D();
aiVector3D* scal = new aiVector3D();
aiQuaternion* rot = new aiQuaternion();
for(int i = 0; i < vert->getBoneNumber(); i++){
int j = 0;
std::cout << "Bone: " << bones[i].C_Str() << "\n";
while (boneStateList[j]->getName() != bones[i] && j < boneNb) {
j++;
}
if (j < boneNb){
*trans += (bWeight[i] * (*boneStateList[j]->getCurrTrans()));
*scal += (bWeight[i] * (*boneStateList[j]->getCurrScal()));
*rot = (*rot) * (bWeight[i] * (*boneStateList[j]->getCurrRot()));
}
}
applyScal(vert, scal);
applyRot(vert, rot);
applyTrans(vert, trans);
}

void applyTrans(Vertice* vert, const aiVector3D* trans){
aiMatrix4x4 T;
T.Translation(*trans, T);
T.Translation(vert->getPosition(), T);
vert->setPosition(getPosition(T));
}
void initAnimList(const aiScene *scene);

void applyScal(Vertice* vert, const aiVector3D* scal){
aiMatrix4x4 S;
S.Scaling(*scal, S);
S.Scaling(vert->getPosition(), S);
vert->setPosition(getScale(S));
}
void updateBoneStateList(float AnimationTime, const aiNode* pNode, const aiMatrix4x4& ParentTransform);

void applyRot(Vertice* vert, aiQuaternion* rot){
vert->setPosition(rot->Rotate(vert->getPosition()));
}
void render(bool anim);

void addVertice(Vertice *vert, aiVector3D *normal, int index) {
if (index < vertNb) {
@@ -251,6 +133,10 @@ class Mesh
}
return -1;
}
Bone *getBone(aiString name) {
int i = getBoneIndex(name);
return (i != -1) ? boneList[i] : NULL;
};
};

#endif

+ 9
- 18
scene.cpp View File

@@ -4,6 +4,7 @@
* Beerware licensed software - 2015
*/
#include <iostream>
#include <time.h>

#include <GL/gl.h>

@@ -93,8 +94,8 @@ void SceneHandler::initMeshList(const aiNode* nd){
const aiNode *p = getNode(scene, bones[j]->mName);
Bone *tmpBone = NULL;
if (p != NULL) p = p->mParent;
if (p != NULL) tmpBone = new Bone(bones[j]->mName, p->mName);
else tmpBone = new Bone(bones[j]->mName, aiString(""));
if (p != NULL) tmpBone = new Bone(bones[j]->mName, p->mName, bones[j]->mOffsetMatrix);
else tmpBone = new Bone(bones[j]->mName, aiString(""), bones[j]->mOffsetMatrix);
for(k = 0; k < bones[j]->mNumWeights; k++){
int vertID = bones[j]->mWeights[k].mVertexId;
float weight =bones[j]->mWeights[k].mWeight;
@@ -114,6 +115,7 @@ void SceneHandler::initMeshList(const aiNode* nd){

void SceneHandler::resetNumFrame(){
numFrame=0;
m_startTime = clock();
}

void SceneHandler::render() {
@@ -121,14 +123,13 @@ void SceneHandler::render() {
const aiNode *nd = scene->mRootNode;
aiMatrix4x4 m = nd->mTransformation;


double runningTime = double(clock() - m_startTime) / CLOCKS_PER_SEC;

glScalef(scale, scale, scale);

glTranslatef( -scene_center.x, -scene_center.y, -scene_center.z );

angle += 0.9;
// angle += 0.9;
glRotatef(angle, 0, 1, 0);

// add root node transform matrix
@@ -138,20 +139,10 @@ void SceneHandler::render() {

// draw all meshes
for (i = 0; i < meshNumber; ++i) {
aiMatrix4x4 ident;
aiMatrix4x4::Scaling(aiVector3D(1, 1, 1), ident);
Mesh *my_mesh = meshList[i];
if(isAnimating){
if(numFrame<scene->mAnimations[numAnimation-1]->mDuration && numFrame!=0){
my_mesh->updateBoneStateList(numFrame);
numFrame++;
}else if (numFrame==0){
my_mesh->initBoneStateList();
numFrame++;
}else{
isAnimating=false;
}
}
if (isAnimating) my_mesh->updateBoneStateList(runningTime, scene->mRootNode, ident);
my_mesh->render(isAnimating);
}
glPopMatrix();

+ 17
- 11
scene.h View File

@@ -23,6 +23,17 @@ const aiNode *getChildNode(aiString name, const aiNode *node);

class SceneHandler
{
private:
const struct aiScene* scene;
Mesh **meshList;
int meshNumber;
aiVector3D scene_min, scene_max, scene_center;
float scale, angle;
int numFrame;
bool isAnimating;
unsigned int numAnimation;
clock_t m_startTime;

public:
virtual ~SceneHandler();
bool load_file (char * fName);
@@ -34,20 +45,15 @@ class SceneHandler
const aiScene *getScene() { return scene; };
void activateAnimation(bool b){if(numAnimation<=scene->mNumAnimations){isAnimating=b;}};
int getMeshNumber() { return meshNumber; };
void setNumAnimation(int n){numAnimation=n;};
void setNumAnimation(int n) {
for (int i = 0; i < meshNumber; i++) {
meshList[i]->setCurrentAnim(n);
}
numAnimation=n;
};
bool getAnimating(){return isAnimating;};



private:
const struct aiScene* scene;
Mesh **meshList;
int meshNumber;
aiVector3D scene_min, scene_max, scene_center;
float scale, angle;
int numFrame;
bool isAnimating;
unsigned int numAnimation;
};

#endif

+ 19
- 1
utils.cpp View File

@@ -22,14 +22,32 @@ const aiNodeAnim *findNodeAnim(const aiAnimation *anim, aiString name) {
aiVector3D operator*( float num, aiVector3D v ) {
return aiVector3D(v.x * num, v.y * num, v.z * num);
}

aiQuaternion operator*( float num, aiQuaternion v ) {
return aiQuaternion(v.w * num, v.x * num, v.y * num, v.z * num);
}

aiMatrix4x4 operator*( float n, aiMatrix4x4 m ) {
return aiMatrix4x4(
n*m.a1, n*m.a2, n*m.a3, n*m.a4,
n*m.b1, n*m.b2, n*m.b3, n*m.b4,
n*m.c1, n*m.c2, n*m.c3, n*m.c4,
n*m.d1, n*m.d2, n*m.d3, n*m.d4
);
}

aiMatrix4x4 operator+=( aiMatrix4x4 m1, aiMatrix4x4 m2 ) {
return aiMatrix4x4(
m1.a1+m2.a1, m1.a2+m2.a2, m1.a3+m2.a3, m1.a4+m2.a4,
m1.b1+m2.b1, m1.b2+m2.b2, m1.b3+m2.b3, m1.b4+m2.b4,
m1.c1+m2.c1, m1.c2+m2.c2, m1.c3+m2.c3, m1.c4+m2.c4,
m1.d1+m2.d1, m1.d2+m2.d2, m1.d3+m2.d3, m1.d4+m2.d4
);
}

aiVector3D getPosition( aiMatrix4x4 mat ) {
return aiVector3D(mat.a4, mat.b4, mat.c4);
}
aiVector3D getScale( aiMatrix4x4 mat ) {
return aiVector3D(mat.a1, mat.b2, mat.c3);
}


+ 2
- 0
utils.h View File

@@ -11,6 +11,8 @@ aiVector3D operator*( float num, aiVector3D v );
aiQuaternion operator*( float num, aiQuaternion v );
aiVector3D getPosition( aiMatrix4x4 mat );
aiVector3D getScale( aiMatrix4x4 mat );
aiMatrix4x4 operator*( float num, aiMatrix4x4 m );
aiMatrix4x4 operator+=( aiMatrix4x4 m1, aiMatrix4x4 m2 );

#endif


+ 1
- 0
vectInterpolation.h View File

@@ -32,6 +32,7 @@ class VectInterpolation{
};

void Update(aiVectorKey newK, int index){
std::cout << "Index: " << index << "\n";
prevKeyframe = nextKeyframe;
indexPrevKeyframe = indexNextKeyframe;
nextKeyframe = newK;

+ 2
- 2
vertice.h View File

@@ -50,11 +50,11 @@ class Vertice {

aiVector3D &getPosition(){return position;};

aiString* getBonesID() { return bonesName; };
aiString getBonesID(int i) { return bonesName[i]; };

int getBoneNumber() { return numBone; };

float* getBonesWeight(){return bonesWeight;};
float getBonesWeight(int i){return bonesWeight[i]; };




Loading…
Cancel
Save