内容纲要

(1)//lerp
/inverseLerp:反向插值
/LerpAngle:与Lerp相同但确保值在360度环绕时正确插值。
参数t被钳位到[0,1]范围。变量a并b假定为度数。
/LerpUnclamped没有限制不会被钳制
//MoveTowards/MoveTowardsAngle
//Pingpong
/Repeat:循环值t,使其永远不会大于length并且永远不会小于0。
//SmoothDamp/SmoothDampAngle/SmoothStep
15.噪点函数/不灵噪点有连续性缓慢的
PerlinNoise

上下抖动

public class PerlinNoiseHeight : MonoBehaviour
{
    public float heightScale = 1.0F;
    public float xScale = 1.0F;
    void Update()
    {
        float height = heightScale * Mathf.PerlinNoise(Time.time * xScale, 0.0F);
        Vector3 pos = transform.position;
        pos.y = height;
        transform.position = pos;
    }
}

旋转角度lerp

public class LerpAngle : MonoBehaviour
{
    public float minAngle = 0.0F;
    public float maxAngle = 90.0F;
    void Update()
    {
        float angle = Mathf.LerpAngle(minAngle, maxAngle, Time.time);
        transform.eulerAngles = new Vector3(0, angle, 0);
    }
}

噪点函数

 void Start()
    {
        rend = GetComponent<Renderer>();
        noiseTex = new Texture2D(pixWidth, pixHeight);
        pix = new Color[noiseTex.width * noiseTex.height];
        rend.material.mainTexture = noiseTex;
    }
    void CalcNoise()
    {
        float y = 0.0F;
        while (y < noiseTex.height)
        {
            float x = 0.0F;
            while (x < noiseTex.width)
            {
                float xCoord = xOrg + x / noiseTex.width * scale;
                float yCoord = yOrg + y / noiseTex.height * scale;
                float sample = Mathf.PerlinNoise(xCoord, yCoord);
                int idx = (int)(y * noiseTex.width + x);
                pix[idx] = new Color(sample, sample, sample);
                x++;
            }
            y++;
        }
        noiseTex.SetPixels(pix);
        noiseTex.Apply();
    }
    void Update()
    {
        CalcNoise();
    }
}

1 对 “UAPI,噪点函数,上下抖动,lerp”的想法;

  1. Pingback: viagra

发表评论