Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

different durations problem #15

Closed
androdlang opened this issue Feb 28, 2020 · 3 comments
Closed

different durations problem #15

androdlang opened this issue Feb 28, 2020 · 3 comments

Comments

@androdlang
Copy link

androdlang commented Feb 28, 2020

Different duration values should result in different interpolation values, but all my values are changing at the same time, no matter if I use seek or step method. Here is my test-code. Am I missing something?

auto tween = tweeny::from(0,0,0);
tween.to(5,5,5);
tween.during(1,2,3);
std::vector<std::array<int, 3>> vec;
std::array<int, 3> ret = tween.peek(0.0f);
long start = millis();
while (tween.progress() < 1.0f) {
  vec.push_back(tween.seek((uint16_t)(millis()-start)));
}
for(std::array<int, 3> ret : vec) {
  Serial.printf("%d %d %d\n",ret[0],ret[1],ret[2]);
}

0 0 0
0 0 0
0 0 0
2 2 2
2 2 2
2 2 2
3 3 3
3 3 3
3 3 3
5 5 5

@mobius3
Copy link
Owner

mobius3 commented Feb 28, 2020

I can reproduce your issue. I'm working on it. Thanks.

@androdlang
Copy link
Author

Oh thank you very much!!!!

mobius3 added a commit that referenced this issue Feb 28, 2020
@mobius3
Copy link
Owner

mobius3 commented Feb 28, 2020

This is fixed now. Some comments for the code you posted:

Values 1, 2, 3 for durations are too small, it is fine to have big values there, in fact is intended to match the unit of time that you are using, since you are using millis, I'd think of using milliseconds there as well, and think of it as 'I want to move from 0 to 5 in X milliseconds'.

I'd also use .step(millis()) instead of seeking like that because it is more straightforward (I understand you might have done this in this example just to demonstrate the error)

As a last point, using straight integers like that for tween target values might be a problem because it is hard to interpolate them properly. Linear interpolation works as intended because it is intentionally prepared to handle integer values (by rounding floats) but other easings don't. I suggest you use floats and cast them if you need integers.

Let me know if it is still broken. Thanks for your issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants