コード例 #1
0
ファイル: Tween.cpp プロジェクト: NeoPeace/oxygine-framework
	std::string ease2String(Tween::EASE ease)
	{
		#define STRINGIFY(x) #x
		#define S(x) STRINGIFY(x)

		switch (ease)
		{
		case Tween::ease_linear:
			return "linear";

		#define DEF_EASY_FROM_IN(EasyPost) \
		case Tween::ease_in ## EasyPost: \
			return  "in" S(EasyPost);\
		case Tween::ease_out ## EasyPost: \
			return "out" S(EasyPost); \
		case Tween::ease_inOut ## EasyPost: \
			return "inOut" S(EasyPost); \
		case Tween::ease_outIn ## EasyPost: \
			return "outIn" S(EasyPost);

			DEF_EASY_FROM_IN(Quad);
			DEF_EASY_FROM_IN(Cubic);
			DEF_EASY_FROM_IN(Quart);
			DEF_EASY_FROM_IN(Quint);
			DEF_EASY_FROM_IN(Sin);
			DEF_EASY_FROM_IN(Expo);
			DEF_EASY_FROM_IN(Circ);
			DEF_EASY_FROM_IN(Back);
			DEF_EASY_FROM_IN(Bounce);
		}

		return "unknown";
	}
コード例 #2
0
    float Tween::calcEase(EASE ease, float t)
    {
        const float s = 1.70158f;

        switch (ease)
        {
            case ease_linear:
                return t;

			#define DEF_EASY_FROM_IN(EasyPost, formula) \
			case ease_in ## EasyPost: \
				return (formula); \
			case ease_out ## EasyPost: \
				return 1 - calcEase(ease_in ## EasyPost, 1 - t); \
			case ease_inOut ## EasyPost: \
				return t <= 0.5f ? calcEase(ease_in ## EasyPost, t * 2) / 2 : 1 - calcEase(ease_in ## EasyPost, 2 - t * 2) / 2; \
			case ease_outIn ## EasyPost: \
				return t <= 0.5f ? calcEase(ease_in ## EasyPost, t * 2) / 2 : 1 - calcEase(ease_in ## EasyPost, 2 - t * 2) / 2; \

				DEF_EASY_FROM_IN(Quad, t * t);
				DEF_EASY_FROM_IN(Cubic, t * t * t);
				DEF_EASY_FROM_IN(Quart, powf(t, 4));
				DEF_EASY_FROM_IN(Quint, powf(t, 5));
				DEF_EASY_FROM_IN(Sin, 1.0f - scalar::cos(t * (MATH_PI / 2.0f)));
				DEF_EASY_FROM_IN(Expo, powf(2, 10 * (t - 1)));
				DEF_EASY_FROM_IN(Circ, -1.0f * (sqrt(1 - t * t) - 1));
				DEF_EASY_FROM_IN(Back, t * t * ((s + 1) * t - s));
				DEF_EASY_FROM_IN(Bounce, 1 - outBounce(1 - t));

			default:
				t = _customEaseHandler(ease, t);
				//OX_ASSERT(!"unsupported ease");
				break;
		}

		#undef DEF_EASY_FROM_IN

		return t;
	}