FigureAction.java :  » UnTagged » eagle-library » eagle » android » fbx » Android Open Source

Android Open Source » UnTagged » eagle library 
eagle library » eagle » android » fbx » FigureAction.java
/**
 *
 * @author eagle.sakura
 * @version 2010/07/11 : 
 */
package eagle.android.fbx;

import java.io.IOException;

import eagle.io.DataInputStream;
import eagle.util.EagleException;

/**
 * 
 *
 * @author eagle.sakura
 * @version 2010/07/11 : 
 */
public class FigureAction {
    /**
     * 
     */
    private NodeAction[] nodes = null;

    /**
     * 
     */
    private float lastKeyFrame = 0.0f;

    /**
     * 
     */
    private boolean loop = false;

    /**
     *
     * @author eagle.sakura
     * @version 2010/07/11 : 
     */
    private FigureAction() {

    }

    /**
     * 
     *
     * @author eagle.sakura
     * @param index
     * @return
     * @version 2010/07/11 : 
     */
    public NodeAction getNodeAction(int index) {
        return nodes[index];
    }

    /**
     * 
     *
     * @author eagle.sakura
     * @return
     * @version 2010/07/11 : 
     */
    public boolean isLoop() {
        return loop;
    }

    /**
     * 
     *
     * @author eagle.sakura
     * @param loop
     * @version 2010/07/11 : 
     */
    public void setLoop(boolean loop) {
        this.loop = loop;
    }

    /**
     * 
     *
     * @author eagle.sakura
     * @return
     * @version 2010/09/21 : 
     */
    public float getMaxFrame() {
        return lastKeyFrame;
    }

    /**
     *
     * @author eagle.sakura
     * @param frame
     * @return
     * @version 2010/07/11 : 
     */
    public float normalizeFrame(float frame) {
        if (frame <= lastKeyFrame) {
            return frame;
        }

        if (loop) {
            while (frame > lastKeyFrame) {
                frame -= lastKeyFrame;
            }
            return frame;
        } else {
            return lastKeyFrame;
        }
    }

    /**
     *
     * @author eagle.sakura
     * @param dis
     * @return
     * @throws IOException
     * @throws EagleException
     * @version 2010/07/11 : 
     */
    public static FigureAction createInstance(DataInputStream dis) throws IOException, EagleException {
        {
            int version = dis.readS32();
            if (version != 0x1) {
                throw new EagleException(EagleException.eStatusUnknownFileVersion);
            }
        }
        FigureAction result = new FigureAction();

        int nodeNum = dis.readS32();
        result.nodes = new NodeAction[nodeNum];
        for (int i = 0; i < nodeNum; ++i) {
            NodeAction node = new NodeAction(dis);
            result.nodes[node.getNodeNumber()] = node;
        }

        result.lastKeyFrame = result.nodes[0].getLastKeyFrame();
        return result;
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.