ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/OniSplit/Physics/ObjectAnimation.cs
Revision: 1114
Committed: Wed Jan 22 14:08:57 2020 UTC (5 years, 8 months ago) by iritscen
File size: 1271 byte(s)
Log Message:
Adding OniSplit source code (v0.9.99.0). Many thanks to Neo for all his work over the years.

File Contents

# Content
1 using System;
2 using System.Collections.Generic;
3
4 namespace Oni.Physics
5 {
6 internal class ObjectAnimation
7 {
8 public string Name;
9 public ObjectAnimationFlags Flags;
10 public int Length;
11 public int Stop;
12 public ObjectAnimationKey[] Keys;
13
14 public List<ObjectAnimationKey> Interpolate()
15 {
16 var result = new List<ObjectAnimationKey>(Length);
17
18 for (int i = 1; i < Keys.Length; i++)
19 {
20 var key0 = Keys[i - 1];
21 var key1 = Keys[i];
22
23 result.Add(key0);
24
25 for (int j = key0.Time + 1; j < key1.Time; j++)
26 {
27 float k = (float)(j - key0.Time) / (key1.Time - key0.Time);
28
29 result.Add(new ObjectAnimationKey {
30 Time = j,
31 Translation = Vector3.Lerp(key0.Translation, key1.Translation, k),
32 Rotation = Quaternion.Lerp(key0.Rotation, key1.Rotation, k),
33 Scale = Vector3.Lerp(key0.Scale, key1.Scale, k)
34 });
35 }
36 }
37
38 result.Add(Keys.Last());
39
40 return result;
41 }
42 }
43 }