return to;
}
-
Model::Mesh::Mesh(const aiMesh *aiMesh, GLuint progId) {
std::vector<glm::vec3> vertices, normals, tangents, bitangents;
}
}
-glm::mat4 lerp(const aiNodeAnim *anim, const float tick) {
-
+glm::mat4 lerpPosition(const aiNodeAnim *anim, const float tick) {
if (anim->mNumPositionKeys == 0) return glm::mat4(1.f);
int yIndex = -1;
}
}
aiVector3D lerpPos;
- if (yIndex < 1) {
+ if (yIndex == 0) {
lerpPos = anim->mPositionKeys[0].mValue;
+ } else if (yIndex == -1) {
+ lerpPos = anim->mPositionKeys[anim->mNumPositionKeys - 1].mValue;
} else {
auto X = anim->mPositionKeys[yIndex - 1];
auto Y = anim->mPositionKeys[yIndex];
aiQuaternion result;
if (yIndex < 1) {
result = anim->mRotationKeys[0].mValue;
+ } else if (yIndex == -1) {
+ result = anim->mRotationKeys[anim->mNumRotationKeys - 1].mValue;
} else {
auto X = anim->mRotationKeys[yIndex - 1];
for (const Animation anim: animMap->at(std::string(ai.mName.C_Str()))) {
float t = fmod(tick, anim.duration);
for (const aiNodeAnim *nodeAnim: anim.nodeAnims) {
- animTrans *= lerp(nodeAnim, t);
+ animTrans *= lerpPosition(nodeAnim, t);
animTrans *= lerpRotation(nodeAnim, t);
animTrans *= lerpScaling(nodeAnim, t);
}
}
- /* std::cerr << std::string(ai.mName.C_Str()) << animTrans[0][0] << std::endl; */
}
glm::mat4 m = parentTrans * animTrans * aiMatrixToMat4(ai.mTransformation) * model;
for (auto child: children) {
- //set to parent transforms
boneTransforms[std::string(ai.mName.C_Str())] = m;
}
glm::mat4 boneOffset = pair.second.second;
glm::mat4 boneTrans(1.f);
- if (boneTransforms.count(nodeName)) boneTrans = boneTransforms[nodeName];
- int j = 0;
+ if (boneTransforms.count(nodeName)) {
+ std::cerr << "got bone transform from map" << std::endl;
+ boneTrans = boneTransforms[nodeName];
+ }
for (const Animation anim: animMap->at(nodeName)) {
float t = fmod(tick, anim.duration);
for (const aiNodeAnim *nodeAnim: anim.nodeAnims) {
- boneTrans = boneTrans * lerp(nodeAnim, t);
+ boneTrans = boneTrans * lerpPosition(nodeAnim, t);
boneTrans = boneTrans * lerpRotation(nodeAnim, t);
- /* boneTrans = boneTrans * lerpScaling(nodeAnim, t); */
- j++;
+ boneTrans = boneTrans * lerpScaling(nodeAnim, t);
}
}
- assert(j == 1);
-
boneTrans = boneTrans * glm::inverse(boneOffset);
std::string nodeName = pair.first;
if (!animMap->count(nodeName)) (*animMap)[nodeName] = std::vector<const Animation>();
- (*animMap)[nodeName].push_back({ 7500, pair.second });
+ (*animMap)[nodeName].push_back({ aiAnim->mDuration, pair.second });
}
}
root = new Node(*(scene->mRootNode), p.progId, animMap);
}
+void Model::calcBoneTransforms(aiNode &node, glm::mat4 parentTrans = glm::mat4(1), BoneTransforms boneTrans = BoneTransforms()) {
+ glm::mat4 animTrans(1.f);
+ if (animMap->count(std::string(ai.mName.C_Str()))) {
+ for (const Animation anim: animMap->at(std::string(ai.mName.C_Str()))) {
+ float t = fmod(tick, anim.duration);
+ for (const aiNodeAnim *nodeAnim: anim.nodeAnims) {
+ animTrans *= lerpPosition(nodeAnim, t);
+ animTrans *= lerpRotation(nodeAnim, t);
+ animTrans *= lerpScaling(nodeAnim, t);
+ }
+ }
+ }
+
+
+ glm::mat4 m = parentTrans * animTrans * aiMatrixToMat4(ai.mTransformation) * model;
+}
+
void Model::draw(Skybox skybox, const float tick) const {
glUseProgram(program.progId);
+
+
+
root->draw(meshes, materials, skybox, tick);
}