• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
  • entries
    114
  • comments
    273
  • views
    596673

Easing along, one step at a time

Sign in to follow this  
Followers 0
Servant of the Lord

2853 views

I just finished adding some of the standard Ease equations to my code base for use in Of Stranger Flames.
In discussion about the equations, it was requested for me to share the code here. This is not a tutorial, I don't have enough familiarity with the subject (or with math in general) to explain how every equation works. I'm just posting what I added to my own code, so others can use it if they want to.

The equations are mostly from Robert Penner's eases, which are under the BSD license. His code seems to be the ones that are used by most software, such as the jQuery, Flash, and other libraries.

Most Ease equations have the function signature:void equation(currentTime, start, distance, totalTime);
I personally like having my eases in start at 0.0, end at 1.0, and have a 'duration' of 1.0, and then I scale the input and output as desired, instead of having the equation scale it. It just makes it easier for me to understand.

That said, all my functions have the format:void equation(position);
...with 'position' being from 0.0 to 1.0.

Because Eases come in various forms (You can ease IN, OUT, IN and OUT, or OUT and IN), I made sure all the ease equations were in EaseIn form, and I created a few functions to convert the input and output to the other forms as desired.

Here's the conversion code:
http://ideone.com/6rc0Zk ([size=2]Posted as links, because all my code kept getting unformatted when hitting 'publish')

EaseFunction is: "typedef std::function EaseFunction;", which nicely permits the use of things like lambdas and functors as well as the regular ease functions. If you don't have C++11, you can just typedef it as: "typedef float(*EaseFunction)(float);" or whatever the correct C-style function-pointer syntax is.

Some of the ease equations have a few extra parameters, like ElasticEase and BackEase, so I provided some C++11 templates to convert the functions to std::functions that meet the function signature shared by the other functions. It's just a wrapper around std::bind for convenience. (I'm big on convenience! wink.png)
http://ideone.com/LPEvC6

You don't have to use C++11 to use the equations! Just the helper functions above.

I also use this function for scaling the output:
http://ideone.com/fhYHJT

Actually, mine looks like this:
http://ideone.com/hucHWu
...but that depends on a 'FloatRange' helper class I made, whereas the previous one has no dependencies.

I actually made two ScaledEase overloads, one for my Point class, and one for my Color class. I haven't tested those out yet. smile.png

I also made a Easer class, that handles most of everything inside of it. This is more for when you want persistent ease data wrapped nicely, and this class would be a member-variable of another class.

Easer.h
Easer.cpp

That also uses FloatRange, but can be easily adjusted to just use 'float begin' and 'float end' instead.

The Ease Equations


And here are a few additional ones I keep inline

The next page has graphs generated to test/demonstrate the output.

[page]

Cubic Ease In

cubiceaseeasein.png

Cubic Ease InOut

cubiceaseeaseinout.png

Cubic Ease Out

cubiceaseeaseout.png

Cubic Ease OutIn

cubiceaseeaseoutin.png

Elastic Ease In

elasticeaseeasein.png

Elastic Ease InOut

elasticeaseeaseinout.png

Elastic Ease Out

elasticeaseeaseout.png

Elastic Ease OutIn

elasticeaseeaseoutin.png

Exponential Ease In

exponentialeaseeasein.png

Exponential Ease InOut

exponentialeaseeaseinou.png

Exponential Ease Out

exponentialeaseeaseout.png

Exponential Ease OutIn

exponentialeaseeaseouti.png

Linear Ease In / InOut / Out / OutIn

lineareaseeasein.png

Power Ease In
powereaseeasein.png

Power Ease InOut

powereaseeaseinout.png

Power Ease Out

powereaseeaseout.png

Power Ease OutIn

powereaseeaseoutin.png

Quadratic Ease In

quadraticeaseeasein.png

Quadratic Ease InOut

quadraticeaseeaseinout.png

Quadratic Ease Out

quadraticeaseeaseout.png

Quadratic Ease OutIn

quadraticeaseeaseoutin.png

Quartic Ease In

quarticeaseeasein.png

Quartic Ease InOut

quarticeaseeaseinout.png

Quartic Ease Out

quarticeaseeaseout.png

Quartic Ease OutIn

quarticeaseeaseoutin.png

Quintic Ease In

quinticeaseeasein.png

Quintic Ease InOut

quinticeaseeaseinout.png

Quintic Ease Out

quinticeaseeaseout.png

Quintic Ease OutIn

quinticeaseeaseoutin.png

Sine Ease In

sineeaseeasein.png

Sine Ease InOut

sineeaseeaseinout.png

Sine Ease Out

sineeaseeaseout.png

Sine Ease OutIn

sineeaseeaseoutin.png

SmoothStep In

smoothstepeasein.png

SmoothStep InOut

smoothstepeaseinout.png

SmoothStep Out

smoothstepeaseout.png

SmoothStep OutIn

smoothstepeaseoutin.png

WeightedAverage In

weightedaverageeasein.png

WeightedAverage InOut

weightedaverageeaseinou.png

WeightedAverage Out

weightedaverageeaseout.png

WeightedAverage OutIn

weightedaverageeaseouti.png

BackEase In

backeaseeasein.png

BackEase InOut

backeaseeaseinout.png

BackEase Out

backeaseeaseout.png

BackEase OutIn

backeaseeaseoutin.png

BounceEase In

bounceeaseeaseing.png

BounceEase InOut

bounceeaseeaseinout.png

BounceEase Out

bounceeaseeaseout.png

BounceEase OutIn

bounceeaseeaseoutin.png

CircleEase In

circleeaseeasein.png

CircleEase InOut

circleeaseeaseinout.png

CircleEase Out

circleeaseeaseout.png

CircleEase OutIn

circleeaseeaseoutin.png

[page]

BounceEase was annoying me alot. I was trying to figure out how it worked, but I'm not very good with math and algorithm-thinking.

The original code looked like this:
http://ideone.com/14kyLm

And trying to figure out all the magic numbers, I eventually broke it down to this:
http://ideone.com/wGCTU9

I never figured out how the '7.5625f' value was calculated, but the others are resolved. laugh.png

Unfortunately, changing the value of 'bounciness' or 'bounces' produces poor results (probably from the constant!), so I didn't bother including the code with the rest of the equations.
custombounceeaseeasein.png


Links that were useful in understanding and converting the equations:
http://www.robertpenner.com/easing/ (The guy who made most of these now-common equations)

http://sol.gfxile.net/interpolation/index.html (also has good descriptions and explanations)
http://hosted.zeh.com.br/tweener/docs/en-us/misc/transitions.html
http://msdn.microsoft.com/en-us/library/ee308751.aspx

Some nice graphs:
http://easings.net/

2
Sign in to follow this  
Followers 0


2 Comments


I prefer to make the the whole thing template based - so I can interpolate floats, ints, doubles, vectors as well as quaternions (anything that has the + and  * operator overloaded :D And yeah, interpolators are awesome :) here's my code : http://ideone.com/RTEmf5

1

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now