mehdiacode / cpptweener Goto Github PK
View Code? Open in Web Editor NEWAutomatically exported from code.google.com/p/cpptweener
Automatically exported from code.google.com/p/cpptweener
For every equation (Sine,Expo,Quint..) we have defined:
- easeIn
- easeOut
- easeInOut
Based on my template usage suggestion, we could extend the Animation mode:
enum
{
EaseIn,
EaseOut,
EaseInOut,
EaseOutIn
}
Then, assuming we have these variables setup this way:
iFrom = from:
iTo = to;
iDistance = to-from;
and let b=from and c=distance, now we can extend the switch statement this way:
template< class T, int mode >
float ease( float lastFrameTime )
{
...
float ret = iFrom;
switch( mode )
{
case EaseIn:
{
ret = T::easeIn( t, b, c, d );
break;
}
case EaseOut:
{
ret = T::easeOut( t, b, c, d );
break;
}
case EaseIn:
{
ret = T::easeInOut( t, b, c, d );
break;
}
case EaseOutIn:
{
float halfDistance = iDistance / 2.f;
if ( iTimeAccu < iDurationSecs / 2 )
ret = T::easeOut( t * 2, b, halfDistance, d );
else
ret = T::easeIn( ( t * 2 ) - d, b + halfDistance, halfDistance, d );
break;
}
}
return ret;
}
Original issue reported on code.google.com by [email protected]
on 14 Feb 2010 at 4:03
Attachments:
As in the subject, you could achieve no-overhead function calls by exploiting
generics programming.
For example, as you already have, define the Animation mode:
enum
{
EaseIn,
EaseOut,
EaseInOut
}
Then defines the equation solvers as static functions:
...
class Expo
{
public:
static float easeIn( float t, float b, float c, float d );
static float easeOut( float t, float b, float c, float d );
static float easeInOut( float t, float b, float c, float d );
};
Then, define the invoker:
template< class T, int mode >
float ease( float accuFrameTime )
{
...
float ret = iFrom;
switch( mode )
{
case EaseIn:
{
ret = T::easeIn( t, b, c, d );
break;
}
case EaseOut:
{
ret = T::easeOut( t, b, c, d );
break;
}
case EaseIn:
{
ret = T::easeInOut( t, b, c, d );
break;
}
}
return ret;
}
Original issue reported on code.google.com by [email protected]
on 14 Feb 2010 at 3:48
What steps will reproduce the problem?
1. download source
2. open the file "CppTweener.cpp"
3. scroll to row 88
the statement "return -c/2 * (((t-2)*(--t)) - 1) + b;"
is undefined behavior due to using --t and t-2 in the same expression, where
its not guaranteed to happen in left-to-right order.
Original issue reported on code.google.com by [email protected]
on 9 Aug 2012 at 9:05
What steps will reproduce the problem?
1. run the test sample without the compiler automatically initializing
variables for you
What is the expected output? What do you see instead?
You should get animation tweened all the times.
Instead, sometimes, wrong values get interpolated.
What version of the product are you using? On what operating system?
HEAD revision from subversion (r6)
Original issue reported on code.google.com by [email protected]
on 14 Feb 2010 at 3:34
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.