나중에 정리
Bezier_Curve
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System.Collections;
using System.Collections.Generic;
using System.Security.Cryptography;
using UnityEngine;
public class BezierCurve : MonoBehaviour
{
LineRenderer lr;
public Transform a, b, c;
public int pointCount = 100;
private void Start()
{
lr = GetComponent<LineRenderer>();
lr.positionCount = 3;
lr.SetPosition(0, a.position);
lr.SetPosition(1, b.position);
lr.SetPosition(2, c.position);
}
private void Update()
{
lr.positionCount = pointCount;
for (int i = 0; i < pointCount; i++)
{
float t = (float)i / (pointCount - 1);
lr.SetPosition(i,GetCurvePoint(a.position,b.position,c.position,t));
}
}
// bezier curve 함수.
Vector3 GetCurvePoint(Vector3 a, Vector3 b,Vector3 c,float t)
{
Vector3 ab = Vector3.Lerp(a,b,t);
Vector3 bc = Vector3.Lerp(b,c,t);
return Vector3.Lerp(ab,bc,t);
}
}