Skip to content

Commit 4f4554c

Browse files
committed
[feat] animation modes and repeat support in library
1 parent 1dcaa12 commit 4f4554c

2 files changed

Lines changed: 85 additions & 2 deletions

File tree

library/private/animationManager.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,16 @@ class animationManager
212212
*/
213213
void SetCheatSheetConfigured(bool configured);
214214

215+
/**
216+
* Internal setter for Mode.
217+
*/
218+
void SetAnimationMode(const std::string& mode);
219+
220+
/**
221+
* Internal setter for repeats.
222+
*/
223+
void SetAnimationRepeat(int repeat);
224+
215225
options& Options;
216226
window_impl& Window;
217227
vtkF3DMetaImporter* Importer = nullptr;
@@ -231,6 +241,19 @@ class animationManager
231241
// Dynamic options
232242
bool Autoplay = false;
233243
double SpeedFactor = 1.0;
244+
245+
/**
246+
* Enum listing possible blending modes.
247+
*/
248+
enum class AnimationModeType : unsigned char
249+
{
250+
FORWARD,
251+
BACKWARD,
252+
PINGPONG
253+
};
254+
AnimationModeType AnimationMode = AnimationModeType::FORWARD;
255+
int AnimationMaxRepeat = -1;
256+
int AnimationCurrentRepeat = 0;
234257
};
235258
}
236259
}

library/src/animationManager.cxx

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,46 @@ void animationManager::Tick()
165165
const double remainder = fmod(val, mod);
166166
return remainder < 0 ? remainder + mod : remainder;
167167
};
168-
this->CurrentTime = this->TimeRange[0] +
169-
modulo(this->CurrentTime - this->TimeRange[0], this->TimeRange[1] - this->TimeRange[0]);
168+
169+
// Switching between animation modes, forward is default
170+
switch (this->AnimationMode)
171+
{
172+
case AnimationModeType::PINGPONG:
173+
this->AnimationDirection *= -1;
174+
if (this->CurrentTime < this->TimeRange[0])
175+
{
176+
this->CurrentTime = this->TimeRange[0] + (this->TimeRange[0] - this->CurrentTime);
177+
}
178+
else if (this->CurrentTime > this->TimeRange[1])
179+
{
180+
this->CurrentTime = this->TimeRange[1] - (this->CurrentTime - this->TimeRange[1]);
181+
}
182+
break;
183+
case AnimationModeType::BACKWARD:
184+
this->AnimationDirection = -1;
185+
this->CurrentTime = this->TimeRange[0] +
186+
modulo(this->CurrentTime - this->TimeRange[0], this->TimeRange[1] - this->TimeRange[0]);
187+
default:
188+
this->AnimationDirection = 1;
189+
this->CurrentTime = this->TimeRange[0] +
190+
modulo(this->CurrentTime - this->TimeRange[0], this->TimeRange[1] - this->TimeRange[0]);
191+
break;
192+
}
193+
if (this->AnimationMaxRepeat != -1)
194+
{
195+
this->AnimationCurrentRepeat++;
196+
}
170197
}
171198

172199
if (this->LoadAtTime(this->CurrentTime))
173200
{
174201
this->Window.render();
175202
}
176203
}
204+
if (this->AnimationMaxRepeat != -1 && this->AnimationCurrentRepeat == this->AnimationMaxRepeat)
205+
{
206+
this->Playing = false;
207+
}
177208
}
178209

179210
//----------------------------------------------------------------------------
@@ -692,10 +723,39 @@ void animationManager::SetAnimationDirection(int direction)
692723
this->AnimationDirection = direction;
693724
}
694725

726+
//----------------------------------------------------------------------------
727+
void animationManager::SetAnimationMode(const std::string& mode)
728+
{
729+
if (mode == "backward")
730+
{
731+
this->AnimationMode = AnimationModeType::BACKWARD;
732+
this->AnimationDirection = -1;
733+
}
734+
else if (mode == "pingpong")
735+
{
736+
this->AnimationMode = AnimationModeType::PINGPONG;
737+
this->AnimationDirection = 1;
738+
}
739+
else
740+
{
741+
this->AnimationMode = AnimationModeType::FORWARD;
742+
this->AnimationDirection = 1;
743+
}
744+
}
745+
746+
//----------------------------------------------------------------------------
747+
void animationManager::SetAnimationRepeat(int repeat)
748+
{
749+
assert(repeat >= -1);
750+
this->AnimationMaxRepeat = repeat;
751+
}
752+
695753
//----------------------------------------------------------------------------
696754
void animationManager::UpdateDynamicOptions()
697755
{
698756
this->SetAutoplay(this->Options.scene.animation.autoplay);
699757
this->SetSpeedFactor(this->Options.scene.animation.speed_factor);
758+
this->SetAnimationMode(this->Options.scene.animation.mode);
759+
this->SetAnimationRepeat(this->Options.scene.animation.repeat);
700760
}
701761
}

0 commit comments

Comments
 (0)