GithubHelp home page GithubHelp logo

mobius3 / tweeny Goto Github PK

View Code? Open in Web Editor NEW
692.0 24.0 47.0 4.56 MB

A modern C++ tweening library

Home Page: http://mobius3.github.io/tweeny

License: MIT License

CMake 6.26% C++ 93.74%
tween interpolation animation cmake

tweeny's People

Contributors

arncarveris avatar balletie avatar johanlindfors avatar lamby avatar mobius3 avatar tastytea avatar wumiliu avatar xfangfang avatar xvitaly avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tweeny's Issues

[FUTURE IDEA] Timeline

Hi,

Just putting this out in the universe, since you seem to be one of the experts that could possibly make this happen. In the future, if you're looking for a new project to tackle, please look into creating a Timeline library. This would be something similar to Tweeny, but it's more encompassing. I'm writing to you because Tweeny is probably already 50% of work.

This is the kind of Timeline library I'm talking about:

If you were to charge for such a thing, I would pay for it.

Warning "conversion from ‘int’ to ‘float’ may change value" when using integer values

When using integer values such as in this example:

auto t = tweeny::from(130).to(130).during(300).to(80).during(400);

The compiler issues warnings for the conversion from int to float for all the different easings, sometimes multiple warnings per easing. I don't want to disable the warnings, because they may be valuable information pointing out where a possible bug exists.

It would be nice if a static_cast<float>() is used where appropriate, so that my warnings list is not flooded.

Missing stepped easing mode

There is some use-case where I need stepped interpolation like in Spine

The current workaround is to implement easing mode:

namespace tweeny
{
    class easing_ex {
    public:
        static constexpr struct steppedEasing {
            template<typename T>
            static T run(float position, T start, T end) {
                return start;
            }
        } stepped = steppedEasing{};
    };
}

Implement type wrapper to avoid compile error due this :

namespace tweeny
{
    template<typename T>
    struct steppedWrapper : T
    {
        steppedWrapper() = default;
        steppedWrapper(steppedWrapper&&) = default;
        steppedWrapper(const steppedWrapper&) = default;

        template<typename... Args>
        explicit steppedWrapper(Args&&... args) :
            T{ std::forward<Args>(args)... }
        { }

        steppedWrapper& operator = (const steppedWrapper&) = default;
        steppedWrapper& operator = (const T& rhs)
        {
            T::operator = (rhs);
            
            return *this;
        }

        friend steppedWrapper operator - (const steppedWrapper& lhs, const steppedWrapper& rhs)
        {
            return lhs;
        }
        friend steppedWrapper operator + (const steppedWrapper& lhs, const steppedWrapper& rhs)
        {
            return lhs;
        }
        friend steppedWrapper operator * (const steppedWrapper& lhs, const steppedWrapper& rhs)
        {
            return lhs;
        }
        friend steppedWrapper operator * (const steppedWrapper& lhs, const float& rhs)
        {
            return lhs;
        }
        friend steppedWrapper operator * (const float& lhs, const steppedWrapper& rhs)
        {
            return rhs;
        }
    };
}

Test class:

struct CSmth
{
    int frame{-1};
    void* user_data{nullptr};
};

Current code:

    using smth_t = tweeny::steppedWrapper<CSmth>;

    auto t = tweeny::from(smth_t{7 })
        .to(smth_t{9}).during(300.0f)
        .via(tweeny::easing_ex::steppedEasing::run<smth_t>);

    t.step(0.1f);

Wanted code:

    auto t = tweeny::from(CSmth{7 })
        .to(CSmth{9}).during(300.0f)
        .via(tweeny::easing::stepped);
    t.step(0.1f);

Method to wait at a point

It would be nice to have a method to wait at a specific point.

For example, right now I do:

auto t = tweeny::from(130).to(130).during(300).to(80).during(400);

But it would be better if I could do:

auto t = tweeny::from(130).wait(300).to(80).during(400);

Current Direction is ignored on 2 of 3 step functions

tweent.tcc

Only the first function:
inline const typename detail::tweentraits<T, Ts...>::valuesType & tween<T, Ts...>::step(int32_t dt, bool suppress) {
return step(static_cast(dt * currentDirection)/static_cast(total), suppress);
}

uses currentDirection. The other 2 step functions not

jump(0) bug ?

321

auto tween123 = tweeny::from(0)
	.to(100).during(100)
	.to(200).during(100);
{
	tween123.jump(0);
	auto value11 = tween123.peek();
	auto point11 = tween123.point();
	int kk;
	kk = 100;
}

/////////
value11= 100 is bug?

Missing cstdint when compiling with gcc13

Thanks for such a great project.

A few days ago MSYS2's gcc upgrade to version 13. and my project failed in ci:

[ 37%] Building CXX object library/borealis/library/CMakeFiles/borealis.dir/lib/core/animation.cpp.obj
[668](https://github.com/xfangfang/wiliwili/actions/runs/4912551410/jobs/8788576312#step:5:669)
In file included from D:/a/wiliwili/wiliwili/library/borealis/library/lib/extern/tweeny/include/tween.h:38,
[669](https://github.com/xfangfang/wiliwili/actions/runs/4912551410/jobs/8788576312#step:5:670)
                 from D:/a/wiliwili/wiliwili/library/borealis/library/lib/extern/tweeny/include/tweeny.h:83,
[670](https://github.com/xfangfang/wiliwili/actions/runs/4912551410/jobs/8788576312#step:5:671)
                 from D:/a/wiliwili/wiliwili/library/borealis/library/include/borealis/core/animation.hpp:19,
[671](https://github.com/xfangfang/wiliwili/actions/runs/4912551410/jobs/8788576312#step:5:672)
                 from D:\a\wiliwili\wiliwili\library\borealis\library\lib\core\animation.cpp:17:
[672](https://github.com/xfangfang/wiliwili/actions/runs/4912551410/jobs/8788576312#step:5:673)
D:/a/wiliwili/wiliwili/library/borealis/library/lib/extern/tweeny/include/tweentraits.h:69:32: error: 'uint16_t' was not declared in this scope
69 |             typedef std::array<uint16_t, sizeof...(Ts)> durationsArrayType;
   |                                ^~~~~~~~
[675](https://github.com/xfangfang/wiliwili/actions/runs/4912551410/jobs/8788576312#step:5:676)
D:/a/wiliwili/wiliwili/library/borealis/library/lib/extern/tweeny/include/tweentraits.h:1:1: note: 'uint16_t' is defined in header '<cstdint>'; did you forget to '#include <cstdint>'?

It seems that we need to manually include cstdint in gcc13. Here is my small patch: xfangfang@5bcfb4d

Alternatively, users may need to manually include cstdint before using tween.h

Related issue: microsoft/vcpkg#31270 (comment)

Question: Set time duration

Hi, first of all, nice work.
Is there any function (or maybe u can add it) to set a tween time duration?
i.e: tween.from(0).to(100).time(10)
if there is, I cannot found it, the only similar "thing" is the duration, but I dont really understand this function name, because it is logic that this define the number (maybe) frames (OR THE STEPS) that the tween needs to end, in my opinion OF COURSE :D
EDIT:
I see the comment in the during function, but I cannot understand how, for example, make a 2 seconds of tween with a simple float
tweeny::from(0.f).to(700.f).during(600000000000)
during parameter ignore the value, if I set another biggest value, it does not care xD
can you explain me that please?

Weird behaviour with multi-valued, multi-point tweens.

Hi,

First, thank you for providing such a great library.

With multi-valued and multi-point tweens, I cannot get the correct results. For example, for this small piece of code:

auto tween = tweeny::from(0.5f, 1.f)
        .to(0.f, 1.f).during(10)
        .to(0.f, 0.f).during(10);

for (auto i = 0; i < 20; ++i)
{
    auto p = tween.step(1);
    std::cout << p[0] << " " << p[1] << "\n";
}

the output is:

0.475 1
0.45 1
0.425 1
0.4 1
0.375 1
0.35 1
0.325 1
0.3 1
0.275 1
0.25 1
0 0.45
0 0.4
0 0.35
0 0.3
0 0.25
0 0.2
0 0.15
0 0.0999998
0 0.0499998
0 0

But I think the output should be:

0.45 1
0.4 1
0.35 1
0.3 1
0.25 1
0.2 1
0.15 1
0.1 1
0.05 1
0 1
0 0.9
0 0.8
0 0.7
0 0.6
0 0.5
0 0.4
0 0.3
0 0.2
0 0.1
0 0

Maybe I'm missing a point but I cannot get the correct results.

Thanks

Coroutine support

hi, Coroutine is powerful and convenient feature for animation scene. just like

await tweeny::from(130).to(130).during(300);

is there a plan to implement coroutine version?

warning C4127: conditional expression is constant

Compiling this with MSVC 16 on C++20 and tweening a glm::vec3 I get the following warning:

[build] [...]\lib\tweeny\include\easingresolve.h(44,35): warning C4127: conditional expression is constant [[...]\build\opengl-tests.vcxproj]
[build] [...]\lib\tweeny\include\easingresolve.h(43,1): message : consider using 'if constexpr' statement instead [[...]\build\opengl-tests.vcxproj]
[build] [...]\lib\tweeny\include\easingresolve.h(43): message : while compiling class template member function 'void tweeny::detail::easingresolve<1,TypeTuple,FunctionTuple>::impl(FunctionTuple &)' [[...]\build\opengl-tests.vcxproj]
[build]           with
[build]           [
[build]               TypeTuple=std::array<glm::vec<3,float,glm::packed_highp>,1>,
[build]               FunctionTuple=std::tuple<std::function<glm::vec3 (float,glm::vec3,glm::vec3)>>
[build]           ]
...

Adding the constexpr removes the warning but you should know more.

different durations problem

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

Error

before #include "tweeny.h", <string> and <stdint.h> must be included first

//without these two, tweeny.h errors
#include <stdint.h>
#include <string>

#include "tweeny.h"

Also, if i do this auto test = tweeny::from(1.0f).to(0.0f).during(10);, can you tell me what's the equivalent of auto? i dont want to use auto

Thank you

fail to build

  /home/xyh/play/cpp/tweeny (master)
rm -rf build/ ; mkdir build/ ; cd build ; cmake .. ; make
removed 'build/CMakeFiles/CMakeOutput.log'
removed 'build/CMakeFiles/cmake.check_cache'
removed 'build/CMakeFiles/feature_tests.cxx'
removed 'build/CMakeFiles/3.11.4/CMakeSystem.cmake'
removed directory 'build/CMakeFiles/3.11.4/CompilerIdC/tmp'
removed 'build/CMakeFiles/3.11.4/CompilerIdC/CMakeCCompilerId.c'
removed 'build/CMakeFiles/3.11.4/CompilerIdC/a.out'
removed directory 'build/CMakeFiles/3.11.4/CompilerIdC'
removed 'build/CMakeFiles/3.11.4/CMakeCXXCompiler.cmake'
removed 'build/CMakeFiles/3.11.4/CMakeDetermineCompilerABI_C.bin'
removed directory 'build/CMakeFiles/3.11.4/CompilerIdCXX/tmp'
removed 'build/CMakeFiles/3.11.4/CompilerIdCXX/CMakeCXXCompilerId.cpp'
removed 'build/CMakeFiles/3.11.4/CompilerIdCXX/a.out'
removed directory 'build/CMakeFiles/3.11.4/CompilerIdCXX'
removed 'build/CMakeFiles/3.11.4/CMakeCCompiler.cmake'
removed 'build/CMakeFiles/3.11.4/CMakeDetermineCompilerABI_CXX.bin'
removed directory 'build/CMakeFiles/3.11.4'
removed 'build/CMakeFiles/feature_tests.bin'
removed directory 'build/CMakeFiles/CMakeTmp'
removed 'build/CMakeFiles/feature_tests.c'
removed directory 'build/CMakeFiles'
removed 'build/CPackConfig.cmake'
removed 'build/TweenyConfigVersion.cmake'
removed directory 'build/examples/CMakeFiles'
removed directory 'build/examples'
removed 'build/CMakeDoxygenDefaults.cmake'
removed 'build/CMakeDoxyfile.in'
removed directory 'build/doc/CMakeFiles'
removed 'build/doc/customdoxygen.css'
removed 'build/doc/doxy-boot.js'
removed 'build/doc/README.md'
removed 'build/doc/MANUAL.dox'
removed 'build/doc/header.html'
removed 'build/doc/Doxyfile'
removed 'build/doc/DoxygenLayout.xml'
removed 'build/doc/footer.html'
removed directory 'build/doc'
removed 'build/CPackSourceConfig.cmake'
removed 'build/CMakeCache.txt'
removed directory 'build/'
-- The C compiler identification is GNU 8.1.1
-- The CXX compiler identification is GNU 8.1.1
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at examples/CMakeLists.txt:62 (string):
  string sub-command STRIP requires two arguments.


-- Found Doxygen: /usr/bin/doxygen (found version "1.8.14") found components:  doxygen dot
-- Configuring incomplete, errors occurred!
See also "/home/xyh/play/cpp/tweeny/build/CMakeFiles/CMakeOutput.log".
make: *** No targets specified and no makefile found.  Stop.

Any ideas how to use it without STL ?

Hi !

Probably the most popular question , yet i'm unable to find answer looking through the code.
There're lots of containers in use, is it possible to make them optional ?

multiple enumeration support

I would like to set everything via enumeration, but alas it can only be done with the first parameter.

auto tween = tweeny::from(0.f, 0.f).to(1.f, 1.f).during(5000).via(tweeny::easing::enumerated::backIn, tweeny::easing::enumerated::bounceIn);

I get an error

tweeny.h(1016,23): error C2679: binary '=': no operator found which takes a right-hand operand of type 'F1' (or there is no acceptable conversion)
1>        with
1>        [
1>            F1=tweeny::easing::enumerated
1>        ]

Conflicting type when using jump function

When trying to compile a simple hello world using the jump function, I'm getting "4. Candidate template ignored: deduced conflicting types for parameter 'T' ('int' vs. 'unsigned long')":

*: error: no matching function for call to 'clip'
        p = detail::clip(p, 0, points.size() -1);
            ^~~~~~~~~~~~
*: note: in instantiation of member function 'tweeny::tween<number, number, number, number, number, number>::jump' requested here
        tween.jump(0, true);
              ^
In file included from *:
In file included from *:
*/tweeny.h:1806:11: note: candidate template ignored: deduced conflicting types for parameter 'T' ('int' vs. 'unsigned long')
        T clip(const T & n, const T & lower, const T & upper) {
          ^

I'm using the stable single header file, all local paths have been replaced with *.
Wondering if this might be due to vector.size() returning size_t that in some systems it might alias to different types.

Using a mac and Xcode

Crash with illegal instruction

When trying to copy a tweeny::tween via assignment, program crashes with
Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)

Code to reproduce:

tweeny::tween<double> anim1;

auto anim2 = tweeny::from(2).to(5).during(100).via(tweeny::easing::linear)

anim1 = anim2;  //crash here

System information:
macOS 10.15.7
Xcode 11.7
Using C++ 17

Help with duration

Hi, I have the following code:

#define DUR_FADE_IN 1
#define DUR_FADE_OUT 50

tweeny::tween<float> t_sidebar;
tweeny::tween<float> t_si;

bool show_sidebar = false;

void SidebarHandler::init(Sidebar* sidebar, SidebarIndicator* sidebar_indicator)
{
	m_sidebar = sidebar;
	m_sidebar_indicator = sidebar_indicator;

	t_sidebar = tweeny::from(m_sidebar->m_alpha).to(1.0f); //starts at 0.0f
	t_si = tweeny::from(m_sidebar_indicator->m_alpha).to(0.0f); //starts at 1.0f
}

void SidebarHandler::update(float dt)
{
	const ImVec2& m_pos = ImGui::GetMousePos();
	const int min = Sidebar_c::pos.x + Sidebar_c::indicator_size.x;
	const int dist = m_pos.x - min;

	if (dist <= 0 || m_sidebar->m_has_opened)
		show_sidebar = true;
	else
		show_sidebar = false;

	if (show_sidebar)
	{
		t_sidebar.during(DUR_FADE_IN);
		t_si.during(DUR_FADE_IN);

		t_sidebar.forward();
		t_si.forward();
	}
	else
	{
		t_sidebar.during(DUR_FADE_OUT);
		t_si.during(DUR_FADE_OUT);

		t_sidebar.backward();
		t_si.backward();
	}

	const float da = t_sidebar.step(dt);
	const float da2 = t_si.step(dt);

	m_sidebar->m_alpha = da;
	m_sidebar_indicator->m_alpha = da2;
}

What the code does is that when the mouse is hovered in the side, the sidebar indicator (instant) should disappear while it shows the sidebar (instant). If unhovered, hide sidebar (should fade out) and show sidebar indicator (should fade in)

But what's happening is when i test the values:

  • Making the DUR_FADE_IN to 1 makes it wait for delay before actually showing for some reason.
  • Making the DUR_FADE_IN to 5 makes it wait for delay (same time as above) but with fading effect.

in other issues (and in the manual) ive observed that the values put in during is higher (around 1000), but in my it takes too long. maybe problem with dt? printing dt seems normal as i get around 0.0166667 and 0.00921989

Instructions on how to run the samples?

I cloned the repro and then ran
cmake .

I get the following output:

➜ tweeny git:(master) cmake .
-- The C compiler identification is AppleClang 8.1.0.8020038
-- The CXX compiler identification is AppleClang 8.1.0.8020038
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at examples/CMakeLists.txt:58 (find_package):
By not providing "FindSDL2.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "SDL2", but
CMake did not find one.

Could not find a package configuration file provided by "SDL2" with any of
the following names:

SDL2Config.cmake
sdl2-config.cmake

Add the installation prefix of "SDL2" to CMAKE_PREFIX_PATH or set
"SDL2_DIR" to a directory containing one of the above files. If "SDL2"
provides a separate development package or SDK, be sure it has been
installed.

-- Configuring incomplete, errors occurred!
See also "/Users/wakka/tmp/tweeny/CMakeFiles/CMakeOutput.log".

Are there some instructions somewhere?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.