| 39 | } |
| 40 | |
| 41 | void Animation::update(float delta_time) |
| 42 | { |
| 43 | current_time += delta_time; |
| 44 | if (current_time > end_time) |
| 45 | { |
| 46 | current_time -= end_time; |
| 47 | } |
| 48 | |
| 49 | for (auto &channel : channels) |
| 50 | { |
| 51 | for (size_t i = 0; i < channel.sampler.inputs.size() - 1; ++i) |
| 52 | { |
| 53 | if ((current_time >= channel.sampler.inputs[i]) && (current_time <= channel.sampler.inputs[i + 1])) |
| 54 | { |
| 55 | float time = (current_time - channel.sampler.inputs[i]) / (channel.sampler.inputs[i + 1] - channel.sampler.inputs[i]); |
| 56 | |
| 57 | auto &transform = channel.node.get_transform(); |
| 58 | |
| 59 | if (channel.sampler.type == AnimationType::Linear) |
| 60 | { |
| 61 | switch (channel.target) |
| 62 | { |
| 63 | case Translation: |
| 64 | { |
| 65 | transform.set_translation(glm::vec3(glm::mix(channel.sampler.outputs[i], |
| 66 | channel.sampler.outputs[i + 1], |
| 67 | time))); |
| 68 | break; |
| 69 | } |
| 70 | case Rotation: |
| 71 | { |
| 72 | glm::quat q1; |
| 73 | q1.x = channel.sampler.outputs[i].x; |
| 74 | q1.y = channel.sampler.outputs[i].y; |
| 75 | q1.z = channel.sampler.outputs[i].z; |
| 76 | q1.w = channel.sampler.outputs[i].w; |
| 77 | |
| 78 | glm::quat q2; |
| 79 | q2.x = channel.sampler.outputs[i + 1].x; |
| 80 | q2.y = channel.sampler.outputs[i + 1].y; |
| 81 | q2.z = channel.sampler.outputs[i + 1].z; |
| 82 | q2.w = channel.sampler.outputs[i + 1].w; |
| 83 | |
| 84 | transform.set_rotation(glm::normalize(glm::slerp(q1, q2, time))); |
| 85 | break; |
| 86 | } |
| 87 | |
| 88 | case Scale: |
| 89 | { |
| 90 | transform.set_scale(glm::vec3(glm::mix(channel.sampler.outputs[i], |
| 91 | channel.sampler.outputs[i + 1], |
| 92 | time))); |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | else if (channel.sampler.type == AnimationType::Step) |
| 97 | { |
| 98 | switch (channel.target) |
nothing calls this directly
no test coverage detected