Subversion Repositories AndroidProjects

Rev

Rev 1775 | 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
                for (int i = 0; i < mRotations.length; i++)
42
                {
43
                        RotationKey key = mRotations[i];
44
 
1776 chris 45
                        if (t >= key.time)
1774 chris 46
                        {
1776 chris 47
                                if (i == (mRotations.length-1))
1775 chris 48
                                {
49
                                        rot.copyFrom(key.rotation);
50
                                        return rot;
51
                                }
1774 chris 52
 
1775 chris 53
                                RotationKey nextKey = mRotations[i+1];
1776 chris 54
                                if (t < (nextKey.time))
1775 chris 55
                                {
56
                                        // TODO: lerp
57
                                        rot.copyFrom(key.rotation);
58
                                        return rot;
59
                                }
1774 chris 60
                        }
61
                }
62
 
63
                return null;
64
        }
65
 
1770 chris 66
        // Getters/Setters==================================================================================
67
 
1773 chris 68
        public final void setRotationKeys(RotationKey[] times) { mRotations = times; }
69
        public final RotationKey[] getRotationKeys() { return mRotations; }
1770 chris 70
 
1774 chris 71
        public final ModelNode getBone() { return mBone; }
72
 
1770 chris 73
}