Subversion Repositories AndroidProjects

Rev

Rev 1774 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1770 chris 1
package com.gebauz.bauzoid2.graphics.animation;
2
 
3
import com.gebauz.bauzoid2.graphics.model.ModelNode;
4
import com.gebauz.bauzoid2.math.Quaternion;
5
 
6
/**
7
 * Created by cchiu on 20.01.2015.
8
 */
9
public class BoneKeyframes
10
{
11
        // Constants========================================================================================
12
 
13
        // Embedded Types===================================================================================
14
 
1773 chris 15
        public static class RotationKey
16
        {
17
                public float time = 0.0f;
18
                public Quaternion rotation = null;
19
 
20
                public RotationKey(float t, Quaternion r)
21
                {
22
                        time = t; rotation = r;
23
                }
24
        }
25
 
1770 chris 26
        // Fields===========================================================================================
27
 
28
        private ModelNode mBone = null;
1773 chris 29
        private RotationKey[] mRotations = null;
1770 chris 30
 
31
        // Methods==========================================================================================
32
 
1774 chris 33
        public BoneKeyframes(ModelNode bone)
34
        {
35
                mBone = bone;
36
        }
37
 
38
        public Quaternion calcRotationAt(float t)
39
        {
1775 chris 40
                Quaternion rot = new Quaternion();
1774 chris 41
                float total = 0.0f;
42
                for (int i = 0; i < mRotations.length; i++)
43
                {
44
                        RotationKey key = mRotations[i];
45
                        total += key.time;
46
 
47
                        if (t >= total)
48
                        {
1775 chris 49
                                if (i == mRotations.length)
50
                                {
51
                                        rot.copyFrom(key.rotation);
52
                                        return rot;
53
                                }
1774 chris 54
 
1775 chris 55
                                RotationKey nextKey = mRotations[i+1];
1774 chris 56
                                if (t < (total + nextKey.time))
1775 chris 57
                                {
58
                                        // TODO: lerp
59
                                        rot.copyFrom(key.rotation);
60
                                        return rot;
61
                                }
1774 chris 62
                        }
63
                }
64
 
65
                return null;
66
        }
67
 
1770 chris 68
        // Getters/Setters==================================================================================
69
 
1773 chris 70
        public final void setRotationKeys(RotationKey[] times) { mRotations = times; }
71
        public final RotationKey[] getRotationKeys() { return mRotations; }
1770 chris 72
 
1774 chris 73
        public final ModelNode getBone() { return mBone; }
74
 
1770 chris 75
}