美文网首页
抛物线采样

抛物线采样

作者: jojo911 | 来源:发表于2019-08-07 17:42 被阅读0次
    Vector3 SampleParabola(Vector3 start, Vector3 end, float height, float t)
        {
            if (Mathf.Abs(start.y - end.y) < 0.1f)
            {
                Vector3 travelDirection = end - start;
                Vector3 result = start + t * travelDirection;
                result.y += Mathf.Sin(t * Mathf.PI) * height;
                return result;
            }
            else
            {
                Vector3 travelDirection = end - start;
                Vector3 levelDirecteion = end - new Vector3(start.x, end.y, start.z);
                Vector3 right = Vector3.Cross(travelDirection, levelDirecteion);
                Vector3 up = Vector3.Cross(right, levelDirecteion);
                if (end.y > start.y) up = -up;
                Vector3 result = start + t * travelDirection;
                result += (Mathf.Sin(t * Mathf.PI) * height) * up.normalized;
                return result;
            }
        }
    

    相关文章

      网友评论

          本文标题:抛物线采样

          本文链接:https://www.haomeiwen.com/subject/hosadctx.html