Subversion Repositories AndroidProjects

Rev

Rev 1775 | Blame | Compare with Previous | Last modification | View Log | RSS feed

package com.gebauz.bauzoid2.graphics.animation;

import com.gebauz.bauzoid2.graphics.model.ModelNode;
import com.gebauz.bauzoid2.math.Quaternion;

/**
 * Created by cchiu on 20.01.2015.
 */

public class BoneKeyframes
{
        // Constants========================================================================================

        // Embedded Types===================================================================================

        public static class RotationKey
        {
                public float time = 0.0f;
                public Quaternion rotation = null;

                public RotationKey(float t, Quaternion r)
                {
                        time = t; rotation = r;
                }
        }

        // Fields===========================================================================================

        private ModelNode mBone = null;
        private RotationKey[] mRotations = null;

        // Methods==========================================================================================

        public BoneKeyframes(ModelNode bone)
        {
                mBone = bone;
        }

        public Quaternion calcRotationAt(float t)
        {
                Quaternion rot = new Quaternion();
                for (int i = 0; i < mRotations.length; i++)
                {
                        RotationKey key = mRotations[i];

                        if (t >= key.time)
                        {
                                if (i == (mRotations.length-1))
                                {
                                        rot.copyFrom(key.rotation);
                                        return rot;
                                }

                                RotationKey nextKey = mRotations[i+1];
                                if (t < (nextKey.time))
                                {
                                        // TODO: lerp
                                        rot.copyFrom(key.rotation);
                                        return rot;
                                }
                        }
                }

                return null;
        }

        // Getters/Setters==================================================================================

        public final void setRotationKeys(RotationKey[] times) { mRotations = times; }
        public final RotationKey[] getRotationKeys() { return mRotations; }

        public final ModelNode getBone() { return mBone; }

}