i have a c++ opengl program, with a model imported with assimp. i am able to render the…
- User
i have a c++ opengl program, with a model imported with assimp. i am able to render the model, but when i try to animate it, it ends up distorted. here are relevant code snippets (getPose calculates the needed transforms for bones): struct BoneTransformTrack { std::vector positionTimestamps = {}; std::vector rotationTimestamps = {}; std::vector scaleTimestamps = {};
codestd::vector<glm::vec3> positions = {}; std::vector<glm::quat> rotations = {}; std::vector<glm::vec3> scales = {};};
// structure containing animation information struct Animation { float duration = 0.0f; float ticksPerSecond = 1.0f; std::unordered_map<std::string, BoneTransformTrack> boneTransforms = {}; };
std::pair<uint, float> getTimeFraction(std::vector& times, float& dt) { //check this as well uint segment = 0;
codefloat start; float end; if (times.size() == 1) { start = times[segment]; end = times[segment]; } while (dt > times[segment]) { segment++; } if (segment < 1) { return { segment, 0.0f }; } else { start = times[segment - 1]; end = times[segment]; } float frac = (dt - start) / (end - start); return {segment, frac};}
void getPose(Animation& animation, Bone& skeletion, float dt, std::vectorglm::mat4& output, glm::mat4 &parentTransform, glm::mat4& globalInverseTransform) { //dont know if this is right
code - Assistant
The code you provided seems to calculate the skeleton pose correctly by interpolating position, rotation, and scale for each bone at a given time of an animation. It is difficult to determine the exact cause of the distortion without understanding the complete rendering pipeline and how the calculated transformations are being used in your shaders.
However, I can give some suggestions to consider:
-
Make sure your model's bone hierarchy is correctly set up. You can try comparing it to the bone hierarchy in the animation tool where you created the model (e.g., Blender, Maya, etc.) to check the correctness.
-