MCPcopy Create free account
hub / github.com/KhronosGroup/Vulkan-Samples / update

Method update

framework/scene_graph/scripts/animation.cpp:41–166  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39}
40
41void 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)

Callers

nothing calls this directly

Calls 5

sizeMethod · 0.80
set_scaleMethod · 0.80
get_transformMethod · 0.45
set_translationMethod · 0.45
set_rotationMethod · 0.45

Tested by

no test coverage detected