- 最后登录
- 2014-10-23
- 注册时间
- 2011-7-19
- 阅读权限
- 90
- 积分
- 81303
 
- 纳金币
- -1
- 精华
- 11
|
print(Mahtf.Sin(3));
◆ static function SmoothDamp(current:float,target:float,ref currentVelocity:float,smoothTime:float,maxSpeed:float = Mahtf.Infinity,deltaTime:float =Time.deltaTime):float
描述:逐步的向期望值变化。
这个值就像被一个不会崩溃的弹簧防震器所影响。这个函数可以用来平滑任何类型的值,位置,颜色,标量。最常用于让一个跟随摄像机的速度变的平滑。
current就是当前位置。target是我们希望达到的位置。currentVelocity是当前速度,这个值在你访问这个函数的时候会被随时修改。smoothTime是要到达目标位置的近似时间,实际到达目标时要快一些。maxSpeed可以让你随意的设定最大速度。deltaTime是上次访问该函
数到现在的时间。缺省为Time.deltaTime。
//平滑到目标高度
var target : Transform;
var smoothTime = 0.3;
private var yVelocity = 0.0;
function Update ()
{
var newPosition = Mathf.SmoothDamp(transform.position.y, target.position.y,yVelocity, smoothTime);
transform.position.y = newPosition;
}
◆ Static function SmoothDampAngle(current: float, target: float, ref currentVelocity): float, smoothTime: float, maxSpeed: float=Mathf.Infinity, deltaTime: float=Time.deltaTime): float
描述: 基于Game Programming Gems4章节1.10
随着时间逐渐的改变一个角度为目的的角度。这个值被像弹簧阻尼一样的函数平滑。这个函数可以用来平滑任何一种值,位置,颜色,标量。最常见的是平滑一个跟随摄像机。
current是当前位置。target是我们试图到达的位置。currentVelocity是当前速度,这个值在每次你调用这个函数的时候都被修改。smoothTime是到达目的地近似时间,实际的时间将更短。maxSpeed为允许的最大速度。deltaTime为从上次调用该函数到现在的时间。缺省为Time.deltaTime。
//一个简单的平滑跟随摄像机。
//跟随目标的朝向
var target : Transform;
var smooth = 0.3;
var distance = 5.0;
private var yVelocity = 0.0;
function Update ()
{
//从目前的y角度变换到目标y角度
var yAngle = Mathf.SmoothDampAngle(transform.eulerAngles.y,target.eulerAngles.y, yVelocity, smooth);
//target的位置
var position = target.position;
//然后,新角度之后的距离便宜
position += Quaternion.Euler(0, angle, 0) * Vector3 (0, 0, -distance);
//应用位置
transform.position = position;
//看向目标
transform.LookAt(target);
}
◆ static function SmoothStep (from : float, to : float, t : float) : float
描述:在min与max中插值并在限定处渐入渐出
◆ static function Sqrt (f : float) : float
描述:返回f的平方根
print(Mathf.Sqrt(10));
◆ static function Tan (f : float) : float
描述:返回弧度f的正切值
print(Mathf.Tan(0.5));
Matrix4x4
一个标准的4x4变换矩阵。
一个变换矩阵可以执行任意的线形3D变换(例如,评议,旋转,缩放,切边等等)并且偷师变化使用齐次坐标。脚本中很少使用矩阵:最常用Vector3,Quaternion,而且Transform类的功能更简单。单纯的矩阵用于特殊情况,如设置非标准相机投影。
参考任何图形学教程获取关于变换矩阵的深入揭示。
在Unity中,Matrix4x4被Transform,Camera,Material和GL函数使用。 |
|