-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathRotationAnimation.cs
More file actions
43 lines (37 loc) · 876 Bytes
/
RotationAnimation.cs
File metadata and controls
43 lines (37 loc) · 876 Bytes
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
40
41
42
using System;
using System.Collections.Generic;
using UnityEngine;
namespace CameraTools
{
public class RotationAnimation
{
Quaternion[] rotations;
float[] times;
public RotationAnimation (Quaternion[] rots, float[] times)
{
this.rotations = rots;
this.times = times;
}
public Quaternion Evaluate(float t)
{
int startIndex = 0;
for(int i = 0; i < times.Length; i++)
{
if(t >= times[i])
{
startIndex = i;
}
else
{
break;
}
}
int nextIndex = Mathf.RoundToInt(Mathf.Min(startIndex + 1, times.Length - 1));
float overTime = t - times[startIndex];
float intervalTime = times[nextIndex] - times[startIndex];
if(intervalTime <= 0) return rotations[nextIndex];
float normTime = overTime/intervalTime;
return Quaternion.Lerp(rotations[startIndex], rotations[nextIndex], normTime);
}
}
}