
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace WindowsGame1
{
    class curvemove
    {
        Curve curveX = new Curve();
        Curve curveY = new Curve();
        Curve curveZ = new Curve();

        // CurveLoopType.Constant  停在第一個點 或 最後的點
        // CurveLoopType.Cycle     回到第一個點
        // CurveLoopType.CycleOffset  回到第一個點 並且要扣除差額
        // CurveLoopType.Linear     以線性方式沿線推估
        // CurveLoopType.Oscillate  往回走
        public curvemove(CurveLoopType curveLoopType)
        {
            curveX.PostLoop = curveLoopType;
            curveY.PostLoop = curveLoopType;
            curveZ.PostLoop = curveLoopType;

            curveX.PreLoop = curveLoopType;
            curveY.PreLoop = curveLoopType;
            curveZ.PreLoop = curveLoopType;
        }

        // CurveTangent.Flat
        // CurveTangent.Linear
        // CurveTangent.Smooth
        public void SetTangents(CurveTangent curveTangent)
        {
            curveX.ComputeTangents(curveTangent);
            curveY.ComputeTangents(curveTangent);
            curveZ.ComputeTangents(curveTangent);
        }

        public void AddPoint(Vector3 point, float time)
        {
            curveX.Keys.Add(new CurveKey(time, point.X));
            curveY.Keys.Add(new CurveKey(time, point.Y));
            curveZ.Keys.Add(new CurveKey(time, point.Z));
        }
        public Vector3 GetPointOnCurve(float time)
        {
            Vector3 point = new Vector3();
            point.X = curveX.Evaluate(time);
            point.Y = curveY.Evaluate(time);
            point.Z = curveZ.Evaluate(time);
            return point;
        }
    }
}