C 实现通用Tween缓动动画(1)插值公式

Tween缓动动画广泛应用于UI设计,通过特定的缓动算法产生平滑过渡效果。本文聚焦于插值算法公式,介绍如何根据初始值、目标值和时间计算中间状态值。文中封装了Robert Penner's Easing Functions,并对其进行归一化处理,允许在[0, 1]范围内控制变化。此外,插值公式的独立性使得它们不仅适用于Tween,还可应用于骨骼动画和实时计算场景。" 45049671,2234703,Android Activity详解:注册、Menu、Intent切换及生命周期,"['Android开发', 'UI设计', 'Intent', 'Activity管理']
摘要由CSDN通过智能技术生成

    Tween缓动动画在ui中大量的使用,根据缓动算法可以很快的创造出,预定的缓冲运动效果。其核心的概念就是,给出初始值,目标值,时间。然后差值之间每个时间点上的数值变化,从而得到一组运动轨迹。


    我实现的Tween通用结构,主要分为3个部分,每个部分单独一篇文章来解释。


第一, 插值算法公式。根据初始值,目标值,和当前时间,来计算当前属性值。

第二, 定义Tween执行状态的各种属性,队列调用,回调函数等数据结构及算法。

第三,在Tween之上,封装一个快捷调用的使用接口。



首先,插值算法公式有预定义的一套算法Robert Penner's Easing Functions,几乎包含了常用的所有套路。当然,也可以再这个模式之上定义自己的算法公式。这里给出,我封装的代码。

/*
 *
 *
 *  Created on: 2013-11-5
 *      Author: scott.cgi
 */

#ifndef tween_ease_h_
#define tween_ease_h_

typedef enum
{
	tween_ease_linear,

	/* quadratic */
	tween_ease_quad_in,
	tween_ease_quad_out,
	tween_ease_quad_both,

	/* cubic */
	tween_ease_cubic_in,
	tween_ease_cubic_out,
	tween_ease_cubic_both,

	/* quartic */
	tween_ease_quart_in,
	tween_ease_quart_out,
	tween_ease_quart_both,

	/* quintic */
	tween_ease_quint_in,
	tween_ease_quint_out,
	tween_ease_quint_both,

	/* sine */
	tween_ease_sine_in,
	tween_ease_sine_out,
	tween_ease_sine_both,

	/* exponential */
	tween_ease_expo_in,
	tween_ease_expo_out,
	tween_ease_expo_both,

	/* circular */
	tween_ease_circ_in,
	tween_ease_circ_out,
	tween_ease_circ_both,

	/* elastic */
	tween_ease_elastic_in,
	tween_ease_elastic_out,
	tween_ease_elastic_both,

	/* back */
	tween_ease_back_in,
	tween_ease_back_out,
	tween_ease_back_both,

	/* bounce */
	tween_ease_bounce_in,
	tween_ease_bounce_out,
	tween_ease_bounce_both,

	tween_ease_type_length,
}
TweenEaseType;


typedef struct
{
	/**
	 * Ease interpolation algorithm function
	 * value between [from, to] control by time between [0.0f, 1.0f]
	 */
	float (*interpolates[tween_ease_type_length])(float from, float to, float time);
}
_ATweenEase_;

extern _ATweenEase_ ATweenEase[1];

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值