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<float> positionTimestamps = {};
	std::vector<float> rotationTimestamps = {};
	std::vector<float> scaleTimestamps = {};

	std::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<float>& times, float& dt) {
	//check this as well
	uint segment = 0;

	float 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::vector<glm::mat4>& output, glm::mat4 &parentTransform, glm::mat4& globalInverseTransform) {
	//dont know if this is right

	BoneTransformTrack& btt = animation.boneTransforms[skeletion.name];
	if (btt.rotations.size() == 0 || btt.positions.size() == 0 || btt.scales.size() == 0) {
		if (skeletion.children.size() == 0) {
			return;
		}
		else {
			for (Bone& child : skeletion.children) {
				glm::mat4 globalTransform = parentTransform * glm::mat4(1.0f);
				output[skeletion.id] = globalInverseTransform * globalTransform * skeletion.offset;
				getPose(animation, child, dt, output, globalTransform, globalInverseTransform);
			}
			return;
		}
		

	}

	
	dt = fmod(dt, animation.duration);
	std::pair<uint, float> fp;



	fp = getTimeFraction(btt.positionTimestamps, dt);

	glm::vec3 position1;
	glm::vec3 position2;
	glm::vec3 position;
	if (fp.first == 0) {

		position1 = btt.positions[fp.first];
		position2 = btt.positions[fp.first];
		position = position1;

	}
	else {

		position1 = btt.positions[fp.first - 1];
		position2 = btt.positions[fp.first];
		position = glm::mix(position1, position2, fp.second);
	}


	fp = getTimeFraction(btt.rotationTimestamps, dt);

	glm::quat rotation1;
	glm::quat rotation2;
	glm::quat rotation;
	if (fp.first == 0) {
		rotation1 = btt.rotations[fp.first];
		rotation2 = btt.rotations[fp.first];
		rotation = rotation1;
	}
	else {
		rotation1 = btt.rotations[fp.first - 1];
		rotation2 = btt.rotations[fp.first];
		rotation = glm::slerp(rotation1, rotation2, fp.second);
	}


	fp = getTimeFraction(btt.scaleTimestamps, dt);

	glm::vec3 scale1;
	glm::vec3 scale2;
	glm::vec3 scale;
	if (fp.first == 0) {

		scale1 = btt.scales[fp.first];
		scale2 = btt.scales[fp.first];
		scale = scale1;
	}
	else {
		glm::vec3 scale1 = btt.scales[fp.first - 1];
		glm::vec3 scale2 = btt.scales[fp.first];
		scale = glm::mix(scale1, scale2, fp.second);
	}

	

	glm::mat4 positionMat = glm::mat4(1.0),
		scaleMat = glm::mat4(1.0);

	// calculate localTransform
	positionMat = glm::translate(positionMat, position);
	glm::mat4 rotationMat = glm::toMat4(rotation);
	scaleMat = glm::scale(scaleMat, scale);
	glm::mat4 localTransform = positionMat * rotationMat * scaleMat;
	glm::mat4 globalTransform = parentTransform * localTransform;

	output[skeletion.id] = globalInverseTransform * globalTransform * skeletion.offset;
	//update values for children bones

	for (Bone& child : skeletion.children) {
		getPose(animation, child, dt, output, globalTransform, globalInverseTransform);
	}
	//std::cout << dt << " => " << position.x << ":" << position.y << ":" << position.z << ":" << std::endl;
}